|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.opengamma.elsql.ElSql
public final class ElSql
Main entry point, providing access to a bundle of elsql formatted SQL.
The bundle encapsulates the SQL needed for a particular feature. This will typically correspond to a data access object, or set of related tables.
This class has no dependencies on any external libraries.
Similar functionality is available from the ElSqlBundle class,
which provides integration with the Spring framework.
This class is immutable and thread-safe.
| Method Summary | |
|---|---|
ElSqlConfig |
getConfig()
Gets the configuration object. |
String |
getSql(String name)
Finds SQL for a named fragment key, without specifying parameters. |
String |
getSql(String name,
Map<String,Object> params)
Finds SQL for a named fragment key, providing a map of SQL parameters. |
String |
getSql(String name,
SqlParams params)
Finds SQL for a named fragment key, providing the SQL parameters. |
static ElSql |
of(ElSqlConfig config,
Class<?> type)
Loads external SQL based for the specified type. |
static ElSql |
parse(ElSqlConfig config,
URL... resources)
Parses a bundle from a resource locating a file, specify the config. |
ElSql |
withConfig(ElSqlConfig config)
Returns a copy of this bundle with a different configuration. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static ElSql of(ElSqlConfig config,
Class<?> type)
The type is used to identify the location and name of the ".elsql" file. The loader will attempt to find and use two files, using the full name of the type to query the class path for resources.
The first resource searched for is optional - the file will have the suffix "-ConfigName.elsql", such as "com/foo/Bar-MySql.elsql". The second resource searched for is mandatory - the file will just have the ".elsql" suffix, such as "com/foo/Bar.elsql".
The config is designed to handle some, but not all, database differences. Other differences should be handled by creating and using a database specific override file (the first optional resource is the override file).
config - the config, not nulltype - the type, not null
IllegalArgumentException - if the input cannot be parsed or if no matching resource exists
public static ElSql parse(ElSqlConfig config,
URL... resources)
This parses a list of resources, expressed as URLs.
Named blocks in later resources override blocks with the same name in earlier resources.
The config is designed to handle some, but not all, database differences. Other differences are handled via the override resources passed in.
Each resource is a URL. A null URL is permitted and ignored.
This allows classpath resources, obtained from Class.getResource(String)
or ClassLoader.getResource(String) to be called and passed in directly
as those methods return null when the target does not exist.
config - the config to use, not nullresources - the resources to load, not null, may contain nulls which are ignored
IllegalArgumentException - if the input cannot be parsed or if none of the resources existspublic ElSqlConfig getConfig()
public ElSql withConfig(ElSqlConfig config)
This does not reload the underlying resources.
config - the new config, not null
public String getSql(String name)
This finds, processes and returns a named block from the bundle. Note that if the SQL contains tags that depend on variables, like AND or LIKE, then an error will be thrown.
name - the name, not null
IllegalArgumentException - if there is no fragment with the specified name
RuntimeException - if a problem occurs
public String getSql(String name,
SqlParams params)
This finds, processes and returns a named block from the bundle. The parameters are used to provide intelligent processing of SQL based on the actual data in the request.
See MapSqlParams and SpringSqlParams.
name - the name, not nullparams - the SQL parameters, not null
IllegalArgumentException - if there is no fragment with the specified name
RuntimeException - if a problem occurs
public String getSql(String name,
Map<String,Object> params)
This finds, processes and returns a named block from the bundle. The parameters are used to provide intelligent processing of SQL based on the actual data in the request.
name - the name, not nullparams - the SQL parameters, not null
IllegalArgumentException - if there is no fragment with the specified name
RuntimeException - if a problem occurs
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||