Search in sources :

Example 36 with RowCallbackHandler

use of org.springframework.jdbc.core.RowCallbackHandler in project ma-core-public by infiniteautomation.

the class DataPointDao method getPointHierarchy.

/**
 * Get the point hierarchy from its cached copy.  The read only cached copy should
 * never be modified, if you intend to modify it ensure you pass readOnly=false
 *
 * @param readOnly - do not modify a read only point hierarchy
 * @return
 */
public PointHierarchy getPointHierarchy(boolean readOnly) {
    if (cachedPointHierarchy == null) {
        final Map<Integer, List<PointFolder>> folders = new HashMap<>();
        // Get the folder list.
        ejt.query("select id, parentId, name from dataPointHierarchy order by name", new RowCallbackHandler() {

            @Override
            public void processRow(ResultSet rs) throws SQLException {
                PointFolder f = new PointFolder(rs.getInt(1), rs.getString(3));
                int parentId = rs.getInt(2);
                List<PointFolder> folderList = folders.get(parentId);
                if (folderList == null) {
                    folderList = new LinkedList<>();
                    folders.put(parentId, folderList);
                }
                folderList.add(f);
            }
        });
        // Create the folder hierarchy.
        PointHierarchy ph = new PointHierarchy();
        addFoldersToHeirarchy(ph, 0, folders);
        // Add data points.
        List<DataPointSummary> points = getDataPointSummaries(DataPointExtendedNameComparator.instance);
        for (DataPointSummary dp : points) ph.addDataPoint(dp.getPointFolderId(), dp);
        cachedPointHierarchy = ph;
    }
    if (readOnly)
        return cachedPointHierarchy;
    else
        return cachedPointHierarchy.clone();
}
Also used : DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SQLException(java.sql.SQLException) PointFolder(com.serotonin.m2m2.vo.hierarchy.PointFolder) PointHierarchy(com.serotonin.m2m2.vo.hierarchy.PointHierarchy) LinkedList(java.util.LinkedList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResultSet(java.sql.ResultSet) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler)

Example 37 with RowCallbackHandler

use of org.springframework.jdbc.core.RowCallbackHandler in project musiccabinet by hakko.

the class JdbcTagDao method getCorrectedTags.

@Override
public Map<String, String> getCorrectedTags() {
    String sql = "select t.tag_name, tc.tag_name from music.tag t" + " inner join music.tag tc on t.corrected_id = tc.id";
    final Map<String, String> correctedTags = new HashMap<>();
    jdbcTemplate.query(sql, new RowCallbackHandler() {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            correctedTags.put(rs.getString(1), rs.getString(2));
        }
    });
    return correctedTags;
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler)

Example 38 with RowCallbackHandler

use of org.springframework.jdbc.core.RowCallbackHandler in project musiccabinet by hakko.

the class JdbcLibraryPresenceDao method getFiles.

@Override
public Set<File> getFiles(String directory) {
    String sql = "select d.path, f.filename, f.modified, f.size from library.file f" + " inner join library.directory d on f.directory_id = d.id" + " where d.path = ?";
    final Set<File> files = new HashSet<>();
    jdbcTemplate.query(sql, new Object[] { directory }, new RowCallbackHandler() {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            String directory = rs.getString(1);
            String filename = rs.getString(2);
            DateTime modified = new DateTime(rs.getTimestamp(3).getTime());
            int size = rs.getInt(4);
            files.add(new File(directory, filename, modified, size));
        }
    });
    return files;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler) File(com.github.hakko.musiccabinet.domain.model.library.File) DateTime(org.joda.time.DateTime) HashSet(java.util.HashSet)

Example 39 with RowCallbackHandler

use of org.springframework.jdbc.core.RowCallbackHandler in project dhis2-core by dhis2.

the class JdbcCompleteDataSetRegistrationExchangeStore method writeCompleteness.

// --------------------------------------------------------------------------
// Supportive methods
// --------------------------------------------------------------------------
private void writeCompleteness(String sql, CompleteDataSetRegistrations completeDataSetRegistrations) {
    final Calendar calendar = PeriodType.getCalendar();
    completeDataSetRegistrations.open();
    jdbcTemplate.query(sql, new RowCallbackHandler() {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            CompleteDataSetRegistration completeDataSetRegistration = completeDataSetRegistrations.getCompleteDataSetRegistrationInstance();
            PeriodType pt = PeriodType.getPeriodTypeByName(rs.getString("ptname"));
            completeDataSetRegistration.open();
            completeDataSetRegistration.setDataSet(rs.getString("dsid"));
            completeDataSetRegistration.setPeriod(pt.createPeriod(rs.getDate("pestart"), calendar).getIsoDate());
            completeDataSetRegistration.setOrganisationUnit(rs.getString("ouid"));
            completeDataSetRegistration.setAttributeOptionCombo(rs.getString("aocid"));
            completeDataSetRegistration.setDate(removeTime(rs.getString("date")));
            completeDataSetRegistration.setStoredBy(rs.getString("storedby"));
            completeDataSetRegistration.setLastUpdatedBy(rs.getString("lastupdatedby"));
            completeDataSetRegistration.setLastUpdated(removeTime(rs.getString("lastupdated")));
            completeDataSetRegistration.setCompleted(rs.getBoolean("iscompleted"));
            completeDataSetRegistration.close();
        }
    });
    completeDataSetRegistrations.close();
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) SQLException(java.sql.SQLException) Calendar(org.hisp.dhis.calendar.Calendar) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler)

Example 40 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)

Aggregations

RowCallbackHandler (org.springframework.jdbc.core.RowCallbackHandler)41 ResultSet (java.sql.ResultSet)38 SQLException (java.sql.SQLException)37 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)6 LinkedHashMap (java.util.LinkedHashMap)4 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)4 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)3 Date (java.util.Date)3 Map (java.util.Map)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)3 ExportDataValue (com.serotonin.m2m2.vo.export.ExportDataValue)2 ExportPointInfo (com.serotonin.m2m2.vo.export.ExportPointInfo)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Calendar (org.hisp.dhis.calendar.Calendar)2 PeriodType (org.hisp.dhis.period.PeriodType)2