net.sourceforge.fluxion.datapublisher.beangen
Interface BeanFactory

All Known Implementing Classes:
BiomartBeanFactory, MySQLBeanFactory, ODBCBeanFactory, PostgresqlBeanFactory, SQLBeanFactory

@Spi
public interface BeanFactory

An interface for generating a bean model of a datasource that will be exposed to the Comparagrid stack. Implementations of this interface should provide a method for generating beans given some connection details, and optionally a set of bean classes that represent the meta-data for the native datasource language.

Clients will discover available bean factories for a database dbms by calling dbms(). As such, each implementation should provide a string that supplies the name of the dbms that this implementation can generate beans for.

Generated beans should be written to the supplied directory when generateBeans() is called. This allows the construction of a jar file containing the bean model. Implementations are free to describe their own strategy for package naming and directory structure. However, the base package name should be retained so clients can callgetPackageName(), enabling them to load the package of classes that have been created.

Implementations of this interface should have an empty constructor, so as to allow dynamic discovery and creation of services at runtime. Any details required to initiate a connection to the underlying database should be set when acquireDatasourceConnection() is called. Implementations should define an initialised map on construction, containing the keys that should be set when a connection is acquired, so as to allow callers to determine those parameters necessary by calling getDatasourceConnectionParameters().keySet() before setting any values. The connection details supplied may include some default values: for example, the MySqlBeanFactory implementation requires parameters "uri", "user" and "password". The Map that is returned from a new instance of this class returns a map containing [uri = null], [user = "anonymous"] and [password = ""]. A client can then set the uri to access a public database using these common settings and a connection can be acquired.

Version:
0.2
Author:
Tony Burdett

Method Summary
 void acquireDatasourceConnection(java.util.Map<java.lang.String,java.lang.String> connectionDetails)
          Acquire a connection to the underlying datasource.
 boolean dbms(java.lang.String dbms)
          Determines whether a BeanFactory implementation can generate beans for the given dbms.
 void donotUseTableFiltering()
          Use this if a single factory is used to generate multiple sets of beans, and you want to stop tables from being filtered.
 void generateBeans(java.io.File sourceDirectory, java.lang.String packageName, java.util.Set<java.lang.Class> metaBeans, java.lang.String... schemas)
          Generate a set of beans to model the dbms the database this factory represents.
 java.util.Map<java.lang.String,java.lang.String> getDatasourceConnectionParameters()
          Returns the map of connection parameters supplied for this BeanFactory.
 java.lang.String getPackageName()
          Returns the package name known for this BeanFactory
 void terminateDatasourceConnection()
          Close the connection to the underlying datasource.
 void useTableFiltering(java.io.File filterTables)
          Enables filtering of tables by parsing a plain text file.
 

Method Detail

getDatasourceConnectionParameters

java.util.Map<java.lang.String,java.lang.String> getDatasourceConnectionParameters()
Returns the map of connection parameters supplied for this BeanFactory. If this hasn't been set, the BeanFactory should return an initialised map containing the keys required for a connection to be acquired.

Returns:
the connection parameters set so far.

acquireDatasourceConnection

void acquireDatasourceConnection(java.util.Map<java.lang.String,java.lang.String> connectionDetails)
                                 throws BeanGenerationException
Acquire a connection to the underlying datasource. This map should contain parameters for databse URL, username, and password. Use getDatasourceConnectionParameters().keySet() to get the parameters that must be set. Or do a lookup on these key values to get the default values (e.g. "anonymous" is the default username). This way, those parameters which have been set can be used, whilst null fields will be ignored if possible (for example, in the case where password="" in accessing a public MySql database).

Parameters:
connectionDetails - a map containing parameters for connection to the database.
Throws:
BeanGenerationException - if the connection could not be acquired

terminateDatasourceConnection

void terminateDatasourceConnection()
                                   throws BeanGenerationException
Close the connection to the underlying datasource. Any open connection will be closed, and it is very important that implementations of this class close all connections correclty to prevent future access problems.

Throws:
BeanGenerationException - if there is a problem closing the connection

generateBeans

void generateBeans(java.io.File sourceDirectory,
                   java.lang.String packageName,
                   java.util.Set<java.lang.Class> metaBeans,
                   java.lang.String... schemas)
                   throws BeanGenerationException
Generate a set of beans to model the dbms the database this factory represents. The output directory where the generated beans should go, the package name to use for all generated sources, and (optionally) the set of annotation classes representing the metadata of this database dbms should be passed.

Parameters:
sourceDirectory - The location for the generated source files to be written to
packageName - The package name to use for generated sources
metaBeans - the set of classes representing the database metadata
schemas - an array of database schema names to use in generating the beans
Throws:
BeanGenerationException - if the beans could not be generated

getPackageName

java.lang.String getPackageName()
Returns the package name known for this BeanFactory

Returns:
the package name

dbms

boolean dbms(java.lang.String dbms)
Determines whether a BeanFactory implementation can generate beans for the given dbms. Returns true if this is a valid dbms name for this service provider, false otherwise.

Parameters:
dbms - the name of the dbms for a service provider, e.g. "mysql"
Returns:
true if this service provider can generate beans for the given dbms

useTableFiltering

void useTableFiltering(java.io.File filterTables)
                       throws java.io.IOException
Enables filtering of tables by parsing a plain text file. The passed file should contain one table name per line. This file will be read in and used to restrict the list of generated OWL classes

Parameters:
filterTables - the file to read that restricts the created owl classes
Throws:
java.io.IOException - if there is a problem reading from the file

donotUseTableFiltering

void donotUseTableFiltering()
Use this if a single factory is used to generate multiple sets of beans, and you want to stop tables from being filtered.



Copyright © 2010. All Rights Reserved.