Occasionally I see some strange exceptions as
> E/idPoiPersistenceManager: bind failed
> jsqlite.Exception: bind failed
> at jsqlite.Stmt.bind(Native Method)
> at org.mapsforge.poi.android.storage.AndroidPoiPersistenceManager.insertPointsOfInterest(AndroidPoiPersistenceManager.java:375)
> at org.openbmap.services.PoiService$AppendTask.doInBackground(PoiService.java:188)
and
> E/idPoiPersistenceManager: cannot start a transaction within a transaction
> jsqlite.Exception: cannot start a transaction within a transaction
> at jsqlite.Database._exec(Native Method)
> at jsqlite.Database.exec(Database.java:177)
> at org.mapsforge.poi.android.storage.AndroidPoiPersistenceManager.insertPointsOfInterest(AndroidPoiPersistenceManager.java:372)
> at org.openbmap.services.PoiService$AppendTask.doInBackground(PoiService.java:188)
I was wondering whether I'm doing something wrong conceptually and if there are some work-arounds to read and write to the database at the same time?
Any hints welcome,
Cheers
Toby
@Override
protected Collection<PointOfInterest> doInBackground(BoundingBox... params) {
PoiPersistenceManager persistenceManager = null;
try {
// open PersistanceManager in Write Mode
persistenceManager = AndroidPoiPersistenceManagerFactory.getPoiPersistenceManager(POI_FILE, false);
PoiCategoryManager categoryManager = persistenceManager.getCategoryManager();
PoiCategoryFilter categoryFilter = new ExactMatchPoiCategoryFilter();
categoryFilter.addCategory(categoryManager.getPoiCategoryByTitle(this.category));
// create POIs at runtime
PointOfInterest poi1 = new PointOfInterest(Math.abs(new Random().nextLong()),
params[0].minLatitude + (params[0].maxLatitude - params[0].minLatitude) * new Random().nextDouble(),
params[0].minLongitude + (params[0].maxLongitude - params[0].minLongitude) * new Random().nextDouble(),
"new poi", categoryManager.getPoiCategoryByTitle(this.category));
PointOfInterest poi2 = new PointOfInterest(Math.abs(new Random().nextLong()),
params[0].minLatitude + (params[0].maxLatitude - params[0].minLatitude) * new Random().nextDouble(),
params[0].minLongitude + (params[0].maxLongitude - params[0].minLongitude) * new Random().nextDouble(),
"new poi", categoryManager.getPoiCategoryByTitle(this.category));
PointOfInterest poi3 = new PointOfInterest(Math.abs(new Random().nextLong()),
params[0].minLatitude + (params[0].maxLatitude - params[0].minLatitude) * new Random().nextDouble(),
params[0].minLongitude + (params[0].maxLongitude - params[0].minLongitude) * new Random().nextDouble(),
"new poi", categoryManager.getPoiCategoryByTitle(this.category));
// WORKS
persistenceManager.insertPointOfInterest(poi1);
ArrayList<PointOfInterest> batch = new ArrayList<>();
batch.add(poi2);
batch.add(poi3);
// DOESN'T WORK: jsqlite.Exception: bind failed
persistenceManager.insertPointsOfInterest(batch);
return persistenceManager.findInRect(params[0], categoryFilter, null, Integer.MAX_VALUE);
} catch (Throwable t) {
Log.e(SamplesApplication.TAG, t.getMessage(), t);
} finally {
if (persistenceManager != null) {
persistenceManager.close();
}
}
return null;
}
In order to trace the issue down I started from scratch with a simple test.
Can somebody reproduce the exception when using insertPointsOfInterest? Or am I doing something obvious wrong here?