com.hardcode.gdbms.engine.data
Class DataSourceFactory

java.lang.Object
  extended by com.hardcode.gdbms.engine.data.DataSourceFactory

public class DataSourceFactory
extends java.lang.Object

Factory of DataSource implementations. It has method to register DataSourceDefinitions and to create DataSource from this asociations. It's also possible to execute SQL statements with the executeSQL method. After using the DataSourceFactory it's hardly recomended to call freeResources method.

Author:
Fernando González Cortés

Field Summary
static int AUTOMATIC_OPENING
          DataSources open automatically and so close (but can be closed manually)
static int MANUAL_OPENING
          DataSources need a explicit call to start()
static int UNDOABLE
           
 
Constructor Summary
DataSourceFactory()
           
 
Method Summary
 void addDataSource(DataSourceDefinition dsd)
          Añade una fuente de datos de objeto.
 void changeDataSourceName(java.lang.String oldName, java.lang.String newName)
          Cambia el nombre de una fuente de datos.
 void createDataSource(DataSourceCreation dsc)
          Creates a data source defined by the DataSourceCreation object
 DataSource createRandomDataSource(Memento m)
          Creates a DataSource from a memento object with the manual opening mode
 DataSource createRandomDataSource(Memento m, int mode)
          Creates a DataSource from a memento object with the specified opening mode
 DataSource createRandomDataSource(SelectAdapter instr, int mode)
          A partir de una instrucción select se encarga de obtener el DataSource resultado de la ejecución de dicha instrucción
 DataSource createRandomDataSource(java.lang.String tableName)
          Dado el nombre de una tabla, se busca la fuente de datos asociada a dicha tabla y se obtiene un datasource adecuado en funcion del tipo de fuente de datos accediendo al subsistema de drivers
 DataSource createRandomDataSource(java.lang.String tableName, int mode)
          Dado el nombre de una tabla, se busca la fuente de datos asociada a dicha tabla y se obtiene un datasource adecuado en funcion del tipo de fuente de datos accediendo al subsistema de drivers
 DataSource createRandomDataSource(java.lang.String tableName, java.lang.String tableAlias)
          Dado el nombre de una tabla, se busca la fuente de datos asociada a dicha tabla y se obtiene un datasource adecuado en funcion del tipo de fuente de datos accediendo al subsistema de drivers.
 DataSource createRandomDataSource(java.lang.String tableName, java.lang.String tableAlias, int mode)
          Dado el nombre de una tabla, se busca la fuente de datos asociada a dicha tabla y se obtiene un datasource adecuado en funcion del tipo de fuente de datos accediendo al subsistema de drivers.
 DataSource createRandomDataSource(UnionAdapter instr, int mode)
          Obtiene el DataSource resultado de ejecutar la instrucción de union
 DataSource executeSQL(java.lang.String sql, int mode)
          Executes a SQL statement where the table names must be valid data source names.
 void freeResources()
          Frees all resources used during execution
 DataSource getDataSource(CustomAdapter instr, int mode)
          Creates a DataSource as a result of a custom query
 DataSourceDefinition getDataSourceDefinition(java.lang.String dataSourceName)
          Obtiene la información de la fuente de datos cuyo nombre se pasa como parámetro
 DataSourceDefinition[] getDataSourcesDefinition()
          Gets the information of all data sources registered in the system
 DelegatingStrategy getDelegatingStrategy()
           
 com.hardcode.driverManager.DriverManager getDriverManager()
          Gets a driver manager reference
 java.lang.String getTempFile()
          Gets the URL of a file in the temporary directory.
 java.lang.String getUID()
          Get's a unique id in the tableSource and nameOperationDataSource key sets
 void initialize()
          Initializes the system.
 void initialize(java.lang.String tempDir)
          Initializes the system
 java.lang.String nameAndAddDataSource(DataSourceDefinition dsd)
          Añade una fuente de datos de objeto.
 void remove(DataSource ds)
          Removes the association between the name and the data sources
 void removeAllDataSources()
          Removes all associations between names and data sources.
 void setClosingDelay(long delay)
          Sets the minimum delay between accesses needed to close the DataSource.
 void setDriverManager(com.hardcode.driverManager.DriverManager dm)
          Establece el DriverManager que se usará para instanciar DataSource's.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNDOABLE

public static final int UNDOABLE
See Also:
Constant Field Values

MANUAL_OPENING

public static final int MANUAL_OPENING
DataSources need a explicit call to start()

See Also:
Constant Field Values

AUTOMATIC_OPENING

public static final int AUTOMATIC_OPENING
DataSources open automatically and so close (but can be closed manually)

See Also:
Constant Field Values
Constructor Detail

DataSourceFactory

public DataSourceFactory()
Method Detail

getUID

public java.lang.String getUID()
Get's a unique id in the tableSource and nameOperationDataSource key sets

Returns:
unique id

removeAllDataSources

public void removeAllDataSources()
Removes all associations between names and data sources.

Throws:
DriverException - If the resources could not be freed

remove

public void remove(DataSource ds)
Removes the association between the name and the data sources

Parameters:
ds - Name of the data source to remove

createDataSource

public void createDataSource(DataSourceCreation dsc)
                      throws DriverException
Creates a data source defined by the DataSourceCreation object

Parameters:
dsc -
Throws:
DriverException - if the source creation fails

addDataSource

public void addDataSource(DataSourceDefinition dsd)
Añade una fuente de datos de objeto. Dado un objeto que implemente la interfaz del driver, se toma como fuente de datos y se le asocia un nombre

Parameters:
rd - objeto con la información
name - Nombre de la fuente de datos

nameAndAddDataSource

public java.lang.String nameAndAddDataSource(DataSourceDefinition dsd)
Añade una fuente de datos de objeto. Dado un objeto que implemente la interfaz del driver, se toma como fuente de datos y se le asocia un nombre

Parameters:
rd - objeto con la información
Returns:
the name of the data source

getDataSourceDefinition

public DataSourceDefinition getDataSourceDefinition(java.lang.String dataSourceName)
Obtiene la información de la fuente de datos cuyo nombre se pasa como parámetro

Parameters:
dataSourceName - Nombre de la base de datos
Returns:
Debido a las distintas formas en las que se puede registrar un datasource, se devuelve un Object, que podrá ser una instancia de DataSourceFactory.FileDriverInfo, DataSourceFactory.DBDriverInfo o ReadDriver

getDataSourcesDefinition

public DataSourceDefinition[] getDataSourcesDefinition()
Gets the information of all data sources registered in the system

Returns:
DataSourceDefinition[]

changeDataSourceName

public void changeDataSourceName(java.lang.String oldName,
                                 java.lang.String newName)
                          throws NoSuchTableException
Cambia el nombre de una fuente de datos. Las consultas SQL que se ejecuten con el nombre anterior fallarán

Parameters:
oldName - Nombre actual de la fuente de datos que se quiere cambiar
newName - Nombre que se le quiere poner a la fuente de datos
Throws:
NoSuchTableException - Si no hay ninguna fuente de datos de nombre 'oldName'

setClosingDelay

public void setClosingDelay(long delay)
Sets the minimum delay between accesses needed to close the DataSource. If accesses are delayed more than 'delay' the DataSource MAY be closed. Only applies when the mode is set to AUTOMATIC_MODE

Parameters:
delay - time un milliseconds

createRandomDataSource

public DataSource createRandomDataSource(java.lang.String tableName)
                                  throws com.hardcode.driverManager.DriverLoadException,
                                         NoSuchTableException,
                                         DataSourceCreationException
Dado el nombre de una tabla, se busca la fuente de datos asociada a dicha tabla y se obtiene un datasource adecuado en funcion del tipo de fuente de datos accediendo al subsistema de drivers

Parameters:
tableName - Nombre de la fuente de datos
Returns:
DataSource que accede a dicha fuente
Throws:
com.hardcode.driverManager.DriverLoadException - If the driver loading fails
NoSuchTableException - If the 'tableName' data source does not exists
DataSourceCreationException - If the DataSource could not be created

createRandomDataSource

public DataSource createRandomDataSource(java.lang.String tableName,
                                         int mode)
                                  throws com.hardcode.driverManager.DriverLoadException,
                                         NoSuchTableException,
                                         DataSourceCreationException
Dado el nombre de una tabla, se busca la fuente de datos asociada a dicha tabla y se obtiene un datasource adecuado en funcion del tipo de fuente de datos accediendo al subsistema de drivers

Parameters:
tableName - Nombre de la fuente de datos
mode - opening mode: AUTOMATIC_OPENING -> the DataSource opens automatically and closes after a while. It can be closed manually. MANUAL_OPENING -> the DataSource opens and closes manually
Returns:
DataSource que accede a dicha fuente
Throws:
com.hardcode.driverManager.DriverLoadException - If the driver loading fails
NoSuchTableException - If the 'tableName' data source does not exists
DataSourceCreationException - If the DataSource could not be created

createRandomDataSource

public DataSource createRandomDataSource(java.lang.String tableName,
                                         java.lang.String tableAlias)
                                  throws NoSuchTableException,
                                         com.hardcode.driverManager.DriverLoadException,
                                         DataSourceCreationException
Dado el nombre de una tabla, se busca la fuente de datos asociada a dicha tabla y se obtiene un datasource adecuado en funcion del tipo de fuente de datos accediendo al subsistema de drivers. Se utiliza internamente como nombre del DataSource el alias que se pasa como parámetro

Parameters:
tableName - Nombre de la fuente de datos
tableAlias - Alias que tiene el DataSource en una instrucción
Returns:
DataSource que accede a dicha fuente de datos si la fuente de datos es alfanumérica o SpatialDataSource si la fuente de datos es espacial
Throws:
com.hardcode.driverManager.DriverLoadException - If the driver loading fails
NoSuchTableException - If the 'tableName' data source does not exists
DataSourceCreationException - If the DataSource could not be created

createRandomDataSource

public DataSource createRandomDataSource(java.lang.String tableName,
                                         java.lang.String tableAlias,
                                         int mode)
                                  throws NoSuchTableException,
                                         com.hardcode.driverManager.DriverLoadException,
                                         DataSourceCreationException
Dado el nombre de una tabla, se busca la fuente de datos asociada a dicha tabla y se obtiene un datasource adecuado en funcion del tipo de fuente de datos accediendo al subsistema de drivers. Se utiliza internamente como nombre del DataSource el alias que se pasa como parámetro

Parameters:
tableName - Nombre de la fuente de datos
tableAlias - Alias que tiene el DataSource en una instrucción
mode - openning mode
Returns:
DataSource que accede a dicha fuente de datos si la fuente de datos es alfanumérica o SpatialDataSource si la fuente de datos es espacial
Throws:
com.hardcode.driverManager.DriverLoadException - If the driver loading fails
NoSuchTableException - If the 'tableName' data source does not exists
DataSourceCreationException - If the DataSource could not be created

createRandomDataSource

public DataSource createRandomDataSource(Memento m)
                                  throws NoSuchTableException,
                                         ExecutionException,
                                         DataSourceCreationException
Creates a DataSource from a memento object with the manual opening mode

Parameters:
m - memento
Throws:
DataSourceCreationException - If the DataSource creation fails
NoSuchTableException - If the memento information is wrong
ExecutionException - If DataSource execution fails

createRandomDataSource

public DataSource createRandomDataSource(Memento m,
                                         int mode)
                                  throws NoSuchTableException,
                                         DataSourceCreationException,
                                         ExecutionException
Creates a DataSource from a memento object with the specified opening mode

Parameters:
m - memento
mode - opening mode
Throws:
DataSourceCreationException - If the DataSource creation fails
NoSuchTableException - If the memento information is wrong
ExecutionException - If DataSource execution fails

createRandomDataSource

public DataSource createRandomDataSource(SelectAdapter instr,
                                         int mode)
                                  throws ExecutionException
A partir de una instrucción select se encarga de obtener el DataSource resultado de la ejecución de dicha instrucción

Parameters:
instr - Instrucción select origen del datasource
mode - opening mode
Returns:
DataSource que accede a los datos resultado de ejecutar la select
Throws:
ExecutionException

createRandomDataSource

public DataSource createRandomDataSource(UnionAdapter instr,
                                         int mode)
                                  throws ExecutionException
Obtiene el DataSource resultado de ejecutar la instrucción de union

Parameters:
instr - instrucción de union
mode - opening mode
Returns:
DataSource
Throws:
ExecutionException

getDataSource

public DataSource getDataSource(CustomAdapter instr,
                                int mode)
                         throws ExecutionException
Creates a DataSource as a result of a custom query

Parameters:
instr - Root node of the adapter tree of the custom query instruction
mode - opening mode
Returns:
DataSource with the custom query result
Throws:
ExecutionException

executeSQL

public DataSource executeSQL(java.lang.String sql,
                             int mode)
                      throws SyntaxException,
                             com.hardcode.driverManager.DriverLoadException,
                             NoSuchTableException,
                             ExecutionException
Executes a SQL statement where the table names must be valid data source names.

Parameters:
sql - sql statement
mode - opening mode MANUAL_OPENING or AUTOMATIC_OPENING
Returns:
DataSource con el resultado
Throws:
SyntaxException - If instruction parsing fails
com.hardcode.driverManager.DriverLoadException - If a driver cannot be loaded
NoSuchTableException - If the instruction references a data source that doesn't exist
ExecutionException - If the execution of the statement fails

setDriverManager

public void setDriverManager(com.hardcode.driverManager.DriverManager dm)
Establece el DriverManager que se usará para instanciar DataSource's. Este metodo debe ser invocado antes que ningún otro

Parameters:
dm - El manager que se encarga de cargar los drivers

getDriverManager

public com.hardcode.driverManager.DriverManager getDriverManager()
Gets a driver manager reference

Returns:
DriverManagers.

freeResources

public void freeResources()
                   throws DataSourceFinalizationException
Frees all resources used during execution

Throws:
DataSourceFinalizationException - If cannot free resources

initialize

public void initialize()
                throws InitializationException
Initializes the system.

Throws:
InitializationException - If the initialization

initialize

public void initialize(java.lang.String tempDir)
                throws InitializationException
Initializes the system

Parameters:
tempDir - temporary directory to write data
Throws:
InitializationException - If the initialization fails

getTempFile

public java.lang.String getTempFile()
Gets the URL of a file in the temporary directory. Does not creates any file

Returns:
String

getDelegatingStrategy

public DelegatingStrategy getDelegatingStrategy()


Copyright © 2005-2006 . All Rights Reserved.