fr.gouv.culture.sdx.utils.database
Class AbstractJDBCDatabase

java.lang.Object
  extended byfr.gouv.culture.sdx.utils.SdxObjectImpl
      extended byfr.gouv.culture.sdx.utils.rdbms.JDBC
          extended byfr.gouv.culture.sdx.utils.rdbms.DataSourceComponentBacked
              extended byfr.gouv.culture.sdx.utils.database.AbstractJDBCDatabase
All Implemented Interfaces:
org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.configuration.Configurable, Database, org.apache.avalon.framework.logger.LogEnabled, SdxObject
Direct Known Subclasses:
HSQLDatabase, JDBCDatabase

public abstract class AbstractJDBCDatabase
extends DataSourceComponentBacked
implements Database

Created by IntelliJ IDEA. User: rpandey Date: Mar 3, 2003 Time: 3:58:12 PM


Nested Class Summary
 
Nested classes inherited from class fr.gouv.culture.sdx.utils.rdbms.JDBC
JDBC.QueryExecutor, JDBC.Template
 
Field Summary
static java.lang.String[] _searchModes
           
protected  int COLUMN_PARAM_INDEX_FIELD_ID
           
protected  int COLUMN_PARAM_INDEX_FIELD_PROPERTY_NAME
           
protected  int COLUMN_PARAM_INDEX_FIELD_PROPERTY_VALUE
           
protected  java.util.Hashtable entityCache
           
protected  java.lang.String FIELD_ID
           
protected  java.lang.String FIELD_PROPERTY_NAME
           
protected  java.lang.String FIELD_PROPERTY_VALUE
           
protected  java.util.Hashtable props
          Hashtable of property values
 
Fields inherited from class fr.gouv.culture.sdx.utils.rdbms.DataSourceComponentBacked
ATTRIBUTE_DSI, dbSelector, dsi, manager
 
Fields inherited from class fr.gouv.culture.sdx.utils.rdbms.JDBC
id, tableName
 
Fields inherited from class fr.gouv.culture.sdx.utils.SdxObjectImpl
encoding, logger
 
Fields inherited from interface fr.gouv.culture.sdx.utils.database.Database
DATABASE_DIR_PATH, SEARCH_MODE_AND, SEARCH_MODE_NOT, SEARCH_MODE_OR
 
Constructor Summary
AbstractJDBCDatabase()
           
 
Method Summary
protected  void addEntityToCache(DatabaseEntity dbe)
           
 void addProperty(java.lang.String entityId, java.lang.String propertyName, java.lang.String propertyValue)
          If the entity does not exist the method fails silently
 void configure(org.apache.avalon.framework.configuration.Configuration configuration)
           
protected  void createIndicies(java.sql.Connection conn)
          Creates and index on the "id" field.
 void delete(DatabaseEntity ent)
          Deletes an entity.
 void delete(DatabaseEntity[] entities)
           
protected  void deleteEntityFromCache(java.lang.String id)
           
 void empty()
          Empties the database.
 boolean entityExists(java.lang.String id)
          Checks whether an entity with the provided id exists within this database
protected  java.lang.String getAllEntitiesQuery()
           
protected  java.lang.String getCreateIndiciesQuery(java.lang.String fieldName)
           
protected  java.lang.String getDeleteAllQuery()
           
 DatabaseEntity[] getEntities()
          Returns the list of entities from the database.
protected  DatabaseEntity[] getEntities(java.sql.ResultSet rs)
          Calling methods should close ResultSet after calling this method
 DatabaseEntity getEntity(java.lang.String id)
          Gets an entity from the database.
protected  DatabaseEntity getEntity(java.lang.String id, java.sql.ResultSet rs)
          Calling methods should close ResultSet after calling this method
protected  java.lang.String getEntityDeleteQuery()
           
protected  DatabaseEntity getEntityFromCache(java.lang.String id)
           
protected  java.lang.String getEntityGetQuery()
          Returns an SQL query that could select a entity using its id.
protected  java.lang.String[] getEntityIds(java.sql.ResultSet rs)
          Calling methods should close ResultSet after calling this method
 java.lang.String getId()
           
 Property[] getProperties(java.lang.String entityId)
          Returns all properties from an entity in the database.
protected  java.lang.String getPropertyAddQuery()
           
protected  java.lang.String getPropertyRemoveQueryWithId()
           
protected  java.lang.String getPropertyRemoveQueryWithoutId()
           
 java.lang.String getPropertyValue(java.lang.String entityId, java.lang.String name)
          Returns a property value from an entity in the database.
 java.lang.String[] getPropertyValues(java.lang.String entityId, java.lang.String propertyName)
          Returns a repeatable property from an entity in the database.
protected  java.lang.String getTableCreationQuery()
          Returns an SQL query that could create the table.
 java.lang.String getWildcardSearchToken()
          Returns a String representing the appropriate wildcard search token for the implementation
 void init()
          Initializes the repository.
protected  boolean isEntityInCache(java.lang.String id)
           
protected  void refreshEntityCache()
           
 void removeProperty(java.lang.String propertyName, java.lang.String propertyValue)
          Removes a property with the provided name and value from the and EXISTING entity having the name/value pair It is up to the implementation to determine proper behavior if the entity with the provided id does not exist.
 void removeProperty(java.lang.String entityId, java.lang.String propertyName, java.lang.String propertyValue)
          If the entity does not exist the method fails silently
 void save(DatabaseEntity ent)
          Saves an entity.
 java.lang.String[] search(org.apache.avalon.framework.parameters.Parameters params)
          Returns an array of database entity ids based upon the provided search parameters One can used Database.getEntity(id) after retrieving a list of ids with this method.
 java.lang.String[] search(org.apache.avalon.framework.parameters.Parameters params, int mode)
           
 java.lang.String[] searchWithParams(org.apache.avalon.framework.parameters.Parameters params)
          Search entities in SDX system databases with two parameters and a single table.
 void setId(java.lang.String id)
           
 void setProperties(java.util.Hashtable props)
          Provides a list of properties of this class which can be used at configuration and/or initialization time
 long size()
          Returns the number of entities within this database.
 void update(DatabaseEntity ent)
          Updates an entity.
 
Methods inherited from class fr.gouv.culture.sdx.utils.rdbms.DataSourceComponentBacked
compose, getDataSourceComponent, releaseDataSourceComponent
 
Methods inherited from class fr.gouv.culture.sdx.utils.rdbms.JDBC
createTable, getTableName, handleUnsupportedTokens
 
Methods inherited from class fr.gouv.culture.sdx.utils.SdxObjectImpl
enableLogging, getChildLogger, setEncoding
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface fr.gouv.culture.sdx.utils.database.Database
getConnection, getDatabaseDirectoryName, optimize, releaseConnection
 
Methods inherited from interface fr.gouv.culture.sdx.utils.SdxObject
setEncoding
 
Methods inherited from interface org.apache.avalon.framework.logger.LogEnabled
enableLogging
 
Methods inherited from interface org.apache.avalon.framework.component.Composable
compose
 

Field Detail

FIELD_ID

protected final java.lang.String FIELD_ID
See Also:
Constant Field Values

FIELD_PROPERTY_NAME

protected final java.lang.String FIELD_PROPERTY_NAME
See Also:
Constant Field Values

FIELD_PROPERTY_VALUE

protected final java.lang.String FIELD_PROPERTY_VALUE
See Also:
Constant Field Values

COLUMN_PARAM_INDEX_FIELD_ID

protected final int COLUMN_PARAM_INDEX_FIELD_ID
See Also:
Constant Field Values

COLUMN_PARAM_INDEX_FIELD_PROPERTY_NAME

protected final int COLUMN_PARAM_INDEX_FIELD_PROPERTY_NAME
See Also:
Constant Field Values

COLUMN_PARAM_INDEX_FIELD_PROPERTY_VALUE

protected final int COLUMN_PARAM_INDEX_FIELD_PROPERTY_VALUE
See Also:
Constant Field Values

_searchModes

public static final java.lang.String[] _searchModes

props

protected java.util.Hashtable props
Hashtable of property values


entityCache

protected java.util.Hashtable entityCache
Constructor Detail

AbstractJDBCDatabase

public AbstractJDBCDatabase()
Method Detail

configure

public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Overrides:
configure in class DataSourceComponentBacked
Throws:
org.apache.avalon.framework.configuration.ConfigurationException

getEntity

public DatabaseEntity getEntity(java.lang.String id)
                         throws SDXException
Description copied from interface: Database
Gets an entity from the database.

Specified by:
getEntity in interface Database
Parameters:
id - The needed entity's id.
Throws:
SDXException

getEntities

public DatabaseEntity[] getEntities()
                             throws SDXException
Description copied from interface: Database
Returns the list of entities from the database.

Specified by:
getEntities in interface Database
Throws:
SDXException

getPropertyValue

public java.lang.String getPropertyValue(java.lang.String entityId,
                                         java.lang.String name)
                                  throws SDXException
Description copied from interface: Database
Returns a property value from an entity in the database.

Specified by:
getPropertyValue in interface Database
Parameters:
entityId - The needed entity's id.
name - The needed property's name.
Returns:
The property is defined, otherwise null. If the property is defined more than once, the first value is returned.
Throws:
SDXException

getPropertyValues

public java.lang.String[] getPropertyValues(java.lang.String entityId,
                                            java.lang.String propertyName)
                                     throws SDXException
Description copied from interface: Database
Returns a repeatable property from an entity in the database.

Specified by:
getPropertyValues in interface Database
Parameters:
entityId - The needed entity's name.
propertyName - The needed property's name.
Returns:
An enumeration of all values for this property, null is this property is not defined for this entity.
Throws:
SDXException

getProperties

public Property[] getProperties(java.lang.String entityId)
                         throws SDXException
Description copied from interface: Database
Returns all properties from an entity in the database.

Specified by:
getProperties in interface Database
Throws:
SDXException

save

public void save(DatabaseEntity ent)
          throws SDXException
Description copied from interface: Database
Saves an entity.

Specified by:
save in interface Database
Throws:
SDXException

delete

public void delete(DatabaseEntity ent)
            throws SDXException
Description copied from interface: Database
Deletes an entity.

Specified by:
delete in interface Database
Throws:
SDXException

delete

public void delete(DatabaseEntity[] entities)
            throws SDXException
Throws:
SDXException

update

public void update(DatabaseEntity ent)
            throws SDXException
Description copied from interface: Database
Updates an entity.

Specified by:
update in interface Database
Throws:
SDXException

size

public long size()
Description copied from interface: Database
Returns the number of entities within this database.

Specified by:
size in interface Database

empty

public void empty()
           throws SDXException
Description copied from interface: Database
Empties the database.

Specified by:
empty in interface Database
Throws:
SDXException

setProperties

public void setProperties(java.util.Hashtable props)
Description copied from interface: Database
Provides a list of properties of this class which can be used at configuration and/or initialization time

Specified by:
setProperties in interface Database
Parameters:
props -

entityExists

public boolean entityExists(java.lang.String id)
Description copied from interface: Database
Checks whether an entity with the provided id exists within this database

Specified by:
entityExists in interface Database
Parameters:
id - identifier of the entity

search

public java.lang.String[] search(org.apache.avalon.framework.parameters.Parameters params)
                          throws SDXException
Description copied from interface: Database
Returns an array of database entity ids based upon the provided search parameters One can used Database.getEntity(id) after retrieving a list of ids with this method.

Specified by:
search in interface Database
Parameters:
params - search params
Throws:
SDXException
See Also:
Database.search(org.apache.avalon.framework.parameters.Parameters)

search

public java.lang.String[] search(org.apache.avalon.framework.parameters.Parameters params,
                                 int mode)
                          throws SDXException
Throws:
SDXException

searchWithParams

public java.lang.String[] searchWithParams(org.apache.avalon.framework.parameters.Parameters params)
                                    throws SDXException
Search entities in SDX system databases with two parameters and a single table. Syntax avalaible in MySQL and HSQL. More than two parameters not implemented at this time. -mp

Throws:
SDXException

setId

public void setId(java.lang.String id)
Specified by:
setId in interface Database

getId

public java.lang.String getId()
Specified by:
getId in interface Database

init

public void init()
          throws SDXException
Initializes the repository. If there are no tables in the database, we create the necessary table

Specified by:
init in interface Database
Throws:
SDXException

getTableCreationQuery

protected java.lang.String getTableCreationQuery()
Description copied from class: JDBC
Returns an SQL query that could create the table.

This query should not have any parameter.

Specified by:
getTableCreationQuery in class JDBC
Returns:
The query. see subclasses for implementation

getEntityGetQuery

protected java.lang.String getEntityGetQuery()
Returns an SQL query that could select a entity using its id.

This query should have one parameter for the id.

Returns:
The query.

getAllEntitiesQuery

protected java.lang.String getAllEntitiesQuery()

getEntityDeleteQuery

protected java.lang.String getEntityDeleteQuery()

getPropertyAddQuery

protected java.lang.String getPropertyAddQuery()

getPropertyRemoveQueryWithId

protected java.lang.String getPropertyRemoveQueryWithId()

getPropertyRemoveQueryWithoutId

protected java.lang.String getPropertyRemoveQueryWithoutId()

getDeleteAllQuery

protected java.lang.String getDeleteAllQuery()

getCreateIndiciesQuery

protected java.lang.String getCreateIndiciesQuery(java.lang.String fieldName)

getEntity

protected DatabaseEntity getEntity(java.lang.String id,
                                   java.sql.ResultSet rs)
                            throws SDXException
Calling methods should close ResultSet after calling this method

Parameters:
id -
rs -
Returns:
Throws:
SDXException

getEntities

protected DatabaseEntity[] getEntities(java.sql.ResultSet rs)
                                throws SDXException
Calling methods should close ResultSet after calling this method

Parameters:
rs -
Returns:
Throws:
SDXException

getEntityIds

protected java.lang.String[] getEntityIds(java.sql.ResultSet rs)
                                   throws SDXException
Calling methods should close ResultSet after calling this method

Parameters:
rs -
Returns:
Throws:
SDXException

createIndicies

protected void createIndicies(java.sql.Connection conn)
                       throws SDXException
Creates and index on the "id" field.

Throws:
SDXException

addProperty

public void addProperty(java.lang.String entityId,
                        java.lang.String propertyName,
                        java.lang.String propertyValue)
                 throws SDXException
If the entity does not exist the method fails silently

Specified by:
addProperty in interface Database
Parameters:
entityId -
propertyName -
propertyValue -
Throws:
SDXException

removeProperty

public void removeProperty(java.lang.String entityId,
                           java.lang.String propertyName,
                           java.lang.String propertyValue)
                    throws SDXException
If the entity does not exist the method fails silently

Specified by:
removeProperty in interface Database
Parameters:
entityId -
propertyName -
propertyValue -
Throws:
SDXException

removeProperty

public void removeProperty(java.lang.String propertyName,
                           java.lang.String propertyValue)
                    throws SDXException
Description copied from interface: Database
Removes a property with the provided name and value from the and EXISTING entity having the name/value pair It is up to the implementation to determine proper behavior if the entity with the provided id does not exist.

Specified by:
removeProperty in interface Database
Parameters:
propertyName - The property to remove
propertyValue - The property value
Throws:
SDXException

getEntityFromCache

protected DatabaseEntity getEntityFromCache(java.lang.String id)

addEntityToCache

protected void addEntityToCache(DatabaseEntity dbe)

deleteEntityFromCache

protected void deleteEntityFromCache(java.lang.String id)

getWildcardSearchToken

public java.lang.String getWildcardSearchToken()
Description copied from interface: Database
Returns a String representing the appropriate wildcard search token for the implementation

Specified by:
getWildcardSearchToken in interface Database

isEntityInCache

protected boolean isEntityInCache(java.lang.String id)

refreshEntityCache

protected void refreshEntityCache()
                           throws SDXException
Throws:
SDXException


Copyright © 2000-2004 Ministere de la culture et de la communication / AJLSM. All Rights Reserved.