protected void initializeTable( String tableName )
throws ArchivaDatabaseException
{
SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();
try
{
sqlMap.startTransaction();
Connection con = sqlMap.getCurrentConnection();
DatabaseMetaData databaseMetaData = con.getMetaData();
ResultSet rs = databaseMetaData.getTables( con.getCatalog(), null, null, null );
// check if the index database exists in the database
while ( rs.next() )
{
String dbTableName = rs.getString( "TABLE_NAME" );
// if it does then we are already initialized
if ( dbTableName.toLowerCase().equals( tableName.toLowerCase() ) )
{
return;
}
}
// Create the tables
getLogger().info( "Creating table: " + tableName );
sqlMap.update( createPrefix + tableName, null );
sqlMap.commitTransaction();
}
catch ( SQLException e )
{
getLogger().error( "Error while initializing database, showing all linked exceptions in SQLException." );
while ( e != null )
{
getLogger().error( e.getMessage(), e );
e = e.getNextException();
}
throw new ArchivaDatabaseException( "Error while setting up database.", e );
}
finally
{
try
{
sqlMap.endTransaction();
}
catch ( SQLException e )
{
e.printStackTrace();
}