|
Anyframe Core | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface IQueryService
This Service simplifies the use of JDBC and helps to avoid common errors. It executes core JDBC workflow, leaving application code to provide SQL and extract results. This class executes query statement or updates, initiating iteration over ResultSets. It must be used with DataSource Service.
QueryService Configuration Example:
<bean name="queryService" class="anyframe.core.query.impl.QueryServiceImpl">
<property name="jdbcTemplate" ref="jdbcTemplate"/>
<property name="sqlRepository" ref="sqlLoader"/>
<property name="pagingSQLGenerator" ref="pagingSQLGenerator"/>
<property name="lobHandler" ref="lobHandler"/>
</bean>
<bean id="jdbcTemplate" class="anyframe.core.query.impl.jdbc.PagingJdbcTemplate">
<property name="dataSource" ref="dataSource" />
<property name="exceptionTranslator" ref="exceptionTranslator" />
</bean>
<bean name="sqlLoader" class="anyframe.core.query.impl.config.loader.SQLLoader">
<config:configuration>
<!-- xml files in folder -->
<filename>file:./testmappings/testcase-*.xml</filename>
<filename>file:./testdynamicreload/testcase-queries-dynamicreload.xml</filename>
<!-- xml files in classpath -->
<filename>classpath*:/META-INF/mappings/testcase-queries-*.xml</filename>
<!-- xml files in jar -->
<filename>classpath*:/testcase-queries-lob.xml</filename>
<nullcheck type="VARCHAR" default-value="" />
<sqlload dynamic="true" frequency="5" />
<skiperror>true</skiperror>
</config:configuration>
</bean>
<bean id="pagingSQLGenerator" class="anyframe.core.query.impl.jdbc.generator.OraclePagingSQLGenerator"/>
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler"
lazy-init="true">
<property name="nativeJdbcExtractor" ref="nativeJdbcExtractor"/>
</bean>
<bean id="exceptionTranslator" class="anyframe.core.query.impl.util.RawSQLExceptionTranslator"/>
<bean id="nativeJdbcExtractor"
class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"
lazy-init="true"/>
Query Mapping XML Example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE queryservice PUBLIC "-//ANYFRAME//DTD QUERYSERVICE//EN"
"http://www.anyframejava.org/dtd/anyframe-core-query-mapping-3.1.dtd">
<queryservice>
<table-mapping>
<table name="TBL_CUSTOMER" class="anyframe.core.query.Customer">
<field-mapping>
<dbms-column>SSNO</dbms-column>
<class-attribute>ssno</class-attribute>
</field-mapping>
<field-mapping>
<dbms-column>NAME</dbms-column>
<class-attribute>nm</class-attribute>
</field-mapping>
<primary-key>
<dbms-column>SSNO</dbms-colum>
</primary-key>
</table>
</table-mapping>
<queries>
<query id="query01" isDynamic="true" isCamelCase="true">
<statement>
select NAME, ADDRESS from TBL_CUSTOMER where SSNO like ?
</statement>
<param type="VARCHAR"/>
<result length=2 class="anyframe.core.query.Customer"/>
</query>
</queries>
</queryservice>
Configuration Attributes: Mapping XML file has <queryservice> </queryservice> element which is composed with table-mapping tag and queries tag. table-mapping tag, queries tag is a required element.
table-mapping tag
table-mapping element
defines mapping informations between table and classtable element defines
mapping informations between table and classfield-mapping defines
mapping informations between table column and class
attributeprimary-key element defines
primary keys of given tabledbms-column element defines
column of given tableclass-attribute element
defines class attribute mapped to given column of
tablequeries tag
query element defines query
statement and attributestatement element defines
single query statementparam defines mapping
informations used in jdbc processing
--------------------------------------- Java Type DBMS Type --------------------------------------- String CHAR String VARCHAR String LONGVARCHAR java.math.BigDecimal NUMERIC java.math.BigDecimal DECIMAL boolean BIT byte TINYINT short SMALLINT int INTEGER long BIGINT float REAL double FLOAT double DOUBLE byte[] BINARY byte[] VARBINARY byte[] LONGVARBINARY java.sql.Date DATE java.sql.Time TIME java.sql.Timestamp TIMESTAMP ---------------------------------------
result element defines
return object type. if it is not defined in mapping
file, Java Collection Map type will be used as
return object typeLet's start with a simple example.
The following class is the Persistent Object Class mapped to the upper sample Query Mapping file.
package anyframe.core.query;
import java.io.Serializable;
public class CustomerVO implements Serializable {
public String ssno;
public String nm;
public Customer() {
}
public Customer(String s, String n) {
ssno = s;
nm = n;
}
public String getSsno() {
return ssno;
}
public String getNm() {
return nm;
}
public void setSsno(String s) {
ssno = s;
}
public void setNm(String n) {
nm = n;
}
}
public class Main {
public static void main(String args[]) throws Exception {
ApplicationContext applicationContext =
new ClasspathXmlApplicationContext(new String[] {"..." });
QueryService qs =
(applicationContext) applicationContext.getBean("queryService");
qs.create("query03", new Object[] {"1234567890123", "AAA" });
Collection allCustomer = qs.find("query01", new Object[] {"12345%" });
Collection customer = qs.find("query01", new Object[] {"12345%" }, 1);
qs.update("query04", new Object[] {"1234567890123", "BBB" });
qs.remove("query05", new Object[] {"1234567890123" });
}
}
| Field Summary | |
|---|---|
static String |
COL_INFO
|
static String |
COUNT
|
static String |
LIST
|
static Log |
LOGGER
|
static String |
ROLE
|
| Method Summary | |
|---|---|
int[] |
batchCreate(List targets)
Issue multiple updates using JDBC 2.0 batch updates and PreparedStatementSetters to set values on a PreparedStatement created by this method |
int[] |
batchRemove(List targets)
Issue multiple updates using JDBC 2.0 batch updates and PreparedStatementSetters to set values on a PreparedStatement created by this method |
int[] |
batchUpdate(List targets)
Issue multiple updates using JDBC 2.0 batch updates and PreparedStatementSetters to set values on a PreparedStatement created by this method |
int[] |
batchUpdate(String queryId,
List targets)
Issue multiple updates using JDBC 2.0 batch updates and PreparedStatementSetters to set values on a PreparedStatement created by this method |
int[] |
batchUpdateBySQL(String sql,
String[] types,
List targets)
Issue multiple updates using JDBC 2.0 batch updates and PreparedStatementSetters to set values on a PreparedStatement created by this method Execute UPDATE query, Using query statement directly without being defined in mapping xml files. |
int |
countQuery()
Count all queries which defined in mapping xml files. |
int |
create(Object obj)
Execute INSERT query, Using object, which class is matched with table by mapping xml files. |
int |
create(String queryId,
Object[] values)
Execute INSERT query, Using given queryId which defined in mapping xml files. |
int |
createBySQL(String sql,
String[] types,
Object[] values)
Execute INSERT query, Using query statement directly without being defined in mapping xml files. |
Map |
execute(String queryId,
Map values)
Execute an sql call using a CallableStatement |
Map |
execute(String queryId,
Map values,
int pageIndex)
Execute an SELECT sql call using a CallableStatement which defined in mapping xml files. |
Map |
execute(String queryId,
Map values,
int pageIndex,
int pageSize)
Execute an SELECT sql call using a CallableStatement which defined in mapping xml files. |
Map |
executeBySQL(String sql,
String[] types,
String[] names,
String[] bindings,
Map values)
Execute an Sql call using a CallableStatement |
Map |
executeBySQL(String sql,
String[] types,
String[] names,
String[] bindings,
Map values,
int pageIndex,
int pageSize)
Execute an Sql call using a CallableStatement |
Collection |
find(Object obj)
Execute a SELECT query, Using object, which class is matched with table by mapping xml files. |
Collection |
find(String queryId,
Object[] values)
Execute a SELECT query, Using given queryId which defined in mapping xml files. |
Collection |
find(String queryId,
Object[] values,
int pageIndex)
Execute a SELECT query, Using given queryId which defined in mapping xml files. |
Collection |
find(String queryId,
Object[] values,
int pageIndex,
int pageSize)
Execute a SELECT query, Using given queryId which defined in mapping xml files. |
Collection |
findBySQL(String sql,
String[] types,
Object[] values)
Execute a SELECT query, Using query statement directly without being defined in mapping xml files. |
Collection |
findBySQL(String sql,
String[] types,
Object[] values,
int pageIndex,
int pageSize)
Execute a SELECT query, Using query statement directly without being defined in mapping xml files. |
Map |
findBySQLWithRowCount(String sql,
String[] types,
Object[] values)
Execute a SELECT query, Using query statement directly without being defined in mapping xml files. |
Map |
findBySQLWithRowCount(String sql,
String[] types,
Object[] values,
int pageIndex,
int pageSize)
Execute a SELECT query, Using query statement directly without being defined in mapping xml files. |
Map |
findWithColInfo(String queryId,
Object[] values)
Execute a SELECT query, using given queryId which defined in mapping xml files. |
Map |
findWithColInfo(String queryId,
Object[] values,
int pageIndex)
Execute a SELECT query, using given queryId which defined in mapping xml files. |
Map |
findWithColInfo(String queryId,
Object[] values,
int pageIndex,
int pageSize)
Execute a SELECT query, using given queryId which defined in mapping xml files. |
Map |
findWithRowCount(String queryId,
Object[] values)
Execute a SELECT query, using given queryId which defined in mapping xml files. |
Map |
findWithRowCount(String queryId,
Object[] values,
int pageIndex)
Execute a SELECT query, using given queryId which defined in mapping xml files. |
Map |
findWithRowCount(String queryId,
Object[] values,
int pageIndex,
int pageSize)
Execute a SELECT query, using given queryId which defined in mapping xml files. |
IQueryInfo |
getQueryInfo(String queryId)
Find specified query information which queryId equal to input parameter. |
Map |
getQueryMap()
Find all query list which defined in mapping xml files. |
ArrayList |
getQueryParams(String queryId)
Find parameters for specified query. |
JdbcTemplate |
getQueryServiceJdbcTemplate()
Get JdbcTemplate which QueryService uses |
String |
getStatement(String queryId)
Find specified query statement which queryId equal to input parameter. |
int |
remove(Object obj)
Execute DELETE query, using object, which class is matched with table by mapping xml files. |
int |
remove(String queryId,
Object[] values)
Execute DELETE query, using given queryId which defined in mapping xml files. |
int |
removeBySQL(String sql,
String[] types,
Object[] values)
Execute DELETE query, using query statement directly without being defined in mapping xml files. |
int |
update(Object obj)
Execute UPDATE query, using object, which class is matched with table by mapping xml files. |
int |
update(String queryId,
Object[] values)
Execute UPDATE query, using given queryId which defined in mapping xml files. |
int |
updateBySQL(String sql,
String[] types,
Object[] values)
Execute UPDATE query, using query statement directly without being defined in mapping xml files. |
| Field Detail |
|---|
static final Log LOGGER
static final String ROLE
static final String COL_INFO
static final String COUNT
static final String LIST
| Method Detail |
|---|
int[] batchCreate(List targets)
throws QueryServiceException
targets - object of class which is matched with
specified table in mapping xml files. is
the List type of Object.
QueryServiceException - if there is any problem issuing the
update
int[] batchRemove(List targets)
throws QueryServiceException
targets - object of class which is matched with
specified table in mapping xml files. is
the List type of Object.
QueryServiceException - if there is any problem issuing the
update
int[] batchUpdate(List targets)
throws QueryServiceException
targets - object of class which is matched with
specified table in mapping xml files. is
the List type of Object.
QueryServiceException - if there is any problem issuing the
update
int[] batchUpdate(String queryId,
List targets)
throws QueryServiceException
queryId - identifier of query statement to executetargets - a set of variable for executing query (is
the List of Object[])
QueryServiceException - if there is any problem issuing the
update
int[] batchUpdateBySQL(String sql,
String[] types,
List targets)
throws QueryServiceException
sql - query statement.types - is matched with input parameters. A type
must belong to fields defined
java.sql.Types packagetargets - object of class which is matched with
specified table in mapping xml files. is
the List type of Object.
QueryServiceException - if there is any problem issuing the
update
int create(Object obj)
throws QueryServiceException
obj - object of class which is matched with
specified table in mapping xml files.
QueryServiceException - if there is any problem executing the
query
int create(String queryId,
Object[] values)
throws QueryServiceException
queryId - identifier of query statement to executevalues - a set of variable for executing query
QueryServiceException - if there is any problem executing the
query
int createBySQL(String sql,
String[] types,
Object[] values)
throws QueryServiceException
sql - query statement.types - is matched with input parameters. A type
must belong to fields defined
java.sql.Types packagevalues - a set of variable for executing query
QueryServiceException - if there is any problem executing the
query
Map execute(String queryId,
Map values)
throws QueryServiceException
queryId - identifier of query statement to executevalues - a key-value set of variable for executing
query
QueryServiceException - if there is any problem issuing the
execute
Map execute(String queryId,
Map values,
int pageIndex)
throws QueryServiceException
queryId - identifier of query statement to executevalues - a key-value set of variable for executing
querypageIndex - page number which expected to be
displayed (pageIndex > 0)
QueryServiceException - if there is any problem issuing the
execute
Map execute(String queryId,
Map values,
int pageIndex,
int pageSize)
throws QueryServiceException
queryId - identifier of query statement to executevalues - a key-value set of variable for executing
querypageIndex - page number which expected to be
displayed (pageIndex > 0)pageSize - page size which expected to be displayed
per page (pageSize > 0)
QueryServiceException - if there is any problem issuing the
execute
Map executeBySQL(String sql,
String[] types,
String[] names,
String[] bindings,
Map values)
throws QueryServiceException
sql - callable statement to executetypes - a set of variable type for executing
querynames - a set of variable name for executing
querybindings - a set of variable in-out type for
executing queryvalues - a key-value set of variable for executing
query
QueryServiceException - if there is any problem issuing the
execute
Map executeBySQL(String sql,
String[] types,
String[] names,
String[] bindings,
Map values,
int pageIndex,
int pageSize)
throws QueryServiceException
sql - callable statement to executetypes - a set of variable type for executing
querynames - a set of variable name for executing
querybindings - a set of variable in-out type for
executing queryvalues - a key-value set of variable for executing
querypageIndex - page number which expected to be
displayed (pageIndex > 0)pageSize - page size which expected to be displayed
per page (pageSize > 0)
QueryServiceException - if there is any problem issuing the
execute
Collection find(Object obj)
throws QueryServiceException
obj - object of class which is matched with
specified table in mapping xml files.
QueryServiceException - if there is any problem executing the
query
Collection find(String queryId,
Object[] values)
throws QueryServiceException
queryId - identifier of query statement to executevalues - a set of variable for executing query
Exception - if there is any problem executing the
query
QueryServiceException
Collection find(String queryId,
Object[] values,
int pageIndex)
throws QueryServiceException
queryId - identifier of query statement to executevalues - a set of variable for executing querypageIndex - page number which expected to be
displayed (pageIndex > 0)
QueryServiceException - if there is any problem executing the
query
Collection find(String queryId,
Object[] values,
int pageIndex,
int pageSize)
throws QueryServiceException
queryId - identifier of query statement to executevalues - a set of variable for executing querypageIndex - page number which expected to be
displayed (pageIndex > 0)pageSize - page size which expected to be displayed
per page (pageSize > 0)
QueryServiceException - if there is any problem executing the
query
Collection findBySQL(String sql,
String[] types,
Object[] values)
throws QueryServiceException
sql - query statement.types - is matched with input parameters. A type
must belong to fields defined
java.sql.Types packagevalues - a set of variable for executing query
QueryServiceException - if there is any problem executing the
query
Collection findBySQL(String sql,
String[] types,
Object[] values,
int pageIndex,
int pageSize)
throws QueryServiceException
sql - query statement.types - is matched with input parameters. A type
must belong to fields defined
java.sql.Types packagevalues - a set of variable for executing querypageIndex - page number which expected to be
displayed (pageIndex > 0)pageSize - page size which expected to be displayed
per page (pageSize > 0)
QueryServiceException - if there is any problem executing the
query
Map findBySQLWithRowCount(String sql,
String[] types,
Object[] values)
throws QueryServiceException
sql - query statement.types - is matched with input parameters. A type
must belong to fields defined
java.sql.Types packagevalues - a set of variable for executing query
QueryServiceException - if there is any problem executing the
query
Map findBySQLWithRowCount(String sql,
String[] types,
Object[] values,
int pageIndex,
int pageSize)
throws QueryServiceException
sql - query statement.types - is matched with input parameters. A type
must belong to fields defined
java.sql.Types packagevalues - a set of variable for executing querypageIndex - page number which expected to be
displayed (pageIndex > 0)pageSize - page size which expected to be displayed
per page (pageSize > 0)
QueryServiceException - if there is any problem executing the
query
Map findWithColInfo(String queryId,
Object[] values)
throws QueryServiceException
queryId - identifier of query statement to executevalues - a set of variable for executing query
QueryServiceException - if there is any problem executing the
query
Map findWithColInfo(String queryId,
Object[] values,
int pageIndex)
throws QueryServiceException
queryId - identifier of query statement to executevalues - a set of variable for executing querypageIndex - page number which expected to be
displayed (pageIndex > 0)
QueryServiceException - if there is any problem executing the
query
Map findWithColInfo(String queryId,
Object[] values,
int pageIndex,
int pageSize)
throws QueryServiceException
queryId - identifier of query statement to executevalues - a set of variable for executing querypageIndex - page number which expected to be
displayed (pageIndex > 0)pageSize - page size which expected to be displayed
per page (pageSize > 0)
QueryServiceException - if there is any problem executing the
query
Map findWithRowCount(String queryId,
Object[] values)
throws QueryServiceException
queryId - identifier of query statement to executevalues - a set of variable for executing query
QueryServiceException - if there is any problem executing the
query
Map findWithRowCount(String queryId,
Object[] values,
int pageIndex)
throws QueryServiceException
queryId - identifier of query statement to executevalues - a set of variable for executing querypageIndex - page number which expected to be
displayed (pageIndex > 0)
QueryServiceException - if there is any problem executing the
query
Map findWithRowCount(String queryId,
Object[] values,
int pageIndex,
int pageSize)
throws QueryServiceException
queryId - identifier of query statement to executevalues - a set of variable for executing querypageIndex - page number which expected to be
displayed (pageIndex > 0)pageSize - page size which expected to be displayed
per page (pageSize > 0)
QueryServiceException - if there is any problem executing the
query
int remove(Object obj)
throws QueryServiceException
obj - object of class which is matched with
specified table in mapping xml files.
QueryServiceException - if there is any problem executing the
query
int remove(String queryId,
Object[] values)
throws QueryServiceException
queryId - identifier of query statement to executevalues - a set of variable for executing query
QueryServiceException - if there is any problem executing the
query
int removeBySQL(String sql,
String[] types,
Object[] values)
throws QueryServiceException
sql - query statement.types - is matched with input parameters. A type
must belong to fields defined
java.sql.Types packagevalues - a set of variable for executing query
QueryServiceException - if there is any problem executing the
query
int update(Object obj)
throws QueryServiceException
obj - object of class which is matched with
specified table in mapping xml files.
QueryServiceException - if there is any problem executing the
query
int update(String queryId,
Object[] values)
throws QueryServiceException
queryId - identifier of query statement to executevalues - a set of variable for executing query
QueryServiceException - if there is any problem executing the
query
int updateBySQL(String sql,
String[] types,
Object[] values)
throws QueryServiceException
sql - query statement.types - is matched with input parameters. A type
must belong to fields defined
java.sql.Types packagevalues - a set of variable for executing query
QueryServiceException - if there is any problem executing the
queryint countQuery()
Map getQueryMap()
throws QueryServiceException
QueryServiceException - if there is any problem making mapping
map
ArrayList getQueryParams(String queryId)
throws QueryServiceException
QueryServiceException - if there is any problem find parameters.JdbcTemplate getQueryServiceJdbcTemplate()
String getStatement(String queryId)
throws QueryServiceException
queryId - query id which defined a mapping xml file
QueryServiceException - if there is any problem find sqlIQueryInfo getQueryInfo(String queryId)
queryId - query id which defined a mapping xml file
|
Anyframe Core | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||