Class NamedTemplate<T>
- java.lang.Object
-
- org.wso2.carbon.database.utils.jdbc.NamedTemplate<T>
-
- Type Parameters:
T- defines the input data type.
public class NamedTemplate<T> extends Object
This class created to have Template which contains the methods for the database transactions is different from Template class as it supports the use of named prepared statement.
-
-
Constructor Summary
Constructors Constructor Description NamedTemplate()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> intexecuteBatchInsert(String query, NamedQueryFilter namedQueryFilter, T bean)Executes the jdbc insert/update query.<T> intexecuteInsert(String query, NamedQueryFilter namedQueryFilter, T bean, boolean fetchInsertedId)<T> List<T>executeQuery(String query, RowMapper<T> rowMapper)Executes a query on JDBC and return the result as a list of domain objects.<T> List<T>executeQuery(String query, RowMapper<T> rowMapper, NamedQueryFilter namedQueryFilter)Executes a query on JDBC and return the result as a list of domain objects.intexecuteUpdate(String query)Executes the jdbc update query and returns the result as updated id integer.voidexecuteUpdate(String query, NamedQueryFilter namedQueryFilter)Executes the jdbc update query and returns nothing.<T> TfetchSingleRecord(String query, RowMapper<T> rowMapper, NamedQueryFilter namedQueryFilter)Executes a query on JDBC and return the result as a domain object.
-
-
-
Method Detail
-
executeInsert
public <T> int executeInsert(String query, NamedQueryFilter namedQueryFilter, T bean, boolean fetchInsertedId) throws DataAccessException
- Type Parameters:
T- return type of the object.- Parameters:
query- The SQL for insert/update.namedQueryFilter- Query filter to named prepared statement parameter binding.bean- the Domain object to be inserted/updated.fetchInsertedId- the boolean value to get the inserted id.- Throws:
DataAccessException
-
executeBatchInsert
public <T> int executeBatchInsert(String query, NamedQueryFilter namedQueryFilter, T bean) throws DataAccessException
Executes the jdbc insert/update query.- Parameters:
query- The SQL for insert/update.namedQueryFilter- Query filter to named prepared statement parameter binding.bean- the Domain object to be inserted/updated.- Throws:
DataAccessException
-
executeQuery
public <T> List<T> executeQuery(String query, RowMapper<T> rowMapper) throws DataAccessException
Executes a query on JDBC and return the result as a list of domain objects.- Parameters:
query- the SQL query with the parameter placeholders.rowMapper- Row mapper functional interface.- Returns:
- List of domain objects of required type.
- Throws:
DataAccessException- See Also:
executeQuery(String, RowMapper, NamedQueryFilter)
-
executeQuery
public <T> List<T> executeQuery(String query, RowMapper<T> rowMapper, NamedQueryFilter namedQueryFilter) throws DataAccessException
Executes a query on JDBC and return the result as a list of domain objects.- Parameters:
query- the SQL query with the parameter placeholders.rowMapper- Row mapper functional interface.namedQueryFilter- parameters for the SQL query parameter replacement.- Returns:
- List of domain objects of required type.
- Throws:
DataAccessException
-
fetchSingleRecord
public <T> T fetchSingleRecord(String query, RowMapper<T> rowMapper, NamedQueryFilter namedQueryFilter) throws DataAccessException
Executes a query on JDBC and return the result as a domain object.- Parameters:
query- the SQL query with the parameter placeholders.rowMapper- Row mapper functional interface.namedQueryFilter- parameters for the SQL query parameter replacement.- Returns:
- domain object of required type.
- Throws:
DataAccessException
-
executeUpdate
public void executeUpdate(String query, NamedQueryFilter namedQueryFilter) throws DataAccessException
Executes the jdbc update query and returns nothing.- Parameters:
query- SQL query with the parameter placeholders.namedQueryFilter- parameters for the SQL query parameter replacement.- Throws:
DataAccessException
-
executeUpdate
public int executeUpdate(String query) throws DataAccessException
Executes the jdbc update query and returns the result as updated id integer.- Parameters:
query- the SQL query with the parameter placeholders.- Returns:
- the updated id.
- Throws:
DataAccessException
-
-