com.astroshare.astroonline.database
Class Database

java.lang.Object
  extended by com.astroshare.astroonline.database.Database
Direct Known Subclasses:
Sql

public class Database
extends java.lang.Object

Implementation of the Astro-Online database connection.

The Astro-Online Database object implements connection pooling by default. Connection pooling is supported in two variants:

  1. Through class Pool
  2. Through JNDI

Whether variant 1 or 2 is used, depends on the value of the node AstroOnlineConfiguration.server.database in the configuration file. If the value is JDNI, variant 2 is used, otherwise variant 1 is used.

Variant 1: Through class Pool

The class Pool is an Astro-Online implementation of a MySQL connection pool. Astro-Online uses this option by default since the value of the node AstroOnlineConfiguration.server.database in the configuration file is POOL by default.

Variant 2: Through JNDI

To use JNDI a connection pool on the web server has to be setup. See the documentation of your the web server for more information on this topic.

Additional information

Astro-Online by default connects to a mysql database. Connecting to other databases should be possible with JNDI but was not tested. It is not possible to connect to other databases with class Pool since this class implicitly implements a connection to MySQL. If an implementation of a pool for another database is necessary, a new pool implementation has to be added and class Database has to be changed to use this implementation.

As a rule of thumb it is best to use the default settings if there runs only one Astro-Online instance on a server. If more than one Astro-Online instance runs on one server, a connection pool can be shared amongst the Astro-Online instances with JNDI. Please, be aware that sharing the connection pool amongst more than one Astro-Online instances means that these instances also share the same tables and therefore use the same configuration table and template table. To give each instance a unique configuration and unique templates, a profile can be added with its own configuration records in the configuration table and its own templates in the templates table. To force an instance to use a specific profile, the node AstroOnlineConfiguration.server.profile in the configuration file has to be modified accordingly. Please read the Astro-Online documentation for more information on the topic.

See Also:
Pool, Sql

Field Summary
protected  java.sql.Connection conn
          Database connection object
protected static org.apache.log4j.Logger log
          init logging
 
Constructor Summary
Database()
           Constructor.
 
Method Summary
 void close()
           Close connection.
 int execute(java.lang.String sqlStatement)
           Execute a SQL DML statement with exception of a SELECT statement (e.q.
 java.sql.ResultSet executeQuery(java.lang.String sqlStatement)
           Execute SQL SELECT statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.apache.log4j.Logger log
init logging


conn

protected java.sql.Connection conn
Database connection object

Constructor Detail

Database

public Database()
         throws javax.naming.NamingException,
                java.sql.SQLException

Constructor.

Throws:
javax.naming.NamingException - Exception is thrown when JNDI datasource is not found
java.sql.SQLException - Exception is thrown when a connection cannot be established
Method Detail

close

public void close()

Close connection.


executeQuery

public java.sql.ResultSet executeQuery(java.lang.String sqlStatement)

Execute SQL SELECT statement. Use method execute(java.lang.String) for other SQL DML statements.

Parameters:
sqlStatement - SQL statement
Returns:
Resultset containing the selected records
See Also:
execute(java.lang.String)

execute

public int execute(java.lang.String sqlStatement)

Execute a SQL DML statement with exception of a SELECT statement (e.q. INSERT, UPDATE and DELETE). Use method executeQuery(java.lang.String) for SELECT statements.

Parameters:
sqlStatement - SQL statement
Returns:
-1=An error accured;0=no records effected; >0=number of records effected
See Also:
executeQuery(java.lang.String)


Astro-Online © 2001 − 2008 Astro Share
Documentation generated on: Thursday August 12th 2008 (PS)