use of org.springframework.jdbc.core.RowCallbackHandler in project dal by ctripcorp.
the class DaoByFreeSql method updateAndGetTasks.
public List<GenTaskByFreeSql> updateAndGetTasks(int projectId) {
final List<GenTaskByFreeSql> tasks = new ArrayList<>();
this.jdbcTemplate.query("SELECT id, project_id,db_name,class_name,pojo_name,method_name,crud_type," + " sql_content,parameters,`generated`,version,update_user_no,update_time," + " comment,scalarType,pojoType,pagination,sql_style,approved,approveMsg,hints" + " FROM task_sql " + " WHERE project_id=? AND `generated`=FALSE", new Object[] { projectId }, new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
GenTaskByFreeSql task = GenTaskByFreeSql.visitRow(rs);
task.setGenerated(true);
if (updateTask(task) > 0) {
tasks.add(task);
}
}
});
return tasks;
}
use of org.springframework.jdbc.core.RowCallbackHandler in project dal by ctripcorp.
the class DaoByFreeSql method updateTask.
public int updateTask(GenTaskByFreeSql task) {
final List<Integer> counts = new ArrayList<>();
this.jdbcTemplate.query("SELECT 1 FROM task_sql WHERE id != ? AND project_id=? AND db_name=? AND class_name=? AND method_name=? LIMIT 1", new Object[] { task.getId(), task.getProject_id(), task.getDatabaseSetName(), task.getClass_name(), task.getMethod_name() }, new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
counts.add(1);
}
});
if (counts.size() > 0)
return -1;
return this.jdbcTemplate.update("UPDATE task_sql SET project_id=?, db_name=?,class_name=?,pojo_name=?," + "method_name=?,crud_type=?,sql_content=?,parameters=?,`generated`=?," + "version=version+1,update_user_no=?,update_time=?,comment=?," + "scalarType=?,pojoType=?,pagination=?,sql_style=?,approved=?,approveMsg=?,hints=?" + " WHERE id=? AND version=?", task.getProject_id(), task.getDatabaseSetName(), task.getClass_name(), task.getPojo_name(), task.getMethod_name(), task.getCrud_type(), task.getSql_content(), task.getParameters(), task.isGenerated(), task.getUpdate_user_no(), task.getUpdate_time(), task.getComment(), task.getScalarType(), task.getPojoType(), task.isPagination(), task.getSql_style(), task.getApproved(), task.getApproveMsg(), task.getHints(), task.getId(), task.getVersion());
}
use of org.springframework.jdbc.core.RowCallbackHandler in project dhis2-core by dhis2.
the class HibernateLockExceptionStore method getCombinations.
@Override
public List<LockException> getCombinations() {
final String sql = "select distinct datasetid, periodid from lockexception";
final List<LockException> lockExceptions = new ArrayList<>();
jdbcTemplate.query(sql, new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
int dataSetId = rs.getInt(1);
int periodId = rs.getInt(2);
LockException lockException = new LockException();
Period period = periodService.getPeriod(periodId);
DataSet dataSet = dataSetStore.get(dataSetId);
lockException.setDataSet(dataSet);
lockException.setPeriod(period);
lockExceptions.add(lockException);
}
});
return lockExceptions;
}
use of org.springframework.jdbc.core.RowCallbackHandler in project dhis2-core by dhis2.
the class SpringDataValueSetStore method writeDataValueSet.
private void writeDataValueSet(String sql, DataExportParams params, Date completeDate, final DataValueSet dataValueSet) {
if (params.isSingleDataValueSet()) {
IdSchemes idScheme = params.getOutputIdSchemes() != null ? params.getOutputIdSchemes() : new IdSchemes();
IdScheme ouScheme = idScheme.getOrgUnitIdScheme();
IdScheme dataSetScheme = idScheme.getDataSetIdScheme();
dataValueSet.setDataSet(params.getFirstDataSet().getPropertyValue(dataSetScheme));
dataValueSet.setCompleteDate(getLongGmtDateString(completeDate));
dataValueSet.setPeriod(params.getFirstPeriod().getIsoDate());
dataValueSet.setOrgUnit(params.getFirstOrganisationUnit().getPropertyValue(ouScheme));
}
final Calendar calendar = PeriodType.getCalendar();
jdbcTemplate.query(sql, new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
DataValue dataValue = dataValueSet.getDataValueInstance();
PeriodType pt = PeriodType.getPeriodTypeByName(rs.getString("ptname"));
boolean deleted = rs.getBoolean("deleted");
dataValue.setDataElement(rs.getString("deid"));
dataValue.setPeriod(pt.createPeriod(rs.getDate("pestart"), calendar).getIsoDate());
dataValue.setOrgUnit(rs.getString("ouid"));
dataValue.setCategoryOptionCombo(rs.getString("cocid"));
dataValue.setAttributeOptionCombo(rs.getString("aocid"));
dataValue.setValue(rs.getString("value"));
dataValue.setStoredBy(rs.getString("storedby"));
dataValue.setCreated(getLongGmtDateString(rs.getTimestamp("created")));
dataValue.setLastUpdated(getLongGmtDateString(rs.getTimestamp("lastupdated")));
dataValue.setComment(rs.getString("comment"));
dataValue.setFollowup(rs.getBoolean("followup"));
if (deleted) {
dataValue.setDeleted(deleted);
}
dataValue.close();
}
});
dataValueSet.close();
}
Aggregations