|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
@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 callingdbms()
. 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.
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 |
---|
java.util.Map<java.lang.String,java.lang.String> getDatasourceConnectionParameters()
BeanFactory
should return an initialised
map containing the keys required for a connection to be acquired.
void acquireDatasourceConnection(java.util.Map<java.lang.String,java.lang.String> connectionDetails) throws BeanGenerationException
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).
connectionDetails
- a map containing parameters for connection to the
database.
BeanGenerationException
- if the connection could not be acquiredvoid terminateDatasourceConnection() throws BeanGenerationException
BeanGenerationException
- if there is a problem closing the
connectionvoid generateBeans(java.io.File sourceDirectory, java.lang.String packageName, java.util.Set<java.lang.Class> metaBeans, java.lang.String... schemas) throws BeanGenerationException
sourceDirectory
- The location for the generated source files to be
written topackageName
- The package name to use for generated sourcesmetaBeans
- the set of classes representing the database
metadataschemas
- an array of database schema names to use in
generating the beans
BeanGenerationException
- if the beans could not be generatedjava.lang.String getPackageName()
boolean dbms(java.lang.String dbms)
dbms
- the name of the dbms for a service provider, e.g. "mysql"
void useTableFiltering(java.io.File filterTables) throws java.io.IOException
filterTables
- the file to read that restricts the created owl
classes
java.io.IOException
- if there is a problem reading from the filevoid donotUseTableFiltering()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |