Package net.ontopia.persistence.proxy
Class RDBMSAccess
- java.lang.Object
-
- net.ontopia.persistence.proxy.RDBMSAccess
-
- All Implemented Interfaces:
StorageAccessIF
public class RDBMSAccess extends Object implements StorageAccessIF
INTERNAL: A storage access implementation accessing relational databases using JDBC.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
batch_updates
protected boolean
closed
protected Connection
connection
protected boolean
debug
protected Collection<FlushableIF>
flushable
protected Map<Class<?>,ClassAccessIF>
handlers
protected String
id
protected RDBMSMapping
mapping
protected boolean
readonly
protected RDBMSStorage
storage
-
Constructor Summary
Constructors Constructor Description RDBMSAccess(String id, RDBMSStorage storage, boolean readonly)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abort()
INTERNAL: Aborts all changes performed in the transaction.void
close()
INTERNAL: Closes the storage access, which allows it to free its resources.void
commit()
INTERNAL: Commits the changes performed in the transaction.void
createObject(ObjectAccessIF oaccess, Object object)
INTERNAL: Called by the transaction when it requests the new object to be created in the data repository.QueryIF
createQuery(String name, ObjectAccessIF oaccess, AccessRegistrarIF registrar)
INTERNAL: Creates a query instance for the given transaction.QueryIF
createQuery(JDOQuery jdoquery, ObjectAccessIF oaccess, AccessRegistrarIF registrar, boolean lookup_identities)
INTERNAL: Build a QueryIF from the specified JDO query instance.void
deleteObject(ObjectAccessIF oaccess, Object object)
INTERNAL: Called by the transaction when it requests the object to be deleted in the data repository.void
flush()
INTERNAL: Called when the transaction requires the transaction changes to be stored by the storage access (i.e.IdentityIF
generateIdentity(Class<?> type)
INTERNAL: Called by the application when it requests a new object identity for a given object type.Connection
getConnection()
INTERNAL: Returns the JDBC database connection used.protected ClassAccessIF
getHandler(Class<?> type)
INTERNAL: Gets up the handler class that is used to manage objects of the given class.String
getId()
INTERNAL: Gets the storage access id.String
getProperty(String property)
INTERNAL: Gets the value of the specified property.StorageIF
getStorage()
INTERNAL: Returns the storage definition that the access uses.boolean
isReadOnly()
INTERNAL: Returns true if the storage access is read-only.protected boolean
isSQLException(Throwable e)
Object
loadField(AccessRegistrarIF registrar, IdentityIF identity, int field)
INTERNAL: Requests the loading of the specified field for the given object identity.Object
loadFieldMultiple(AccessRegistrarIF registrar, Collection<IdentityIF> identities, IdentityIF current, Class<?> type, int field)
INTERNAL: Requests the loading of the specified field for all the given object identities.boolean
loadObject(AccessRegistrarIF registrar, IdentityIF identity)
INTERNAL: Check for the existence of the object identity in the data repository.protected void
needsFlushing(FlushableIF handler)
PreparedStatement
prepareStatement(String sql)
void
storeDirty(ObjectAccessIF oaccess, Object object)
INTERNAL: Stores object fields that are dirty in the database.boolean
validate()
INTERNAL: Returns true if the storage access is valid.protected boolean
validateConnection(Connection conn)
-
-
-
Field Detail
-
debug
protected boolean debug
-
id
protected String id
-
readonly
protected boolean readonly
-
storage
protected RDBMSStorage storage
-
mapping
protected RDBMSMapping mapping
-
connection
protected Connection connection
-
closed
protected boolean closed
-
handlers
protected Map<Class<?>,ClassAccessIF> handlers
-
batch_updates
protected boolean batch_updates
-
flushable
protected Collection<FlushableIF> flushable
-
-
Constructor Detail
-
RDBMSAccess
public RDBMSAccess(String id, RDBMSStorage storage, boolean readonly)
-
-
Method Detail
-
getId
public String getId()
Description copied from interface:StorageAccessIF
INTERNAL: Gets the storage access id. This id is unique for a given StorageIF instance.- Specified by:
getId
in interfaceStorageAccessIF
-
getStorage
public StorageIF getStorage()
Description copied from interface:StorageAccessIF
INTERNAL: Returns the storage definition that the access uses.- Specified by:
getStorage
in interfaceStorageAccessIF
-
isReadOnly
public boolean isReadOnly()
Description copied from interface:StorageAccessIF
INTERNAL: Returns true if the storage access is read-only.- Specified by:
isReadOnly
in interfaceStorageAccessIF
-
getProperty
public String getProperty(String property)
Description copied from interface:StorageAccessIF
INTERNAL: Gets the value of the specified property.- Specified by:
getProperty
in interfaceStorageAccessIF
-
getConnection
public Connection getConnection()
INTERNAL: Returns the JDBC database connection used. It is important that this connection is neither closed, nor commited or rolled back. If this access has already been closed, a non-transactional read connection is requested from the storage. The connection is validated using validateConnection and renewed if not validated.
-
prepareStatement
public PreparedStatement prepareStatement(String sql) throws SQLException
- Throws:
SQLException
-
isSQLException
protected boolean isSQLException(Throwable e)
-
getHandler
protected ClassAccessIF getHandler(Class<?> type)
INTERNAL: Gets up the handler class that is used to manage objects of the given class.
-
validate
public boolean validate()
Description copied from interface:StorageAccessIF
INTERNAL: Returns true if the storage access is valid.- Specified by:
validate
in interfaceStorageAccessIF
-
validateConnection
protected boolean validateConnection(Connection conn)
-
commit
public void commit()
Description copied from interface:StorageAccessIF
INTERNAL: Commits the changes performed in the transaction.- Specified by:
commit
in interfaceStorageAccessIF
-
abort
public void abort()
Description copied from interface:StorageAccessIF
INTERNAL: Aborts all changes performed in the transaction.- Specified by:
abort
in interfaceStorageAccessIF
-
close
public void close()
Description copied from interface:StorageAccessIF
INTERNAL: Closes the storage access, which allows it to free its resources.- Specified by:
close
in interfaceStorageAccessIF
-
flush
public void flush()
Description copied from interface:StorageAccessIF
INTERNAL: Called when the transaction requires the transaction changes to be stored by the storage access (i.e. written to the database).This method exists mainly to allow storage access implementations to optimize its communication with data repositories. An example of this is writing transaction changes in batches to improve performance.
Note that the transaction will always call this method at the end of its store method. It will do this so that it is sure that the changes will be visible inside the data repository.
- Specified by:
flush
in interfaceStorageAccessIF
-
loadObject
public boolean loadObject(AccessRegistrarIF registrar, IdentityIF identity)
Description copied from interface:StorageAccessIF
INTERNAL: Check for the existence of the object identity in the data repository. An exception will be thrown if the object does not exist. If it exists the access registrar will be notified.- Specified by:
loadObject
in interfaceStorageAccessIF
- Returns:
- true if object was found in the data store, false otherwise.
-
loadField
public Object loadField(AccessRegistrarIF registrar, IdentityIF identity, int field)
Description copied from interface:StorageAccessIF
INTERNAL: Requests the loading of the specified field for the given object identity. An exception will be thrown if the object does not exist. If it exists the access registrar will be notified.- Specified by:
loadField
in interfaceStorageAccessIF
- Returns:
- The value loaded for the specific field. Note that if the field is a reference field the identity will be returned, not the actual object. This is because the storage system does not deal with persistent object instances directly.
-
loadFieldMultiple
public Object loadFieldMultiple(AccessRegistrarIF registrar, Collection<IdentityIF> identities, IdentityIF current, Class<?> type, int field)
Description copied from interface:StorageAccessIF
INTERNAL: Requests the loading of the specified field for all the given object identities. An exception will be thrown if the current object does not exist. If it exists the access registrar will be notified.- Specified by:
loadFieldMultiple
in interfaceStorageAccessIF
- Returns:
- The value loaded for the specific field. Note that if the field is a reference field the identity will be returned, not the actual object. This is because the storage system does not deal with persistent object instances directly.
-
createObject
public void createObject(ObjectAccessIF oaccess, Object object)
Description copied from interface:StorageAccessIF
INTERNAL: Called by the transaction when it requests the new object to be created in the data repository. The ObjectAccessIF object is used to access information about the object as needed.- Specified by:
createObject
in interfaceStorageAccessIF
-
deleteObject
public void deleteObject(ObjectAccessIF oaccess, Object object)
Description copied from interface:StorageAccessIF
INTERNAL: Called by the transaction when it requests the object to be deleted in the data repository.- Specified by:
deleteObject
in interfaceStorageAccessIF
-
storeDirty
public void storeDirty(ObjectAccessIF oaccess, Object object)
Description copied from interface:StorageAccessIF
INTERNAL: Stores object fields that are dirty in the database.- Specified by:
storeDirty
in interfaceStorageAccessIF
-
needsFlushing
protected void needsFlushing(FlushableIF handler)
-
createQuery
public QueryIF createQuery(String name, ObjectAccessIF oaccess, AccessRegistrarIF registrar)
Description copied from interface:StorageAccessIF
INTERNAL: Creates a query instance for the given transaction.- Specified by:
createQuery
in interfaceStorageAccessIF
-
createQuery
public QueryIF createQuery(JDOQuery jdoquery, ObjectAccessIF oaccess, AccessRegistrarIF registrar, boolean lookup_identities)
Description copied from interface:StorageAccessIF
INTERNAL: Build a QueryIF from the specified JDO query instance.- Specified by:
createQuery
in interfaceStorageAccessIF
-
generateIdentity
public IdentityIF generateIdentity(Class<?> type)
Description copied from interface:StorageAccessIF
INTERNAL: Called by the application when it requests a new object identity for a given object type.- Specified by:
generateIdentity
in interfaceStorageAccessIF
-
-