com.opengamma.elsql
Class ElSqlBundle

java.lang.Object
  extended by com.opengamma.elsql.ElSqlBundle

public final class ElSqlBundle
extends Object

Entry point integrated with the Spring framework, 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 uses features from the Spring framework. The same functionality is available from the ElSql class, which does not depend on Spring.

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, org.springframework.jdbc.core.namedparam.SqlParameterSource paramSource)
          Finds SQL for a named fragment key.
static ElSqlBundle of(ElSqlConfig config, Class<?> type)
          Loads external SQL based for the specified type.
static ElSqlBundle parse(ElSqlConfig config, org.springframework.core.io.Resource... resources)
          Parses a bundle from a resource locating a file, specify the config.
 ElSqlBundle 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

of

public static ElSqlBundle of(ElSqlConfig config,
                             Class<?> type)
Loads external SQL based for the specified 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).

Parameters:
config - the config, not null
type - the type, not null
Returns:
the bundle, not null
Throws:
IllegalArgumentException - if the input cannot be parsed

parse

public static ElSqlBundle parse(ElSqlConfig config,
                                org.springframework.core.io.Resource... resources)
Parses a bundle from a resource locating a file, specify the config.

This parses a list of resources. 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.

Parameters:
config - the config to use, not null
resources - the resources to load, not null
Returns:
the external identifier, not null
Throws:
IllegalArgumentException - if the input cannot be parsed or if none of the resources exists

getConfig

public ElSqlConfig getConfig()
Gets the configuration object.

Returns:
the config, not null

withConfig

public ElSqlBundle withConfig(ElSqlConfig config)
Returns a copy of this bundle with a different configuration.

This does not reload the underlying resources.

Parameters:
config - the new config, not null
Returns:
a bundle with the config updated, not null

getSql

public String getSql(String name)
Finds SQL for a named fragment key, without specifying parameters.

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.

Parameters:
name - the name, not null
Returns:
the SQL, not null
Throws:
IllegalArgumentException - if there is no fragment with the specified name
RuntimeException - if a problem occurs

getSql

public String getSql(String name,
                     org.springframework.jdbc.core.namedparam.SqlParameterSource paramSource)
Finds SQL for a named fragment key.

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.

Parameters:
name - the name, not null
paramSource - the Spring SQL parameters, not null
Returns:
the SQL, not null
Throws:
IllegalArgumentException - if there is no fragment with the specified name
RuntimeException - if a problem occurs


Copyright 2009-Present by OpenGamma Inc. and individual contributors, released under the Apache License Version 2.0