Class RDBMSPersistenceHandler

java.lang.Object
org.datanucleus.store.AbstractPersistenceHandler
org.datanucleus.store.rdbms.RDBMSPersistenceHandler
All Implemented Interfaces:
org.datanucleus.store.StorePersistenceHandler

public class RDBMSPersistenceHandler extends org.datanucleus.store.AbstractPersistenceHandler
Handler for persistence for RDBMS datastores.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.datanucleus.store.StorePersistenceHandler

    org.datanucleus.store.StorePersistenceHandler.PersistenceBatchType
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The cache of database requests.

    Fields inherited from class org.datanucleus.store.AbstractPersistenceHandler

    storeMgr
  • Constructor Summary

    Constructors
    Constructor
    Description
    RDBMSPersistenceHandler(org.datanucleus.store.StoreManager storeMgr)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    checkForSchemaUpdatesForFieldsOfObject(org.datanucleus.state.DNStateManager sm, int[] fieldNumbers)
    Check if we need to update the schema before performing an insert/update.
    void
    Method to close the handler and release any resources.
    void
    deleteObject(org.datanucleus.state.DNStateManager sm)
    Deletes a persistent object from the database.
    private void
    deleteObjectFromTable(DatastoreClass table, org.datanucleus.state.DNStateManager sm, org.datanucleus.ClassLoaderResolver clr)
    Convenience method to handle the delete from the various tables that this object is persisted into.
    void
    fetchObject(org.datanucleus.state.DNStateManager sm, int[] memberNumbers)
    Fetches (fields of) a persistent object from the database.
    findObject(org.datanucleus.ExecutionContext ec, Object id)
    Method to return a persistable object with the specified id.
    getDatastoreClass(String className, org.datanucleus.ClassLoaderResolver clr)
     
    private Request
    getDeleteRequest(DatastoreClass table, org.datanucleus.metadata.AbstractClassMetaData acmd, org.datanucleus.ClassLoaderResolver clr)
    Returns a request object that will delete a row from the given table.
    private Request
    getFetchRequest(DatastoreClass table, org.datanucleus.FetchPlanForClass fpClass, org.datanucleus.ClassLoaderResolver clr, org.datanucleus.metadata.AbstractClassMetaData cmd, org.datanucleus.metadata.AbstractMemberMetaData[] mmdsFetch, org.datanucleus.metadata.AbstractMemberMetaData[] mmdsStore)
    Returns a request object that will fetch a row from the given table.
    private Request
    getInsertRequest(DatastoreClass table, org.datanucleus.metadata.AbstractClassMetaData cmd, org.datanucleus.ClassLoaderResolver clr)
    Returns a request object that will insert a row in the given table.
    private Request
    getLocateRequest(DatastoreClass table, org.datanucleus.metadata.AbstractClassMetaData cmd, org.datanucleus.ClassLoaderResolver clr)
    Returns a request object that will locate a row from the given table.
    private Request
    getUpdateRequest(DatastoreClass table, org.datanucleus.metadata.AbstractMemberMetaData[] mmds, org.datanucleus.metadata.AbstractClassMetaData cmd, org.datanucleus.ClassLoaderResolver clr)
    Returns a request object that will update a row in the given table.
    void
    insertObject(org.datanucleus.state.DNStateManager sm)
    Inserts a persistent object into the database.
    private void
    insertObjectInTable(DatastoreClass table, org.datanucleus.state.DNStateManager sm, org.datanucleus.ClassLoaderResolver clr)
    Convenience method to handle the insert into the various tables that this object is persisted into.
    void
    insertObjects(org.datanucleus.state.DNStateManager... sms)
     
    void
    locateObject(org.datanucleus.state.DNStateManager sm)
    Locates this object in the datastore.
    void
    locateObjects(org.datanucleus.state.DNStateManager[] sms)
     
    void
    Convenience method to remove all requests since the schema has changed.
    void
    Convenience method to remove all requests that use a particular table since the structure of the table has changed potentially leading to missing columns in the cached version.
    void
    updateObject(org.datanucleus.state.DNStateManager sm, int[] fieldNumbers)
    Updates a persistent object in the database.
    private void
    updateObjectInTable(DatastoreClass table, org.datanucleus.state.DNStateManager sm, org.datanucleus.ClassLoaderResolver clr, org.datanucleus.metadata.AbstractMemberMetaData[] mmds)
    Convenience method to handle the update into the various tables that this object is persisted into.

    Methods inherited from class org.datanucleus.store.AbstractPersistenceHandler

    assertReadOnlyForUpdateOfObject, findObjectForUnique

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.datanucleus.store.StorePersistenceHandler

    batchEnd, batchStart, deleteObjects, fetchObjects, findObjects
  • Field Details

    • requestsByID

      private Map<RequestIdentifier,Request> requestsByID
      The cache of database requests. Access is synchronized on the map object itself.
  • Constructor Details

    • RDBMSPersistenceHandler

      public RDBMSPersistenceHandler(org.datanucleus.store.StoreManager storeMgr)
      Constructor.
      Parameters:
      storeMgr - StoreManager
  • Method Details

    • close

      public void close()
      Method to close the handler and release any resources.
    • getDatastoreClass

      private DatastoreClass getDatastoreClass(String className, org.datanucleus.ClassLoaderResolver clr)
    • insertObjects

      public void insertObjects(org.datanucleus.state.DNStateManager... sms)
    • insertObject

      public void insertObject(org.datanucleus.state.DNStateManager sm)
      Inserts a persistent object into the database. The insert can take place in several steps, one insert per table that it is stored in. e.g When persisting an object that uses "new-table" inheritance for each level of the inheritance tree then will get an INSERT into each table. When persisting an object that uses "complete-table" inheritance then will get a single INSERT into its table.
      Parameters:
      sm - StateManager for the object to be inserted.
      Throws:
      org.datanucleus.exceptions.NucleusDataStoreException - when an error occurs in the datastore communication
    • insertObjectInTable

      private void insertObjectInTable(DatastoreClass table, org.datanucleus.state.DNStateManager sm, org.datanucleus.ClassLoaderResolver clr)
      Convenience method to handle the insert into the various tables that this object is persisted into.
      Parameters:
      table - The table to process
      sm - StateManager for the object being inserted
      clr - ClassLoader resolver
    • getInsertRequest

      private Request getInsertRequest(DatastoreClass table, org.datanucleus.metadata.AbstractClassMetaData cmd, org.datanucleus.ClassLoaderResolver clr)
      Returns a request object that will insert a row in the given table. The store manager will cache the request object for re-use by subsequent requests to the same table.
      Parameters:
      table - The table into which to insert.
      cmd - ClassMetaData of the object of the request
      clr - ClassLoader resolver
      Returns:
      An insertion request object.
    • fetchObject

      public void fetchObject(org.datanucleus.state.DNStateManager sm, int[] memberNumbers)
      Fetches (fields of) a persistent object from the database. This does a single SELECT on the candidate of the class in question. Will join to inherited tables as appropriate to get values persisted into other tables. Can also join to the tables of related objects (1-1, N-1) as necessary to retrieve those objects.
      Parameters:
      sm - StateManager of the object to be fetched.
      memberNumbers - The numbers of the members to be fetched.
      Throws:
      org.datanucleus.exceptions.NucleusObjectNotFoundException - if the object doesn't exist
      org.datanucleus.exceptions.NucleusDataStoreException - when an error occurs in the datastore communication
    • getFetchRequest

      private Request getFetchRequest(DatastoreClass table, org.datanucleus.FetchPlanForClass fpClass, org.datanucleus.ClassLoaderResolver clr, org.datanucleus.metadata.AbstractClassMetaData cmd, org.datanucleus.metadata.AbstractMemberMetaData[] mmdsFetch, org.datanucleus.metadata.AbstractMemberMetaData[] mmdsStore)
      Returns a request object that will fetch a row from the given table. The store manager will cache the request object for re-use by subsequent requests to the same table.
      Parameters:
      table - The table from which to fetch.
      fpClass - FetchPlan for class
      clr - ClassLoader resolver
      cmd - ClassMetaData of the object of the request
      mmdsFetch - MetaData for the members to be fetched.
      mmdsStore - MetaData for the members to store the values for later processing
      Returns:
      A fetch request object.
    • updateObject

      public void updateObject(org.datanucleus.state.DNStateManager sm, int[] fieldNumbers)
      Updates a persistent object in the database. The update can take place in several steps, one update per table that it is stored in (depending on which fields are updated). e.g When updating an object that uses "new-table" inheritance for each level of the inheritance tree then will get an UPDATE into each table. When updating an object that uses "complete-table" inheritance then will get a single UPDATE into its table.
      Parameters:
      sm - StateManager for the object to be updated.
      fieldNumbers - The numbers of the fields to be updated.
      Throws:
      org.datanucleus.exceptions.NucleusDataStoreException - when an error occurs in the datastore communication
    • updateObjectInTable

      private void updateObjectInTable(DatastoreClass table, org.datanucleus.state.DNStateManager sm, org.datanucleus.ClassLoaderResolver clr, org.datanucleus.metadata.AbstractMemberMetaData[] mmds)
      Convenience method to handle the update into the various tables that this object is persisted into.
      Parameters:
      table - The table to process
      sm - StateManager for the object being updated
      clr - ClassLoader resolver
      mmds - MetaData for the fields being updated
    • getUpdateRequest

      private Request getUpdateRequest(DatastoreClass table, org.datanucleus.metadata.AbstractMemberMetaData[] mmds, org.datanucleus.metadata.AbstractClassMetaData cmd, org.datanucleus.ClassLoaderResolver clr)
      Returns a request object that will update a row in the given table. The store manager will cache the request object for re-use by subsequent requests to the same table.
      Parameters:
      table - The table in which to update.
      mmds - The metadata corresponding to the columns to be updated. MetaData whose columns exist in supertables will be ignored.
      cmd - ClassMetaData of the object of the request
      clr - ClassLoader resolver
      Returns:
      An update request object.
    • deleteObject

      public void deleteObject(org.datanucleus.state.DNStateManager sm)
      Deletes a persistent object from the database. The delete can take place in several steps, one delete per table that it is stored in. e.g When deleting an object that uses "new-table" inheritance for each level of the inheritance tree then will get an DELETE for each table. When deleting an object that uses "complete-table" inheritance then will get a single DELETE for its table.
      Parameters:
      sm - StateManager for the object to be deleted.
      Throws:
      org.datanucleus.exceptions.NucleusDataStoreException - when an error occurs in the datastore communication
    • deleteObjectFromTable

      private void deleteObjectFromTable(DatastoreClass table, org.datanucleus.state.DNStateManager sm, org.datanucleus.ClassLoaderResolver clr)
      Convenience method to handle the delete from the various tables that this object is persisted into.
      Parameters:
      table - The table to process
      sm - StateManager for the object being deleted
      clr - ClassLoader resolver
    • getDeleteRequest

      private Request getDeleteRequest(DatastoreClass table, org.datanucleus.metadata.AbstractClassMetaData acmd, org.datanucleus.ClassLoaderResolver clr)
      Returns a request object that will delete a row from the given table. The store manager will cache the request object for re-use by subsequent requests to the same table.
      Parameters:
      table - The table from which to delete.
      acmd - ClassMetaData of the object of the request
      clr - ClassLoader resolver
      Returns:
      A deletion request object.
    • locateObjects

      public void locateObjects(org.datanucleus.state.DNStateManager[] sms)
    • locateObject

      public void locateObject(org.datanucleus.state.DNStateManager sm)
      Locates this object in the datastore.
      Parameters:
      sm - StateManager for the object to be found
      Throws:
      org.datanucleus.exceptions.NucleusObjectNotFoundException - if the object doesnt exist
      org.datanucleus.exceptions.NucleusDataStoreException - when an error occurs in the datastore communication
    • getLocateRequest

      private Request getLocateRequest(DatastoreClass table, org.datanucleus.metadata.AbstractClassMetaData cmd, org.datanucleus.ClassLoaderResolver clr)
      Returns a request object that will locate a row from the given table. The store manager will cache the request object for re-use by subsequent requests to the same table.
      Parameters:
      table - The table from which to locate.
      cmd - Metadata for the class being located
      clr - ClassLoader resolver
      Returns:
      A locate request object.
    • findObject

      public Object findObject(org.datanucleus.ExecutionContext ec, Object id)
      Method to return a persistable object with the specified id. Optional operation for StoreManagers. Should return a (at least) hollow persistable object if the store manager supports the operation. If the StoreManager is managing the in-memory object instantiation (as part of co-managing the object lifecycle in general), then the StoreManager has to create the object during this call (if it is not already created). Most relational databases leave the in-memory object instantion to Core, but some object databases may manage the in-memory object instantion, effectively preventing Core of doing this.

      StoreManager implementations may simply return null, indicating that they leave the object instantiate to us. Other implementations may instantiate the object in question (whether the implementation may trust that the object is not already instantiated has still to be determined). If an implementation believes that an object with the given ID should exist, but in fact does not exist, then the implementation should throw a RuntimeException. It should not silently return null in this case.

      Parameters:
      ec - execution context
      id - the id of the object in question.
      Returns:
      a persistable object with a valid object state (for example: hollow) or null, indicating that the implementation leaves the instantiation work to us.
    • removeAllRequests

      public void removeAllRequests()
      Convenience method to remove all requests since the schema has changed.
    • removeRequestsForTable

      public void removeRequestsForTable(DatastoreClass table)
      Convenience method to remove all requests that use a particular table since the structure of the table has changed potentially leading to missing columns in the cached version.
      Parameters:
      table - The table
    • checkForSchemaUpdatesForFieldsOfObject

      private void checkForSchemaUpdatesForFieldsOfObject(org.datanucleus.state.DNStateManager sm, int[] fieldNumbers)
      Check if we need to update the schema before performing an insert/update. This is typically of use where the user has an interface field and some new implementation is trying to be persisted to that field, so we need to update the schema.
      Parameters:
      sm - StateManager for the object
      fieldNumbers - The fields to check for required schema updates