de.topicmapslab.majortom.database.jdbc.rdbms
Class RDBMSConnectionProvider

java.lang.Object
  extended by de.topicmapslab.majortom.database.jdbc.rdbms.RDBMSConnectionProvider
All Implemented Interfaces:
IConnectionProvider
Direct Known Subclasses:
BasePostGreSqlConnectionProvider, HSQLDBConnectionProvider, MonetDBConnectionProvider, MySqlConnectionProvider

public abstract class RDBMSConnectionProvider
extends java.lang.Object
implements IConnectionProvider

Special connection provider for PostGreSQL.

Author:
Sven Krosse

Field Summary
private  long connectionCount
          the number of connections for connection pool
private  java.lang.String database
          the database name
private  ISession globalSession
          the global session of the connection provider
private  java.lang.String host
          the host
private  java.lang.String password
          the database password
private  JdbcTopicMapStore store
          internal reference of the topic map store
private  java.lang.String url
          the database URL
private  java.lang.String user
          the database user
 
Fields inherited from interface de.topicmapslab.majortom.database.jdbc.model.IConnectionProvider
DATABASE_NOT_EXISTS, STATE_DATABASE_IS_EMPTY, STATE_DATABASE_IS_INVALID, STATE_DATABASE_IS_VALID
 
Constructor Summary
RDBMSConnectionProvider()
          constructor
RDBMSConnectionProvider(java.lang.String host, java.lang.String database, java.lang.String user, java.lang.String password)
          Constructor
 
Method Summary
 void close()
          Closing the connection provider
 void createSchema()
          Method called by the connection provider to initialize the database schema.
 long getConnectionCount()
           
 java.lang.String getDatabase()
          Returns the database name
 java.sql.DatabaseMetaData getDatabaseMetaData()
          Return the meta data of the existing connection.
 int getDatabaseState()
          Method checks if the schema of the current database connection is valid..
protected  ISession getGlobalSession()
          Returns the internal session of the connection provider
 java.lang.String getHost()
          Returns the database host server
protected  java.lang.String getPassword()
          Returns the password database property
protected  java.lang.String[] getSchemaQueries()
          Returns the queries needed to create the database schema (because mysql does not support multi-statements)
protected  java.lang.String getSchemaQuery()
          Returns the SQL query to create the database schema.
 JdbcTopicMapStore getTopicMapStore()
          Returns the internal reference of the encapsulated topic map store
protected  java.lang.String getUrl()
          Returns the URL to the database
protected  java.lang.String getUser()
          Returns the user database property
 RDBMSSession openSession()
          Creating a new session for accessing the database
 void setTopicMapStore(JdbcTopicMapStore store)
          Method set the internal reference of the JDBC topic map store to the given reference.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.topicmapslab.majortom.database.jdbc.model.IConnectionProvider
getDriverClassName, getRdbmsName
 

Field Detail

store

private JdbcTopicMapStore store
internal reference of the topic map store


user

private java.lang.String user
the database user


password

private java.lang.String password
the database password


url

private java.lang.String url
the database URL


database

private java.lang.String database
the database name


host

private java.lang.String host
the host


connectionCount

private long connectionCount
the number of connections for connection pool


globalSession

private ISession globalSession
the global session of the connection provider

Constructor Detail

RDBMSConnectionProvider

public RDBMSConnectionProvider()
constructor


RDBMSConnectionProvider

public RDBMSConnectionProvider(java.lang.String host,
                               java.lang.String database,
                               java.lang.String user,
                               java.lang.String password)
Constructor

Parameters:
host - the host
database - database
user - the user
password - the password
Method Detail

openSession

public RDBMSSession openSession()
Creating a new session for accessing the database

Specified by:
openSession in interface IConnectionProvider
Returns:
the new session

getUrl

protected java.lang.String getUrl()
Returns the URL to the database

Returns:
the URl

getUser

protected java.lang.String getUser()
Returns the user database property

Returns:
the user

getPassword

protected java.lang.String getPassword()
Returns the password database property

Returns:
the passwords

getDatabase

public java.lang.String getDatabase()
Returns the database name

Returns:
the database

getHost

public java.lang.String getHost()
Returns the database host server

Returns:
the host

getConnectionCount

public long getConnectionCount()
Returns:
the connectionCount

setTopicMapStore

public void setTopicMapStore(JdbcTopicMapStore store)
Method set the internal reference of the JDBC topic map store to the given reference.

Specified by:
setTopicMapStore in interface IConnectionProvider
Parameters:
store - the topic map store

getTopicMapStore

public JdbcTopicMapStore getTopicMapStore()
Returns the internal reference of the encapsulated topic map store

Specified by:
getTopicMapStore in interface IConnectionProvider

close

public void close()
           throws java.sql.SQLException
Closing the connection provider

Specified by:
close in interface IConnectionProvider
Throws:
java.sql.SQLException - thrown if operation fails

getGlobalSession

protected ISession getGlobalSession()
Returns the internal session of the connection provider

Returns:
the internal session of the connection provider

getDatabaseMetaData

public java.sql.DatabaseMetaData getDatabaseMetaData()
                                              throws de.topicmapslab.majortom.model.exception.TopicMapStoreException
Return the meta data of the existing connection. If the connection is not open, an exception will be thrown.

Specified by:
getDatabaseMetaData in interface IConnectionProvider
Returns:
the meta data
Throws:
de.topicmapslab.majortom.model.exception.TopicMapStoreException - thrown if the connection is not established

createSchema

public void createSchema()
                  throws java.sql.SQLException
Method called by the connection provider to initialize the database schema.

Specified by:
createSchema in interface IConnectionProvider
Throws:
java.sql.SQLException

getSchemaQuery

protected java.lang.String getSchemaQuery()
Returns the SQL query to create the database schema.

Returns:
the query

getSchemaQueries

protected java.lang.String[] getSchemaQueries()
Returns the queries needed to create the database schema (because mysql does not support multi-statements)

Returns:
an array of queries

getDatabaseState

public int getDatabaseState()
                     throws java.sql.SQLException
Method checks if the schema of the current database connection is valid..

Specified by:
getDatabaseState in interface IConnectionProvider
Returns:

0 if the database is empty.
1 if the database schema is invalid.
2 if the database schema is valid.

Throws:
java.sql.SQLException