public abstract class AbstractHibernateDatasource extends AbstractHibernateCoreDatasource implements SQLConstants
C3P0_CONNECTION_POOL, DATABASE_DEFAULT_VALUE, DATABASE_DESCRIPTION, DATABASE_KEY, DATABASE_TITLE, HOST_DEFAULT_VALUE, HOST_DESCRIPTION, HOST_KEY, HOST_TITLE, MAX_POOL_SIZE_DEFAULT_VALUE, MAX_POOL_SIZE_DESCRIPTION, MAX_POOL_SIZE_KEY, MAX_POOL_SIZE_TITLE, MIN_POOL_SIZE_DEFAULT_VALUE, MIN_POOL_SIZE_DESCRIPTION, MIN_POOL_SIZE_KEY, MIN_POOL_SIZE_TITLE, PASSWORD_KEY, PASSWORD_TITLE, PORT_KEY, PORT_TITLE, USERNAME_KEY, USERNAME_TITLE
DEFAULT_COUNT, FROM, SELECT
AMPERSAND_CHAR, AMPERSAND_STRING, BACKSLASH_CHAR, BACKSLASH_STRING, BLANK_CHAR, BLANK_STRING, CLOSE_BRACE_CHAR, CLOSE_BRACE_STRING, COLON_CHAR, COLON_STRING, COMMA_CHAR, COMMA_SPACE_STRING, COMMA_STRING, CSV_BLOCK_SEPARATOR, CSV_TOKEN_SEPARATOR, DASH_CHAR, DASH_STRING, DEFAULT_ENCODING, DOLLAR_CHAR, DOLLAR_STRING, DOT_CHAR, DOT_STRING, EMPTY_STRING, EPSG_WGS84, EPSG_WGS84_3D, EQUAL_SIGN_CHAR, EQUAL_SIGN_STRING, GREATER_THAN_SIGN_STRING, HASH_CODE_13, HASH_CODE_17, HASH_CODE_19, HASH_CODE_23, HASH_CODE_29, HASH_CODE_3, HASH_CODE_31, HASH_CODE_37, HASH_CODE_41, HASH_CODE_43, HASH_CODE_47, HASH_CODE_5, HASH_CODE_7, INT_0, INT_1, INT_2, INT_3, INT_4, LESS_THAN_SIGN_STRING, LINE_SEPARATOR_CHAR, LINE_SEPARATOR_STRING, MINUS_CHAR, MINUS_STRING, NUMBER_SIGN_CHAR, NUMBER_SIGN_STRING, OPEN_BRACE_CHAR, OPEN_BRACE_STRING, PERCENT_CHAR, PERCENT_STRING, PLUS_CHAR, PLUS_STRING, QUERSTIONMARK_CHAR, QUERSTIONMARK_STRING, SEMICOLON_CHAR, SEMICOLON_STRING, SLASH_CHAR, SLASH_STRING, UNDERSCORE_CHAR, UNDERSCORE_STRING
ADVANCED_GROUP, BASE_GROUP
CONNECTION_PROVIDER_IDENTIFIER
DATASOURCE_DAO_IDENTIFIER, IDEPENDET_IDENTIFIER
HIBERNATE_ANNOTADED_CLASSES, HIBERNATE_DEFAULT_OGM_PACKAGE, HIBERNATE_DIRECTORY, HIBERNATE_DRIVER_CLASS, HIBERNATE_MAPPING_CORE_PATH, HIBERNATE_MAPPING_EXTENSION, HIBERNATE_MAPPING_EXTENSION_READONLY, HIBERNATE_MAPPING_OLD_CONCEPT_OBSERVATION_PATH, HIBERNATE_MAPPING_OLD_CONCEPT_SPATIAL_FILTERING_PROFILE_PATH, HIBERNATE_MAPPING_PATH, HIBERNATE_MAPPING_SERIES_CONCEPT_OBSERVATION_PATH, HIBERNATE_MAPPING_SERIES_CONCEPT_PATH, HIBERNATE_MAPPING_SERIES_CONCEPT_SPATIAL_FILTERING_PROFILE_PATH, HIBERNATE_MAPPING_TRANSACTIONAL_PATH, HIBERNATE_RESOURCES, HIBERNATPE_MAPPING_OLD_CONCEPT_PATH, OGM_CONNECTION_PROVIDER_IDENTIFIER, OGM_DATASOURCE_DAO_IDENTIFIER, ORM_CONNECTION_PROVIDER_IDENTIFIER, ORM_DATASOURCE_DAO_IDENTIFIER, PATH_SEPERATOR, PROVIDED_JDBC
Constructor and Description |
---|
AbstractHibernateDatasource() |
Modifier and Type | Method and Description |
---|---|
protected void |
addMappingFileDirectories(Map<String,Object> settings,
Properties p)
Add mapping files directories to properties
|
private void |
addSpatialFilteringProfilePathToConfig(CustomConfiguration config,
Map<String,Object> settings,
String spatialFilteringProfilePath)
Deprecated.
|
private void |
addSpatialFilteringProfilePathToDirList(StringBuilder builder,
Map<String,Object> settings,
String spatialFilteringProfilePath)
Deprecated.
|
private String |
checkCatalog(Connection conn) |
protected String[] |
checkCreateSchema(String[] script)
Remove duplicated foreign key definition for table observationHasOffering
otherwise database model creation fails in Oracle
|
protected String[] |
checkDropSchema(String[] dropSchema)
Check if drop schema contains alter table ... drop constraint ... .
|
private boolean |
checkIfExtensionDirectoryExists() |
boolean |
checkIfSchemaExists(Map<String,Object> settings)
Check if the schema exists.
|
boolean |
checkIfSchemaExists(Properties current,
Map<String,Object> changed)
Check if the schema exists.
|
void |
checkPostCreation(Properties properties) |
protected String |
checkSchema(String schema,
String catalog,
Connection conn) |
protected String[] |
checkScriptForGeneratedAndDuplicatedEntries(String[] script)
Remove generated foreign key definition and duplicated entries.
|
protected void |
close(Connection conn)
Close SQL connection
|
protected void |
close(Statement stmt)
Close SQL statement
|
private <T> T[] |
concat(T[] first,
T[]... rest)
Concatenate two arrays
|
protected IntegerSettingDefinition |
createBatchSizeDefinition()
Create settings definition for JDBC batch size
|
protected abstract org.hibernate.dialect.Dialect |
createDialect()
Create a new Hibernate dialect
|
protected BooleanSettingDefinition |
createOldConceptDefinition()
Create settings definition for old concept
|
protected BooleanSettingDefinition |
createProvidedJdbcDriverDefinition()
Create settings definition for JDBC driver
|
String[] |
createSchema(Map<String,Object> settings)
Create the schema for the supplied settings.
|
protected StringSettingDefinition |
createSchemaDefinition()
Create settings definition for database schema
|
protected BooleanSettingDefinition |
createSpatialFilteringProfileDefinition()
Create settings definition for Spatial Filtering Profile support
|
protected BooleanSettingDefinition |
createTransactionalDefinition()
Create settings definition for transactional support
|
String[] |
dropSchema(Map<String,Object> settings)
Drop the present schema (or parts of it).
|
protected void |
execute(String[] sql,
Connection conn)
Execute SQL script
|
void |
execute(String[] sql,
Map<String,Object> settings) |
void |
executePostCreateSchema(Map<String,Object> databaseSettings) |
DatasourceCallback |
getCallback() |
CustomConfiguration |
getConfig(Map<String,Object> settings)
Get custom configuration from datasource settings
|
String |
getConnectionProviderIdentifier() |
protected org.hibernate.tool.hbm2ddl.DatabaseMetadata |
getDatabaseMetadata(Connection conn,
CustomConfiguration customConfiguration) |
String |
getDatasourceDaoIdentifier() |
protected org.hibernate.dialect.Dialect |
getDialectInternal()
Get internal Hibernate dialect
|
protected abstract String |
getDriverClass()
Gets the qualified name of the driver class.
|
private String |
getGeneratedForeignKeyFor(String tableName)
Create the beginning character of a generated foreign key from a table
name hasCode()
|
protected BooleanSettingDefinition |
getOldConceptDefiniton()
Get the old database schema concept
|
protected String[] |
getPostSchemaScript()
Get the schema script after the database schema is created
|
protected String[] |
getPreSchemaScript()
Get the schema script before the database schema is created
|
protected String |
getSchema(Map<String,Object> settings) |
protected BooleanSettingDefinition |
getSpatialFilteringProfileDefiniton()
Deprecated.
|
protected BooleanSettingDefinition |
getTransactionalDefiniton()
Get transactional setting definition
|
private boolean |
isOldConceptDatasource(Map<String,Object> settings)
Check if this datasource supported the old concept
|
boolean |
isPostCreateSchema() |
private boolean |
isSeriesConceptDatasource(Map<String,Object> settings)
Check if this datasource supported the series concept
|
protected boolean |
isSetSchema(Map<String,Object> settings) |
protected boolean |
isSpatialFilteringProfile(Properties properties)
Deprecated.
|
boolean |
isSpatialFilteringProfileDatasource()
Deprecated.
|
protected boolean |
isTransactional(Properties properties)
Check if properties contains transactional mapping path
|
boolean |
isTransactionalDatasource()
Check if the datasource is transactional
|
boolean |
needsSchema() |
protected abstract Connection |
openConnection(Map<String,Object> settings)
Open a new SQL connection
|
void |
prepare(Map<String,Object> settings)
Called right before a schema is created.
|
protected File |
resource(String resource)
Get File from resource String
|
void |
setSpatialFilteringProfile(boolean spatialFilteringProfileDatasource)
Deprecated.
|
void |
setTransactional(boolean transactionalDatasource)
Set transactional datasource flag
|
String[] |
updateSchema(Map<String,Object> settings)
Creates an update schema for the supplied settings.
|
void |
validateConnection(Map<String,Object> settings)
Check if a connection is possible.
|
void |
validateConnection(Properties current,
Map<String,Object> changed)
Check if a connection is still possible with the newSettings settings.
|
protected abstract void |
validatePrerequisites(Connection con,
org.hibernate.tool.hbm2ddl.DatabaseMetadata metadata,
Map<String,Object> settings)
Check if the required extensions are available
|
void |
validatePrerequisites(Map<String,Object> settings)
Validate if all prerequisites (e.g. datasource version) are met.
|
void |
validatePrerequisites(Properties current,
Map<String,Object> changed)
Used to validate prerequisites after the connections settings newSettings
in the admin interface.
|
void |
validateSchema(Map<String,Object> settings)
Validate the existing schema.
|
void |
validateSchema(Properties current,
Map<String,Object> changed)
Validate the existing schema.
|
createDatabaseDefinition, createDatabaseDefinition, createHostDefinition, createHostDefinition, createMaxPoolSizeDefinition, createMaxPoolSizeDefinition, createMinPoolSizeDefinition, createMinPoolSizeDefinition, createPasswordDefinition, createPasswordDefinition, createPortDefinition, createPortDefinition, createUsernameDefinition, createUsernameDefinition, getChangableSettingDefinitions, getDatasourceProperties, getSettingDefinitions, mergeProperties, parseDatasourceProperties, parseURL, setDatabaseDefault, setDatabaseDescription, setHostDefault, setHostDescription, setMaxPoolSizeDefault, setMinPoolSizeDefault, setPasswordDefault, setPasswordDescription, setPortDefault, setPortDescription, setUsernameDefault, setUsernameDescription, toURL
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
checkSchemaCreation, clear, getDatasourceProperties, getDialectName, supportsClear
private static final org.slf4j.Logger LOG
protected static final String SCHEMA_KEY
protected static final String SCHEMA_TITLE
protected static final String SCHEMA_DESCRIPTION
protected static final String SCHMEA_DEFAULT_VALUE
protected static final String OLD_CONCEPT_TITLE
protected static final String OLD_CONCEPT_DESCRIPTION
protected static final String OLD_CONCEPT_KEY
protected static final boolean OLD_CONCEPT_DEFAULT_VALUE
protected static final String TRANSACTIONAL_TITLE
protected static final String TRANSACTIONAL_DESCRIPTION
protected static final String TRANSACTIONAL_KEY
protected static final boolean TRANSACTIONAL_DEFAULT_VALUE
@Deprecated protected static final String SPATIAL_FILTERING_PROFILE_TITLE
@Deprecated protected static final String SPATIAL_FILTERING_PROFILE_DESCRIPTION
@Deprecated protected static final String SPATIAL_FILTERING_PROFILE_KEY
@Deprecated protected static final boolean SPATIAL_FILTERING_PROFILE_DEFAULT_VALUE
protected static final Boolean PROVIDED_JDBC_DRIVER_DEFAULT_VALUE
protected static final String PROVIDED_JDBC_DRIVER_TITLE
protected static final String PROVIDED_JDBC_DRIVER_DESCRIPTION
protected static final String PROVIDED_JDBC_DRIVER_KEY
protected static final String BATCH_SIZE_KEY
protected static final String BATCH_SIZE_TITLE
protected static final String BATCH_SIZE_DESCRIPTION
protected static final Integer BATCH_SIZE_DEFAULT_VALUE
private org.hibernate.dialect.Dialect dialect
private final BooleanSettingDefinition oldConceptDefiniton
private final BooleanSettingDefinition transactionalDefiniton
private boolean transactionalDatasource
@Deprecated private final BooleanSettingDefinition spatialFilteringProfileDefinition
@Deprecated private boolean spatialFilteringProfileDatasource
protected StringSettingDefinition createSchemaDefinition()
protected BooleanSettingDefinition createOldConceptDefinition()
protected BooleanSettingDefinition createTransactionalDefinition()
protected BooleanSettingDefinition createSpatialFilteringProfileDefinition()
protected BooleanSettingDefinition createProvidedJdbcDriverDefinition()
protected IntegerSettingDefinition createBatchSizeDefinition()
public CustomConfiguration getConfig(Map<String,Object> settings)
settings
- Datasource settings to create custom configuration fromprivate boolean isSeriesConceptDatasource(Map<String,Object> settings)
settings
- Datasource settingstrue
, if this datasource supported the series
conceptprivate boolean isOldConceptDatasource(Map<String,Object> settings)
settings
- Datasource settingstrue
, if this datasource supported the old concept@Deprecated private void addSpatialFilteringProfilePathToConfig(CustomConfiguration config, Map<String,Object> settings, String spatialFilteringProfilePath)
config
- Datasource configurationsettings
- Datasource settingsspatialFilteringProfilePath
- Spatial Filtering Profile mapping files pathprotected File resource(String resource)
resource
- Resource Stringpublic String[] createSchema(Map<String,Object> settings)
Datasource
needsSchema()
and
checkSchemaCreation()
return
true
. If checkIfSchemaExists()
returned true
,
dropSchema()
will be called first.createSchema
in interface Datasource
settings
- the settings to connectpublic String[] dropSchema(Map<String,Object> settings)
Datasource
needsSchema()
and
checkIfSchemaExists()
return
true
.dropSchema
in interface Datasource
settings
- the settings to connectpublic String[] updateSchema(Map<String,Object> settings)
Datasource
needsSchema()
and
checkSchemaCreation()
return
true
. If checkIfSchemaExists()
returned true
,
dropSchema()
will be called first.updateSchema
in interface Datasource
settings
- the settings to connectpublic void validateSchema(Map<String,Object> settings)
Datasource
needsSchema()
and
checkIfSchemaExists()
return
true
.validateSchema
in interface Datasource
settings
- the settings to connectprotected org.hibernate.tool.hbm2ddl.DatabaseMetadata getDatabaseMetadata(Connection conn, CustomConfiguration customConfiguration) throws SQLException
SQLException
public boolean checkIfSchemaExists(Map<String,Object> settings)
Datasource
true
even if parts are
missing. Will only be called if needsSchema()
returns true
.checkIfSchemaExists
in interface Datasource
settings
- the settings to connectprotected String checkSchema(String schema, String catalog, Connection conn) throws SQLException
SQLException
private String checkCatalog(Connection conn) throws SQLException
SQLException
public void execute(String[] sql, Map<String,Object> settings) throws org.hibernate.HibernateException
execute
in interface Datasource
org.hibernate.HibernateException
public void validateConnection(Map<String,Object> settings)
Datasource
validateConnection
in interface Datasource
settings
- the settings to connectpublic boolean needsSchema()
needsSchema
in interface Datasource
public void validatePrerequisites(Map<String,Object> settings)
Datasource
validateConnection()
succeeded.validatePrerequisites
in interface Datasource
settings
- the settings to connectpublic void validateConnection(Properties current, Map<String,Object> changed)
Datasource
validateConnection
in interface Datasource
current
- the current datasource settingschanged
- the newSettings settingspublic void validatePrerequisites(Properties current, Map<String,Object> changed)
Datasource
validatePrerequisites
in interface Datasource
current
- the current datasource settingschanged
- the newSettings settingspublic void validateSchema(Properties current, Map<String,Object> changed)
Datasource
needsSchema()
and
checkIfSchemaExists()
return true
.validateSchema
in interface Datasource
current
- the current datasource settingschanged
- the newSettings settingspublic boolean checkIfSchemaExists(Properties current, Map<String,Object> changed)
Datasource
true
even if parts are
missing. Will only be called if needsSchema()
returns true
.checkIfSchemaExists
in interface Datasource
current
- the current datasource settingschanged
- the newSettings settingspublic void checkPostCreation(Properties properties)
checkPostCreation
in interface Datasource
private boolean checkIfExtensionDirectoryExists()
protected org.hibernate.dialect.Dialect getDialectInternal()
protected void execute(String[] sql, Connection conn) throws org.hibernate.HibernateException
sql
- SQL script to executeconn
- SQL connectionorg.hibernate.HibernateException
- If an error occursprotected void close(Connection conn)
conn
- SQL connection to closeprotected void close(Statement stmt)
stmt
- SQL statement to closeprotected void addMappingFileDirectories(Map<String,Object> settings, Properties p)
settings
- Datasource settingsp
- Datasource properties@Deprecated private void addSpatialFilteringProfilePathToDirList(StringBuilder builder, Map<String,Object> settings, String spatialFilteringProfilePath)
builder
- Mapping files directories Stringsettings
- Datasource settingsspatialFilteringProfilePath
- Spatial Filtering Profile mapping files pathprotected BooleanSettingDefinition getOldConceptDefiniton()
protected boolean isTransactional(Properties properties)
properties
- Datasource propertiestrue
, if properties contains transactional mapping
pathprotected BooleanSettingDefinition getTransactionalDefiniton()
@Deprecated protected boolean isSpatialFilteringProfile(Properties properties)
properties
- Datasource propertiestrue
, if properties contains Spatial Filtering
Profile mapping path@Deprecated protected BooleanSettingDefinition getSpatialFilteringProfileDefiniton()
private <T> T[] concat(T[] first, T[]... rest)
first
- First arrayrest
- The other arrayprotected String[] getPreSchemaScript()
protected String[] getPostSchemaScript()
public boolean isTransactionalDatasource()
true
, if it is a transactionalDatasourcepublic void setTransactional(boolean transactionalDatasource)
transactionalDatasource
- the transactionalDatasource flag to set@Deprecated public boolean isSpatialFilteringProfileDatasource()
true
, if it has Spatial Filtering Profile@Deprecated public void setSpatialFilteringProfile(boolean spatialFilteringProfileDatasource)
spatialFilteringProfileDatasource
- the spatialFilteringProfileDatasource to setprotected String[] checkCreateSchema(String[] script)
script
- Create and not checked script.protected String[] checkScriptForGeneratedAndDuplicatedEntries(String[] script)
script
- Not checked script.private String getGeneratedForeignKeyFor(String tableName)
string
- Table nameprotected String[] checkDropSchema(String[] dropSchema)
dropSchema
- Schema to checkpublic DatasourceCallback getCallback()
getCallback
in interface Datasource
public void prepare(Map<String,Object> settings)
Datasource
prepare
in interface Datasource
settings
- the settings to connectpublic boolean isPostCreateSchema()
isPostCreateSchema
in interface Datasource
public void executePostCreateSchema(Map<String,Object> databaseSettings)
executePostCreateSchema
in interface Datasource
public String getConnectionProviderIdentifier()
getConnectionProviderIdentifier
in interface ConnectionProviderIdentificator
public String getDatasourceDaoIdentifier()
getDatasourceDaoIdentifier
in interface DatasourceDaoIdentifier
protected abstract String getDriverClass()
protected abstract void validatePrerequisites(Connection con, org.hibernate.tool.hbm2ddl.DatabaseMetadata metadata, Map<String,Object> settings)
con
- SQL connectionmetadata
- Current database metadatasettings
- Datasource settingsprotected abstract org.hibernate.dialect.Dialect createDialect()
protected abstract Connection openConnection(Map<String,Object> settings) throws SQLException
settings
- Datasource setting: URL, username, passsword, database, ...SQLException
- If the SQL connection creation failsCopyright © 2012-2014 52north.org. All Rights Reserved.