net.sourceforge.fluxion.datapublisher.sql.impl
Class SQLBeanFactory

java.lang.Object
  extended by net.sourceforge.fluxion.datapublisher.sql.impl.SQLBeanFactory
All Implemented Interfaces:
BeanFactory
Direct Known Subclasses:
MySQLBeanFactory, ODBCBeanFactory, PostgresqlBeanFactory

public abstract class SQLBeanFactory
extends java.lang.Object
implements BeanFactory

An implementation of BeanFactory that generates beans from an SQL datasource connection.

Version:
0.2
Author:
Tony Burdett

Field Summary
protected  java.util.Set<BeanConfig> beanConfigs
           
protected  java.sql.Connection connection
           
protected  java.util.Map<java.lang.String,java.lang.String> connectionDetails
           
protected  java.util.Set<java.lang.String> filterTables
           
protected  java.util.Set<java.lang.Class> metaBeans
           
protected  java.lang.String packageName
           
protected  boolean usingTableFiltering
           
 
Constructor Summary
SQLBeanFactory()
           
 
Method Summary
protected  void analyseColumns(BeanConfig tableBC, java.sql.ResultSet column, java.lang.String fieldName, java.util.List<java.lang.String> keyNames)
           
protected  void analyseKeys(BeanConfig tableBC, java.sql.DatabaseMetaData metadata, java.lang.String schemaName, java.lang.String tableName, boolean multipleSchemas)
           
protected  void analyseTable(BeanConfig tableBC, java.sql.DatabaseMetaData metadata, java.lang.String schemaName, java.lang.String tableName, boolean multipleSchemas)
           
 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 javabeans from sql metadata specific to the supplied connection
 java.util.Map<java.lang.String,java.lang.String> getDatasourceConnectionParameters()
          Returns the map of connection parameters supplied for this BeanFactory.
protected abstract  java.lang.String getJavaType(java.lang.String sqlType)
          Returns a string giving the name of a java field type, given a specified type in the datasource.
 java.lang.String getPackageName()
          Returns the package name known for this BeanFactory
protected abstract  java.lang.Class getQueryGeneratorClass()
          Return the class that concrete BeanFactory implementations use to the create a query.
protected  void makeExportedObjectPropertyMethods(BeanConfig tableBC, java.lang.String linkedTableName, java.util.Map<java.lang.String,java.lang.String> key2keyMap, boolean multipleRoles, boolean compoundKeys)
           
protected  void makeImportedObjectPropertyMethods(BeanConfig tableBC, java.lang.String linkedTableName, java.util.Map<java.lang.String,java.lang.String> key2keyMap, boolean multipleRoles, boolean compoundKeys)
           
protected  void readTableFilterFile(java.io.File tableFilterFile)
          This reads a plain text file that contains a list of tables to represent in OWL.
protected  void setType(BeanConfig config, java.lang.String structureType)
           
 void useTableFiltering(java.io.File tableFilterFile)
          Enables filtering of tables by parsing a plain text file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sourceforge.fluxion.datapublisher.beangen.BeanFactory
acquireDatasourceConnection, dbms, terminateDatasourceConnection
 

Field Detail

connection

protected java.sql.Connection connection

connectionDetails

protected java.util.Map<java.lang.String,java.lang.String> connectionDetails

usingTableFiltering

protected boolean usingTableFiltering

filterTables

protected java.util.Set<java.lang.String> filterTables

packageName

protected java.lang.String packageName

metaBeans

protected java.util.Set<java.lang.Class> metaBeans

beanConfigs

protected java.util.Set<BeanConfig> beanConfigs
Constructor Detail

SQLBeanFactory

public SQLBeanFactory()
Method Detail

getDatasourceConnectionParameters

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

For example, for SQL databases, the connection parameters map will normally contain the keys "uri", "user" and "password", representing the URI of the database, and the username and password for this database. If not explicitly set, the default username is "anonymous" and the default password is empty. The URI is null until set, so to acquire a connection a user must at least specify this

Specified by:
getDatasourceConnectionParameters in interface BeanFactory
Returns:
A map containing the current connection details

useTableFiltering

public void useTableFiltering(java.io.File tableFilterFile)
                       throws java.io.IOException
Description copied from interface: BeanFactory
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

Specified by:
useTableFiltering in interface BeanFactory
Parameters:
tableFilterFile - the file to read that restricts the created owl classes
Throws:
java.io.IOException - if there is a problem reading from the file

donotUseTableFiltering

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

Specified by:
donotUseTableFiltering in interface BeanFactory

generateBeans

public void generateBeans(java.io.File sourceDirectory,
                          java.lang.String packageName,
                          java.util.Set<java.lang.Class> metaBeans,
                          java.lang.String... schemas)
                   throws BeanGenerationException
Generate javabeans from sql metadata specific to the supplied connection

Specified by:
generateBeans in interface BeanFactory
Parameters:
packageName - the name of the package the generate beans should be placed in
sourceDirectory - The location for the generated source files to be written to
metaBeans - the set of classes representing the database metadata
schemas - an array of database schema names to use in generating the beans
Throws:
BeanGenerationException

getPackageName

public java.lang.String getPackageName()
Description copied from interface: BeanFactory
Returns the package name known for this BeanFactory

Specified by:
getPackageName in interface BeanFactory
Returns:
the package name

analyseTable

protected void analyseTable(BeanConfig tableBC,
                            java.sql.DatabaseMetaData metadata,
                            java.lang.String schemaName,
                            java.lang.String tableName,
                            boolean multipleSchemas)
                     throws java.sql.SQLException,
                            BeanGenerationException
Throws:
java.sql.SQLException
BeanGenerationException

analyseColumns

protected void analyseColumns(BeanConfig tableBC,
                              java.sql.ResultSet column,
                              java.lang.String fieldName,
                              java.util.List<java.lang.String> keyNames)
                       throws java.sql.SQLException,
                              BeanGenerationException
Throws:
java.sql.SQLException
BeanGenerationException

analyseKeys

protected void analyseKeys(BeanConfig tableBC,
                           java.sql.DatabaseMetaData metadata,
                           java.lang.String schemaName,
                           java.lang.String tableName,
                           boolean multipleSchemas)
                    throws java.sql.SQLException
Throws:
java.sql.SQLException

getQueryGeneratorClass

protected abstract java.lang.Class getQueryGeneratorClass()
Return the class that concrete BeanFactory implementations use to the create a query.

Returns:
the corresponding QueryGeneratorClass for BeanFactory concrete implementations

getJavaType

protected abstract java.lang.String getJavaType(java.lang.String sqlType)
                                         throws BeanGenerationException
Returns a string giving the name of a java field type, given a specified type in the datasource. It is anticipated that most implementations of this class will describe a set of static constants of all the types available in the datasource, and enumerate the java types these datasources types correspond or map to. For example, the MySqlBeanFactory describes the datasource type "varchar", and states in an enum that this corresponds to a java String type.

Parameters:
sqlType - the name underlying datasource type
Returns:
the Java type name
Throws:
BeanGenerationException - if the datasource type is not recognised by the factory implementation

setType

protected void setType(BeanConfig config,
                       java.lang.String structureType)

makeImportedObjectPropertyMethods

protected void makeImportedObjectPropertyMethods(BeanConfig tableBC,
                                                 java.lang.String linkedTableName,
                                                 java.util.Map<java.lang.String,java.lang.String> key2keyMap,
                                                 boolean multipleRoles,
                                                 boolean compoundKeys)

makeExportedObjectPropertyMethods

protected void makeExportedObjectPropertyMethods(BeanConfig tableBC,
                                                 java.lang.String linkedTableName,
                                                 java.util.Map<java.lang.String,java.lang.String> key2keyMap,
                                                 boolean multipleRoles,
                                                 boolean compoundKeys)

readTableFilterFile

protected void readTableFilterFile(java.io.File tableFilterFile)
                            throws java.io.IOException
This reads a plain text file that contains a list of tables to represent in OWL. You shouldn't override this. This only gets called if "usingTableFiltering" is set to true.

Parameters:
tableFilterFile - the file containing the tables to read
Throws:
java.io.FileNotFoundException - if there is some problem reading the file
java.io.IOException


Copyright © 2010. All Rights Reserved.