/** * The finalize() method is used to warn about a non-closed connection being forgotten. */ protected void finalize() throws Throwable { super.finalize(); SWIGTYPE_p_sqlite3 handle = myHandle; boolean disposed = myDisposed; if (handle != null || !disposed) { Internal.recoverableError(this, "wasn't disposed before finalizing", true); } }
private void forgetStatement(SQLiteStatement statement) { assert Thread.holdsLock(myLock); boolean removed = myStatements.remove(statement); if (!removed) { Internal.recoverableError(statement, "alien statement", true); } }
private void forgetBlob(SQLiteBlob blob) { assert Thread.holdsLock(myLock); boolean removed = myBlobs.remove(blob); if (!removed) { Internal.recoverableError(blob, "alien blob", true); } }
private static String getClassUrl() { Class c = Internal.class; String name = c.getName().replace('.', '/') + ".class"; URL url = c.getClassLoader().getResource(name); if (url == null) return null; String classUrl = url.toString(); try { return URLDecoder.decode(classUrl, "UTF-8"); } catch (UnsupportedEncodingException e) { recoverableError(Internal.class, e.getMessage(), true); return classUrl; } }
protected boolean checkDispose(Object object) { try { SQLiteConnection.this.checkThread(); } catch (SQLiteException e) { Internal.recoverableError(this, "disposing " + object + " from alien thread", true); return false; } return true; }
private void finalizeBlobs() { boolean alienThread = myConfinement != Thread.currentThread(); if (!alienThread) { Internal.logFine(this, "finalizing blobs"); while (true) { SQLiteBlob[] blobs = null; synchronized (myLock) { if (myBlobs.isEmpty()) break; blobs = myBlobs.toArray(new SQLiteBlob[myBlobs.size()]); } for (SQLiteBlob blob : blobs) { finalizeBlob(blob); } } } synchronized (myLock) { if (!myBlobs.isEmpty()) { int count = myBlobs.size(); if (alienThread) { Internal.logWarn(this, "cannot finalize " + count + " blobs from alien thread"); } else { Internal.recoverableError(this, count + " blobs are not finalized", false); } } myBlobs.clear(); } }
private void freeBuffer(DirectBuffer buffer) throws SQLiteException { checkThread(); boolean cached; synchronized (myLock) { cached = myBuffers.indexOf(buffer) >= 0; } buffer.decUsed(); if (!cached) { int rc = _SQLiteManual.wrapper_free(buffer); if (rc != 0) { Internal.recoverableError(this, "error deallocating buffer", true); } } }
Internal.logWarn(this, "cannot finalize " + count + " statements from alien thread"); } else { Internal.recoverableError(this, count + " statements are not finalized", false);
private int getColumnCount(SWIGTYPE_p_sqlite3_stmt handle) { int cc = myColumnCount; if (cc < 0) { // data_count seems more safe than column_count Internal.logFine(this, "asking column count"); myColumnCount = cc = _SQLiteSwigged.sqlite3_column_count(handle); if (cc < 0) { Internal.recoverableError(this, "columnsCount=" + cc, true); cc = 0; } else if (Internal.isFineLogging()) { Internal.logFine(this, "columnCount=" + cc); } } return cc; }
/** * Disposes this blob and frees allocated resources. * <p> * After blob is disposed, it is no longer usable and holds no references to connection * or sqlite db. */ public void dispose() { if (myHandle == null) return; try { myController.validate(); } catch (SQLiteException e) { Internal.recoverableError(this, "invalid dispose: " + e, true); return; } Internal.logFine(this, "disposing"); myController.dispose(this); // clear may be called from dispose() too clear(); }
/** * Disposes this statement and frees allocated resources. If the statement's handle is cached, * it is returned to the connection's cache and can be reused by later calls to <code>prepare</code> * <p/> * Calling this method on an already disposed instance has no effect. * <p/> * After SQLiteStatement instance is disposed, it is no longer usable and holds no references to its originating * connection or SQLite database. */ public void dispose() { if (myHandle == null) return; try { myController.validate(); } catch (SQLiteException e) { Internal.recoverableError(this, "invalid dispose: " + e, true); return; } Internal.logFine(this, "disposing"); myController.dispose(this); // clear may be called from dispose() too clear(); }
/** * Disposes this instance, making it unusable and freeing the resources. If the array table is cached, * then it is unbound from values (emptied) and returned to the cache. If the array table is not cached, * it is deleted from the database. * <p/> * This method is partially thread-safe. When called not from the confining thread, the exception will not be * thrown, but the method will do nothing. * <p/> * Calling <code>dispose()</code> second time has no effect. * <p/> * Calling {@link #bind} after instance has been disposed would result in exception. */ public void dispose() { if (myHandle == null) return; SQLiteController controller = myController; try { controller.validate(); } catch (SQLiteException e) { Internal.recoverableError(this, "invalid dispose: " + e, true); return; } Internal.logFine(this, "disposing"); controller.dispose(this); myHandle = null; myController = SQLiteController.getDisposed(myController); myDisposed = true; }
private void finalizeArrays() { boolean alienThread = myConfinement != Thread.currentThread(); if (!alienThread) { Internal.logFine(this, "finalizing arrays"); FastMap<String, SWIGTYPE_p_intarray> fastMap; while (true) { synchronized (myLock) { if (myLongArrays.isEmpty()) break; fastMap = new FastMap<String, SWIGTYPE_p_intarray>(myLongArrays); myLongArrays.clear(); } for (Map.Entry<String, SWIGTYPE_p_intarray> entry : fastMap.entrySet()) { finalizeArrayHandle(entry.getValue(), entry.getKey()); } } } synchronized (myLock) { if (!myLongArrays.isEmpty()) { int count = myLongArrays.size(); if (alienThread) { Internal.logWarn(this, "cannot finalize " + count + " arrays from alien thread"); } else { Internal.recoverableError(this, count + " arrays are not finalized", false); } myLongArrays.clear(); } } }
/** * Dispose this backup instance and, if <code>disposeDestination</code> is true, dispose the connection to * the destination database as well. * <p/> * You might want to pass <code>false</code> to this method to subsequently call {@link #getDestinationConnection()} * and perform any actions on the fresh backup of the database, then dispose it yourself. * * @param disposeDestination if true, connection to the destination database will be disposed */ public void dispose(boolean disposeDestination) { try { mySourceController.validate(); myDestinationController.validate(); } catch (SQLiteException e) { Internal.recoverableError(this, "invalid dispose: " + e, true); return; } Internal.logFine(this, "disposing"); SWIGTYPE_p_sqlite3_backup handle = myHandle; if (handle != null) { _SQLiteSwigged.sqlite3_backup_finish(handle); myHandle = null; mySourceController = SQLiteController.getDisposed(mySourceController); myDestinationController = SQLiteController.getDisposed(myDestinationController); } if (disposeDestination) { myDestination.dispose(); } }
return columnBlob(column); default: Internal.recoverableError(this, "value type " + valueType + " not yet supported", true); return null;
Thread confinement = myConfinement; if (confinement != null && confinement != Thread.currentThread()) { Internal.recoverableError(this, "will not dispose from a non-confining thread", true); return;
Internal.recoverableError(this, "already opened", true); return;
if (expunged != null) { if (expunged == handle) { Internal.recoverableError(statement, "handle appeared in cache when inserted", true); } else {