Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.objectstyle.cayenne.dba
Class JdbcAdapter  view JdbcAdapter download JdbcAdapter.java

java.lang.Object
  extended byorg.objectstyle.cayenne.dba.JdbcAdapter
All Implemented Interfaces:
DbAdapter

public class JdbcAdapter
extends java.lang.Object
implements DbAdapter

A generic DbAdapter implementation. Can be used as a default adapter or as a superclass of a concrete adapter implementation.


Field Summary
protected  org.objectstyle.cayenne.access.types.ExtendedTypeMap extendedTypes
           
protected  PkGenerator pkGenerator
           
protected  boolean supportsBatchUpdates
           
protected  TypesHandler typesHandler
           
 
Fields inherited from interface org.objectstyle.cayenne.dba.DbAdapter
availableAdapterClassNames, DB2, FIREBIRD, HSQLDB, JDBC, MYSQL, ORACLE, POSTGRES, SYBASE
 
Constructor Summary
JdbcAdapter()
           
 
Method Summary
 void bindParameter(java.sql.PreparedStatement statement, java.lang.Object object, int pos, int sqlType, int precision)
          Binds an object value to PreparedStatement's numbered parameter.
 org.objectstyle.cayenne.map.DbAttribute buildAttribute(java.lang.String name, java.lang.String typeName, int type, int size, int precision, boolean allowNulls)
          Creates and returns a DbAttribute based on supplied parameters (usually obtained from database meta data).
protected  void configureExtendedTypes(org.objectstyle.cayenne.access.types.ExtendedTypeMap map)
          Installs appropriate ExtendedTypes as converters for passing values between JDBC and Java layers.
 org.objectstyle.cayenne.access.DataNode createDataNode(java.lang.String name)
          Creates an instance of DataNode class.
 java.lang.String createFkConstraint(org.objectstyle.cayenne.map.DbRelationship rel)
          Returns a SQL string that can be used to create a foreign key constraint for the relationship.
protected  PkGenerator createPkGenerator()
          Creates and returns a primary key generator.
 java.lang.String createTable(org.objectstyle.cayenne.map.DbEntity ent)
          Returns a SQL string that can be used to create database table corresponding to ent parameter.
 java.lang.String dropTable(org.objectstyle.cayenne.map.DbEntity ent)
          Returns a SQL string to drop a table corresponding to ent DbEntity.
 java.lang.String[] externalTypesForJdbcType(int type)
          Returns an array of RDBMS types that can be used with JDBC type.
 org.objectstyle.cayenne.access.types.ExtendedTypeMap getExtendedTypes()
          Returns a map of ExtendedTypes that is used to translate values between Java and JDBC layer.
 PkGenerator getPkGenerator()
          Returns primary key generator associated with this DbAdapter.
 org.objectstyle.cayenne.access.trans.QualifierTranslator getQualifierTranslator(org.objectstyle.cayenne.access.trans.QueryAssembler queryAssembler)
          Creates and returns a default implementation of a qualifier translator.
 org.objectstyle.cayenne.access.QueryTranslator getQueryTranslator(org.objectstyle.cayenne.query.Query query)
          Creates and returns a QueryTranslator appropriate for the specified query parameter.
protected  java.lang.Class queryTranslatorClass(org.objectstyle.cayenne.query.Query q)
          Returns a class of the query translator that should be used to translate the query q to SQL.
 void setSupportsBatchUpdates(boolean flag)
           
 boolean shouldRunBatchQuery(org.objectstyle.cayenne.access.DataNode node, java.sql.Connection con, org.objectstyle.cayenne.query.BatchQuery query, org.objectstyle.cayenne.access.OperationObserver delegate)
          Always returns true, letting DataNode to handle the query.
 boolean supportsBatchUpdates()
          Returns true if the target database supports batch updates.
 boolean supportsFkConstraints()
          Returns true.
 java.lang.String tableTypeForTable()
          Returns the name of the table type (as returned by DatabaseMetaData.getTableTypes) for a simple user table.
 java.lang.String tableTypeForView()
          Returns the name of the table type (as returned by DatabaseMetaData.getTableTypes) for a view table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pkGenerator

protected PkGenerator pkGenerator

typesHandler

protected TypesHandler typesHandler

extendedTypes

protected org.objectstyle.cayenne.access.types.ExtendedTypeMap extendedTypes

supportsBatchUpdates

protected boolean supportsBatchUpdates
Constructor Detail

JdbcAdapter

public JdbcAdapter()
Method Detail

configureExtendedTypes

protected void configureExtendedTypes(org.objectstyle.cayenne.access.types.ExtendedTypeMap map)
Installs appropriate ExtendedTypes as converters for passing values between JDBC and Java layers. Called from default constructor.


createPkGenerator

protected PkGenerator createPkGenerator()
Creates and returns a primary key generator. This factory method should be overriden by JdbcAdapter subclasses to provide custom implementations of PKGenerator.


getPkGenerator

public PkGenerator getPkGenerator()
Returns primary key generator associated with this DbAdapter.

Specified by:
getPkGenerator in interface DbAdapter

getQueryTranslator

public org.objectstyle.cayenne.access.QueryTranslator getQueryTranslator(org.objectstyle.cayenne.query.Query query)
                                                                  throws java.lang.Exception
Description copied from interface: DbAdapter
Creates and returns a QueryTranslator appropriate for the specified query parameter. Sets translator "query" and "adapter" property.

This factory method allows subclasses to specify their own translators that implement vendor-specific optimizations.

Specified by:
getQueryTranslator in interface DbAdapter

queryTranslatorClass

protected java.lang.Class queryTranslatorClass(org.objectstyle.cayenne.query.Query q)
Returns a class of the query translator that should be used to translate the query q to SQL. Exists mainly for the benefit of subclasses that can override this method providing their own translator.


supportsFkConstraints

public boolean supportsFkConstraints()
Returns true.

Specified by:
supportsFkConstraints in interface DbAdapter

dropTable

public java.lang.String dropTable(org.objectstyle.cayenne.map.DbEntity ent)
Returns a SQL string to drop a table corresponding to ent DbEntity.

Specified by:
dropTable in interface DbAdapter

createTable

public java.lang.String createTable(org.objectstyle.cayenne.map.DbEntity ent)
Returns a SQL string that can be used to create database table corresponding to ent parameter.

Specified by:
createTable in interface DbAdapter

createFkConstraint

public java.lang.String createFkConstraint(org.objectstyle.cayenne.map.DbRelationship rel)
Returns a SQL string that can be used to create a foreign key constraint for the relationship.

Specified by:
createFkConstraint in interface DbAdapter

externalTypesForJdbcType

public java.lang.String[] externalTypesForJdbcType(int type)
Description copied from interface: DbAdapter
Returns an array of RDBMS types that can be used with JDBC type. Valid types are defined in java.sql.Types.

Specified by:
externalTypesForJdbcType in interface DbAdapter

getExtendedTypes

public org.objectstyle.cayenne.access.types.ExtendedTypeMap getExtendedTypes()
Description copied from interface: DbAdapter
Returns a map of ExtendedTypes that is used to translate values between Java and JDBC layer.

Specified by:
getExtendedTypes in interface DbAdapter

buildAttribute

public org.objectstyle.cayenne.map.DbAttribute buildAttribute(java.lang.String name,
                                                              java.lang.String typeName,
                                                              int type,
                                                              int size,
                                                              int precision,
                                                              boolean allowNulls)
Description copied from interface: DbAdapter
Creates and returns a DbAttribute based on supplied parameters (usually obtained from database meta data).

Specified by:
buildAttribute in interface DbAdapter

tableTypeForTable

public java.lang.String tableTypeForTable()
Description copied from interface: DbAdapter
Returns the name of the table type (as returned by DatabaseMetaData.getTableTypes) for a simple user table.

Specified by:
tableTypeForTable in interface DbAdapter

tableTypeForView

public java.lang.String tableTypeForView()
Description copied from interface: DbAdapter
Returns the name of the table type (as returned by DatabaseMetaData.getTableTypes) for a view table.

Specified by:
tableTypeForView in interface DbAdapter

getQualifierTranslator

public org.objectstyle.cayenne.access.trans.QualifierTranslator getQualifierTranslator(org.objectstyle.cayenne.access.trans.QueryAssembler queryAssembler)
Creates and returns a default implementation of a qualifier translator.

Specified by:
getQualifierTranslator in interface DbAdapter

createDataNode

public org.objectstyle.cayenne.access.DataNode createDataNode(java.lang.String name)
Creates an instance of DataNode class.

Specified by:
createDataNode in interface DbAdapter

bindParameter

public void bindParameter(java.sql.PreparedStatement statement,
                          java.lang.Object object,
                          int pos,
                          int sqlType,
                          int precision)
                   throws java.sql.SQLException,
                          java.lang.Exception
Description copied from interface: DbAdapter
Binds an object value to PreparedStatement's numbered parameter.

Specified by:
bindParameter in interface DbAdapter

supportsBatchUpdates

public boolean supportsBatchUpdates()
Description copied from interface: DbAdapter
Returns true if the target database supports batch updates.

Specified by:
supportsBatchUpdates in interface DbAdapter

setSupportsBatchUpdates

public void setSupportsBatchUpdates(boolean flag)

shouldRunBatchQuery

public boolean shouldRunBatchQuery(org.objectstyle.cayenne.access.DataNode node,
                                   java.sql.Connection con,
                                   org.objectstyle.cayenne.query.BatchQuery query,
                                   org.objectstyle.cayenne.access.OperationObserver delegate)
                            throws java.sql.SQLException,
                                   java.lang.Exception
Always returns true, letting DataNode to handle the query.

Specified by:
shouldRunBatchQuery in interface DbAdapter