Class OObjectDatabaseTx

All Implemented Interfaces:
ODatabaseObject, ODatabase<Object>, ODatabaseInternal<Object>, OUserObject2RecordHandler, OBackupable, Closeable, AutoCloseable

public class OObjectDatabaseTx extends ODatabaseWrapperAbstract<ODatabaseDocumentInternal,Object> implements ODatabaseObject
Object Database instance. It's a wrapper to the class ODatabaseDocumentTx that handles conversion between ODocument instances and POJOs using javassist APIs.
Author:
Luca Molino
  • Field Details

    • TYPE

      public static final String TYPE
      See Also:
    • dictionary

      protected ODictionary<Object> dictionary
    • entityManager

      protected OEntityManager entityManager
    • saveOnlyDirty

      protected boolean saveOnlyDirty
    • lazyLoading

      protected boolean lazyLoading
    • automaticSchemaGeneration

      protected boolean automaticSchemaGeneration
    • metadata

      protected OMetadataObject metadata
  • Constructor Details

    • OObjectDatabaseTx

      public OObjectDatabaseTx(ODatabaseDocumentInternal iDatabase)
      Constructor to wrap an existing database connect for object connections
      Parameters:
      iDatabase - an open database connection
  • Method Details

    • newInstance

      public <T> T newInstance(Class<T> iType)
      Description copied from interface: ODatabaseObject
      Creates a new entity of the specified class.
      Specified by:
      newInstance in interface ODatabaseObject
      Parameters:
      iType - Class name where to originate the instance
      Returns:
      New instance
    • newInstance

      public <T> T newInstance(Class<T> iType, Object... iArgs)
      Specified by:
      newInstance in interface ODatabaseObject
    • newInstance

      public <RET> RET newInstance(String iClassName)
      Description copied from interface: ODatabaseObject
      Creates a new entity instance. Each database implementation will return the right type.
      Specified by:
      newInstance in interface ODatabaseObject
      Returns:
      The new instance.
    • getUser

      public OSecurityUser getUser()
      Description copied from interface: ODatabase
      Returns the current user logged into the database.
      Specified by:
      getUser in interface ODatabase<Object>
      See Also:
    • setUser

      public void setUser(OSecurityUser user)
      Description copied from interface: ODatabaseInternal
      Set user for current database instance.
      Specified by:
      setUser in interface ODatabaseInternal<Object>
    • getMetadata

      public OMetadataObject getMetadata()
      Description copied from interface: ODatabase
      Return the OMetadata instance. Cannot be null.
      Specified by:
      getMetadata in interface ODatabase<Object>
      Specified by:
      getMetadata in interface ODatabaseObject
      Returns:
      The OMetadata instance.
    • setInternal

      public void setInternal(ODatabase.ATTRIBUTES attribute, Object iValue)
      Description copied from interface: ODatabaseInternal
      Internal method. Don't call it directly unless you're building an internal component.
      Specified by:
      setInternal in interface ODatabaseInternal<Object>
    • getListeners

      public Iterable<ODatabaseListener> getListeners()
      Description copied from interface: ODatabase
      Retrieves all the registered listeners.
      Specified by:
      getListeners in interface ODatabase<Object>
      Returns:
      An iterable of ODatabaseListener instances.
    • registerHook

      public <DBTYPE extends ODatabase<?>> DBTYPE registerHook(ORecordHook iHookImpl)
      Description copied from interface: ODatabase
      Registers a hook to listen all events for Records.
      Specified by:
      registerHook in interface ODatabase<Object>
      Parameters:
      iHookImpl - ORecordHook implementation
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • registerHook

      public <DBTYPE extends ODatabase<?>> DBTYPE registerHook(ORecordHook iHookImpl, ORecordHook.HOOK_POSITION iPosition)
      Specified by:
      registerHook in interface ODatabase<Object>
    • callbackHooks

      public ORecordHook.RESULT callbackHooks(ORecordHook.TYPE iType, OIdentifiable iObject)
    • getHooks

      Description copied from interface: ODatabase
      Retrieves all the registered hooks.
      Specified by:
      getHooks in interface ODatabase<Object>
      Returns:
      A not-null unmodifiable map of ORecordHook and position instances. If there are no hooks registered, the Map is empty.
    • unregisterHook

      public <DBTYPE extends ODatabase<?>> DBTYPE unregisterHook(ORecordHook iHookImpl)
      Description copied from interface: ODatabase
      Unregisters a previously registered hook.
      Specified by:
      unregisterHook in interface ODatabase<Object>
      Parameters:
      iHookImpl - ORecordHook implementation
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain. deprecated since 2.2
    • newInstance

      public <RET> RET newInstance(String iClassName, Object iEnclosingClass, Object... iArgs)
      Create a new POJO by its class name. Assure to have called the registerEntityClasses() declaring the packages that are part of entity classes.
      See Also:
    • newInstance

      public <RET> RET newInstance(String iClassName, Object iEnclosingClass, ODocument iDocument, Object... iArgs)
      Create a new POJO by its class name. Assure to have called the registerEntityClasses() declaring the packages that are part of entity classes.
      See Also:
    • browseClass

      public <RET> OObjectIteratorClass<RET> browseClass(Class<RET> iClusterClass)
      Description copied from interface: ODatabaseObject
      Browses all the records of the specified class.
      Specified by:
      browseClass in interface ODatabaseObject
      Parameters:
      iClusterClass - Class name to iterate
      Returns:
      Iterator of Object instances
    • browseClass

      public <RET> OObjectIteratorClass<RET> browseClass(Class<RET> iClusterClass, boolean iPolymorphic)
    • browseClass

      public <RET> OObjectIteratorClass<RET> browseClass(String iClassName)
      Specified by:
      browseClass in interface ODatabaseObject
    • browseClass

      public <RET> OObjectIteratorClass<RET> browseClass(String iClassName, boolean iPolymorphic)
      Specified by:
      browseClass in interface ODatabaseObject
    • browseCluster

      public <RET> OObjectIteratorCluster<RET> browseCluster(String iClusterName)
      Description copied from interface: ODatabaseObject
      Browses all the records of the specified cluster.
      Specified by:
      browseCluster in interface ODatabaseObject
      Parameters:
      iClusterName - Cluster name to iterate
      Returns:
      Iterator of Object instances
    • load

      public <RET> RET load(Object iPojo)
      Description copied from interface: ODatabase
      Loads the entity and return it.
      Specified by:
      load in interface ODatabase<Object>
      Parameters:
      iPojo - The entity to load. If the entity was already loaded it will be reloaded and all the changes will be lost.
      Returns:
    • reload

      public <RET> RET reload(Object iPojo)
      Specified by:
      reload in interface ODatabaseObject
    • reload

      public <RET> RET reload(Object iPojo, boolean iIgnoreCache)
      Specified by:
      reload in interface ODatabaseObject
    • reload

      public <RET> RET reload(Object iPojo, String iFetchPlan, boolean iIgnoreCache)
      Description copied from interface: ODatabase
      Force the reloading of the entity.
      Specified by:
      reload in interface ODatabase<Object>
      Specified by:
      reload in interface ODatabaseObject
      Parameters:
      iPojo - The entity to load. If the entity was already loaded it will be reloaded and all the changes will be lost.
      iFetchPlan - Fetch plan used
      iIgnoreCache - Ignore cache or use it
      Returns:
      The loaded entity
    • reload

      public <RET> RET reload(Object iObject, String iFetchPlan, boolean iIgnoreCache, boolean force)
      Description copied from interface: ODatabase
      Force the reloading of the entity.
      Specified by:
      reload in interface ODatabase<Object>
      Specified by:
      reload in interface ODatabaseObject
      Parameters:
      iObject - The entity to load. If the entity was already loaded it will be reloaded and all the changes will be lost.
      iFetchPlan - Fetch plan used
      iIgnoreCache - Ignore cache or use it
      force - Force to reload record even if storage has the same record as reloaded record, it is useful if fetch plan is not null and alongside with root record linked records will be reloaded.
      Returns:
      The loaded entity
    • load

      public <RET> RET load(Object iPojo, String iFetchPlan)
      Description copied from interface: ODatabase
      Loads a record using a fetch plan.
      Specified by:
      load in interface ODatabase<Object>
      Parameters:
      iPojo - Record to load
      iFetchPlan - Fetch plan used
      Returns:
      The record received
    • attach

      public void attach(Object iPojo)
      Specified by:
      attach in interface ODatabaseObject
    • attachAndSave

      public <RET> RET attachAndSave(Object iPojo)
      Specified by:
      attachAndSave in interface ODatabaseObject
    • detach

      public <RET> RET detach(Object iPojo)
      Method that detaches all fields contained in the document to the given object. It returns by default a proxied instance.
      Specified by:
      detach in interface ODatabaseObject
      Parameters:
      iPojo - :- the object to detach
      Returns:
      the detached object
    • detach

      public <RET> RET detach(Object iPojo, boolean returnNonProxiedInstance)
      Method that detaches all fields contained in the document to the given object.
      Specified by:
      detach in interface ODatabaseObject
      Type Parameters:
      RET -
      Parameters:
      iPojo - :- the object to detach
      returnNonProxiedInstance - :- defines if the return object will be a proxied instance or not. If set to TRUE and the object does not contains @Id and @Version fields it could procude data replication
      Returns:
      the object serialized or with detached data
    • detachAll

      public <RET> RET detachAll(Object iPojo, boolean returnNonProxiedInstance)
      Method that detaches all fields contained in the document to the given object and recursively all object tree. This may throw a StackOverflowError with big objects tree. To avoid it set the stack size with -Xss java option
      Specified by:
      detachAll in interface ODatabaseObject
      Type Parameters:
      RET -
      Parameters:
      iPojo - :- the object to detach
      returnNonProxiedInstance - :- defines if the return object will be a proxied instance or not. If set to TRUE and the object does not contains @Id and @Version fields it could procude data replication
      Returns:
      the object serialized or with detached data
    • load

      public <RET> RET load(Object iPojo, String iFetchPlan, boolean iIgnoreCache)
      Description copied from interface: ODatabase
      Loads a record using a fetch plan.
      Specified by:
      load in interface ODatabase<Object>
      Parameters:
      iPojo - Record to load
      iFetchPlan - Fetch plan used
      iIgnoreCache - Ignore cache or use it
      Returns:
      The record received
    • lock

      public <RET> RET lock(ORID recordId) throws OLockException
      Description copied from interface: ODatabase
      Pessimistic lock a record.

      In case of lock inside the transaction the lock will be release by the commit operation, In case of lock outside a transaction unlock need to be call manually.

      Specified by:
      lock in interface ODatabase<Object>
      Parameters:
      recordId - the id of the record that need to be locked
      Returns:
      the record updated to the last state after the lock.
      Throws:
      OLockException - In case of deadlock detected
    • lock

      public <RET> RET lock(ORID recordId, long timeout, TimeUnit timeoutUnit) throws OLockException
      Description copied from interface: ODatabase
      Pessimistic lock a record.
      Specified by:
      lock in interface ODatabase<Object>
      Parameters:
      recordId - the id of the record that need to be locked
      timeout - for the record locking
      timeoutUnit - relative for the timeout
      Returns:
      the record updated to the last state after the lock.
      Throws:
      OLockException - In case of deadlock detected
    • unlock

      public void unlock(ORID recordId) throws OLockException
      Description copied from interface: ODatabase
      Pessimistic unlock
      Specified by:
      unlock in interface ODatabase<Object>
      Parameters:
      recordId - the id of the record to unlock
      Throws:
      OLockException - if the record is not locked.
    • load

      public <RET> RET load(ORID recordId)
      Description copied from interface: ODatabase
      Loads the entity by the Record ID.
      Specified by:
      load in interface ODatabase<Object>
      Parameters:
      recordId - The unique record id of the entity to load.
      Returns:
      The loaded entity
    • load

      public <RET> RET load(ORID iRecordId, String iFetchPlan)
      Description copied from interface: ODatabase
      Loads the entity by the Record ID using a fetch plan.
      Specified by:
      load in interface ODatabase<Object>
      Parameters:
      iRecordId - The unique record id of the entity to load.
      iFetchPlan - Fetch plan used
      Returns:
      The loaded entity
    • load

      public <RET> RET load(ORID iRecordId, String iFetchPlan, boolean iIgnoreCache)
      Description copied from interface: ODatabase
      Loads the entity by the Record ID using a fetch plan and specifying if the cache must be ignored.
      Specified by:
      load in interface ODatabase<Object>
      Parameters:
      iRecordId - The unique record id of the entity to load.
      iFetchPlan - Fetch plan used
      iIgnoreCache - Ignore cache or use it
      Returns:
      The loaded entity
    • save

      public <RET> RET save(Object iContent)
      Saves an object to the databasein synchronous mode . First checks if the object is new or not. In case it's new a new ODocument is created and bound to the object, otherwise the ODocument is retrieved and updated. The object is introspected using the Java Reflection to extract the field values.
      If a multi value (array, collection or map of objects) is passed, then each single object is stored separately.
      Specified by:
      save in interface ODatabase<Object>
      Parameters:
      iContent - The entity to save
      Returns:
      The saved entity.
    • save

      public <RET> RET save(Object iPojo, String iClusterName)
      Saves an object in synchronous mode to the database forcing a record cluster where to store it. First checks if the object is new or not. In case it's new a new ODocument is created and bound to the object, otherwise the ODocument is retrieved and updated. The object is introspected using the Java Reflection to extract the field values.
      If a multi value (array, collection or map of objects) is passed, then each single object is stored separately.

      Before to use the specified cluster a check is made to know if is allowed and figures in the configured and the record is valid following the constraints declared in the schema.

      Specified by:
      save in interface ODatabase<Object>
      Parameters:
      iPojo - The entity to save
      iClusterName - Name of the cluster where to save
      Returns:
      The saved entity.
      See Also:
    • save

      public <RET> RET save(Object iPojo, String iClusterName, boolean iForceCreate)
      Saves an object to the database forcing a record cluster where to store it. First checks if the object is new or not. In case it's new a new ODocument is created and bound to the object, otherwise the ODocument is retrieved and updated. The object is introspected using the Java Reflection to extract the field values.
      If a multi value (array, collection or map of objects) is passed, then each single object is stored separately.

      Before to use the specified cluster a check is made to know if is allowed and figures in the configured and the record is valid following the constraints declared in the schema.

      Specified by:
      save in interface ODatabaseInternal<Object>
      Parameters:
      iPojo - The entity to save
      iClusterName - Name of the cluster where to save
      See Also:
    • delete

      public ODatabaseObject delete(Object iPojo)
      Description copied from interface: ODatabase
      Deletes an entity from the database in synchronous mode.
      Specified by:
      delete in interface ODatabase<Object>
      Parameters:
      iPojo - The entity to delete.
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • delete

      public ODatabaseObject delete(ORID iRID)
      Description copied from interface: ODatabase
      Deletes the entity with the received RID from the database.
      Specified by:
      delete in interface ODatabase<Object>
      Parameters:
      iRID - The RecordID to delete.
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • delete

      public ODatabaseObject delete(ORID iRID, int iVersion)
      Description copied from interface: ODatabase
      Deletes the entity with the received RID from the database.
      Specified by:
      delete in interface ODatabase<Object>
      Parameters:
      iRID - The RecordID to delete.
      iVersion - for MVCC
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • delete

      public ODatabaseObject delete(ORecord iRecord)
    • countClass

      public long countClass(String iClassName)
      Description copied from interface: ODatabaseObject
      Counts the entities contained in the specified class and sub classes (polymorphic).
      Specified by:
      countClass in interface ODatabaseObject
      Parameters:
      iClassName - Class name
      Returns:
      Total entities
    • countClass

      public long countClass(String iClassName, boolean iPolymorphic)
      Description copied from interface: ODatabaseObject
      Counts the entities contained in the specified class.
      Specified by:
      countClass in interface ODatabaseObject
      Parameters:
      iClassName - Class name
      iPolymorphic - True if consider also the sub classes, otherwise false
      Returns:
      Total entities
    • countClass

      public long countClass(Class<?> iClass)
      Specified by:
      countClass in interface ODatabaseObject
    • getDictionary

      @Deprecated public ODictionary<Object> getDictionary()
      Deprecated.
      Returns the Dictionary manual index.
      Specified by:
      getDictionary in interface ODatabase<Object>
      Returns:
      ODictionary instance
    • getTransaction

      public OTransaction getTransaction()
      Description copied from interface: ODatabase
      Return active transaction. Cannot be null. If no transaction is active, then a OTransactionNoTx instance is returned.
      Specified by:
      getTransaction in interface ODatabase<Object>
      Returns:
      OTransaction implementation
    • begin

      public OObjectDatabaseTx begin()
      Description copied from interface: ODatabase
      Begins a new transaction. By default the type is OPTIMISTIC. If a previous transaction is running a nested call counter is incremented. A transaction once begun has to be closed by calling the ODatabase.commit() or ODatabase.rollback().
      Specified by:
      begin in interface ODatabase<Object>
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • begin

      public OObjectDatabaseTx begin(OTransaction.TXTYPE iType)
      Description copied from interface: ODatabase
      Begins a new transaction specifying the transaction type. If a previous transaction is running a nested call counter is incremented. A transaction once begun has to be closed by calling the ODatabase.commit() or ODatabase.rollback().
      Specified by:
      begin in interface ODatabase<Object>
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • commit

      public OObjectDatabaseTx commit()
      Description copied from interface: ODatabase
      Commits the current transaction. The approach is all or nothing. All changes will be permanent following the storage type. If the operation succeed all the entities changed inside the transaction context will be effective. If the operation fails, all the changed entities will be restored in the data store.
      Specified by:
      commit in interface ODatabase<Object>
      Returns:
    • commit

      public OObjectDatabaseTx commit(boolean force) throws OTransactionException
      Specified by:
      commit in interface ODatabase<Object>
      Throws:
      OTransactionException
    • rollback

      public OObjectDatabaseTx rollback()
      Description copied from interface: ODatabase
      Aborts the current running transaction. All the pending changed entities will be restored in the data store.
      Specified by:
      rollback in interface ODatabase<Object>
      Returns:
    • rollback

      public OObjectDatabaseTx rollback(boolean force) throws OTransactionException
      Specified by:
      rollback in interface ODatabase<Object>
      Throws:
      OTransactionException
    • getEntityManager

      public OEntityManager getEntityManager()
      Description copied from interface: ODatabaseObject
      Returns the entity manager that handle the binding from ODocuments and POJOs.
      Specified by:
      getEntityManager in interface ODatabaseObject
      Returns:
    • getUnderlying

      public ODatabaseDocumentInternal getUnderlying()
      Description copied from interface: ODatabaseInternal
      Return the underlying database. Used in wrapper instances to know the down level ODatabase instance.
      Specified by:
      getUnderlying in interface ODatabaseInternal<Object>
      Specified by:
      getUnderlying in interface ODatabaseObject
      Overrides:
      getUnderlying in class ODatabaseWrapperAbstract<ODatabaseDocumentInternal,Object>
      Returns:
      The underlying ODatabase implementation.
    • getVersion

      public int getVersion(Object iPojo)
      Returns the version number of the object. Version starts from 0 assigned on creation.
      Parameters:
      iPojo - User object
    • getIdentity

      public ORID getIdentity(Object iPojo)
      Returns the object unique identity.
      Specified by:
      getIdentity in interface ODatabaseObject
      Parameters:
      iPojo - User object
    • isSaveOnlyDirty

      public boolean isSaveOnlyDirty()
    • setSaveOnlyDirty

      public void setSaveOnlyDirty(boolean saveOnlyDirty)
    • isAutomaticSchemaGeneration

      public boolean isAutomaticSchemaGeneration()
    • setAutomaticSchemaGeneration

      public void setAutomaticSchemaGeneration(boolean automaticSchemaGeneration)
      Specified by:
      setAutomaticSchemaGeneration in interface ODatabaseObject
    • newInstance

      public Object newInstance()
      Description copied from interface: ODatabase
      Creates a new entity instance.
      Specified by:
      newInstance in interface ODatabase<Object>
      Returns:
      The new instance.
    • checkSecurity

      public <DBTYPE extends ODatabase> DBTYPE checkSecurity(ORule.ResourceGeneric resourceGeneric, String resourceSpecific, byte iOperation)
    • checkSecurity

      public <DBTYPE extends ODatabase> DBTYPE checkSecurity(ORule.ResourceGeneric iResource, int iOperation, Object iResourceSpecific)
    • checkSecurity

      public <DBTYPE extends ODatabase> DBTYPE checkSecurity(ORule.ResourceGeneric iResource, int iOperation, Object... iResourcesSpecific)
    • pojo2Stream

      public ODocument pojo2Stream(Object iPojo, ODocument iRecord)
      Specified by:
      pojo2Stream in interface ODatabaseObject
    • stream2pojo

      public Object stream2pojo(ODocument iRecord, Object iPojo, String iFetchPlan)
      Specified by:
      stream2pojo in interface ODatabaseObject
    • stream2pojo

      public Object stream2pojo(ODocument iRecord, Object iPojo, String iFetchPlan, boolean iReload)
    • isLazyLoading

      public boolean isLazyLoading()
      Specified by:
      isLazyLoading in interface ODatabaseObject
    • setLazyLoading

      public void setLazyLoading(boolean lazyLoading)
      Specified by:
      setLazyLoading in interface ODatabaseObject
    • getType

      public String getType()
      Specified by:
      getType in interface ODatabase<Object>
    • getConflictStrategy

      public ORecordConflictStrategy getConflictStrategy()
      Description copied from interface: ODatabase
      Returns the current record conflict strategy.
      Specified by:
      getConflictStrategy in interface ODatabase<Object>
    • setConflictStrategy

      public OObjectDatabaseTx setConflictStrategy(ORecordConflictStrategy iResolver)
      Description copied from interface: ODatabase
      Overrides record conflict strategy.
      Specified by:
      setConflictStrategy in interface ODatabase<Object>
      Parameters:
      iResolver - ORecordConflictStrategy implementation
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • setConflictStrategy

      public OObjectDatabaseTx setConflictStrategy(String iStrategyName)
      Description copied from interface: ODatabase
      Overrides record conflict strategy selecting the strategy by name.
      Specified by:
      setConflictStrategy in interface ODatabase<Object>
      Parameters:
      iStrategyName - ORecordConflictStrategy strategy name
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • getRecordByUserObject

      public ODocument getRecordByUserObject(Object iPojo, boolean iCreateIfNotAvailable)
      Description copied from interface: OUserObject2RecordHandler
      Returns the record associated to a user object. If iCreateIfNotAvailable is true, then a new record instance will be created transparently.
      Specified by:
      getRecordByUserObject in interface ODatabaseObject
      Specified by:
      getRecordByUserObject in interface OUserObject2RecordHandler
      Parameters:
      iPojo - User object
      iCreateIfNotAvailable - Create the record if not available
      Returns:
      The record associated
    • getUserObjectByRecord

      public Object getUserObjectByRecord(OIdentifiable iRecord, String iFetchPlan)
      Description copied from interface: OUserObject2RecordHandler
      Returns the user object associated to a record. If the record is not loaded yet, iFetchPlan will be used as fetch plan.
      Specified by:
      getUserObjectByRecord in interface OUserObject2RecordHandler
      Parameters:
      iRecord - Record
      iFetchPlan - If the record is not loaded yet, use this as fetch plan
      Returns:
      The user object associated
    • getUserObjectByRecord

      public Object getUserObjectByRecord(OIdentifiable iRecord, String iFetchPlan, boolean iCreate)
    • registerUserObject

      public void registerUserObject(Object iObject, ORecord iRecord)
      Description copied from interface: OUserObject2RecordHandler
      Registers the association between a user object and a record.
      Specified by:
      registerUserObject in interface OUserObject2RecordHandler
      Parameters:
      iObject - User object
      iRecord - record
    • registerUserObjectAfterLinkSave

      public void registerUserObjectAfterLinkSave(ORecord iRecord)
      Description copied from interface: OUserObject2RecordHandler
      Registers the saved linked record. Needed only to make the old object database implementation work
      Specified by:
      registerUserObjectAfterLinkSave in interface OUserObject2RecordHandler
      Parameters:
      iRecord - record
    • unregisterPojo

      public void unregisterPojo(Object iObject, ODocument iRecord)
    • existsUserObjectByRID

      public boolean existsUserObjectByRID(ORID iRID)
      Description copied from interface: OUserObject2RecordHandler
      Tells if e user object exists for a certain RecordId.
      Specified by:
      existsUserObjectByRID in interface OUserObject2RecordHandler
    • registerClassMethodFilter

      public void registerClassMethodFilter(Class<?> iClass, OObjectMethodFilter iMethodFilter)
    • deregisterClassMethodFilter

      public void deregisterClassMethodFilter(Class<?> iClass)
    • incrementalBackup

      public String incrementalBackup(String path)
      Description copied from interface: ODatabase
      Performs incremental backup of database content to the selected folder. This is thread safe operation and can be done in normal operational mode.

      If it will be first backup of data full content of database will be copied into folder otherwise only changes after last backup in the same folder will be copied.

      Specified by:
      incrementalBackup in interface ODatabase<Object>
      Parameters:
      path - Path to backup folder.
      Returns:
      File name of the backup
    • resetInitialization

      public void resetInitialization()
      Specified by:
      resetInitialization in interface ODatabaseInternal<Object>
    • detachAll

      protected <RET> RET detachAll(Object iPojo, boolean returnNonProxiedInstance, Map<Object,Object> alreadyDetached, Map<Object,Object> lazyObjects)
    • deleteCascade

      protected void deleteCascade(ODocument record)
    • init

      protected void init()
    • deleteOrphans

      protected void deleteOrphans(OObjectProxyMethodHandler handler)
    • addBlobCluster

      public int addBlobCluster(String iClusterName, Object... iParameters)
      Description copied from interface: ODatabase
      Adds a new cluster for store blobs.
      Specified by:
      addBlobCluster in interface ODatabase<Object>
      Parameters:
      iClusterName - Cluster name
      iParameters - Additional parameters to pass to the factories
      Returns:
      Cluster id
    • getBlobClusterIds

      public Set<Integer> getBlobClusterIds()
      Description copied from interface: ODatabase
      Retrieve the set of defined blob cluster.
      Specified by:
      getBlobClusterIds in interface ODatabase<Object>
      Returns:
      the set of defined blob cluster ids.
    • getSharedContext

      public OSharedContext getSharedContext()
      Specified by:
      getSharedContext in interface ODatabaseInternal<Object>
    • convertParameters

      protected void convertParameters(Object... iArgs)
      Converts an array of parameters: if a POJO is used, then replace it with its record id.
      Parameters:
      iArgs - Array of parameters as Object
      See Also:
    • setDirty

      public void setDirty(Object iPojo)
      Sets as dirty a POJO. This is useful when you change the object and need to tell to the engine to treat as dirty.
      Specified by:
      setDirty in interface ODatabaseObject
      Parameters:
      iPojo - User object
    • unsetDirty

      public void unsetDirty(Object iPojo)
      Sets as not dirty a POJO. This is useful when you change some other object and need to tell to the engine to treat this one as not dirty.
      Specified by:
      unsetDirty in interface ODatabaseObject
      Parameters:
      iPojo - User object
    • convertParameter

      protected Object convertParameter(Object iParameter)
      Convert a parameter: if a POJO is used, then replace it with its record id.
      Parameters:
      iParameter - Parameter to convert, if applicable
      See Also:
    • live

      public OLiveQueryMonitor live(String query, OLiveQueryResultListener listener, Object... args)
      Description copied from interface: ODatabase
      Subscribe a query as a live query for future create/update event with the referred conditions
      Specified by:
      live in interface ODatabase<Object>
      Parameters:
      query - live query
      listener - the listener that receive the query results
      args - the live query args
    • live

      public OLiveQueryMonitor live(String query, OLiveQueryResultListener listener, Map<String,?> args)
      Description copied from interface: ODatabase
      Subscribe a query as a live query for future create/update event with the referred conditions
      Specified by:
      live in interface ODatabase<Object>
      Parameters:
      query - live query
      listener - the listener that receive the query results
      args - the live query args
    • query

      Description copied from interface: ODatabase
      Executes an SQL query. The result set has to be closed after usage

      Sample usage:

      OResultSet rs = db.query("SELECT FROM V where name = ?", "John"); while(rs.hasNext()){ OResult item = rs.next(); ... } rs.close();

      Specified by:
      query in interface ODatabase<Object>
      Parameters:
      query - the query string
      args - query parameters (positional)
      Returns:
      the query result set
      Throws:
      OCommandSQLParsingException
      OCommandExecutionException
    • query

      Description copied from interface: ODatabase
      Executes an SQL query (idempotent). The result set has to be closed after usage

      Sample usage:

      Map<String, Object&gt params = new HashMapMap<&gt(); params.put("name", "John"); OResultSet rs = db.query("SELECT FROM V where name = :name", params); while(rs.hasNext()){ OResult item = rs.next(); ... } rs.close();

      Specified by:
      query in interface ODatabase<Object>
      Parameters:
      query - the query string
      args - query parameters (named)
      Returns:
      Throws:
      OCommandSQLParsingException
      OCommandExecutionException
    • command

      Description copied from interface: ODatabase
      Executes a generic (idempotent or non idempotent) command. The result set has to be closed after usage

      Sample usage:

      OResultSet rs = db.command("INSERT INTO Person SET name = ?", "John"); ... rs.close();

      Specified by:
      command in interface ODatabase<Object>
      args - query arguments
      Returns:
      Throws:
      OCommandSQLParsingException
      OCommandExecutionException
    • objectQuery

      public <RET extends List<?>> RET objectQuery(String iCommand, Object... iArgs)
      Specified by:
      objectQuery in interface ODatabaseObject
    • objectQuery

      public <RET extends List<?>> RET objectQuery(String iCommand, Map<String,Object> iArgs)
      Specified by:
      objectQuery in interface ODatabaseObject
    • objectCommand

      public <RET extends List<?>> RET objectCommand(String iCommand, Object... iArgs)
      Specified by:
      objectCommand in interface ODatabaseObject
    • objectCommand

      public <RET extends List<?>> RET objectCommand(String iCommand, Map<String,Object> iArgs)
      Specified by:
      objectCommand in interface ODatabaseObject
    • command

      Description copied from interface: ODatabase
      Executes a generic (idempotent or non idempotent) command. The result set has to be closed after usage

      Sample usage:

      Map<String, Object&gt params = new HashMapMap<&gt(); params.put("name", "John"); OResultSet rs = db.query("INSERT INTO Person SET name = :name", params); ... rs.close();

      Specified by:
      command in interface ODatabase<Object>
      Returns:
      Throws:
      OCommandSQLParsingException
      OCommandExecutionException
    • execute

      public OResultSet execute(String language, String script, Object... args) throws OCommandExecutionException, OCommandScriptException
      Description copied from interface: ODatabase
      Execute a script in a specified query language. The result set has to be closed after usage

      Sample usage:

      String script = "INSERT INTO Person SET name = 'foo', surname = ?;"+ "INSERT INTO Person SET name = 'bar', surname = ?;"+ "INSERT INTO Person SET name = 'baz', surname = ?;";

      OResultSet rs = db.execute("sql", script, "Surname1", "Surname2", "Surname3"); ... rs.close();

      Specified by:
      execute in interface ODatabase<Object>
      Returns:
      Throws:
      OCommandExecutionException
      OCommandScriptException
    • execute

      public OResultSet execute(String language, String script, Map<String,?> args) throws OCommandExecutionException, OCommandScriptException
      Description copied from interface: ODatabase
      Execute a script of a specified query language The result set has to be closed after usage

      Sample usage:

      Map<String, Object&gt params = new HashMapMap<&gt(); params.put("surname1", "Jones"); params.put("surname2", "May"); params.put("surname3", "Ali");

      String script = "INSERT INTO Person SET name = 'foo', surname = :surname1;"+ "INSERT INTO Person SET name = 'bar', surname = :surname2;"+ "INSERT INTO Person SET name = 'baz', surname = :surname3;";

      OResultSet rs = db.execute("sql", script, params); ... rs.close();

      Specified by:
      execute in interface ODatabase<Object>
      Returns:
      Throws:
      OCommandExecutionException
      OCommandScriptException
    • executeWithRetry

      Description copied from interface: ODatabase
      Tries to execute a lambda in a transaction, retrying it if an ONeedRetryException is thrown.

      If the DB does not have an active transaction, after the execution you will still be out of tx.

      If the DB has an active transaction, then the transaction has to be empty (no operations executed yet) and after the execution you will be in a new transaction.

      Specified by:
      executeWithRetry in interface ODatabase<Object>
      Specified by:
      executeWithRetry in interface ODatabaseObject
      Type Parameters:
      T - the return type of the lambda
      Parameters:
      nRetries - the maximum number of retries (> 0)
      function - a lambda containing application code to execute in a commit/retry loop
      Returns:
      The result of the execution of the lambda
      Throws:
      IllegalStateException - if there are operations in the current transaction
      IllegalArgumentException - if nRetries is <= 0
      ONeedRetryException - if the maximum number of retries is executed and all failed with an ONeedRetryException
      UnsupportedOperationException - if this type of database does not support automatic commit/retry
    • getStorageInfo

      public OStorageInfo getStorageInfo()
      Specified by:
      getStorageInfo in interface ODatabaseInternal<Object>