org.nuiton.topia.persistence.util
Class DBMapping

java.lang.Object
  extended by org.nuiton.topia.persistence.util.DBMapping

public abstract class DBMapping
extends Object

Une classe qui permet d'obtenir les mapping de noms entre les entités et les objets de la base.

On retrouve aussi ici des méthodes utils pour executer du code sql sur la base (notamment la gestion des séquences).

Author:
tchemit

Field Summary
protected static String CLASS_PATTERN
           
protected static String CREATE_SEQUENCE_FORMAT
           
protected static String CURRENT_VALUE_SEQUENCE_FORMAT
           
protected static String DBNAME_ATTRIBUTE_PATTERN
           
protected static String DOT
           
protected static org.apache.commons.logging.Log log
          log
protected  Map<String,String> mappingBeanToDb
           
protected static String NEXT_VALUE_SEQUENCE_FORMAT
           
protected  String schema
           
protected static String SCHEMA_FORMAT
           
protected static String SEQUENCE_ATTRIBUTE_PATTERN
           
protected  Map<String,Class<? extends TopiaEntity>> sequences
           
protected static String UPDATE_SEQUENCE_FORMAT
           
 
Constructor Summary
DBMapping(String propertyFile, String path)
           
 
Method Summary
protected  String checkSequence(Class<? extends TopiaEntity> entityClass, String propertyName)
           
protected  String checkSequence(String sequenceKey)
           
 void close()
           
 void createSequence(Class<? extends TopiaEntity> entityClass, String propertyName, TopiaContext ctxt)
           
 void createSequence(String sequenceKey, TopiaContext ctxt)
           
 void createSequence(String sequenceKey, TopiaContext ctxt, boolean check)
           
 void createSequences(TopiaContext ctxt)
           
protected  void doSQLWork(TopiaContext ctxt, String sql)
           
 boolean existSequence(Class<? extends TopiaEntity> entityClass, String propertyName, TopiaContext ctxt)
           
 boolean existSequence(String sequenceKey, TopiaContext ctxt)
           
 boolean existSequence(String sequenceKey, TopiaContext ctxt, boolean check)
           
protected  void finalize()
           
protected  BigInteger getBigInteger(TopiaContext ctxt, String sql, BigInteger defaultSize)
           
protected abstract  Class<? extends TopiaEntity> getContractClass(Class<? extends TopiaEntity> entityClass)
           
 BigInteger getCurrentValueFromSequence(Class<? extends TopiaEntity> entityClass, String propertyName, TopiaContext ctxt)
           
 BigInteger getCurrentValueFromSequence(String sequenceKey, TopiaContext ctxt)
           
 BigInteger getCurrentValueFromSequence(String sequenceKey, TopiaContext ctxt, boolean check)
           
protected  String getDBProperty(Class<? extends TopiaEntity> entityClass, String property)
           
protected  String getDBTable(Class<? extends TopiaEntity> entityClass)
           
 BigInteger getNextValueFromSequence(Class<? extends TopiaEntity> entityClass, String propertyName, TopiaContext ctxt)
           
 BigInteger getNextValueFromSequence(String sequenceKey, TopiaContext ctxt)
           
 BigInteger getNextValueFromSequence(String sequenceKey, TopiaContext ctxt, boolean check)
           
 Iterator<String> getSequenceKeysIterator()
           
protected  String getSequencePropertyName(String sequenceKey)
           
protected  String getSequenceSQL(String pattern, Class<? extends TopiaEntity> entityClass, String propertyName)
           
protected  String getSequenceSQL(String pattern, String sequenceKey)
           
 void init(TopiaContext ctxt, boolean doCreate, boolean doUpdate)
           
protected  void initMapping(Properties props)
           
 void updateSequence(Class<? extends TopiaEntity> entityClass, String propertyName, TopiaContext ctxt)
           
 void updateSequence(String sequenceKey, TopiaContext ctxt)
           
 void updateSequence(String sequenceKey, TopiaContext ctxt, boolean check)
           
 void updateSequences(TopiaContext ctxt)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.commons.logging.Log log
log


CLASS_PATTERN

protected static final String CLASS_PATTERN
See Also:
Constant Field Values

DBNAME_ATTRIBUTE_PATTERN

protected static final String DBNAME_ATTRIBUTE_PATTERN
See Also:
Constant Field Values

SEQUENCE_ATTRIBUTE_PATTERN

protected static final String SEQUENCE_ATTRIBUTE_PATTERN
See Also:
Constant Field Values

CREATE_SEQUENCE_FORMAT

protected static final String CREATE_SEQUENCE_FORMAT
See Also:
Constant Field Values

UPDATE_SEQUENCE_FORMAT

protected static final String UPDATE_SEQUENCE_FORMAT
See Also:
Constant Field Values

CURRENT_VALUE_SEQUENCE_FORMAT

protected static final String CURRENT_VALUE_SEQUENCE_FORMAT
See Also:
Constant Field Values

NEXT_VALUE_SEQUENCE_FORMAT

protected static final String NEXT_VALUE_SEQUENCE_FORMAT
See Also:
Constant Field Values

SCHEMA_FORMAT

protected static final String SCHEMA_FORMAT
See Also:
Constant Field Values

DOT

protected static final String DOT
See Also:
Constant Field Values

mappingBeanToDb

protected Map<String,String> mappingBeanToDb

sequences

protected Map<String,Class<? extends TopiaEntity>> sequences

schema

protected String schema
Constructor Detail

DBMapping

public DBMapping(String propertyFile,
                 String path)
          throws IOException
Throws:
IOException
Method Detail

getContractClass

protected abstract Class<? extends TopiaEntity> getContractClass(Class<? extends TopiaEntity> entityClass)
                                                          throws TopiaException
Throws:
TopiaException

init

public void init(TopiaContext ctxt,
                 boolean doCreate,
                 boolean doUpdate)
          throws TopiaException
Throws:
TopiaException

createSequences

public void createSequences(TopiaContext ctxt)
                     throws TopiaException
Throws:
TopiaException

updateSequences

public void updateSequences(TopiaContext ctxt)
                     throws TopiaException
Throws:
TopiaException

existSequence

public boolean existSequence(String sequenceKey,
                             TopiaContext ctxt)
                      throws TopiaException
Throws:
TopiaException

createSequence

public void createSequence(String sequenceKey,
                           TopiaContext ctxt)
                    throws TopiaException
Throws:
TopiaException

updateSequence

public void updateSequence(String sequenceKey,
                           TopiaContext ctxt)
                    throws TopiaException
Throws:
TopiaException

getCurrentValueFromSequence

public BigInteger getCurrentValueFromSequence(String sequenceKey,
                                              TopiaContext ctxt)
                                       throws TopiaException
Throws:
TopiaException

getNextValueFromSequence

public BigInteger getNextValueFromSequence(String sequenceKey,
                                           TopiaContext ctxt)
                                    throws TopiaException
Throws:
TopiaException

existSequence

public boolean existSequence(Class<? extends TopiaEntity> entityClass,
                             String propertyName,
                             TopiaContext ctxt)
                      throws TopiaException
Throws:
TopiaException

createSequence

public void createSequence(Class<? extends TopiaEntity> entityClass,
                           String propertyName,
                           TopiaContext ctxt)
                    throws TopiaException
Throws:
TopiaException

updateSequence

public void updateSequence(Class<? extends TopiaEntity> entityClass,
                           String propertyName,
                           TopiaContext ctxt)
                    throws TopiaException
Throws:
TopiaException

getCurrentValueFromSequence

public BigInteger getCurrentValueFromSequence(Class<? extends TopiaEntity> entityClass,
                                              String propertyName,
                                              TopiaContext ctxt)
                                       throws TopiaException
Throws:
TopiaException

getNextValueFromSequence

public BigInteger getNextValueFromSequence(Class<? extends TopiaEntity> entityClass,
                                           String propertyName,
                                           TopiaContext ctxt)
                                    throws TopiaException
Throws:
TopiaException

getSequenceKeysIterator

public Iterator<String> getSequenceKeysIterator()

existSequence

public boolean existSequence(String sequenceKey,
                             TopiaContext ctxt,
                             boolean check)
                      throws TopiaException
Throws:
TopiaException

createSequence

public void createSequence(String sequenceKey,
                           TopiaContext ctxt,
                           boolean check)
                    throws TopiaException
Throws:
TopiaException

updateSequence

public void updateSequence(String sequenceKey,
                           TopiaContext ctxt,
                           boolean check)
                    throws TopiaException
Throws:
TopiaException

getCurrentValueFromSequence

public BigInteger getCurrentValueFromSequence(String sequenceKey,
                                              TopiaContext ctxt,
                                              boolean check)
                                       throws TopiaException
Throws:
TopiaException

getNextValueFromSequence

public BigInteger getNextValueFromSequence(String sequenceKey,
                                           TopiaContext ctxt,
                                           boolean check)
                                    throws TopiaException
Throws:
TopiaException

getDBProperty

protected String getDBProperty(Class<? extends TopiaEntity> entityClass,
                               String property)
                        throws TopiaException
Parameters:
entityClass - the seek entity class
property - the name of the property to translate
Returns:
the DB name for the given property
Throws:
TopiaException - if any db pb

getDBTable

protected String getDBTable(Class<? extends TopiaEntity> entityClass)
                     throws TopiaException
Parameters:
entityClass - the seek entity class
Returns:
the DB name for the given property
Throws:
TopiaException - if any db pb

getSequenceSQL

protected String getSequenceSQL(String pattern,
                                Class<? extends TopiaEntity> entityClass,
                                String propertyName)
                         throws TopiaException
Throws:
TopiaException

getSequenceSQL

protected String getSequenceSQL(String pattern,
                                String sequenceKey)
                         throws TopiaException
Throws:
TopiaException

getBigInteger

protected BigInteger getBigInteger(TopiaContext ctxt,
                                   String sql,
                                   BigInteger defaultSize)
                            throws TopiaException
Throws:
TopiaException

doSQLWork

protected void doSQLWork(TopiaContext ctxt,
                         String sql)
                  throws TopiaException
Throws:
TopiaException

getSequencePropertyName

protected String getSequencePropertyName(String sequenceKey)

checkSequence

protected String checkSequence(Class<? extends TopiaEntity> entityClass,
                               String propertyName)
                        throws IllegalArgumentException,
                               TopiaException
Throws:
IllegalArgumentException
TopiaException

checkSequence

protected String checkSequence(String sequenceKey)
                        throws IllegalArgumentException,
                               TopiaException
Throws:
IllegalArgumentException
TopiaException

initMapping

protected void initMapping(Properties props)
                    throws IOException
Throws:
IOException

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

close

public void close()


Copyright © 2004-2010 CodeLutin. All Rights Reserved.