Jody,
Is there a JUnit test or example written for testing
FeatureLock.TRANSACTION? There seems to be a problem when using
FeatureLock.TRANSACTION to lock and modify features. There is always a
java.lang.IllegalMonitorStateException exception being thrown out when the
release() is called on instance of TransactionLock. The change has actually
been committed to the database already before the exception.
I'm kind of stuck here, and I don't think there is any JUnit tests or sample
written using FeatureLock.TRANSACTION. Will source code of GeoServer shed
any light on this?
The code below will reproduce the issue:
for(int i=0; i<4; i++) {
// spread a new thread
final String id = String.valueOf(i);
threadPool.execute(
new Runnable() {
public void run() {
try {
String targetFeatureTypeName =
"sf_pizzastores_wgs84";
JDBCFeatureStore jdbcFeatureStore =
(JDBCFeatureStore)jdbcDataStore.getFeatureSource(targetFeatureTypeName);
Transaction transaction = new
DefaultTransaction();
FeatureLock featureLock =
FeatureLock.TRANSACTION;
String lockId = featureLock.getAuthorization();
jdbcFeatureStore.setTransaction(transaction);
jdbcFeatureStore.setFeatureLock(featureLock);
transaction.addAuthorization(lockId);
FeatureWriter<SimpleFeatureType, SimpleFeature>
featureWriter = jdbcDataStore.getFeatureWriter(targetFeatureTypeName,
transaction);
jdbcFeatureStore.lockFeatures();
while(featureWriter.hasNext()) {
SimpleFeature simpleFeature =
featureWriter.next();
String store_id =
(String)simpleFeature.getAttribute("store_id");
simpleFeature.setAttribute("name", "ps"+ id
+ "." + store_id);
transaction.addAuthorization(lockId);
featureWriter.write();
}
try {
transaction.addAuthorization(lockId);
transaction.commit();
} catch(Exception e) {
transaction.rollback();
e.printStackTrace();
} finally {
transaction.addAuthorization(lockId);
jdbcFeatureStore.unLockFeatures();
featureWriter.close();
transaction.close();
}
} catch(Exception e) {
e.printStackTrace();
} finally {
}
}
}
);
}
threadPool.shutdown();
--
View this message in context:
http://osgeo-org.1803224.n2.nabble.com/How-to-use-FeatureLock-TRANSACTION-when-modifying-features-and-committing-changes-tp5491953p5508478.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:
Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users