jp.sf.amateras.mirage
Class SqlManagerImpl

java.lang.Object
  extended by jp.sf.amateras.mirage.SqlManagerImpl
All Implemented Interfaces:
SqlManager
Direct Known Subclasses:
MockSqlManager

public class SqlManagerImpl
extends Object
implements SqlManager


Field Summary
protected  boolean cacheMode
           
protected  CallExecutor callExecutor
           
protected  ConnectionProvider connectionProvider
           
protected  Dialect dialect
           
protected  NameConverter nameConverter
           
protected  Map<String,Node> nodeCache
           
protected  SqlExecutor sqlExecutor
           
 
Constructor Summary
SqlManagerImpl()
           
 
Method Summary
 void addValueType(ValueType<?> valueType)
          Adds the implementation of the ValueType.
<T> T
call(Class<T> resultClass, String functionName)
           
<T> T
call(Class<T> resultClass, String functionName, Object param)
           
 void call(String procedureName)
          Invokes the stored procedure.
 void call(String procedureName, Object parameter)
          Invokes the stored procedure.
<T> List<T>
callForList(Class<T> resultClass, String functionName)
           
<T> List<T>
callForList(Class<T> resultClass, String functionName, Object param)
           
<T> int
deleteBatch(List<T> entities)
          Deletes given entities in batch mode.
<T> int
deleteBatch(T... entities)
          Deletes given entities in batch mode.
 int deleteEntity(Object entity)
          Deletes the given entity.
 int executeUpdate(String sqlPath)
           
 int executeUpdate(String sqlPath, Object param)
           
 int executeUpdateBySql(String sql)
          Executes the given SQL.
 int executeUpdateBySql(String sql, Object... params)
          Executes the given SQL with parameters.
<T> T
findEntity(Class<T> clazz, Object... id)
          Finds the entity by the given primary key.
 ConnectionProvider getConnectionProvider()
           
 int getCount(String sqlPath)
          Returns the row count of the result of the given SQL.
 int getCount(String sqlPath, Object param)
          Returns the row count of the result of the given SQL.
 int getCountBySql(String sql)
           
 int getCountBySql(String sql, Object... params)
           
 Dialect getDialect()
           
 NameConverter getNameConverter()
           
<T> List<T>
getResultList(Class<T> clazz, String sqlPath)
           
<T> List<T>
getResultList(Class<T> clazz, String sqlPath, Object param)
           
<T> List<T>
getResultListBySql(Class<T> clazz, String sql)
           
<T> List<T>
getResultListBySql(Class<T> clazz, String sql, Object... params)
           
<T> T
getSingleResult(Class<T> clazz, String sqlPath)
           
<T> T
getSingleResult(Class<T> clazz, String sqlPath, Object param)
           
<T> T
getSingleResultBySql(Class<T> clazz, String sql)
           
<T> T
getSingleResultBySql(Class<T> clazz, String sql, Object... params)
           
<T> int
insertBatch(List<T> entities)
          Inserts given entities in batch mode.
<T> int
insertBatch(T... entities)
          Inserts given entities in batch mode.
 int insertEntity(Object entity)
          Inserts the given entity.
<T,R> R
iterate(Class<T> clazz, IterationCallback<T,R> callback, String sqlPath)
           
<T,R> R
iterate(Class<T> clazz, IterationCallback<T,R> callback, String sqlPath, Object param)
           
<T,R> R
iterateBySql(Class<T> clazz, IterationCallback<T,R> callback, String sql)
           
<T,R> R
iterateBySql(Class<T> clazz, IterationCallback<T,R> callback, String sql, Object... params)
           
protected  boolean needsParameter(PropertyDesc pd)
           
protected  Node prepareNode(String sqlPath)
           
protected  SqlContext prepareSqlContext(Object param)
           
 void setCacheMode(boolean cacheMode)
           
 void setConnectionProvider(ConnectionProvider connectionProvider)
          Sets the implementation of ConnectionProvider.
 void setDialect(Dialect dialect)
          Sets the implementation of the Dialect.
 void setEntityCreator(ResultEntityCreator entityCreator)
          Sets the implementation of the ResultEntityCreator.
 void setNameConverter(NameConverter nameConverter)
          Sets the implementation of NameConverter.
 void setValueTypes(List<ValueType<?>> valueTypes)
           
protected  String toCallString(String moduleName, boolean function)
           
protected  String toCallString(String moduleName, Object param, boolean function)
           
<T> int
updateBatch(List<T> entities)
          Updates given entities in batch mode.
<T> int
updateBatch(T... entities)
          Updates given entities in batch mode.
 int updateEntity(Object entity)
          Updates the given entity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connectionProvider

protected ConnectionProvider connectionProvider

nameConverter

protected NameConverter nameConverter

dialect

protected Dialect dialect

sqlExecutor

protected SqlExecutor sqlExecutor

callExecutor

protected CallExecutor callExecutor

nodeCache

protected Map<String,Node> nodeCache

cacheMode

protected boolean cacheMode
Constructor Detail

SqlManagerImpl

public SqlManagerImpl()
Method Detail

setCacheMode

public void setCacheMode(boolean cacheMode)

setNameConverter

public void setNameConverter(NameConverter nameConverter)
Description copied from interface: SqlManager
Sets the implementation of NameConverter.

Specified by:
setNameConverter in interface SqlManager
Parameters:
nameConverter - the name converter

getNameConverter

public NameConverter getNameConverter()

setConnectionProvider

public void setConnectionProvider(ConnectionProvider connectionProvider)
Description copied from interface: SqlManager
Sets the implementation of ConnectionProvider.

Specified by:
setConnectionProvider in interface SqlManager
Parameters:
connectionProvider - the connection provider

setEntityCreator

public void setEntityCreator(ResultEntityCreator entityCreator)
Description copied from interface: SqlManager
Sets the implementation of the ResultEntityCreator.

Specified by:
setEntityCreator in interface SqlManager
Parameters:
entityCreator - the entity creator

getConnectionProvider

public ConnectionProvider getConnectionProvider()

setDialect

public void setDialect(Dialect dialect)
Description copied from interface: SqlManager
Sets the implementation of the Dialect.

Specified by:
setDialect in interface SqlManager
Parameters:
dialect - the database dialect

getDialect

public Dialect getDialect()

prepareNode

protected Node prepareNode(String sqlPath)

prepareSqlContext

protected SqlContext prepareSqlContext(Object param)

executeUpdate

public int executeUpdate(String sqlPath)
Specified by:
executeUpdate in interface SqlManager

executeUpdate

public int executeUpdate(String sqlPath,
                         Object param)
Specified by:
executeUpdate in interface SqlManager

getResultList

public <T> List<T> getResultList(Class<T> clazz,
                                 String sqlPath)
Specified by:
getResultList in interface SqlManager

getResultList

public <T> List<T> getResultList(Class<T> clazz,
                                 String sqlPath,
                                 Object param)
Specified by:
getResultList in interface SqlManager

getSingleResult

public <T> T getSingleResult(Class<T> clazz,
                             String sqlPath)
Specified by:
getSingleResult in interface SqlManager

getSingleResult

public <T> T getSingleResult(Class<T> clazz,
                             String sqlPath,
                             Object param)
Specified by:
getSingleResult in interface SqlManager

deleteEntity

public int deleteEntity(Object entity)
Description copied from interface: SqlManager
Deletes the given entity.

Specified by:
deleteEntity in interface SqlManager
Parameters:
entity - the entity to delete
Returns:
the number of updated rows

deleteBatch

public <T> int deleteBatch(T... entities)
Description copied from interface: SqlManager
Deletes given entities in batch mode.

Specified by:
deleteBatch in interface SqlManager
Type Parameters:
T - the entity type
Parameters:
entities - entities to delete
Returns:
the number of deleted rows

deleteBatch

public <T> int deleteBatch(List<T> entities)
Description copied from interface: SqlManager
Deletes given entities in batch mode.

Specified by:
deleteBatch in interface SqlManager
Type Parameters:
T - the entity type
Parameters:
entities - entities to delete
Returns:
the number of deleted rows

insertEntity

public int insertEntity(Object entity)
Description copied from interface: SqlManager
Inserts the given entity.

Specified by:
insertEntity in interface SqlManager
Parameters:
entity - the entity to insert
Returns:
the number of updated rows

insertBatch

public <T> int insertBatch(T... entities)
Description copied from interface: SqlManager
Inserts given entities in batch mode.

Specified by:
insertBatch in interface SqlManager
Type Parameters:
T - the entity type
Parameters:
entities - entities to insert
Returns:
the number of inserted rows

insertBatch

public <T> int insertBatch(List<T> entities)
Description copied from interface: SqlManager
Inserts given entities in batch mode.

Specified by:
insertBatch in interface SqlManager
Type Parameters:
T - the entity type
Parameters:
entities - entities to insert
Returns:
the number of inserted rows

updateEntity

public int updateEntity(Object entity)
Description copied from interface: SqlManager
Updates the given entity.

Specified by:
updateEntity in interface SqlManager
Parameters:
entity - the entity to update
Returns:
the number of updated rows

updateBatch

public <T> int updateBatch(T... entities)
Description copied from interface: SqlManager
Updates given entities in batch mode.

Specified by:
updateBatch in interface SqlManager
Type Parameters:
T - the entity type
Parameters:
entities - entities to update
Returns:
the number of updated rows

updateBatch

public <T> int updateBatch(List<T> entities)
Description copied from interface: SqlManager
Updates given entities in batch mode.

Specified by:
updateBatch in interface SqlManager
Type Parameters:
T - the entity type
Parameters:
entities - entities to update
Returns:
the number of updated rows

findEntity

public <T> T findEntity(Class<T> clazz,
                        Object... id)
Description copied from interface: SqlManager
Finds the entity by the given primary key.

Specified by:
findEntity in interface SqlManager
Type Parameters:
T - the type of entity
Parameters:
clazz - the type of entity
id - the primary key
Returns:
the entity. If the entity which corresponds to the given primary key is not found, this method returns null.

setValueTypes

public void setValueTypes(List<ValueType<?>> valueTypes)
Parameters:
valueTypes -
Throws:
IllegalArgumentException - if the valueTypes is null or an element in the valueTypes is null

addValueType

public void addValueType(ValueType<?> valueType)
Description copied from interface: SqlManager
Adds the implementation of the ValueType.

Specified by:
addValueType in interface SqlManager
Parameters:
valueType - the value type

getCount

public int getCount(String sqlPath)
Description copied from interface: SqlManager
Returns the row count of the result of the given SQL.

Specified by:
getCount in interface SqlManager
Parameters:
sqlPath - the SQL file path
Returns:
the row count

getCount

public int getCount(String sqlPath,
                    Object param)
Description copied from interface: SqlManager
Returns the row count of the result of the given SQL.

Specified by:
getCount in interface SqlManager
Parameters:
sqlPath - the SQL file path
param - the parameter object
Returns:
the row count

getCountBySql

public int getCountBySql(String sql)
Specified by:
getCountBySql in interface SqlManager

getCountBySql

public int getCountBySql(String sql,
                         Object... params)
Specified by:
getCountBySql in interface SqlManager

iterate

public <T,R> R iterate(Class<T> clazz,
                       IterationCallback<T,R> callback,
                       String sqlPath)
Specified by:
iterate in interface SqlManager

iterate

public <T,R> R iterate(Class<T> clazz,
                       IterationCallback<T,R> callback,
                       String sqlPath,
                       Object param)
Specified by:
iterate in interface SqlManager

call

public void call(String procedureName)
Description copied from interface: SqlManager
Invokes the stored procedure.

Specified by:
call in interface SqlManager
Parameters:
procedureName - the procedure name

call

public void call(String procedureName,
                 Object parameter)
Description copied from interface: SqlManager
Invokes the stored procedure.

Specified by:
call in interface SqlManager
Parameters:
procedureName - the procedure name
parameter - the parameter object

call

public <T> T call(Class<T> resultClass,
                  String functionName)
Specified by:
call in interface SqlManager

call

public <T> T call(Class<T> resultClass,
                  String functionName,
                  Object param)
Specified by:
call in interface SqlManager

callForList

public <T> List<T> callForList(Class<T> resultClass,
                               String functionName)
Specified by:
callForList in interface SqlManager

callForList

public <T> List<T> callForList(Class<T> resultClass,
                               String functionName,
                               Object param)
Specified by:
callForList in interface SqlManager

toCallString

protected String toCallString(String moduleName,
                              boolean function)

toCallString

protected String toCallString(String moduleName,
                              Object param,
                              boolean function)

needsParameter

protected boolean needsParameter(PropertyDesc pd)

getResultListBySql

public <T> List<T> getResultListBySql(Class<T> clazz,
                                      String sql)
Specified by:
getResultListBySql in interface SqlManager

getResultListBySql

public <T> List<T> getResultListBySql(Class<T> clazz,
                                      String sql,
                                      Object... params)
Specified by:
getResultListBySql in interface SqlManager

getSingleResultBySql

public <T> T getSingleResultBySql(Class<T> clazz,
                                  String sql)
Specified by:
getSingleResultBySql in interface SqlManager

getSingleResultBySql

public <T> T getSingleResultBySql(Class<T> clazz,
                                  String sql,
                                  Object... params)
Specified by:
getSingleResultBySql in interface SqlManager

iterateBySql

public <T,R> R iterateBySql(Class<T> clazz,
                            IterationCallback<T,R> callback,
                            String sql)
Specified by:
iterateBySql in interface SqlManager

iterateBySql

public <T,R> R iterateBySql(Class<T> clazz,
                            IterationCallback<T,R> callback,
                            String sql,
                            Object... params)
Specified by:
iterateBySql in interface SqlManager

executeUpdateBySql

public int executeUpdateBySql(String sql)
Description copied from interface: SqlManager
Executes the given SQL.
 int rows = sqlManager.executeUpdateBySql("DELETE FROM EMPLOYEE");
 

Specified by:
executeUpdateBySql in interface SqlManager
Parameters:
sql - the SQL to execute
Returns:
the number of updated rows

executeUpdateBySql

public int executeUpdateBySql(String sql,
                              Object... params)
Description copied from interface: SqlManager
Executes the given SQL with parameters.
 int rows = sqlManager.executeUpdateBySql("DELETE FROM EMPLOYEE WHERE ID=?", id);
 

Specified by:
executeUpdateBySql in interface SqlManager
Parameters:
sql - the SQL to execute which contains placeholder (This is not a 2waySQL)
params - the parameters which are set to the placeholder
Returns:
the number of updated rows


Copyright © 2010-2012 Project Amateras. All Rights Reserved.