use of org.sagacity.sqltoy.executor.QueryExecutor in project sagacity-sqltoy by chenrenfei.
the class DialectFactory method executeSql.
/**
* @todo 执行sql修改性质的操作语句
* @param sqlToyContext
* @param sqlOrNamedSql
* @param paramsNamed
* @param paramsValue
* @param autoCommit
* @param dataSource
* @return
* @throws Exception
*/
public Long executeSql(final SqlToyContext sqlToyContext, final String sqlOrNamedSql, final String[] paramsNamed, final Object[] paramsValue, final Boolean autoCommit, final DataSource dataSource) throws Exception {
final SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(sqlOrNamedSql, SqlType.update);
try {
SqlExecuteStat.start(sqlToyConfig.getId(), "update", sqlToyConfig.isShowSql());
return (Long) DataSourceUtils.processDataSource(sqlToyContext, ShardingUtils.getShardingDataSource(sqlToyContext, sqlToyConfig, new QueryExecutor(sqlOrNamedSql, paramsNamed, paramsValue), dataSource), new DataSourceCallbackHandler() {
public void doConnection(Connection conn, Integer dbType, String dialect) throws Exception {
SqlToyResult queryParam = SqlConfigParseUtils.processSql(sqlToyContext.convertFunctions(sqlToyConfig.getSql(), dialect), paramsNamed, paramsValue);
String executeSql = queryParam.getSql();
// 替换sharding table
executeSql = ShardingUtils.replaceShardingTables(sqlToyContext, executeSql, sqlToyConfig, paramsNamed, paramsValue);
// debug 显示sql
SqlExecuteStat.showSql(executeSql, queryParam.getParamsValue());
this.setResult(DialectUtils.executeSql(executeSql, queryParam.getParamsValue(), null, conn, autoCommit));
}
});
} catch (Exception e) {
SqlExecuteStat.error(e);
throw e;
} finally {
SqlExecuteStat.destroy();
}
}
use of org.sagacity.sqltoy.executor.QueryExecutor in project sagacity-sqltoy by chenrenfei.
the class SqlToyDaoSupport method findByCriteria.
/**
* @todo 根据链式条件构造查询语句(不建议使用,并没有写sql直观)
* @param criteria
* @return
* @throws Exception
*/
protected List findByCriteria(final Criteria criteria) throws Exception {
EntityMeta entityMeta = this.getEntityMeta(criteria.getEntity().getClass());
// 构造条件查询
StringBuilder queryStr = new StringBuilder(entityMeta.getLoadAllSql());
// 增加空白增强容错性
queryStr.append(" ").append(criteria.wrapSqlFragments(entityMeta));
return findByQuery(new QueryExecutor(queryStr.toString(), null, criteria.getParamValues().toArray()).resultType(criteria.getEntity().getClass())).getRows();
}
use of org.sagacity.sqltoy.executor.QueryExecutor in project sagacity-sqltoy by chenrenfei.
the class SqlToyDaoSupport method findPageByCriteria.
protected PaginationModel findPageByCriteria(PaginationModel pageModel, Criteria criteria) throws Exception {
EntityMeta entityMeta = this.getEntityMeta(criteria.getEntity().getClass());
// 构造条件查询
StringBuilder queryStr = new StringBuilder(entityMeta.getLoadAllSql());
// 增加一个空格增强容错
queryStr.append(" ").append(criteria.wrapSqlFragments(entityMeta));
return findPageByQuery(pageModel, new QueryExecutor(queryStr.toString(), null, criteria.getParamValues().toArray()).resultType(criteria.getEntity().getClass())).getPageResult();
}
use of org.sagacity.sqltoy.executor.QueryExecutor in project sagacity-sqltoy by chenrenfei.
the class Mongo method findPage.
/**
* @todo 分页查询
* @param pageModel
* @return
* @throws Exception
*/
public PaginationModel findPage(PaginationModel pageModel) throws Exception {
QueryExecutor queryExecutor = build();
SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(sql);
NoSqlConfigModel noSqlModel = sqlToyConfig.getNoSqlConfigModel();
if (noSqlModel == null || noSqlModel.getCollection() == null || noSqlModel.getFields() == null)
throw new Exception(ERROR_MESSAGE);
// 最后的执行语句
String realMql = MongoElasticUtils.wrapMql(sqlToyConfig, queryExecutor.getParamsName(sqlToyConfig), queryExecutor.getParamsValue(sqlToyConfig));
return findPage(new MongoTemplate(getMongoDbFactory(noSqlModel.getMongoFactory())), sqlToyConfig, pageModel, realMql, queryExecutor.getResultTypeName());
}
use of org.sagacity.sqltoy.executor.QueryExecutor in project sagacity-sqltoy by chenrenfei.
the class DemeServiceImpl method updateFetch.
/*
* (non-Javadoc)
*
* @see org.sagacity.sqltoy.demo.service.DemoService#updateFetch()
*/
@Override
public List updateFetch() throws Exception {
StringBuilder query = new StringBuilder("SELECT STAFF_ID, STAFF_CODE, ORGAN_ID, STAFF_NAME, ENGLISH_NAME, SEX_TYPE,");
query.append("LINK_PHONE, BIRTHDAY, DUTY_DATE, OUT_DUTY_DATE, POST, PHOTO, EMAIL, IS_VIRTUAL, OPERATOR, OPERATE_DATE, ENABLED ");
query.append(" FROM SYS_STAFF_INFO where SEX_TYPE=:sexType");
// String sql =
// "select t.TRIGGER_ID, t.MANUAL_END, t.STATUS from cron_trigger t where t.STATUS in (:status) ";
QueryExecutor queryExecutor = new QueryExecutor(query.toString(), new String[] { "sexType" }, new Object[] { "F" });
List result = sqlToyLazyDao.updateFetch(queryExecutor, new UpdateRowHandler() {
@Override
public void updateRow(ResultSet rs, int index) throws SQLException {
rs.updateString("LINK_PHONE", "13918799460");
rs.updateString("ENGLISH_NAME", rs.getString("STAFF_NAME") + "EN");
}
});
for (int i = 0; i < result.size(); i++) {
System.err.println(((List) result.get(i)).get(0));
System.err.println(((List) result.get(i)).get(3));
}
// );
return result;
}
Aggregations