|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.nec.tdd.tools.dbMapper.ORDBMapper | +--com.nec.tdd.tools.dbMapper.DefaultMapper
A mapper implementation with one-to-one relationship with mapping context.
Constructor Summary | |
DefaultMapper()
|
|
DefaultMapper(DataSource aDataSource,
ORMappingInfo aMappingInfo)
|
Method Summary | |
void |
beginTransaction()
Create a new transaction and associate it with the current thread. |
void |
commitTransaction()
Complete the transaction associated with the current thread. |
void |
create(java.lang.Object userObject)
This generic insert/create method stores user object to database associated with this DBInterface. |
void |
createTree(java.lang.Object userObject)
This generic insert/create method stores user object(whole object containment tree *note1) to database associated with this DBInterface. |
void |
createTree(java.lang.Object userObject,
int level)
This method is similar to the createTree(Object) method, with only difference that user can specify maximum recursion depth. |
boolean |
delete(java.lang.Object userObject)
This generic delete method deletes an user object (if found) from database associated with this DBInterface. |
int |
deleteAll(java.lang.Class userObjectClass)
This generic method deletes all persistent user objects of given class type from the database. |
int |
deleteByAttributes(AttrValMap attrValMap,
java.lang.Class userObjectClass)
This generic delete method deletes user object whose attribute values matches with those specified in attribute value map. |
boolean |
deleteByPrimaryKey(java.lang.Object primaryKey,
java.lang.Class userObjectClass)
This generic delete method deletes an user object, if found, (from database associated with this DBInterface) based on primary key. |
java.sql.ResultSet |
executeQuery(java.lang.String query)
Executes an SQL statement that returns a single ResultSet object. |
int |
executeUpdate(java.lang.String query)
Executes an SQL INSERT, UPDATE or DELETE statement. |
java.util.Collection |
findAll(java.lang.Class userObjectClass)
This generic finder method returns collection of all user object stored in database. Only basic attributes are filled in user object. |
java.util.Collection |
findAllPrimaryKeys(java.lang.Class userObjectClass)
This generic finder method returns collection of all primary keys associated with a user object stored in database. |
java.util.Collection |
findByAttributes(AttrValMap attrValMap,
java.lang.Class userObjectClass)
This generic finder method returns a collection of user object whose attribute values matches with those specified in attribute value map. |
java.lang.Object |
findByPrimaryKey(java.lang.Object primaryKey,
java.lang.Class userObjectClass)
This generic finder method returns a user object, if found, (from database associated with this DBInterface) based on the primary key. |
java.lang.Object |
findByPrimaryKey(java.lang.Object primaryKey,
java.lang.Class userObjectClass,
int level)
This generic finder method loads partial or whole user object containment tree, if found, (from database associated with this DBInterface) based on the primary key and depth parameters. |
java.util.Collection |
findByQuery(java.lang.String query,
java.lang.Class userObjectClass)
This generic finder method returns a collection of user object based on the user SQL query. Only basic attributes are filled in user object. One should use this method only none of other finder methods (findByPrimaryKey, findByAttributes etc) solve the purpose. This method is most flexible of all the finder methods but requires SQL details in user code. |
ORMapEntry |
findMapEntry(java.lang.Class cls)
Method to find the mapping entry corresponding the user class. |
ORMapEntry |
findMapEntry(java.lang.Object data)
Method to find the mapping entry corresponding the data object (class). |
java.util.Collection |
findPrimaryKeysByAttributes(AttrValMap attrValMap,
java.lang.Class userObjectClass)
This generic finder method returns a collection of primary key objects based on given attribute value map. |
java.util.Collection |
findPrimaryKeysByQuery(java.lang.String query,
java.lang.Class userObjectClass)
This generic finder method returns a collection of primary key objects based on the user SQL query. One should use this method only none of other primary key finder methods (findPrimaryKeysByAttributes, findAllPrimaryKeys etc) solve the purpose. This method is most flexible of all the primary key finder methods but requires SQL details in user code. |
DBConnection |
getConnection()
Get a DBConnection from the connection manager associated with this ORDBMapper. |
DataSource |
getDataSource()
Methods accessible in db package only |
ORMappingInfo |
getORMappingInfo()
|
boolean |
isActiveTransaction()
Obtain the status of the transaction associated with the current thread. |
void |
releaseConnection(DBConnection conn)
Method to release an previously acquired DBConnection to the connection manager associated with this ORDBMapper. |
void |
rollbackTransaction()
Rollback the transaction associated with the current thread. |
void |
setDataSource(DataSource ds)
|
void |
setORMappingInfo(ORMappingInfo mi)
|
java.lang.String |
toString()
|
boolean |
update(java.lang.Object userObject)
This generic update method updates all basic non-key attributes of an user object (if found) to database associated with this DBInterface. |
boolean |
update(java.lang.Object userObject,
AttrValMap attrValMap,
boolean bUpdateUserObject)
This generic update method updates only the specified attributes (basic or non-basic) of an user object (if found) to database associated with this DBInterface. Important: This class may modify attrValMap input parameter. |
boolean |
update(java.lang.Object userObject,
java.util.HashMap attrValMap,
boolean bUpdateUserObject)
This method is similar to the update(Object,HashMap,boolean) method, with only difference that attribute names and values are passed in HashMap instead of AttrValMap. Note: Java primitive types should be wrapped in objects (ex. |
boolean |
updateTree(java.lang.Object userObject)
This generic update method updates all non-key attributes of an user object (if found) to database associated with this DBInterface. |
boolean |
updateTree(java.lang.Object userObject,
int level)
This method is similar to the updateTree(Object) method, with only difference that user can specify maximum recursion depth. |
void |
validatePrimaryKeyClass(ORMapEntry mapEntry,
java.lang.Object primaryKey)
Validate that given class has a primary key. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public DefaultMapper()
public DefaultMapper(DataSource aDataSource, ORMappingInfo aMappingInfo)
Method Detail |
public DBConnection getConnection()
getConnection
in interface DataSource
public void releaseConnection(DBConnection conn)
releaseConnection
in interface DataSource
conn
- DBConnection to be released.public void create(java.lang.Object userObject) throws java.lang.Exception
Assumption: An OR mapping exists for this user object (class type) in mapping file.
create
in interface DBInterface
userObject
- The user object to be inserted.Exception
- if any problems in saving the
user object.ORDBMapper.createTree(Object)
,
ORDBMapper.createTree(Object,int)
public void createTree(java.lang.Object userObject) throws java.lang.Exception
Assumption: An OR mapping exists for the user object and all non-basic type attributes in the mapping file.
createTree
in interface DBInterface
userObject
- The user object (tree root) to be inserted.Exception
- if any problems in saving the user
object.ORDBMapper.create(Object)
,
ORDBMapper.createTree(Object,int)
public void createTree(java.lang.Object userObject, int level) throws java.lang.Exception
depth = 1 is equivalent to create(Object).
depth = Constants.MAX_DEPTH is equivalent to createTree(Object) method.
createTree
in interface DBInterface
userObject
- The user object (tree root) to be inserted.depth
- The maximum recursion depth.Exception
- if any problems in saving the user
object.ORDBMapper.create(Object)
,
ORDBMapper.createTree(Object)
public boolean delete(java.lang.Object userObject) throws java.lang.Exception
Assumption: An OR mapping exists for this user object (class type) in mapping file.
delete
in interface DBInterface
userObject
- The user object to be deleted.Exception
- if any problems in deleting the user
object.public boolean deleteByPrimaryKey(java.lang.Object primaryKey, java.lang.Class userObjectClass) throws java.lang.Exception
Assumptions:
1) An OR mapping exists for this userObjectClass in mapping file.
2) primaryKey class exists.
deleteByPrimaryKey
in interface DBInterface
primaryKey
- The primaryKey based on which user object of type
userObjectClass is deleted.userObjectClass
- The user object class type (ex. HashMap.class
gives HashMap class type).Exception
- if any problems in deleting the user
object.public int deleteByAttributes(AttrValMap attrValMap, java.lang.Class userObjectClass) throws java.lang.Exception
This method is equivalent to deleteByPrimaryKey(pkey, userObjectClass) method if all the key attributes for this userObjectClass type are specified in the attrValMap.
Assumptions:
1) An OR mapping exists for this userObjectClass in mapping file.
2) AttrValMap attributes are valid userObjectClass attribute names
(specified in mapping file).
deleteByAttributes
in interface DBInterface
attrValMap
- Map of attributes and values based on which user
objects of type userObjectClass is deleted.userObjectClass
- The user object class type (ex. HashMap.class
gives HashMap class type).Exception
- if any databse problems in deleting
the user objects.public int deleteAll(java.lang.Class userObjectClass) throws java.lang.Exception
deleteAll
in interface DBInterface
userObjectClass
- The user object class type (ex.
HashMap.class gives HashMap class type).java.lang.Exception
- if any databse problems in deleting the user objects.public boolean update(java.lang.Object userObject) throws java.lang.Exception
Assumptions:
1) An OR mapping exists for this user object (class) in mapping
file.
2) Only non-key non-basic attributes are saved.
3) Original KEY attribues are not modified by user.
update
in interface DBInterface
userObject
- The user object to be updated.Exception
- if any problems in updating the user
object.ORDBMapper.updateTree(Object)
,
ORDBMapper.updateTree(Object,int)
,
ORDBMapper.update(Object,AttrValMap,boolean)
,
ORDBMapper.update(Object,HashMap,boolean)
public boolean updateTree(java.lang.Object userObject) throws java.lang.Exception
Assumptions:
1) An OR mapping exists for the user object and all non-basic type
attributes in the mapping file.
2) Only non-key attributes are saved.
3) Original KEY attribues are not modified by user.
updateTree
in interface DBInterface
userObject
- The user object to be updated.Exception
- if any problems in updating the
user object.ORDBMapper.updateTree(Object,int)
,
ORDBMapper.update(Object,AttrValMap,boolean)
,
ORDBMapper.update(Object,HashMap,boolean)
,
ORDBMapper.update(Object)
public boolean updateTree(java.lang.Object userObject, int level) throws java.lang.Exception
depth = 1 is equivalent to update(Object).
depth = Constants.MAX_DEPTH is equivalent to updateTree(Object) method.
updateTree
in interface DBInterface
userObject
- The user object (tree root) to be inserted.depth
- The maximum recursion depth.Exception
- if any problems in saving the
user object.ORDBMapper.updateTree(Object)
,
ORDBMapper.update(Object,AttrValMap,boolean)
,
ORDBMapper.update(Object,HashMap,boolean)
,
ORDBMapper.update(Object)
public boolean update(java.lang.Object userObject, AttrValMap attrValMap, boolean bUpdateUserObject) throws java.lang.Exception
Assumptions:
1) An OR mapping exists for this user object (class type) in mapping
file.
2) Only non-key attributes are listed in attrValMap and original KEY
attribues are not modified by user.
update
in interface DBInterface
userObject
- The user object to be updated.attrValMap
- Map of attributes and values to be updatedbUpdateUserObject
- Indicates whether or not after successful
database update, to apply
attrValMap changes on user object.java.lang.Exception
- if any problems in updating the user object.ORDBMapper.update(Object,HashMap,boolean)
,
ORDBMapper.update(Object)
,
ORDBMapper.updateTree(Object)
,
ORDBMapper.updateTree(Object,int)
public boolean update(java.lang.Object userObject, java.util.HashMap attrValMap, boolean bUpdateUserObject) throws java.lang.Exception
update
in interface DBInterface
userObject
- The user object to be updated.attrValMap
- Map of attributes and values to be updatedbUpdateUserObject
- Indicates whether or not after successful
database update, to apply
attrValMap changes on user object.java.lang.Exception
- if any problems in updating the user object.ORDBMapper.update(Object,AttrValMap,boolean)
,
ORDBMapper.update(Object)
,
ORDBMapper.updateTree(Object)
,
ORDBMapper.updateTree(Object,int)
public java.lang.Object findByPrimaryKey(java.lang.Object primaryKey, java.lang.Class userObjectClass) throws java.lang.Exception
Assumptions:
1) An OR mapping exists for this userObjectClass in mapping file.
2) PrimaryKey class exists (refer to Terminology section).
findByPrimaryKey
in interface DBInterface
primaryKey
- The primaryKey based on which user object of type
userObjectClass is returned.userObjectClass
- The user object class type (ex. HashMap.class
gives HashMap class type).java.lang.Exception
- if any databse problems in finding the user object.ORDBMapper.findByPrimaryKey(Object,Class,int)
,
ORDBMapper.findByAttributes(AttrValMap,Class)
,
ORDBMapper.findByQuery(String,Class)
,
ORDBMapper.findAll(Class)
public java.lang.Object findByPrimaryKey(java.lang.Object primaryKey, java.lang.Class userObjectClass, int level) throws java.lang.Exception
Assumptions:
1) An OR mapping exists for the userObjectClass and all non-basic type
attributes in the mapping file.
2) PrimaryKey class exists (refer to Terminology section).
findByPrimaryKey
in interface DBInterface
primaryKey
- The primaryKey based on which user object of type
userObjectClass is returned.userObjectClass
- The user object class type (ex. HashMap.class
gives HashMap class type).level
- The maximum recursion depth.java.lang.Exception
- if any databse problems in finding the user object.ORDBMapper.findByPrimaryKey(Object,Class)
,
ORDBMapper.findByAttributes(AttrValMap,Class)
,
ORDBMapper.findByQuery(String,Class)
,
ORDBMapper.findAll(Class)
public java.util.Collection findByAttributes(AttrValMap attrValMap, java.lang.Class userObjectClass) throws java.lang.Exception
Assumptions:
1) An OR mapping exists for this userObjectClass in mapping file.
2) AttrValMap attributes are valid userObjectClass attribute names
(specified in mapping file).
3) AttrValMap contains atleast one entry.
findByAttributes
in interface DBInterface
attrValMap
- Map of attributes and values based on which
user objects of type userObjectClass is returned.userObjectClass
- The user object class type (ex. HashMap.class
gives HashMap class type).java.lang.Exception
- if any databse problems in finding the user objects.ORDBMapper.findAll(Class)
,
ORDBMapper.findByQuery(String,Class)
,
ORDBMapper.findByPrimaryKey(Object,Class)
,
ORDBMapper.findByPrimaryKey(Object,Class,int)
public java.util.Collection findByQuery(java.lang.String query, java.lang.Class userObjectClass) throws java.lang.Exception
Assumptions:
1) An OR mapping exists for this userObjectClass in mapping file.
2) Valid user SQL query, which should return rows that contains all
the attributes/columns in userObjectClass.
findByQuery
in interface DBInterface
query
- User SQL query.userObjectClass
- The user object class type (ex. HashMap.class
gives HashMap class type).java.lang.Exception
- if any databse problems in finding the user
objects or executing the query.ORDBMapper.findByAttributes(AttrValMap,Class)
,
ORDBMapper.findAll(Class)
,
ORDBMapper.findByPrimaryKey(Object,Class)
,
ORDBMapper.findByPrimaryKey(Object,Class,int)
public java.util.Collection findAll(java.lang.Class userObjectClass) throws java.lang.Exception
Assumptions:
1) An OR mapping exists for this userObjectClass in mapping file.
findAll
in interface DBInterface
userObjectClass
- The user object class type (ex.
HashMap.class gives HashMap class type).java.lang.Exception
- if any databse problems in finding the user objects.ORDBMapper.findByAttributes(AttrValMap,Class)
,
ORDBMapper.findByQuery(String,Class)
,
ORDBMapper.findByPrimaryKey(Object,Class)
,
ORDBMapper.findByPrimaryKey(Object,Class,int)
public java.util.Collection findPrimaryKeysByAttributes(AttrValMap attrValMap, java.lang.Class userObjectClass) throws java.lang.Exception
Assumptions:
1) An OR mapping exists for the userObjectClass in mapping file.
2) AttrValMap attributes are valid userObjectClass attribute names
(specified in mapping file).
3) AttrValMap contains atleast one entry.
4) primaryKey class exists.
findPrimaryKeysByAttributes
in interface DBInterface
attrValMap
- Map of attributes and values based on which
primary key objects associated with userObjectClass
is returned.userObjectClass
- The user object class type (ex. HashMap.class
gives HashMap class type).java.lang.Exception
- if any databse problems in finding the primary keys.ORDBMapper.findPrimaryKeysByQuery(String,Class)
,
ORDBMapper.findAllPrimaryKeys(Class)
public java.util.Collection findPrimaryKeysByQuery(java.lang.String query, java.lang.Class userObjectClass) throws java.lang.Exception
Assumptions:
1) An OR mapping exists for this userObjectClass in mapping file.
2) Valid user SQL query, which should return rows that contains
all the key attributes/columns in userObjectClass.
3) primaryKey class exists.
findPrimaryKeysByQuery
in interface DBInterface
query
- User SQL query.userObjectClass
- The user object class type (ex. HashMap.class
gives HashMap class type).java.lang.Exception
- if any databse problems in finding the primary
keys or executing the query.ORDBMapper.findPrimaryKeysByAttributes(AttrValMap,Class)
,
ORDBMapper.findAllPrimaryKeys(Class)
public java.util.Collection findAllPrimaryKeys(java.lang.Class userObjectClass) throws java.lang.Exception
Assumptions:
1) An OR mapping exists for this userObjectClass in mapping file.
findAllPrimaryKeys
in interface DBInterface
userObjectClass
- The user object class type (ex. HashMap.class
gives HashMap class type).java.lang.Exception
- if any databse problems in finding the primary
keys or executing the query.ORDBMapper.findPrimaryKeysByAttributes(AttrValMap,Class)
,
ORDBMapper.findPrimaryKeysByQuery(String,Class)
public void beginTransaction() throws java.lang.Exception
beginTransaction
in interface DBInterface
java.lang.Exception
- Thrown if the thread is already associated
with a transaction or no available resource.ORDBMapper.isActiveTransaction()
,
ORDBMapper.commitTransaction()
,
ORDBMapper.rollbackTransaction()
public boolean isActiveTransaction()
isActiveTransaction
in interface DBInterface
ORDBMapper.beginTransaction()
,
ORDBMapper.commitTransaction()
,
ORDBMapper.rollbackTransaction()
public void commitTransaction() throws java.lang.Exception
commitTransaction
in interface DBInterface
java.lang.Exception
- Thrown if the thread is not associated with a
transaction or any databse problems during database
commit.ORDBMapper.rollbackTransaction()
,
ORDBMapper.beginTransaction()
,
ORDBMapper.isActiveTransaction()
public void rollbackTransaction() throws java.lang.Exception
rollbackTransaction
in interface DBInterface
java.lang.Exception
- Thrown if the thread is not associated with a
transaction or any databse problems during database
rollback.ORDBMapper.commitTransaction()
,
ORDBMapper.beginTransaction()
,
ORDBMapper.isActiveTransaction()
public java.sql.ResultSet executeQuery(java.lang.String query) throws java.lang.Exception
executeQuery
in interface DBInterface
query
- typically this is a static SQL SELECT statement.java.lang.Exception
- if a database error occurs.Statement.executeQuery(String)
public int executeUpdate(java.lang.String query) throws java.lang.Exception
executeUpdate
in interface DBInterface
query
- an SQL INSERT, UPDATE or DELETE statement or an
SQL statement that returns nothingjava.lang.Exception
- if a database error occurs.Statement.executeUpdate(String)
public DataSource getDataSource()
public void setDataSource(DataSource ds)
public ORMappingInfo getORMappingInfo()
public void setORMappingInfo(ORMappingInfo mi)
public ORMapEntry findMapEntry(java.lang.Object data)
data
- User object.public ORMapEntry findMapEntry(java.lang.Class cls)
cls
- User class.public void validatePrimaryKeyClass(ORMapEntry mapEntry, java.lang.Object primaryKey) throws java.lang.Exception
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |