*/
@Override
protected void initDatabase() throws NamingException, RepositoryException, IOException
{
StorageDBInitializer dbInitializer = null;
String sqlPath = DBInitializerHelper.scriptPath(dbDialect, multiDb);
if (dbDialect == DBConstants.DB_DIALECT_ORACLEOCI)
{
LOG.warn(DBConstants.DB_DIALECT_ORACLEOCI + " dialect is experimental!");
// sample of connection factory customization
if (dbSourceName != null)
{
this.connFactory =
new DefaultOracleConnectionFactory(getDataSource(), containerName, multiDb, valueStorageProvider, maxBufferSize,
swapDirectory, swapCleaner, useQueryHints);
}
else
this.connFactory =
new OracleConnectionFactory(dbDriver, dbUrl, dbUserName, dbPassword, containerName, multiDb,
valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner, useQueryHints);
// a particular db initializer may be configured here too
dbInitializer = new OracleDBInitializer(containerName, this.connFactory.getJdbcConnection(), sqlPath, multiDb);
}
else if (dbDialect == DBConstants.DB_DIALECT_ORACLE)
{
if (dbSourceName != null)
{
this.connFactory =
new DefaultOracleConnectionFactory(getDataSource(), containerName, multiDb, valueStorageProvider, maxBufferSize,
swapDirectory, swapCleaner, useQueryHints);
}
else
this.connFactory =
new DefaultOracleConnectionFactory(dbDriver, dbUrl, dbUserName, dbPassword, containerName, multiDb,
valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner, useQueryHints);
dbInitializer = new OracleDBInitializer(containerName, this.connFactory.getJdbcConnection(), sqlPath, multiDb);
}
else if (dbDialect == DBConstants.DB_DIALECT_PGSQL)
{
if (dbSourceName != null)
{
this.connFactory =
new PostgreConnectionFactory(getDataSource(), containerName, multiDb, valueStorageProvider,
maxBufferSize, swapDirectory, swapCleaner);
}
else
this.connFactory =
new PostgreConnectionFactory(dbDriver, dbUrl, dbUserName, dbPassword, containerName, multiDb,
valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
dbInitializer = new PgSQLDBInitializer(containerName, this.connFactory.getJdbcConnection(), sqlPath, multiDb);
}
else if (dbDialect == DBConstants.DB_DIALECT_MYSQL || dbDialect == DBConstants.DB_DIALECT_MYSQL_UTF8 ||
dbDialect == DBConstants.DB_DIALECT_MYSQL_MYISAM || dbDialect == DBConstants.DB_DIALECT_MYSQL_MYISAM_UTF8)
{
if (dbDialect == DBConstants.DB_DIALECT_MYSQL_MYISAM || dbDialect == DBConstants.DB_DIALECT_MYSQL_MYISAM_UTF8)
{
LOG.warn("MyISAM is not supported due to its lack of transaction support and integrity check, so use it only" +
" if you don't expect any support and performances in read accesses are more important than the consistency" +
" in your use-case. This dialect is only dedicated to the community.");
}
if (dbSourceName != null)
{
this.connFactory =
new MySQLConnectionFactory(getDataSource(), containerName, multiDb, valueStorageProvider, maxBufferSize,
swapDirectory, swapCleaner);
}
else
this.connFactory =
new MySQLConnectionFactory(dbDriver, dbUrl, dbUserName, dbPassword, containerName, multiDb,
valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
dbInitializer = defaultDBInitializer(sqlPath);
}
else if (dbDialect == DBConstants.DB_DIALECT_MSSQL)
{
if (dbSourceName != null)
{
this.connFactory =
new MSSQLConnectionFactory(getDataSource(), containerName, multiDb, valueStorageProvider, maxBufferSize,
swapDirectory, swapCleaner);
}
else
{
this.connFactory =
new MSSQLConnectionFactory(dbDriver, dbUrl, dbUserName, dbPassword, containerName, multiDb,
valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
}
dbInitializer = defaultDBInitializer(sqlPath);
}
else if (dbDialect == DBConstants.DB_DIALECT_DERBY)
{
this.connFactory = defaultConnectionFactory();
dbInitializer = defaultDBInitializer(sqlPath);
}
else if (dbDialect == DBConstants.DB_DIALECT_DB2)
{
if (dbSourceName != null)
{
this.connFactory =
new DB2ConnectionFactory(getDataSource(), containerName, multiDb, valueStorageProvider, maxBufferSize,
swapDirectory, swapCleaner);
}
else
{
this.connFactory =
new DB2ConnectionFactory(dbDriver, dbUrl, dbUserName, dbPassword, containerName, multiDb,
valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
}
dbInitializer = defaultDBInitializer(sqlPath);
}
else if (dbDialect == DBConstants.DB_DIALECT_DB2V8)
{
if (dbSourceName != null)
{
this.connFactory =
new DB2ConnectionFactory(getDataSource(), containerName, multiDb, valueStorageProvider, maxBufferSize,
swapDirectory, swapCleaner);
}
else
{
this.connFactory =
new DB2ConnectionFactory(dbDriver, dbUrl, dbUserName, dbPassword, containerName, multiDb,
valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
}
dbInitializer = defaultDBInitializer(sqlPath);
}
else if (dbDialect == DBConstants.DB_DIALECT_SYBASE)
{
if (dbSourceName != null)
{
this.connFactory =
new SybaseConnectionFactory(getDataSource(), containerName, multiDb, valueStorageProvider, maxBufferSize,
swapDirectory, swapCleaner);
}
else
{
this.connFactory =
new SybaseConnectionFactory(dbDriver, dbUrl, dbUserName, dbPassword, containerName, multiDb,
valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
}
dbInitializer = defaultDBInitializer(sqlPath);
}
else if (dbDialect == DBConstants.DB_DIALECT_INGRES)
{
this.connFactory = defaultConnectionFactory();
// using Postgres initializer
dbInitializer =
new IngresSQLDBInitializer(containerName, this.connFactory.getJdbcConnection(), sqlPath, multiDb);
}
else if (dbDialect == DBConstants.DB_DIALECT_HSQLDB)
{
if (dbSourceName != null)
{
this.connFactory =
new HSQLDBConnectionFactory(getDataSource(), containerName, multiDb, valueStorageProvider, maxBufferSize,
swapDirectory, swapCleaner);
}
else
this.connFactory =
new HSQLDBConnectionFactory(dbDriver, dbUrl, dbUserName, dbPassword, containerName, multiDb,
valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
dbInitializer = defaultDBInitializer(sqlPath);
}
else
{
// generic, DB_HSQLDB
this.connFactory = defaultConnectionFactory();
dbInitializer = defaultDBInitializer(sqlPath);
}
// database type
try
{
dbInitializer.init();
}
catch (DBInitializerException e)
{
LOG.error("Error of init db " + e, e);
}