|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.gjt.tw.dbobjects.DBManager
DBManager is responsible for the access to the database. It has to be itialized before the first use with a set of properties. Most of its functions are used by StorableObject and don't need to be called by a high level application.
The most important functions are insert, update, and delete for manipulating data stored in the database. Each of these function take an ObjectMapping as argument to identify which table has to be changed using which SQL string.
The methods getByField and getByWhereClause take the name of an object field, or a WHERE clause, respectively, as arguments. They create objects according to the information stored in the ObjectMapping given.
There are two kinds of get-methods: one kind returns arrays of objects. These arrays can be cast directly to an array of the real class of the objects. Use these methods to get lists of objects if you do not save the resulting list for further uses and do not change the number of objects.
The other kind of get-methods return vectors of objects. Use these methods if you are developping an application with single access to a database. Under these circumstances you can read the objects from the database once and add and remove objects during lifetime of your program without further calls to fetch the objects again.
Method Summary | |
static boolean |
delete(ObjectMapping mapping,
java.lang.Object[] parameters)
Deletes an object that is stored in the database. |
static void |
destroy()
Detroys the connection to the database and gives used resources free. |
static StorableObject[] |
getAll(ObjectMapping mapping)
Retrieves all objects stored in a table of the database and returns an array of objects. |
static StorableObject[] |
getAll(ObjectMapping mapping,
java.lang.String appendedSqlString)
Retrieves all objects stored in a table of the database and returns an array of objects. |
static java.util.Vector |
getAllVector(ObjectMapping mapping)
Retrieves all objects stored in a table of the database and returns a vector of all objects.. |
static java.util.Vector |
getAllVector(ObjectMapping mapping,
java.lang.String appendedSqlString)
Retrieves all objects stored in a table of the database and returns a vector of all objects. |
static IBroker |
getBroker()
Returns the current database connection broker. |
static StorableObject[] |
getByField(ObjectMapping mapping,
java.lang.String fieldName,
java.lang.Object fieldContent)
Retrieves the objects stored in the database for which a given field corresponds to the content given and returns an array of objects. |
static StorableObject[] |
getByField(ObjectMapping mapping,
java.lang.String fieldName,
java.lang.Object fieldContent,
java.lang.String appendedSqlString)
Retrieves the objects stored in the database for which a given field corresponds to the content given and returns an array of objects. |
static java.util.Vector |
getByFieldVector(ObjectMapping mapping,
java.lang.String fieldName,
java.lang.Object fieldContent)
Retrieves the objects stored in the database for which a given field corresponds to the content given and returns a vector of all objects. |
static java.util.Vector |
getByFieldVector(ObjectMapping mapping,
java.lang.String fieldName,
java.lang.Object fieldContent,
java.lang.String appendedSqlString)
Retrieves the objects stored in the database for which a given field corresponds to the content given and returns a vector of all objects. |
static StorableObject[] |
getByWhereClause(ObjectMapping mapping,
java.lang.String whereClause)
Retrieves the objects stored in the database an SQL SELECT returns given a WHERE clause and returns an array of objects. |
static java.util.Vector |
getByWhereClauseVector(ObjectMapping mapping,
java.lang.String whereClause)
Retrieves the objects stored in the database an SQL SELECT returns given a WHERE clause and returns a vector of all objects. |
static void |
handleException(java.lang.Exception e)
This method is called for any exception happened during database access. |
static void |
init(IBroker broker)
init use init if you want to access the initialized variable setBroker can be used instead of init |
static long |
insert(ObjectMapping mapping,
java.lang.Object[] parameters)
Executes an SQL INSERT string generated by the object mapping. |
static boolean |
isInitialized()
Checks whether the database manager has already been initialized. |
static void |
setBroker(IBroker ibroker)
Sets the connection broker |
static boolean |
update(ObjectMapping mapping,
java.lang.Object[] parameters)
Updates an object that is stored in the database. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static void setBroker(IBroker ibroker)
ibroker
- The new broker valuepublic static StorableObject[] getAll(ObjectMapping mapping) throws DatabaseException, ObjectException
mapping
- Description of ParameterDatabaseException
- Description of ExceptionObjectException
- Description of Exceptionpublic static StorableObject[] getAll(ObjectMapping mapping, java.lang.String appendedSqlString) throws DatabaseException, ObjectException
appendedSqlString
- A string that is appended after the where
clause. Might contain "order by", "group by", etc statements.mapping
- Description of ParameterDatabaseException
- Description of ExceptionObjectException
- Description of Exceptionpublic static java.util.Vector getAllVector(ObjectMapping mapping) throws DatabaseException, ObjectException
mapping
- Description of ParameterDatabaseException
- Description of ExceptionObjectException
- Description of Exceptionpublic static java.util.Vector getAllVector(ObjectMapping mapping, java.lang.String appendedSqlString) throws DatabaseException, ObjectException
appendedSqlString
- A string that is appended after the where
clause. Might contain "order by", "group by", etc statements.mapping
- Description of ParameterDatabaseException
- Description of ExceptionObjectException
- Description of Exceptionpublic static IBroker getBroker()
public static StorableObject[] getByField(ObjectMapping mapping, java.lang.String fieldName, java.lang.Object fieldContent) throws DatabaseException, ObjectException
fieldName
- Name of the object's field (not the name of
the database column!)fieldContent
- Object containing the value that is
searched for. Simple types have to wrapped by their corresponding
class. Example: Integer integer = new Integer (i).mapping
- Description of ParameterDatabaseException
- Description of ExceptionObjectException
- Description of Exceptionpublic static StorableObject[] getByField(ObjectMapping mapping, java.lang.String fieldName, java.lang.Object fieldContent, java.lang.String appendedSqlString) throws DatabaseException, ObjectException
fieldName
- Name of the object's field (not the name of
the database column!)fieldContent
- Object containing the value that is
searched for. Simple types have to wrapped by their corresponding
class. Example: Integer integer = new Integer (i).appendedSqlString
- string appended behind the WHERE clause
(e.g. "ORDER BY", etc).mapping
- Description of ParameterDatabaseException
- Description of ExceptionObjectException
- Description of Exceptionpublic static java.util.Vector getByFieldVector(ObjectMapping mapping, java.lang.String fieldName, java.lang.Object fieldContent) throws DatabaseException, ObjectException
fieldName
- Name of the object's field (not the name of
the database column!)fieldContent
- Object containing the value that is
searched for. Simple types have to wrapped by their corresponding
class. Example: Integer integer = new Integer (i).mapping
- Description of ParameterDatabaseException
- Description of ExceptionObjectException
- Description of Exceptionpublic static java.util.Vector getByFieldVector(ObjectMapping mapping, java.lang.String fieldName, java.lang.Object fieldContent, java.lang.String appendedSqlString) throws DatabaseException, ObjectException
fieldName
- Name of the object's field (not the name of
the database column!)fieldContent
- Object containing the value that is
searched for. Simple types have to wrapped by their corresponding
class. Example: Integer integer = new Integer (i).appendedSqlString
- string appended behind the WHERE clause
(e.g. "ORDER BY", etc).mapping
- Description of ParameterDatabaseException
- Description of ExceptionObjectException
- Description of Exceptionpublic static StorableObject[] getByWhereClause(ObjectMapping mapping, java.lang.String whereClause) throws DatabaseException, ObjectException
whereClause
- The WHERE clause as used by the select SQL
string.mapping
- Description of ParameterDatabaseException
- Description of ExceptionObjectException
- Description of Exceptionpublic static java.util.Vector getByWhereClauseVector(ObjectMapping mapping, java.lang.String whereClause) throws DatabaseException, ObjectException
whereClause
- The WHERE clause as used by the select SQL
string.mapping
- Description of ParameterDatabaseException
- Description of ExceptionObjectException
- Description of Exceptionpublic static boolean isInitialized()
public static boolean delete(ObjectMapping mapping, java.lang.Object[] parameters) throws DatabaseException
mapping
- The object mappingparameters
- An array of objects used as parametersDatabaseException
- Description of Exceptionpublic static void destroy() throws DatabaseException
DatabaseException
- Description of Exceptionpublic static void handleException(java.lang.Exception e)
e
- the exception that happenedpublic static void init(IBroker broker)
broker
- Description of Parameterpublic static long insert(ObjectMapping mapping, java.lang.Object[] parameters) throws DatabaseException
mapping
- the object mappingparameters
- An array of objects used as parametersDatabaseException
- Description of Exceptionpublic static boolean update(ObjectMapping mapping, java.lang.Object[] parameters) throws DatabaseException
mapping
- The object mappingparameters
- An array of objects used as parametersDatabaseException
- Description of Exception
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |