org.mmbase.storage.implementation.database
Class DatabaseStorageManagerFactory

Package class diagram package DatabaseStorageManagerFactory
java.lang.Object
  extended by org.mmbase.storage.StorageManagerFactory<DatabaseStorageManager>
      extended by org.mmbase.storage.implementation.database.DatabaseStorageManagerFactory

public class DatabaseStorageManagerFactory
extends StorageManagerFactory<DatabaseStorageManager>

A storage manager factory for database storages. This factory sets up a datasource for connecting to the database. If you specify the datasource URI in the 'datasource' property in mmbaseroot.xml configuration file, the factory attempts to obtain the datasource from the application server. If this fails, or no datasource URI is given, it attempts to use the connectivity offered by the JDBC Module, which is then wrapped in a datasource. Note that if you provide a datasource you should make the JDBC Module inactive to prevent the module from interfering with the storage layer.

Since:
MMBase-1.7
Version:
$Id: DatabaseStorageManagerFactory.java 45315 2011-02-18 20:23:11Z michiel $
Author:
Pierre van Rooden
To Do:
backward compatibility with the old supportclasses should be done by creating a separate Factory (LegacyStorageManagerFactory ?).

Field Summary
protected  String catalog
          The catalog used by this storage.
protected  DataSource dataSource
          The datasource in use by this factory.
(package private) static long MS
           
protected  boolean supportsForeignKeys
           
protected  boolean supportsTransactions
          Whether transactions and rollback are supported by this database
protected  int transactionIsolation
          The transaction isolation level available for this storage.
(package private)  UtilReader.PropertiesMap<String> utilProperties
           
 
Fields inherited from class org.mmbase.storage.StorageManagerFactory
attributes, changeManager, collationMappings, disallowedFields, getSurrogator, mmbase, queryHandler, queryHandlerClasses, setSurrogator, storageManagerClass, storeBinaryAsFileObjects, typeMappings
 
Constructor Summary
DatabaseStorageManagerFactory()
           
 
Method Summary
static boolean checkBinaryFileBasePath(File baseDir)
          Tries to ensure that baseDir exists and is writable.
protected  DataSource createDataSource(File binaryFileBasePath)
           
 File getBinaryFileBasePath()
          As getBinaryFileBasePath(boolean) with true
protected  File getBinaryFileBasePath(boolean check)
          Returns the base path for 'binary file'
 String getCatalog()
          Returns the name of the catalog used by this storage (null if no catalog is used).
 String getDatabaseName()
          Doing some best effort to get a 'database name'.
 DataSource getDataSource()
          Returns the DataSource associated with this factory.
 StorageReader getDocumentReader()
          Locates and opens the storage configuration document, if available.
protected  int getMaxKeyLength()
          The maximal length an index in the database can have, or Integer.MAX_VALUE.
protected  Throwable getTraceException()
           
 double getVersion()
          Returns the version of this factory implementation.
protected  Object instantiateBasicHandler(Class handlerClass)
          Instantiate a basic handler object using the specified class.
protected  Object instantiateChainedHandler(Class handlerClass, Object handler)
          Instantiate a chained handler object using the specified class.
protected  SearchQueryHandler instantiateQueryHandler(Object data)
          Instantiate a SearchQueryHandler object using the specified object.
protected  void load()
          Opens and reads the storage configuration document.
protected  boolean logQuery(String query, long duration)
           
static void main(String[] args)
           
 boolean supportsTransactions()
          Returns whether transactions, and specifically rollback, is supported in the storage layer.
 
Methods inherited from class org.mmbase.storage.StorageManagerFactory
beginTransaction, commit, createStorageManager, getAttribute, getAttributes, getChangeManager, getDisallowedFields, getGetSurrogator, getMappedCollation, getMMBase, getScheme, getScheme, getSearchQueryHandler, getSetSurrogator, getStorageIdentifier, getStorageIdentifier, getStorageManager, getStoreBinaryAsFileObjects, getTimeZoneOffset, getTypeMappings, hasOption, init, newInstance, newInstance, rollback, setAttribute, setAttributes, setDisallowedFields, setOption, setScheme
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

catalog

protected String catalog
The catalog used by this storage.


dataSource

protected DataSource dataSource
The datasource in use by this factory. The datasource is retrieved either from the application server, or by wrapping the JDBC Module in a generic datasource.


transactionIsolation

protected int transactionIsolation
The transaction isolation level available for this storage. Default TRANSACTION_NONE (no transaction support). The actual value is determined from the database metadata.


supportsTransactions

protected boolean supportsTransactions
Whether transactions and rollback are supported by this database


supportsForeignKeys

protected boolean supportsForeignKeys
Since:
MMBase-1.9.2

MS

static final long MS
Since:
MMBase-1.9.1
See Also:
Constant Field Values

utilProperties

final UtilReader.PropertiesMap<String> utilProperties
Constructor Detail

DatabaseStorageManagerFactory

public DatabaseStorageManagerFactory()
Method Detail

getVersion

public double getVersion()
Description copied from class: StorageManagerFactory
Returns the version of this factory implementation. The factory uses this number to verify whether it can handle storage configuration files that list version requirements.

Specified by:
getVersion in class StorageManagerFactory<DatabaseStorageManager>
Returns:
the version as an integer

supportsTransactions

public boolean supportsTransactions()
Description copied from class: StorageManagerFactory
Returns whether transactions, and specifically rollback, is supported in the storage layer.

Specified by:
supportsTransactions in class StorageManagerFactory<DatabaseStorageManager>
Returns:
true if trasnactions are supported

getCatalog

public String getCatalog()
Description copied from class: StorageManagerFactory
Returns the name of the catalog used by this storage (null if no catalog is used).

Overrides:
getCatalog in class StorageManagerFactory<DatabaseStorageManager>

getDatabaseName

public String getDatabaseName()
Doing some best effort to get a 'database name'.

Since:
MMBase-1.8

getDataSource

public DataSource getDataSource()
Returns the DataSource associated with this factory.

Since:
MMBase-1.8

createDataSource

protected DataSource createDataSource(File binaryFileBasePath)
Parameters:
binaryFileBasePath - For some datasource a file base path may be needed (some configurations of hsql). It can be null during bootstrap. In lookup.xml an alternative URL may be configured then which does not need the file base path.
Since:
MMBase-1.8

load

protected void load()
             throws StorageException
Opens and reads the storage configuration document. Obtain a datasource to the storage, and load configuration attributes.

Overrides:
load in class StorageManagerFactory<DatabaseStorageManager>
Throws:
StorageException - if the storage could not be accessed or necessary configuration data is missing or invalid

getDocumentReader

public StorageReader getDocumentReader()
                                throws StorageException
Locates and opens the storage configuration document, if available. The configuration document to open can be set in mmbasereoot (using the storage property). The property should point to a resource which is to be present in the MMBase classpath. Overriding factories may provide ways to auto-detect the location of a configuration file. MMBase determine it using information gained from the datasource, and the lookup.xml file in the database configuration directory Storage configuration files should become resource files, and configurable using a storageresource property. The type of reader to return should be a StorageReader.

Overrides:
getDocumentReader in class StorageManagerFactory<DatabaseStorageManager>
Returns:
a StorageReader instance
Throws:
StorageException - if the storage could not be accessed while determining the database type

getBinaryFileBasePath

public File getBinaryFileBasePath()
As getBinaryFileBasePath(boolean) with true


getBinaryFileBasePath

protected File getBinaryFileBasePath(boolean check)
Returns the base path for 'binary file'

Parameters:
check - If the path is only perhaps needed, you may want to provide 'false' here.
Since:
MMBase-1.8.1

checkBinaryFileBasePath

public static boolean checkBinaryFileBasePath(File baseDir)
Tries to ensure that baseDir exists and is writable. Logs error and returns false otherwise.

Parameters:
baseDir - a Directory name
Since:
MMBase-1.8.1

instantiateBasicHandler

protected Object instantiateBasicHandler(Class handlerClass)
Description copied from class: StorageManagerFactory
Instantiate a basic handler object using the specified class. A basic handler can be any type of class and is dependent on the factory implementation. For instance, the database factory expects an org.mmbase.storage.search.implentation.database.SQLHandler class.

Specified by:
instantiateBasicHandler in class StorageManagerFactory<DatabaseStorageManager>
Parameters:
handlerClass - the class to instantuate teh object with
Returns:
the new handler class

instantiateChainedHandler

protected Object instantiateChainedHandler(Class handlerClass,
                                           Object handler)
Description copied from class: StorageManagerFactory
Instantiate a chained handler object using the specified class. A chained handler can be any type of class and is dependent on the factory implementation. For instance, the database factory expects an org.mmbase.storage.search.implentation.database.ChainedSQLHandler class.

Specified by:
instantiateChainedHandler in class StorageManagerFactory<DatabaseStorageManager>
Parameters:
handlerClass - the class to instantuate teh object with
handler - a handler thatw a sinstantiated previously. this handler should be passed to the new handler class during or after constrcution, so the ne whandler can 'chain' any events it cannot handle to this class.
Returns:
the new handler class

instantiateQueryHandler

protected SearchQueryHandler instantiateQueryHandler(Object data)
Description copied from class: StorageManagerFactory
Instantiate a SearchQueryHandler object using the specified object. The specified parameter may be an actual SearchQueryHandler object, or it may be a utility class. For instance, the database factory expects an org.mmbase.storage.search.implentation.database.SQLHandler object, which is used as a parameter in the construction of the actual SearchQueryHandler class.

Specified by:
instantiateQueryHandler in class StorageManagerFactory<DatabaseStorageManager>
Parameters:
data - the object to instantuate a SearchQueryHandler object with

getMaxKeyLength

protected int getMaxKeyLength()
The maximal length an index in the database can have, or Integer.MAX_VALUE.

Since:
MMBase-1.9.6

getTraceException

protected Throwable getTraceException()

logQuery

protected boolean logQuery(String query,
                           long duration)
Returns:
whether logged
Since:
MMBase-1.9.1

main

public static void main(String[] args)


MMBase2 Core 2.0-SNAPSHOT - 2013-03-30T06:36