An Apache Cordova adapter for PawSQLite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

44 lines
1.1 KiB

package org.n0m.pawsqlite;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.cordova.CordovaInterface;
import java.io.File;
public class DBManager {
private static final String TAG = "PawSQLite";
private CordovaInterface cordova;
private ConcurrentHashMap<String, DBRunner> dbRunnerMap =
new ConcurrentHashMap<String, DBRunner>();
DBManager(CordovaInterface cordova) {
this.cordova = cordova;
}
public void queueRequest(String dbName, DBRequest request) {
DBRunner dbRunner = dbRunnerMap.get(dbName);
if (dbRunner == null) {
File dbFile = cordova.getActivity().getDatabasePath(dbName);
dbRunner = new DBRunner(dbFile, dbName);
this.cordova.getThreadPool().execute(dbRunner);
dbRunnerMap.put(dbName, dbRunner);
}
dbRunner.queueRequest(request);
// Remove dbRunner if it is being closed
if (request.action == DBAction.CLOSE ||
request.action == DBAction.DELETE) {
this.remove(dbName);
}
}
public void remove(String dbName) {
dbRunnerMap.remove(dbName);
}
}