Java Doc for GenericDatabase.java in  » Database-ORM » beankeeper » hu » netmind » persistence » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » beankeeper » hu.netmind.persistence 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


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$



Constructor Summary
public  GenericDatabase()
    

Method Summary
protected  DatabaseStatisticsaddColumn(Connection connection, String tableName, String columnName, String columnType)
     Add a column to a table.
protected  DatabaseStatisticsalterTable(Connection connection, String tableName, List removedAttributes, List addedAttributes, Map attributeTypes, List keyAttributeNames)
     Alter the table.
protected  DatabaseStatisticscreateIndexes(Connection connection, String tableName, Map attributeTypes)
     Create indexes to the given attributes.
protected  DatabaseStatisticscreateTable(Connection connection, String tableName, Map attributeTypes, List keyAttributeNames)
     Create table with given name, attribute types, and keys.
protected  DatabaseStatisticsdropColumn(Connection connection, String tableName, String columnName)
     Drop a column from a table.
protected  DatabaseStatisticsdropTable(Connection connection, String tableName)
     Drop the table with given name.
public  DatabaseStatisticsensureTable(Connection connection, String tableName, Map attributeTypes, List keyAttributeNames, boolean create)
     Ensure that table exists in database.
protected  voidexecuteUpdate(Connection connection, String statement)
     Execute update statement.
protected  StringgetAddColumnStatement(String tableName, String columnName, String columnType)
     Get the statement to add a column to a table.
protected  ClassgetAttributeType(String tableName, String attributeName)
    
protected  MapgetAttributes(String tableName)
    
protected  StringgetCountStatement(String stmt)
     Get the count statement for the given statement.
protected  StringgetCreateIndexName(Connection connection, String tableName, String field)
     Get an unused index name.
protected  StringgetCreateIndexStatement(String indexName, String tableName, String field, Class fieldClass)
     Get index creation statement for a given table and field.
protected  StringgetCreateTableStatement(Connection connection, String tableName)
     Get the create table statement before the attributes part.
protected  StringgetDropColumnStatement(String tableName, String columnName)
     Get the statement to drop a column.
protected  StringgetInsertStatement(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  ObjectgetJavaValue(Object value, int type, Class javaType)
     Convert incoming value from database into java format.
protected  StringgetLimitStatement(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  StringgetQuerySource(TableTerm term, Set queryColumns, List types)
     Assemble the query columns of a given term.
protected  StringgetQuerySource(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  StringgetRemoveStatement(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  intgetSQLType(Class type)
     Get the sql type string for a class.
protected  StringgetSQLTypeName(int sqltype)
     Get the class for an sql type.
protected  ObjectgetSQLValue(Object value)
     Convert incoming values from java into database acceptable format.
protected  StringgetSaveStatement(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  intgetTableAttributeType(ResultSet rs)
     Override this method to get different types for attributes than the database reports.
protected  HashMapgetTableAttributeTypes(Connection connection, String tableName)
     Get the data types of a given table.
protected  StringgetTableDeclaration(String tableName, String alias)
     Get the table declaration for a select statment.
public  DatabaseStatisticsinsert(Connection connection, String tableName, Map attributes)
     Insert an object into the database.
protected  voidprepareResultSet(ResultSet rs, Limits limits)
     Prepare the result set to be iterated.
protected  voidprepareStatement(PreparedStatement pstmt, Limits limits)
     Prepare the sql statment to be executed.
public  voidrelease(ConnectionSource source)
     The generic implementation holds no resources, so do nothing.
public  DatabaseStatisticsremove(Connection connection, String tableName, Map attributes)
     Remove an entry from database.
public  DatabaseStatisticssave(Connection connection, String tableName, Map keys, Map attributes)
     Modifies an object already in database with given fields.
public  DatabaseStatisticssearch(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  ExpressiontransformExpression(Expression expr)
     Transform the expression.


Constructor Detail
GenericDatabase
public GenericDatabase()(Code)




Method Detail
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.



getAttributeType
protected Class getAttributeType(String tableName, String attributeName)(Code)



getAttributes
protected Map getAttributes(String tableName)(Code)



getCountStatement
protected String getCountStatement(String stmt)(Code)
Get the count statement for the given statement.



getCreateIndexName
protected String getCreateIndexName(Connection connection, String tableName, String field)(Code)
Get an unused index name.



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.



prepareResultSet
protected void prepareResultSet(ResultSet rs, Limits limits) throws SQLException(Code)
Prepare the result set to be iterated.



prepareStatement
protected void prepareStatement(PreparedStatement pstmt, Limits limits) throws SQLException(Code)
Prepare the sql statment to be executed.



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.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.