Class DBInitializer
- java.lang.Object
-
- edu.uiuc.ncsa.security.storage.sql.SQLDatabase
-
- edu.uiuc.ncsa.security.storage.sql.DBInitializer
-
- All Implemented Interfaces:
Initializable
public abstract class DBInitializer extends SQLDatabase implements Initializable
A class that automates the creation of tables and indices for an SQL database. This implements theInitializable
interface to manage create, init and destroy correctly. Note that init and destroy are scoped at the schema level, that is to say destroy does not remove a database, just a given schema within the database.Created by Jeff Gaynor
on May 9, 2010 at 1:05:53 PM
-
-
Constructor Summary
Constructors Constructor Description DBInitializer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
createNew()
Creates a completely new instance.abstract void
createSchema(Statement s)
This should create the schema for the database.abstract void
createTables(Statement s)
Create the tables for a given database.boolean
destroy()
Destroy the object completely.protected void
destroy2()
This really does what destroy does.abstract void
dropSchema(Statement s)
Drops the schema if it exists.abstract void
dropTables(Statement s)
Drops the tables within the schema.protected AdminConnectionParameters
getAdminConnectionParameters()
String
getDatabaseName()
String
getSchema()
The schema for the databaseString
getUser()
The user who will be running the server -- this *should* in general be different from the administratorboolean
init()
Initialize an existing object.protected void
init2()
This will call createSchema, then createTables and setPermissions.boolean
isCreated()
(Optional) Returns true if the object in question has been created.boolean
isDestroyed()
(Optional) Returns true if the object in question has been destroyed.boolean
isInitialized()
(Optional) Returns true if the object in question has been initialized.abstract void
recreateTransactionTables(Statement s)
A specific call to recreate only the transaction tables.abstract void
setPermissions(Statement s)
The permissions are automatically given to the admin, but the user needs to be able to access the database, schema and tables as well.-
Methods inherited from class edu.uiuc.ncsa.security.storage.sql.SQLDatabase
destroyConnection, getConnection, getConnectionPool, releaseConnection, rsToMap, setConnectionPool
-
-
-
-
Method Detail
-
getDatabaseName
public String getDatabaseName()
-
getAdminConnectionParameters
protected AdminConnectionParameters getAdminConnectionParameters()
-
getSchema
public String getSchema()
The schema for the database- Returns:
-
getUser
public String getUser()
The user who will be running the server -- this *should* in general be different from the administrator- Returns:
-
setPermissions
public abstract void setPermissions(Statement s) throws SQLException
The permissions are automatically given to the admin, but the user needs to be able to access the database, schema and tables as well. This sets these permissions.- Parameters:
s
-- Throws:
SQLException
-
createSchema
public abstract void createSchema(Statement s) throws SQLException
This should create the schema for the database. If the schema already exists, it should be removed and recreated.- Throws:
SQLException
-
dropSchema
public abstract void dropSchema(Statement s) throws SQLException
Drops the schema if it exists. Otherwise has no effect.- Parameters:
s
-- Throws:
SQLException
-
createTables
public abstract void createTables(Statement s) throws SQLException
Create the tables for a given database. This should also create any indices needed.- Parameters:
s
-- Throws:
SQLException
-
recreateTransactionTables
public abstract void recreateTransactionTables(Statement s) throws SQLException
A specific call to recreate only the transaction tables. This is usable by both client and server.- Parameters:
s
-- Throws:
SQLException
-
dropTables
public abstract void dropTables(Statement s) throws SQLException
Drops the tables within the schema.- Throws:
SQLException
-
init2
protected void init2() throws SQLException
This will call createSchema, then createTables and setPermissions.- Throws:
SQLException
-
init
public boolean init()
Description copied from interface:Initializable
Initialize an existing object. This throws an exception if the object does not exist. The state after this call is exactly as if the system were created for the first time. Calls to the object before invocation have no guarantee of success.- Specified by:
init
in interfaceInitializable
- Returns:
- Returns True if the operation succeeds.
-
destroy2
protected void destroy2() throws SQLException
This really does what destroy does. Destroy() has to catch exceptions and return booleans.- Throws:
SQLException
-
destroy
public boolean destroy()
Description copied from interface:Initializable
Destroy the object completely. Returnstrue
if the object existed before destroy was called. Further calls to this object must fail after this invocation.- Specified by:
destroy
in interfaceInitializable
-
createNew
public boolean createNew()
Description copied from interface:Initializable
Creates a completely new instance. Fails if an instance already exists. In that case, call destroy first. For instance, this might create all file system entries or drop then recreate all tables in an SQL database. Compare this with init which might delete any entries in a file store or SQL table.- Specified by:
createNew
in interfaceInitializable
- Returns:
-
isCreated
public boolean isCreated()
Description copied from interface:Initializable
(Optional) Returns true if the object in question has been created. If this cannot be determined then the call should throw an exception.- Specified by:
isCreated
in interfaceInitializable
- Returns:
-
isInitialized
public boolean isInitialized()
Description copied from interface:Initializable
(Optional) Returns true if the object in question has been initialized. If this cannot be determined this call should throw an exception.- Specified by:
isInitialized
in interfaceInitializable
- Returns:
-
isDestroyed
public boolean isDestroyed()
Description copied from interface:Initializable
(Optional) Returns true if the object in question has been destroyed. If this cannot be determined this call should throw an exception.- Specified by:
isDestroyed
in interfaceInitializable
- Returns:
-
-