| java.lang.Object hu.netmind.persistence.GenericDatabase
All known Subclasses: hu.netmind.persistence.MysqlDatabaseImpl, hu.netmind.persistence.OracleDatabaseImpl, hu.netmind.persistence.HSQLDatabaseImpl, hu.netmind.persistence.PostgresDatabaseImpl, hu.netmind.persistence.DerbyDatabaseImpl,
GenericDatabase | public class GenericDatabase implements DatabaseImplementation(Code) | | This is a generic database implementation. It contains no optimization,
and tries to be as generic with types and sql syntax as possible, this also
means, it cannot handle limits and offsets, which causes all
results to be returned, even with lazy lists.
author: Brautigam Robert version: Revision: $Revision$ |
Method Summary | |
protected DatabaseStatistics | addColumn(Connection connection, String tableName, String columnName, String columnType) Add a column to a table. | protected DatabaseStatistics | alterTable(Connection connection, String tableName, List removedAttributes, List addedAttributes, Map attributeTypes, List keyAttributeNames) Alter the table. | protected DatabaseStatistics | createIndexes(Connection connection, String tableName, Map attributeTypes) Create indexes to the given attributes. | protected DatabaseStatistics | createTable(Connection connection, String tableName, Map attributeTypes, List keyAttributeNames) Create table with given name, attribute types, and keys. | protected DatabaseStatistics | dropColumn(Connection connection, String tableName, String columnName) Drop a column from a table. | protected DatabaseStatistics | dropTable(Connection connection, String tableName) Drop the table with given name. | public DatabaseStatistics | ensureTable(Connection connection, String tableName, Map attributeTypes, List keyAttributeNames, boolean create) Ensure that table exists in database. | protected void | executeUpdate(Connection connection, String statement) Execute update statement. | protected String | getAddColumnStatement(String tableName, String columnName, String columnType) Get the statement to add a column to a table. | protected Class | getAttributeType(String tableName, String attributeName) | protected Map | getAttributes(String tableName) | protected String | getCountStatement(String stmt) Get the count statement for the given statement. | protected String | getCreateIndexName(Connection connection, String tableName, String field) Get an unused index name. | protected String | getCreateIndexStatement(String indexName, String tableName, String field, Class fieldClass) Get index creation statement for a given table and field. | protected String | getCreateTableStatement(Connection connection, String tableName) Get the create table statement before the attributes part. | protected String | getDropColumnStatement(String tableName, String columnName) Get the statement to drop a column. | protected String | getInsertStatement(String tableName, List attributeNames) Make an insert statement for given table, id and attributes.
Override this method in a subclass for a non-generic behaviour.
The attributes' placeholders must be in the same order as given
by the attributeNames list.
Parameters: tableName - The table to insert attributes to. Parameters: attributeNames - The attributes that will be inserted. | protected Object | getJavaValue(Object value, int type, Class javaType) Convert incoming value from database into java format. | protected String | getLimitStatement(String statement, Limits limits, List types) Get the limit component of statement, if it can be expressed in
the current database with simple statement part. | protected String | getQuerySource(TableTerm term, Set queryColumns, List types) Assemble the query columns of a given term. | protected String | getQuerySource(QueryStatement stmt, List types) Assemble the query columns of select statement.
Parameters: stmt - The statement to get query source from. Parameters: types - The type list to fill in. | protected String | getRemoveStatement(String tableName, List attributeNames) Make a remove statement for given table and attributes.
Override this method in a subclass for a non-generic behaviour.
The attributes' placeholders must be in the same order as given
by the attributeNames list.
Parameters: tableName - The table to remove attributes from. Parameters: attributeNames - The attributes that will be search for by the remove. | protected int | getSQLType(Class type) Get the sql type string for a class. | protected String | getSQLTypeName(int sqltype) Get the class for an sql type. | protected Object | getSQLValue(Object value) Convert incoming values from java into database acceptable format. | protected String | getSaveStatement(String tableName, List keyNames, List attributeNames, Map keys) Make a save statement for given table, id and changed attributes.
Override this method in a subclass for a non-generic behaviour.
The attributes' placeholders must be in the same order as given
by the attributeNames list.
Parameters: tableName - The table to save attributes to. Parameters: keyNames - The keys of object to save (All object entries have keys). Parameters: attributeNames - The attributes that will change.the statement. Parameters: keys - Keys. | protected int | getTableAttributeType(ResultSet rs) Override this method to get different types for attributes than
the database reports. | protected HashMap | getTableAttributeTypes(Connection connection, String tableName) Get the data types of a given table. | protected String | getTableDeclaration(String tableName, String alias) Get the table declaration for a select statment. | public DatabaseStatistics | insert(Connection connection, String tableName, Map attributes) Insert an object into the database. | protected void | prepareResultSet(ResultSet rs, Limits limits) Prepare the result set to be iterated. | protected void | prepareStatement(PreparedStatement pstmt, Limits limits) Prepare the sql statment to be executed. | public void | release(ConnectionSource source) The generic implementation holds no resources, so do nothing. | public DatabaseStatistics | remove(Connection connection, String tableName, Map attributes) Remove an entry from database. | public DatabaseStatistics | save(Connection connection, String tableName, Map keys, Map attributes) Modifies an object already in database with given fields. | public DatabaseStatistics | search(Connection connection, QueryStatement stmt, Limits limits, SearchResult searchResult) Select objects from database as ordered list of attribute maps.
Parameters: connection - The connection to run statements in. Parameters: stmt - The query statement. Parameters: limits - The limits of the result. | protected Expression | transformExpression(Expression expr) Transform the expression. |
GenericDatabase | public GenericDatabase()(Code) | | |
addColumn | protected DatabaseStatistics addColumn(Connection connection, String tableName, String columnName, String columnType)(Code) | | Add a column to a table.
Parameters: connection - The connection object. Parameters: tableName - The table to drop column from. Parameters: columnName - The column to create. Parameters: columnType - The column type to create. |
alterTable | protected DatabaseStatistics alterTable(Connection connection, String tableName, List removedAttributes, List addedAttributes, Map attributeTypes, List keyAttributeNames)(Code) | | Alter the table. Implementation: Not all databases support
altering multiple columns, so all columns are separately modified.
Parameters: connection - The connection object. Parameters: tableName - The table name. Parameters: removedAttributes - Attribute names which should be removed. Parameters: addedAttributes - Attribute names which should be added. Parameters: attributeTypes - Types in form of Classes to given names. |
createIndexes | protected DatabaseStatistics createIndexes(Connection connection, String tableName, Map attributeTypes)(Code) | | Create indexes to the given attributes.
Parameters: connection - The SQL connection. Parameters: tableName - The table to create indexes to. Parameters: attributeTypes - The attributes and their types to create indexes to. |
createTable | protected DatabaseStatistics createTable(Connection connection, String tableName, Map attributeTypes, List keyAttributeNames)(Code) | | Create table with given name, attribute types, and keys.
This method is not called directly, but from ensureTable .
Parameters: tableName - The table to create. Parameters: attributeTypes - The attribute names together with whichjava class they should hold. |
dropColumn | protected DatabaseStatistics dropColumn(Connection connection, String tableName, String columnName)(Code) | | Drop a column from a table.
Parameters: connection - The connection object. Parameters: tableName - The table to drop column from. Parameters: columnName - The column to drop. |
dropTable | protected DatabaseStatistics dropTable(Connection connection, String tableName)(Code) | | Drop the table with given name.
This method is not called directly, but from ensureTable .
Parameters: tableName - The table to drop. |
ensureTable | public DatabaseStatistics ensureTable(Connection connection, String tableName, Map attributeTypes, List keyAttributeNames, boolean create)(Code) | | Ensure that table exists in database. Implementation does
not check keys. If keys differ, this implementation will not correct
the problem. Column renames are not detected, if a column is renamed,
the old column will be dropped and a new column will be created.
Parameters: tableName - The table to check. Parameters: attributeTypes - The attribute names together with whichjava class they should hold. Parameters: keyAttributeNames - The keys of table. |
executeUpdate | protected void executeUpdate(Connection connection, String statement)(Code) | | Execute update statement. Simply and safely execute the
given statement.
Parameters: connection - The connection to execute statement on. Parameters: statement - The statement to execute. |
getAddColumnStatement | protected String getAddColumnStatement(String tableName, String columnName, String columnType)(Code) | | Get the statement to add a column to a table.
|
getCountStatement | protected String getCountStatement(String stmt)(Code) | | Get the count statement for the given statement.
|
getCreateIndexStatement | protected String getCreateIndexStatement(String indexName, String tableName, String field, Class fieldClass)(Code) | | Get index creation statement for a given table and field.
The statement to use, or null, of no such index can becreated. |
getCreateTableStatement | protected String getCreateTableStatement(Connection connection, String tableName)(Code) | | Get the create table statement before the attributes part.
|
getDropColumnStatement | protected String getDropColumnStatement(String tableName, String columnName)(Code) | | Get the statement to drop a column.
|
getInsertStatement | protected String getInsertStatement(String tableName, List attributeNames)(Code) | | Make an insert statement for given table, id and attributes.
Override this method in a subclass for a non-generic behaviour.
The attributes' placeholders must be in the same order as given
by the attributeNames list.
Parameters: tableName - The table to insert attributes to. Parameters: attributeNames - The attributes that will be inserted. An SQL insert statement specific to database backend. |
getJavaValue | protected Object getJavaValue(Object value, int type, Class javaType)(Code) | | Convert incoming value from database into java format.
|
getLimitStatement | protected String getLimitStatement(String statement, Limits limits, List types)(Code) | | Get the limit component of statement, if it can be expressed in
the current database with simple statement part.
Parameters: limits - The limits to apply. |
getQuerySource | protected String getQuerySource(TableTerm term, Set queryColumns, List types)(Code) | | Assemble the query columns of a given term.
|
getQuerySource | protected String getQuerySource(QueryStatement stmt, List types)(Code) | | Assemble the query columns of select statement.
Parameters: stmt - The statement to get query source from. Parameters: types - The type list to fill in. Each queried column'stype should be inserted into this list in order. The columns part of the select statement. |
getRemoveStatement | protected String getRemoveStatement(String tableName, List attributeNames)(Code) | | Make a remove statement for given table and attributes.
Override this method in a subclass for a non-generic behaviour.
The attributes' placeholders must be in the same order as given
by the attributeNames list.
Parameters: tableName - The table to remove attributes from. Parameters: attributeNames - The attributes that will be search for by the remove. An SQL insert statement specific to database backend. |
getSQLType | protected int getSQLType(Class type)(Code) | | Get the sql type string for a class.
|
getSQLTypeName | protected String getSQLTypeName(int sqltype)(Code) | | Get the class for an sql type.
|
getSQLValue | protected Object getSQLValue(Object value)(Code) | | Convert incoming values from java into database acceptable format.
|
getSaveStatement | protected String getSaveStatement(String tableName, List keyNames, List attributeNames, Map keys)(Code) | | Make a save statement for given table, id and changed attributes.
Override this method in a subclass for a non-generic behaviour.
The attributes' placeholders must be in the same order as given
by the attributeNames list.
Parameters: tableName - The table to save attributes to. Parameters: keyNames - The keys of object to save (All object entries have keys). Parameters: attributeNames - The attributes that will change.the statement. Parameters: keys - Keys. An SQL save/update statement specific to database backend. |
getTableAttributeType | protected int getTableAttributeType(ResultSet rs) throws SQLException(Code) | | Override this method to get different types for attributes than
the database reports.
|
getTableAttributeTypes | protected HashMap getTableAttributeTypes(Connection connection, String tableName) throws SQLException(Code) | | Get the data types of a given table.
A map of names with the sql type number as value. |
getTableDeclaration | protected String getTableDeclaration(String tableName, String alias)(Code) | | Get the table declaration for a select statment.
|
insert | public DatabaseStatistics insert(Connection connection, String tableName, Map attributes)(Code) | | Insert an object into the database.
Parameters: tableName - The table to save attributes to. Parameters: id - The id of object to save (All object entries have an id). Parameters: attributes - The attributes in form of name:value pairs. |
release | public void release(ConnectionSource source)(Code) | | The generic implementation holds no resources, so do nothing.
|
remove | public DatabaseStatistics remove(Connection connection, String tableName, Map attributes)(Code) | | Remove an entry from database.
Parameters: tableName - The table to remove object from. Parameters: attributes - The attributes which identify the object.Equality is assumed with each attribute and it's value. |
save | public DatabaseStatistics save(Connection connection, String tableName, Map keys, Map attributes)(Code) | | Modifies an object already in database with given fields.
Parameters: tableName - The table to save attributes to. Parameters: id - The id of object to save (All object entries have an id). Parameters: attributes - The attributes in form of name:value pairs. |
search | public DatabaseStatistics search(Connection connection, QueryStatement stmt, Limits limits, SearchResult searchResult)(Code) | | Select objects from database as ordered list of attribute maps.
Parameters: connection - The connection to run statements in. Parameters: stmt - The query statement. Parameters: limits - The limits of the result. (Offset, maximum result count) Parameters: result - The result object. |
transformExpression | protected Expression transformExpression(Expression expr)(Code) | | Transform the expression. This method is called on each subsequent
expressions too, so implementation does not have to be recursive.
Parameters: expr - The expression to possibly transform. A transformed expression. |
|
|