org.eobjects.metamodel
Interface DataContext

All Known Subinterfaces:
UpdateableDataContext
All Known Implementing Classes:
AbstractDataContext, CompositeDataContext, InterceptableDataContext, QueryPostprocessDataContext, QueryPostprocessDelegate

public interface DataContext

A DataContext represents the central entry point for interactions with datastores. The DataContext contains of the structure of data (in the form of schemas) and interactions (in the form of queries) with data.

Author:
Kasper Sørensen

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(Query query)
          Executes a query against the DataContext.
 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.
 Schema getSchemaByName(String name)
          Gets a schema by a specified name.
 String[] getSchemaNames()
          Gets the names of all schemas within this DataContext.
 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.
 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.
 

Method Detail

refreshSchemas

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

Returns:
this DataContext

getSchemas

Schema[] getSchemas()
                    throws MetaModelException
Gets all schemas within this 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

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

Returns:
an array of valid schema names
Throws:
MetaModelException - if an error occurs retrieving the schema model

getDefaultSchema

Schema getDefaultSchema()
                        throws MetaModelException
Gets the default schema of this 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

getSchemaByName

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

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

query

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.

Returns:
a query builder component at the initial position in building a query.

parseQuery

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

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

executeQuery

DataSet executeQuery(Query query)
                     throws MetaModelException
Executes a query against the DataContext.

Parameters:
query - the query object to execute
Returns:
the DataSet produced from executing the query
Throws:
MetaModelException - if the specified query does not make sense or cannot be executed because of restraints on the type of datastore.

compileQuery

CompiledQuery compileQuery(Query query)
                           throws MetaModelException
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.

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

DataSet executeQuery(CompiledQuery compiledQuery,
                     Object... values)
Executes a compiled query with given values as parameters.

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

executeQuery

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

Parameters:
query - the SQL query to parse
Returns:
the DataSet produced from executing the query
Throws:
MetaModelException - if either parsing or executing the query produces an exception

getColumnByQualifiedLabel

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 (.).

Parameters:
columnName -
Returns:
a column that matches the qualified label, or null if no such column exists

getTableByQualifiedLabel

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 (.).

Parameters:
tableName -
Returns:
a table that matches the qualified label, or null if no such table exists


Copyright © 2007-2013. All Rights Reserved.