Search in sources :

Example 6 with SingleClassObjectSerializationFactory

use of org.openstreetmap.osmosis.core.store.SingleClassObjectSerializationFactory in project osmosis by openstreetmap.

the class EntityDao method getTagHistory.

private ReleasableIterator<DbFeatureHistory<DbFeature<Tag>>> getTagHistory(String selectedEntityStatement, MapSqlParameterSource parameterSource) {
    FileBasedSort<DbFeatureHistory<DbFeature<Tag>>> sortingStore = new FileBasedSort<DbFeatureHistory<DbFeature<Tag>>>(new SingleClassObjectSerializationFactory(DbFeatureHistory.class), new DbFeatureHistoryComparator<Tag>(), true);
    try {
        String sql;
        SortingStoreRowMapperListener<DbFeatureHistory<DbFeature<Tag>>> storeListener;
        DbFeatureHistoryRowMapper<DbFeature<Tag>> dbFeatureHistoryRowMapper;
        DbFeatureRowMapper<Tag> dbFeatureRowMapper;
        TagRowMapper tagRowMapper;
        ReleasableIterator<DbFeatureHistory<DbFeature<Tag>>> resultIterator;
        sql = "SELECT et." + entityName + "_id AS id, et.k, et.v, et.version" + " FROM " + entityName + "_tags et" + " INNER JOIN " + selectedEntityStatement + " t ON et." + entityName + "_id = t." + entityName + "_id AND et.version = t.version";
        LOG.log(Level.FINER, "Tag history query: " + sql);
        // Sends all received data into the object store.
        storeListener = new SortingStoreRowMapperListener<DbFeatureHistory<DbFeature<Tag>>>(sortingStore);
        // Retrieves the version information associated with the tag.
        dbFeatureHistoryRowMapper = new DbFeatureHistoryRowMapper<DbFeature<Tag>>(storeListener);
        // Retrieves the entity information associated with the tag.
        dbFeatureRowMapper = new DbFeatureRowMapper<Tag>(dbFeatureHistoryRowMapper);
        // Retrieves the basic tag information.
        tagRowMapper = new TagRowMapper(dbFeatureRowMapper);
        // Perform the query passing the row mapper chain to process rows in a streamy fashion.
        namedParamJdbcTemplate.query(sql, parameterSource, tagRowMapper);
        // Open a iterator on the store that will release the store upon completion.
        resultIterator = new StoreReleasingIterator<DbFeatureHistory<DbFeature<Tag>>>(sortingStore.iterate(), sortingStore);
        // The store itself shouldn't be released now that it has been attached to the iterator.
        sortingStore = null;
        return resultIterator;
    } finally {
        if (sortingStore != null) {
            sortingStore.close();
        }
    }
}
Also used : SingleClassObjectSerializationFactory(org.openstreetmap.osmosis.core.store.SingleClassObjectSerializationFactory) DbFeatureHistory(org.openstreetmap.osmosis.core.database.DbFeatureHistory) DbFeature(org.openstreetmap.osmosis.core.database.DbFeature) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag) FileBasedSort(org.openstreetmap.osmosis.core.sort.common.FileBasedSort)

Example 7 with SingleClassObjectSerializationFactory

use of org.openstreetmap.osmosis.core.store.SingleClassObjectSerializationFactory in project osmosis by openstreetmap.

the class RelationDao method getRelationMembers.

private ReleasableIterator<DbOrderedFeature<RelationMember>> getRelationMembers(String tablePrefix) {
    FileBasedSort<DbOrderedFeature<RelationMember>> sortingStore = new FileBasedSort<DbOrderedFeature<RelationMember>>(new SingleClassObjectSerializationFactory(DbOrderedFeature.class), new DbOrderedFeatureComparator<RelationMember>(), true);
    try {
        String sql;
        SortingStoreRowMapperListener<DbOrderedFeature<RelationMember>> storeListener;
        RowMapperRowCallbackListener<DbOrderedFeature<RelationMember>> rowCallbackListener;
        ReleasableIterator<DbOrderedFeature<RelationMember>> resultIterator;
        sql = relationMemberMapper.getSqlSelect(tablePrefix, false, false);
        // Sends all received data into the object store.
        storeListener = new SortingStoreRowMapperListener<DbOrderedFeature<RelationMember>>(sortingStore);
        // Converts result set rows into objects and passes them into the store.
        rowCallbackListener = new RowMapperRowCallbackListener<DbOrderedFeature<RelationMember>>(relationMemberMapper.getRowMapper(), storeListener);
        // Perform the query passing the row mapper chain to process rows in a streamy fashion.
        jdbcTemplate.query(sql, rowCallbackListener);
        // Open a iterator on the store that will release the store upon completion.
        resultIterator = new StoreReleasingIterator<DbOrderedFeature<RelationMember>>(sortingStore.iterate(), sortingStore);
        // The store itself shouldn't be released now that it has been attached to the iterator.
        sortingStore = null;
        return resultIterator;
    } finally {
        if (sortingStore != null) {
            sortingStore.close();
        }
    }
}
Also used : SingleClassObjectSerializationFactory(org.openstreetmap.osmosis.core.store.SingleClassObjectSerializationFactory) RelationMember(org.openstreetmap.osmosis.core.domain.v0_6.RelationMember) DbOrderedFeature(org.openstreetmap.osmosis.core.database.DbOrderedFeature) FileBasedSort(org.openstreetmap.osmosis.core.sort.common.FileBasedSort)

Aggregations

SingleClassObjectSerializationFactory (org.openstreetmap.osmosis.core.store.SingleClassObjectSerializationFactory)7 FileBasedSort (org.openstreetmap.osmosis.core.sort.common.FileBasedSort)5 DbFeatureHistory (org.openstreetmap.osmosis.core.database.DbFeatureHistory)3 DbOrderedFeature (org.openstreetmap.osmosis.core.database.DbOrderedFeature)3 RelationMember (org.openstreetmap.osmosis.core.domain.v0_6.RelationMember)2 Comparator (java.util.Comparator)1 Random (java.util.Random)1 Test (org.junit.Test)1 DbFeature (org.openstreetmap.osmosis.core.database.DbFeature)1 CommonEntityData (org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData)1 Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)1 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)1 EntityByTypeThenIdComparator (org.openstreetmap.osmosis.core.sort.v0_6.EntityByTypeThenIdComparator)1 EntitySubClassComparator (org.openstreetmap.osmosis.core.sort.v0_6.EntitySubClassComparator)1