Search in sources :

Example 21 with RowCallbackHandler

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;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) GenTaskByFreeSql(com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler)

Example 22 with RowCallbackHandler

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());
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler)

Example 23 with RowCallbackHandler

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;
}
Also used : LockException(org.hisp.dhis.dataset.LockException) SQLException(java.sql.SQLException) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) Period(org.hisp.dhis.period.Period) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler)

Example 24 with RowCallbackHandler

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();
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) IdSchemes(org.hisp.dhis.common.IdSchemes) SQLException(java.sql.SQLException) DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) Calendar(org.hisp.dhis.calendar.Calendar) ResultSet(java.sql.ResultSet) IdScheme(org.hisp.dhis.common.IdScheme) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler)

Aggregations

RowCallbackHandler (org.springframework.jdbc.core.RowCallbackHandler)24 ResultSet (java.sql.ResultSet)23 SQLException (java.sql.SQLException)23 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 GenTaskByFreeSql (com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql)2 GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)2 GenTaskByTableViewSp (com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp)2 MockNode (org.opennms.netmgt.mock.MockNode)2 Customer (org.springframework.jdbc.Customer)2 File (com.github.hakko.musiccabinet.domain.model.library.File)1 Album (com.github.hakko.musiccabinet.domain.model.music.Album)1 AlbumInfo (com.github.hakko.musiccabinet.domain.model.music.AlbumInfo)1 Timestamp (java.sql.Timestamp)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 CountDownLatch (java.util.concurrent.CountDownLatch)1