当前位置: 首页>>代码示例>>Java>>正文


Java Transaction类代码示例

本文整理汇总了Java中org.geotools.data.Transaction的典型用法代码示例。如果您正苦于以下问题:Java Transaction类的具体用法?Java Transaction怎么用?Java Transaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Transaction类属于org.geotools.data包,在下文中一共展示了Transaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testFidFilterQuery

import org.geotools.data.Transaction; //导入依赖的package包/类
@Test
public void testFidFilterQuery() throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
    final String fidsString = fids.stream().collect(Collectors.joining("','", "'", "'"));
    final Filter filter = ECQL.toFilter("IN (" + fidsString + ")");
    final Query query = new Query(
            "GeoWaveFeatureReaderTest",
            filter,
            new String[] {
                "geometry",
                "pid"
            });
    final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
        dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
    int count = 0;
    while (reader.hasNext()) {
        final SimpleFeature feature = reader.next();
        assertTrue(fids.contains(feature.getID()));
        count++;
    }
    assertTrue(count == fids.size());
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:22,代码来源:GeoWaveFeatureReaderTest.java

示例2: testPidFilterQuery

import org.geotools.data.Transaction; //导入依赖的package包/类
@Test
public void testPidFilterQuery() throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
    // Filter it so that it only queries for everything but the first pid.
    // There's only 2 pids total so it should just return the second one.
    final String pidsString = pids.subList(1, pids.size()).stream().collect(Collectors.joining("','", "'", "'"));
    final Filter filter = ECQL.toFilter("pid IN (" + pidsString + ")");
    final Query query = new Query(
            "GeoWaveFeatureReaderTest",
            filter,
            new String[] {
                "geometry",
                "pid"
            });
    final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
        dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
    int count = 0;
    while (reader.hasNext()) {
        final SimpleFeature feature = reader.next();
        assertTrue(fids.contains(feature.getID()));
        count++;
    }
    assertTrue(count == pids.size() - 1);
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:24,代码来源:GeoWaveFeatureReaderTest.java

示例3: testLike

import org.geotools.data.Transaction; //导入依赖的package包/类
@Test
public void testLike() throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
    final Query query = new Query(
            "GeoWaveFeatureReaderTest",
            ECQL.toFilter("pid like '" + pids.get(
                    0).substring(
                    0,
                    1) + "%'"),
            new String[] {
                "geometry",
                "pid"
            });
    final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
        dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
    int count = 0;
    while (reader.hasNext()) {
        final SimpleFeature feature = reader.next();
        assertTrue(fids.contains(feature.getID()));
        count++;
    }
    assertEquals(1, count);
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:23,代码来源:GeoWaveFeatureReaderTest.java

示例4: addFeature

import org.geotools.data.Transaction; //导入依赖的package包/类
/**
 * Add a feature to the store.
 * 
 * @param feature the feature to add.
 */
default public void addFeature( SimpleFeature feature) {
    FeatureStoreInfo featureStoreInfo = getFeatureStoreInfo();
    SimpleFeatureStore featureStore = featureStoreInfo.getFeatureStore();
    if (featureStore != null) {
        Transaction transaction = new DefaultTransaction("add");
        featureStore.setTransaction(transaction);
        
        try {
            DefaultFeatureCollection fc = new DefaultFeatureCollection();
            fc.add(feature);
            featureStore.addFeatures(fc);
            transaction.commit();
        } catch (Exception eek) {
            try {
                transaction.rollback();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:27,代码来源:IFeatureShape.java

示例5: makeLineLayer

import org.geotools.data.Transaction; //导入依赖的package包/类
private void makeLineLayer( IEpanetType[] types, File baseFolder, CoordinateReferenceSystem mapCrs )
        throws MalformedURLException, IOException {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    String shapefileName = types[0].getShapefileName();
    String typeName = types[0].getName();
    b.setName(typeName);
    b.setCRS(mapCrs);
    b.add("the_geom", LineString.class);
    for( IEpanetType type : types ) {
        b.add(type.getAttributeName(), type.getClazz());
    }
    SimpleFeatureType tanksType = b.buildFeatureType();
    ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();
    File file = new File(baseFolder, shapefileName);
    Map<String, Serializable> create = new HashMap<String, Serializable>();
    create.put("url", file.toURI().toURL());
    ShapefileDataStore newDataStore = (ShapefileDataStore) factory.createNewDataStore(create);
    newDataStore.createSchema(tanksType);
    Transaction transaction = new DefaultTransaction();
    SimpleFeatureStore featureStore = (SimpleFeatureStore) newDataStore.getFeatureSource();
    featureStore.setTransaction(transaction);
    try {
        featureStore.addFeatures(new DefaultFeatureCollection());
        transaction.commit();
    } catch (Exception problem) {
        problem.printStackTrace();
        transaction.rollback();
    } finally {
        transaction.close();
    }
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:32,代码来源:OmsEpanetProjectFilesGenerator.java

示例6: writeShapefile

import org.geotools.data.Transaction; //导入依赖的package包/类
private void writeShapefile(MemoryDataStore memoryDataStore, File outputFile) throws Exception {

		SimpleFeatureSource featureSource = memoryDataStore.getFeatureSource(memoryDataStore.getTypeNames()[0]);
		SimpleFeatureType featureType = featureSource.getSchema();

		Map<String, java.io.Serializable> creationParams = new HashMap<String, java.io.Serializable>();
		creationParams.put("url", DataUtilities.fileToURL(outputFile));

		ShapefileDataStoreFactory factory = (ShapefileDataStoreFactory) FileDataStoreFinder.getDataStoreFactory("shp");
		ShapefileDataStore dataStore = (ShapefileDataStore) factory.createNewDataStore(creationParams);
		dataStore.setCharset(Charset.forName("UTF-8"));
		dataStore.createSchema(featureType);

		SimpleFeatureStore featureStore = (SimpleFeatureStore) dataStore.getFeatureSource(dataStore.getTypeNames()[0]);

		Transaction transaction = new DefaultTransaction();
		try {
			SimpleFeatureCollection collection = featureSource.getFeatures();
			featureStore.addFeatures(collection);
			transaction.commit();
		} catch (IOException e) {
			try {
				transaction.rollback();
				throw new Exception("Failed to commit data to feature store", e);
			} catch (IOException e2 ) {
				logger.error("Failed to commit data to feature store", e);
				throw new Exception("Transaction rollback failed", e2);
			}
		} finally {
			transaction.close();
		}
	}
 
开发者ID:dainst,项目名称:gazetteer,代码行数:33,代码来源:ShapefileCreator.java

示例7: example3

import org.geotools.data.Transaction; //导入依赖的package包/类
private static void example3() throws IOException {
    System.out.println("example3 start\n");
    // example3 start
    Map<String, Serializable> params = new HashMap<String, Serializable>();
    params.put("directory", directory);
    DataStore datastore = DataStoreFinder.getDataStore(params);

    Query query = new Query("example");
    FeatureReader<SimpleFeatureType, SimpleFeature> reader = datastore
            .getFeatureReader(query, Transaction.AUTO_COMMIT);
    try {
        int count = 0;
        while (reader.hasNext()) {
            SimpleFeature feature = reader.next();
            System.out.println("feature " + count + ": " + feature.getID());
            count++;
        }
        System.out.println("read in " + count + " features");
    } finally {
        reader.close();
    }
    // example3 end
    System.out.println("\nexample3 end\n");
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:25,代码来源:PropertyExamples.java

示例8: main

import org.geotools.data.Transaction; //导入依赖的package包/类
public static void main(String[] args) throws MalformedURLException,
		IOException, NoSuchAuthorityCodeException, FactoryException {
	if (args.length < 3) {
		System.err.println("Usage: ReprojectShapeFile in.shp out.shp epsg:code");
		System.exit(3);
	}
	File in = new File(args[0]);
	File out = new File(args[1]);
	CoordinateReferenceSystem crs = CRS.decode(args[2]);

	ShapefileDataStoreFactory fac = new ShapefileDataStoreFactory();
	FileDataStore inStore = fac.createDataStore(in.toURI().toURL());
	FileDataStore outStore = fac.createDataStore(out.toURI().toURL());

	SimpleFeatureCollection inFeatures = inStore.getFeatureSource()
			.getFeatures();

	ReprojectShapeFile reprojector = new ReprojectShapeFile();

	SimpleFeatureCollection outFeatures = reprojector
			.reproject(inFeatures, crs);
	outStore.createSchema(outFeatures.getSchema());
	Transaction transaction = new DefaultTransaction("create");
	String outName = outStore.getNames().get(0).getLocalPart();
	SimpleFeatureSource featureSource = outStore.getFeatureSource(outName);
	FeatureStore featureStore = (FeatureStore) featureSource;
	featureStore.setTransaction(transaction);
	featureStore.addFeatures(outFeatures);
	transaction.commit();
	outStore.dispose();
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:32,代码来源:ReprojectShapeFile.java

示例9: modify

import org.geotools.data.Transaction; //导入依赖的package包/类
/**
 * Record a modification to the indicated fid
 * 
 * @param fid
 * @param original
 *            the original feature(prior state)
 * @param updated
 *            the update feature replacement feature; null to indicate
 *            remove
 */
public void modify(
		String fid,
		SimpleFeature original,
		SimpleFeature updated )
		throws IOException {
	// point move?
	if (!updated.getBounds().equals(
			original.getBounds())) {
		this.components.remove(
				original,
				this);
		this.components.writeCommit(
				updated,
				new GeoWaveEmptyTransaction(
						components));
	}
	else {
		this.components.writeCommit(
				updated,
				new GeoWaveEmptyTransaction(
						components));
	}

	ReferencedEnvelope bounds = new ReferencedEnvelope();
	bounds.include(updated.getBounds());
	bounds.include(original.getBounds());
	this.components.getGTstore().getListenerManager().fireFeaturesChanged(
			updated.getFeatureType().getTypeName(),
			Transaction.AUTO_COMMIT,
			bounds,
			true);

}
 
开发者ID:locationtech,项目名称:geowave,代码行数:44,代码来源:GeoWaveEmptyTransaction.java

示例10: setTransaction

import org.geotools.data.Transaction; //导入依赖的package包/类
@Override
public synchronized void setTransaction(
		final Transaction transaction ) {
	if (transaction != null) {
		// configure
		this.transaction = transaction;
	}
	else {
		this.transaction = null;

		if (typeNameDiff != null) {
			for (final Iterator<GeoWaveTransactionManagement> i = typeNameDiff.values().iterator(); i.hasNext();) {
				final GeoWaveTransactionManagement diff = i.next();
				diff.clear();
			}

			typeNameDiff.clear();
		}
	}
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:21,代码来源:GeoWaveTransactionManagementState.java

示例11: GeoWaveTransactionManagement

import org.geotools.data.Transaction; //导入依赖的package包/类
/**
 * Create an empty Diff
 * 
 * @throws IOException
 */
public GeoWaveTransactionManagement(
		final int maxAdditionBufferSize,
		final GeoWaveDataStoreComponents components,
		final String typeName,
		final Transaction transaction,
		final LockingManagement lockingManager,
		final String txID )
		throws IOException {
	super(
			components);
	this.maxAdditionBufferSize = maxAdditionBufferSize;
	mutex = this;
	this.typeName = typeName;
	this.transaction = transaction;
	this.lockingManager = lockingManager;
	this.txID = txID;
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:23,代码来源:GeoWaveTransactionManagement.java

示例12: unlock

import org.geotools.data.Transaction; //导入依赖的package包/类
private void unlock(
		Transaction transaction,
		String featureID,
		Set<String> authorizations,
		long expiryInMinutes ) {
	AuthorizedLock lock = transaction == Transaction.AUTO_COMMIT ? null : (AuthorizedLock) transaction
			.getState(this);
	if (lock == null) {
		lock = new AuthorizedLock(
				this,
				authorizations,
				expiryInMinutes);
		if (transaction != Transaction.AUTO_COMMIT) transaction.putState(
				this,
				lock);
	}
	unlock(
			lock,
			featureID);
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:21,代码来源:AbstractLockingManagement.java

示例13: testFID

import org.geotools.data.Transaction; //导入依赖的package包/类
@Test
public void testFID()
		throws IllegalArgumentException,
		NoSuchElementException,
		IOException,
		CQLException {
	final FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(
			query,
			Transaction.AUTO_COMMIT);
	int count = 0;
	while (reader.hasNext()) {
		final SimpleFeature feature = reader.next();
		assertTrue(fids.contains(feature.getID()));
		count++;
	}
	assertTrue(count > 0);
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:18,代码来源:GeoWaveFeatureReaderTest.java

示例14: testRangeIndex

import org.geotools.data.Transaction; //导入依赖的package包/类
@Test
public void testRangeIndex()
		throws IllegalArgumentException,
		NoSuchElementException,
		IOException {
	final FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(
			query,
			Transaction.AUTO_COMMIT);
	int count = 0;
	while (reader.hasNext()) {
		final SimpleFeature feature = reader.next();
		assertTrue(fids.contains(feature.getID()));
		count++;
	}
	assertEquals(
			1,
			count);

}
 
开发者ID:locationtech,项目名称:geowave,代码行数:20,代码来源:GeoWaveFeatureReaderTest.java

示例15: testMax

import org.geotools.data.Transaction; //导入依赖的package包/类
@Test
public void testMax()
		throws IllegalArgumentException,
		NoSuchElementException,
		IOException {
	final FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(
			query,
			Transaction.AUTO_COMMIT);
	final MaxVisitor visitor = new MaxVisitor(
			"start",
			type);
	unwrapDelegatingFeatureReader(
			reader).getFeatureCollection().accepts(
			visitor,
			null);
	assertTrue(visitor.getMax().equals(
			etime));

}
 
开发者ID:locationtech,项目名称:geowave,代码行数:20,代码来源:GeoWaveFeatureReaderTest.java


注:本文中的org.geotools.data.Transaction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。