22
33import javolution .util .FastMap ;
44import javolution .util .FastTable ;
5- import sqlite .SWIGTYPE_p_sqlite3 ;
6- import sqlite .SWIGTYPE_p_sqlite3_blob ;
7- import sqlite .SWIGTYPE_p_sqlite3_stmt ;
8- import sqlite ._SQLiteSwigged ;
95
106import java .io .File ;
117import java .io .IOException ;
1511import java .util .Map ;
1612import java .util .logging .Level ;
1713
14+ import static com .almworks .sqlite4java .SQLiteConstants .*;
15+
1816/**
1917 * SQLiteConnection is a single connection to sqlite database. Most methods are thread-confined,
2018 * and will throw errors if called from alien thread. Confinement thread is defined at the
@@ -178,13 +176,13 @@ public SQLiteConnection open() throws SQLiteException {
178176 * be true
179177 */
180178 public SQLiteConnection open (boolean allowCreate ) throws SQLiteException {
181- int flags = SQLiteConstants . Open .SQLITE_OPEN_READWRITE ;
179+ int flags = Open .SQLITE_OPEN_READWRITE ;
182180 if (!allowCreate ) {
183181 if (isMemoryDatabase ()) {
184- throw new SQLiteException (SQLiteConstants . Wrapper .WRAPPER_WEIRD , "cannot open memory database without creation" );
182+ throw new SQLiteException (Wrapper .WRAPPER_WEIRD , "cannot open memory database without creation" );
185183 }
186184 } else {
187- flags |= SQLiteConstants . Open .SQLITE_OPEN_CREATE ;
185+ flags |= Open .SQLITE_OPEN_CREATE ;
188186 }
189187 openX (flags );
190188 return this ;
@@ -195,9 +193,9 @@ public SQLiteConnection open(boolean allowCreate) throws SQLiteException {
195193 */
196194 public SQLiteConnection openReadonly () throws SQLiteException {
197195 if (isMemoryDatabase ()) {
198- throw new SQLiteException (SQLiteConstants . Wrapper .WRAPPER_WEIRD , "cannot open memory database in read-only mode" );
196+ throw new SQLiteException (Wrapper .WRAPPER_WEIRD , "cannot open memory database in read-only mode" );
199197 }
200- openX (SQLiteConstants . Open .SQLITE_OPEN_READONLY );
198+ openX (Open .SQLITE_OPEN_READONLY );
201199 return this ;
202200 }
203201
@@ -377,7 +375,7 @@ public SQLiteStatement prepare(SQLParts parts, boolean cached) throws SQLiteExce
377375 stmt = mySQLiteManual .sqlite3_prepare_v2 (handle , parts .toString ());
378376 throwResult (mySQLiteManual .getLastReturnCode (), "prepare()" , parts );
379377 if (stmt == null )
380- throw new SQLiteException (SQLiteConstants . Wrapper .WRAPPER_WEIRD , "sqlite did not return stmt" );
378+ throw new SQLiteException (Wrapper .WRAPPER_WEIRD , "sqlite did not return stmt" );
381379 } else {
382380 if (Internal .isFineLogging ())
383381 Internal .logFine (this , "using cached stmt for [" + parts + "]" );
@@ -403,7 +401,7 @@ public SQLiteStatement prepare(SQLParts parts, boolean cached) throws SQLiteExce
403401 } catch (Exception e ) {
404402 // ignore
405403 }
406- throw new SQLiteException (SQLiteConstants . Wrapper .WRAPPER_NOT_OPENED , "connection disposed" );
404+ throw new SQLiteException (Wrapper .WRAPPER_NOT_OPENED , "connection disposed" );
407405 }
408406 return statement ;
409407 }
@@ -420,7 +418,7 @@ public SQLiteBlob blob(String dbname, String table, String column, long rowid, b
420418 SWIGTYPE_p_sqlite3_blob blob = mySQLiteManual .sqlite3_blob_open (handle , dbname , table , column , rowid , writeAccess );
421419 throwResult (mySQLiteManual .getLastReturnCode (), "openBlob()" , null );
422420 if (blob == null )
423- throw new SQLiteException (SQLiteConstants . Wrapper .WRAPPER_WEIRD , "sqlite did not return blob" );
421+ throw new SQLiteException (Wrapper .WRAPPER_WEIRD , "sqlite did not return blob" );
424422 SQLiteBlob result = null ;
425423 synchronized (myLock ) {
426424 // the connection may close while openBlob in progress
@@ -439,7 +437,7 @@ public SQLiteBlob blob(String dbname, String table, String column, long rowid, b
439437 } catch (Exception e ) {
440438 // ignore
441439 }
442- throw new SQLiteException (SQLiteConstants . Wrapper .WRAPPER_NOT_OPENED , "connection disposed" );
440+ throw new SQLiteException (Wrapper .WRAPPER_NOT_OPENED , "connection disposed" );
443441 }
444442 return result ;
445443 }
@@ -596,14 +594,14 @@ private void finalizeBlob(SQLiteBlob blob) {
596594
597595 private void softFinalize (SWIGTYPE_p_sqlite3_stmt handle , Object source ) {
598596 int rc = _SQLiteSwigged .sqlite3_finalize (handle );
599- if (rc != SQLiteConstants . Result .SQLITE_OK ) {
597+ if (rc != Result .SQLITE_OK ) {
600598 Internal .logWarn (this , "error [" + rc + "] finishing " + source );
601599 }
602600 }
603601
604602 private void softClose (SWIGTYPE_p_sqlite3_blob handle , Object source ) {
605603 int rc = _SQLiteSwigged .sqlite3_blob_close (handle );
606- if (rc != SQLiteConstants . Result .SQLITE_OK ) {
604+ if (rc != Result .SQLITE_OK ) {
607605 Internal .logWarn (this , "error [" + rc + "] finishing " + source );
608606 }
609607 }
@@ -682,10 +680,10 @@ private void forgetBlob(SQLiteBlob blob) {
682680 private SWIGTYPE_p_sqlite3 handle () throws SQLiteException {
683681 synchronized (myLock ) {
684682 if (myDisposed )
685- throw new SQLiteException (SQLiteConstants . Wrapper .WRAPPER_MISUSE , "connection is disposed" );
683+ throw new SQLiteException (Wrapper .WRAPPER_MISUSE , "connection is disposed" );
686684 SWIGTYPE_p_sqlite3 handle = myHandle ;
687685 if (handle == null )
688- throw new SQLiteException (SQLiteConstants . Wrapper .WRAPPER_NOT_OPENED , null );
686+ throw new SQLiteException (Wrapper .WRAPPER_NOT_OPENED , null );
689687 return handle ;
690688 }
691689 }
@@ -712,9 +710,9 @@ void throwResult(int resultCode, String operation, Object additional) throws SQL
712710 Internal .log (Level .WARNING , this , "cannot get sqlite3_errmsg" , e );
713711 }
714712 }
715- if (resultCode == SQLiteConstants . Result .SQLITE_BUSY || resultCode == SQLiteConstants . Result .SQLITE_IOERR_BLOCKED ) {
713+ if (resultCode == Result .SQLITE_BUSY || resultCode == Result .SQLITE_IOERR_BLOCKED ) {
716714 throw new SQLiteBusyException (resultCode , message );
717- } else if (resultCode == SQLiteConstants . Result .SQLITE_INTERRUPT ) {
715+ } else if (resultCode == Result .SQLITE_INTERRUPT ) {
718716 throw new SQLiteCancelledException (resultCode , message );
719717 } else {
720718 throw new SQLiteException (resultCode , message );
@@ -729,7 +727,7 @@ private void openX(int flags) throws SQLiteException {
729727 SWIGTYPE_p_sqlite3 handle ;
730728 synchronized (myLock ) {
731729 if (myDisposed ) {
732- throw new SQLiteException (SQLiteConstants . Wrapper .WRAPPER_MISUSE , "cannot reopen closed connection" );
730+ throw new SQLiteException (Wrapper .WRAPPER_MISUSE , "cannot reopen closed connection" );
733731 }
734732 if (myConfinement == null ) {
735733 myConfinement = Thread .currentThread ();
@@ -749,7 +747,7 @@ private void openX(int flags) throws SQLiteException {
749747 Internal .logFine (this , "dbname [" + dbname + "]" );
750748 handle = mySQLiteManual .sqlite3_open_v2 (dbname , flags );
751749 int rc = mySQLiteManual .getLastReturnCode ();
752- if (rc != SQLiteConstants . Result .SQLITE_OK ) {
750+ if (rc != Result .SQLITE_OK ) {
753751 if (handle != null ) {
754752 if (Internal .isFineLogging ())
755753 Internal .logFine (this , "error on open (" + rc + "), closing handle" );
@@ -763,7 +761,7 @@ private void openX(int flags) throws SQLiteException {
763761 throw new SQLiteException (rc , errorMessage );
764762 }
765763 if (handle == null ) {
766- throw new SQLiteException (SQLiteConstants . Wrapper .WRAPPER_WEIRD , "sqlite didn't return db handle" );
764+ throw new SQLiteException (Wrapper .WRAPPER_WEIRD , "sqlite didn't return db handle" );
767765 }
768766 synchronized (myLock ) {
769767 myHandle = handle ;
@@ -774,7 +772,7 @@ private void openX(int flags) throws SQLiteException {
774772
775773 private void configureConnection (SWIGTYPE_p_sqlite3 handle ) {
776774 int rc = _SQLiteSwigged .sqlite3_extended_result_codes (handle , 1 );
777- if (rc != SQLiteConstants . Result .SQLITE_OK ) {
775+ if (rc != Result .SQLITE_OK ) {
778776 Internal .logWarn (this , "cannot enable extended result codes [" + rc + "]" );
779777 }
780778 }
@@ -796,7 +794,7 @@ void checkThread() throws SQLiteException {
796794 Thread thread = Thread .currentThread ();
797795 if (thread != confinement ) {
798796 String message = this + " confined(" + confinement + ") used(" + thread + ")" ;
799- throw new SQLiteException (SQLiteConstants . Wrapper .WRAPPER_CONFINEMENT_VIOLATED , message );
797+ throw new SQLiteException (Wrapper .WRAPPER_CONFINEMENT_VIOLATED , message );
800798 }
801799 }
802800
0 commit comments