/** * Abort current transaction and rollback operations. * * @param fireEvent */ public void abort(boolean fireEvent) { if (!aborted && active) { if (transaction != null) { transaction.executeSQL( "invalid sql statement", null, null, new SQLTransaction.SQLStatementErrorCallback() { @Override public boolean onError(SQLTransaction tx, SQLError error) { return true; // tell web sql to rollback transaction } }); transaction = null; } aborted = true; active = false; requestProcessor.stop(); if (fireEvent) { if (LogConfiguration.loggingIsEnabled()) { logger.log(Level.INFO, db.messages.databaseTransactionAborted(db.getName())); } if (transactionCallback != null) { try { transactionCallback.onAbort(); } catch (Exception e) { String message = db.messages.databaseTransactionError(db.getName(), e.getMessage()); reportError(transactionCallback, message, e); } } } } }
public void addRequest(RequestOperation operation, Mode[] supportedMode) { if (!active || aborted) { onError(db.messages.databaseTransactionInactive(db.getName())); return; } boolean supported = checkSupportedModes(supportedMode); if (!supported) { onError(db.messages.databaseTransactionNotSupportedOperation(db.getName())); return; } requestProcessor.addRequest(operation).executeRequests(); }
public void onSuccess() { if (LogConfiguration.loggingIsEnabled()) { logger.log(Level.INFO, db.messages.databaseTransactionCompleted(db.getName())); } active = false; requestProcessor.stop(); if (transactionCallback != null) { try { transactionCallback.onComplete(); } catch (Exception e) { String message = db.messages.databaseTransactionError(db.getName(), e.getMessage()); reportError(transactionCallback, message, e); } } }
/** * Retrieve an ObjectStore manipulated by the current transaction. * * @param <K> * @param <V> * @param storeName * @return */ @Override public <K, V> ObjectStore<K, V> getObjectStore(String storeName) { if (!containsObjectStore(storeName)) { onError(db.messages.databaseTransactionStoreNotFound(storeName)); return null; } WSQLAbstractObjectStore<K, V> objectStore = db.getObjectStore(storeName, this); return objectStore; }
public void onError(String errorMessage) { String message = db.messages.databaseTransactionError(db.getName(), errorMessage); active = false; requestProcessor.stop(); if (LogConfiguration.loggingIsEnabled()) { logger.log(Level.SEVERE, message); } if (transactionCallback != null) { transactionCallback.onError(message); } }
protected WSQLTransaction(final WSQLAbstractDatabase db, String[] storeNames, Mode mode) { super(db, storeNames, mode); this.db = db; this.active = true; this.aborted = false; this.transaction = null; this.requestProcessor = new RequestProcessor(this); if (db == null || !db.isOpen()) { throw new DatabaseException(db.messages.databaseNotOpenedError()); } if (mode != null && Mode.readOnly.equals(getMode())) { db.database.readTransaction(this, this, this); } else { db.database.transaction(this, this, this); } }