org.eobjects.metamodel
Class AbstractDataContext

java.lang.Object
  extended by org.eobjects.metamodel.AbstractDataContext
All Implemented Interfaces:
DataContext
Direct Known Subclasses:
CompositeDataContext, QueryPostprocessDataContext

public abstract class AbstractDataContext
extends Object
implements DataContext

Abstract implementation of the DataContext interface. Provides convenient implementations of all trivial and datastore-independent methods.

Author:
Kasper Sørensen

Constructor Summary
AbstractDataContext()
           
 
Method Summary
 CompiledQuery compileQuery(Query query)
          Compiles a query, preparing it for reuse.
 DataSet executeQuery(CompiledQuery compiledQuery, Object... values)
          Executes a compiled query with given values as parameters.
 DataSet executeQuery(String queryString)
          Parses and executes a string-based SQL query.
 Column getColumnByQualifiedLabel(String columnName)
          Finds a column in the DataContext based on a fully qualified column label.
 Schema getDefaultSchema()
          Gets the default schema of this DataContext.
protected abstract  String getDefaultSchemaName()
          Gets the name of the default schema.
 Schema getSchemaByName(String name)
          Gets a schema by a specified name.
protected abstract  Schema getSchemaByNameInternal(String name)
          Gets a specific schema from the non-abstract implementation.
 String[] getSchemaNames()
          m Gets the names of all schemas within this DataContext.
protected abstract  String[] getSchemaNamesInternal()
          Gets schema names from the non-abstract implementation.
 Schema[] getSchemas()
          Gets all schemas within this DataContext.
 Table getTableByQualifiedLabel(String tableName)
          Finds a table in the DataContext based on a fully qualified table label.
protected  boolean isQualifiedPathDelim(char c)
           
 Query parseQuery(String queryString)
          Parses a string-based SQL query and produces a corresponding Query object.
 InitFromBuilder query()
          Starts building a query using the query builder API.
 DataContext refreshSchemas()
          Enforces a refresh of the schemas.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eobjects.metamodel.DataContext
executeQuery
 

Constructor Detail

AbstractDataContext

public AbstractDataContext()
Method Detail

refreshSchemas

public final DataContext refreshSchemas()
Enforces a refresh of the schemas. If not refreshed, cached schema objects may be used.

Specified by:
refreshSchemas in interface DataContext
Returns:
this DataContext

getSchemas

public final Schema[] getSchemas()
                          throws MetaModelException
Gets all schemas within this DataContext.

Specified by:
getSchemas in interface DataContext
Returns:
the schemas in this data context. Schemas are cached for reuse in many situations so if you want to update the schemas, use the refreshSchemas() method.
Throws:
MetaModelException - if an error occurs retrieving the schema model

getSchemaNames

public final String[] getSchemaNames()
                              throws MetaModelException
m Gets the names of all schemas within this DataContext.

Specified by:
getSchemaNames in interface DataContext
Returns:
an array of valid schema names
Throws:
MetaModelException - if an error occurs retrieving the schema model

getDefaultSchema

public final Schema getDefaultSchema()
                              throws MetaModelException
Gets the default schema of this DataContext.

Specified by:
getDefaultSchema in interface DataContext
Returns:
the schema that you are most probable to be interested in. The default schema is determined by finding the schema with most available of tables. In a lot of situations there will only be a single available schema and in that case this will of course be the schema returned.
Throws:
MetaModelException - if an error occurs retrieving the schema model

query

public final InitFromBuilder query()
Starts building a query using the query builder API. This way of building queries is the preferred approach since it provides a more type-safe approach to building API's as well as allows the DataContext implementation to be aware of the query building process.

Specified by:
query in interface DataContext
Returns:
a query builder component at the initial position in building a query.

parseQuery

public Query parseQuery(String queryString)
                 throws MetaModelException
Parses a string-based SQL query and produces a corresponding Query object.

Specified by:
parseQuery in interface DataContext
Parameters:
queryString - the SQL query to parse
Returns:
a Query object corresponding to the SQL query.
Throws:
MetaModelException - in case the parsing was unsuccesful.

compileQuery

public CompiledQuery compileQuery(Query query)
                           throws MetaModelException
Description copied from interface: DataContext
Compiles a query, preparing it for reuse. Often times compiled queries have a performance improvement when executed, but at the cost of a preparation time penalty. Therefore it is adviced to use compiled queries when the same query is to be fired multiple times. Compiled queries can contain QueryParameters as operands in the WHERE clause, making it possible to reuse the same query with different parameter values.

Specified by:
compileQuery in interface DataContext
Parameters:
query - the query object to execute, possibly holding one or more QueryParameters.
Returns:
the CompiledQuery after preparing the query
Throws:
MetaModelException - if preparing the query is unsuccesful
See Also:
CompiledQuery, QueryParameter

executeQuery

public DataSet executeQuery(CompiledQuery compiledQuery,
                            Object... values)
Description copied from interface: DataContext
Executes a compiled query with given values as parameters.

Specified by:
executeQuery in interface DataContext
Parameters:
compiledQuery - the compiledQuery object to execute
values - the values for parameters in the CompiledQuery.
Returns:
the DataSet produced from executing the query.

executeQuery

public final DataSet executeQuery(String queryString)
                           throws MetaModelException
Parses and executes a string-based SQL query. This method is essentially equivalent to calling first DataContext.parseQuery(String) and then DataContext.executeQuery(Query) with the parsed query.

Specified by:
executeQuery in interface DataContext
Returns:
the DataSet produced from executing the query
Throws:
MetaModelException - if either parsing or executing the query produces an exception

getSchemaByName

public final Schema getSchemaByName(String name)
                             throws MetaModelException
Gets a schema by a specified name.

Specified by:
getSchemaByName in interface DataContext
Parameters:
name - the name of the desired schema
Returns:
the Schema with the specified name or null if no such schema exists
Throws:
MetaModelException - if an error occurs retrieving the schema model

getColumnByQualifiedLabel

public final Column getColumnByQualifiedLabel(String columnName)
Finds a column in the DataContext based on a fully qualified column label. The qualified label consists of the the schema, table and column name, delimited by a dot (.).

Specified by:
getColumnByQualifiedLabel in interface DataContext
Returns:
a column that matches the qualified label, or null if no such column exists

getTableByQualifiedLabel

public final Table getTableByQualifiedLabel(String tableName)
Finds a table in the DataContext based on a fully qualified table label. The qualified label consists of the the schema and table name, delimited by a dot (.).

Specified by:
getTableByQualifiedLabel in interface DataContext
Returns:
a table that matches the qualified label, or null if no such table exists

isQualifiedPathDelim

protected boolean isQualifiedPathDelim(char c)

getSchemaNamesInternal

protected abstract String[] getSchemaNamesInternal()
Gets schema names from the non-abstract implementation. These schema names will be cached except if the refreshSchemas() method is called.

Returns:
an array of schema names.

getDefaultSchemaName

protected abstract String getDefaultSchemaName()
Gets the name of the default schema.

Returns:
the default schema name.

getSchemaByNameInternal

protected abstract Schema getSchemaByNameInternal(String name)
Gets a specific schema from the non-abstract implementation. This schema object will be cached except if the refreshSchemas() method is called.

Parameters:
name - the name of the schema to get
Returns:
a schema object representing the named schema, or null if no such schema exists.


Copyright © 2007-2013. All Rights Reserved.