FileDocCategorySizeDatePackage
JDBCConnection.javaAPI DocAndroid 1.5 API11140Wed May 06 22:41:06 BST 2009SQLite.JDBC2y

JDBCConnection

public class JDBCConnection extends Object implements Connection, SQLite.BusyHandler

Fields Summary
protected DatabaseX
db
Open database.
protected String
url
Database URL.
protected String
enc
Character encoding.
protected boolean
autocommit
Autocommit flag, true means autocommit.
protected boolean
intrans
In-transaction flag. Can be true only when autocommit false.
protected int
timeout
Timeout for Database.exec()
private String
dbfile
File name of database.
private JDBCDatabaseMetaData
meta
Reference to meta data or null.
private long
t0
Base time value for timeout handling.
private boolean
readonly
Database in readonly mode.
Constructors Summary
public JDBCConnection(String url, String enc)

    if (url.startsWith("sqlite:/")) {
        dbfile = url.substring(8);
    } else if (url.startsWith("jdbc:sqlite:/")) {
        dbfile = url.substring(13);
    } else {
        throw new SQLException("unsupported url");
    }
    this.url = url;
    this.enc = enc;
    try {
        db = open(readonly);
        db.busy_handler(this);
    } catch (SQLException e) {
        if (db != null) {
        try {
            db.close();
        } catch (SQLite.Exception ee) {
        }
        }
        throw e;
    }
    
Methods Summary
public booleanbusy(java.lang.String table, int count)

    return busy0(db, count);
    
private booleanbusy0(SQLite.JDBC2y.DatabaseX db, int count)



          
    if (count <= 1) {
        t0 = System.currentTimeMillis();
    }
    if (db != null) {
        long t1 = System.currentTimeMillis();
        if (t1 - t0 > timeout) {
        return false;
        }
        db.wait(100);
        return true;
    }
    return false;
    
protected booleanbusy3(SQLite.JDBC2y.DatabaseX db, int count)

    if (count <= 1) {
        t0 = System.currentTimeMillis();
    }
    if (db != null) {
        long t1 = System.currentTimeMillis();
        if (t1 - t0 > timeout) {
        return false;
        }
        return true;
    }
    return false;
    
public voidclearWarnings()

    
public voidclose()

    try {
        rollback();
    } catch (SQLException e) {
        /* ignored */
    }
    intrans = false;
    if (db != null) {
        try {
        db.close();
        db = null;
        } catch (SQLite.Exception e) {
        throw new SQLException(e.toString());
        }
    }
    
public voidcommit()

    if (db == null) {
        throw new SQLException("stale connection");
    }
    if (!intrans) {
        return;
    }
    try {
        db.exec("COMMIT", null);
        intrans = false;
    } catch (SQLite.Exception e) {
        throw new SQLException(e.toString());
    }
    
public java.sql.StatementcreateStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)

    if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT) {
        throw new SQLException("not supported");
    }
    return createStatement(resultSetType, resultSetConcurrency);
    
public java.sql.StatementcreateStatement()

    JDBCStatement s = new JDBCStatement(this);
    return s;
    
public java.sql.StatementcreateStatement(int resultSetType, int resultSetConcurrency)

    JDBCStatement s = new JDBCStatement(this);
    return s;
    
public booleangetAutoCommit()

    return autocommit;
    
public java.lang.StringgetCatalog()

    return null;
    
public intgetHoldability()

    return ResultSet.HOLD_CURSORS_OVER_COMMIT;
    
public java.sql.DatabaseMetaDatagetMetaData()

    if (meta == null) {
        meta = new JDBCDatabaseMetaData(this);
    }
    return meta;
    
public SQLite.DatabasegetSQLiteDatabase()

    return (SQLite.Database) db;
    
public intgetTransactionIsolation()

    return TRANSACTION_SERIALIZABLE;
    
public java.util.MapgetTypeMap()

    throw new SQLException("not supported");
    
public java.sql.SQLWarninggetWarnings()

    return null;
    
public booleanisClosed()

    return db == null;
    
public booleanisReadOnly()

    return readonly;
    
public java.lang.StringnativeSQL(java.lang.String sql)

    throw new SQLException("not supported");
    
private SQLite.JDBC2y.DatabaseXopen(boolean readonly)

    DatabaseX db = null;
    try {
        db = new DatabaseX();
        db.open(dbfile, readonly ? 0444 : 0644);
        db.set_encoding(enc);
    } catch (SQLite.Exception e) {
        throw new SQLException(e.toString());
    }
    int loop = 0;
    while (true) {
        try {
        db.exec("PRAGMA short_column_names = off;", null);
        db.exec("PRAGMA full_column_names = on;", null);
        db.exec("PRAGMA empty_result_callbacks = on;", null);
        if (SQLite.Database.version().compareTo("2.6.0") >= 0) {
            db.exec("PRAGMA show_datatypes = on;", null);
        }
        } catch (SQLite.Exception e) {
        if (db.last_error() != SQLite.Constants.SQLITE_BUSY ||
            !busy0(db, ++loop)) {
            try {
            db.close();
            } catch (SQLite.Exception ee) {
            }
            throw new SQLException(e.toString());
        }
        continue;
        }
        break;
    }
    return db;
    
public java.sql.CallableStatementprepareCall(java.lang.String sql)

    throw new SQLException("not supported");
    
public java.sql.CallableStatementprepareCall(java.lang.String sql, int x, int y)

    throw new SQLException("not supported");
    
public java.sql.CallableStatementprepareCall(java.lang.String sql, int x, int y, int z)

    throw new SQLException("not supported");
    
public java.sql.PreparedStatementprepareStatement(java.lang.String sql)

    JDBCPreparedStatement s = new JDBCPreparedStatement(this, sql);
    return s;
    
public java.sql.PreparedStatementprepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)

    JDBCPreparedStatement s = new JDBCPreparedStatement(this, sql);
    return s;
    
public java.sql.PreparedStatementprepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)

    if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT) {
        throw new SQLException("not supported");
    }
    return prepareStatement(sql, resultSetType, resultSetConcurrency);
    
public java.sql.PreparedStatementprepareStatement(java.lang.String sql, int autokeys)

    if (autokeys != Statement.NO_GENERATED_KEYS) {
        throw new SQLException("not supported");
    }
    return prepareStatement(sql);
    
public java.sql.PreparedStatementprepareStatement(java.lang.String sql, int[] colIndexes)

    throw new SQLException("not supported");
    
public java.sql.PreparedStatementprepareStatement(java.lang.String sql, java.lang.String[] columns)

    throw new SQLException("not supported");
    
public voidreleaseSavepoint(java.sql.Savepoint x)

    throw new SQLException("not supported");
    
public voidrollback()

    if (db == null) {
        throw new SQLException("stale connection");
    }
    if (!intrans) {
        return;
    }
    try {
        db.exec("ROLLBACK", null);
        intrans = false;
    } catch (SQLite.Exception e) {
        throw new SQLException(e.toString());
    }
    
public voidrollback(java.sql.Savepoint x)

    throw new SQLException("not supported");
    
public voidsetAutoCommit(boolean ac)

    if (ac && intrans && db != null) {
        try {
        db.exec("ROLLBACK", null);
        } catch (SQLite.Exception e) {
        throw new SQLException(e.toString());
        }
    }
    intrans = false;
    autocommit = ac;
    
public voidsetCatalog(java.lang.String catalog)

    
public voidsetHoldability(int holdability)

    if (holdability == ResultSet.HOLD_CURSORS_OVER_COMMIT) {
        return;
    }
    throw new SQLException("not supported");
    
public voidsetReadOnly(boolean ro)

    if (intrans) {
        throw new SQLException("incomplete transaction");
    }
    if (ro != readonly) {
        DatabaseX db = null;
        try {
        db = open(ro);
        this.db.close();
        this.db = db;
        db = null;
        readonly = ro;
        } catch (SQLException e) {
        throw e;
        } catch (SQLite.Exception ee) {
        if (db != null) {
            try {
            db.close();
            } catch (SQLite.Exception eee) {
            }
        }
        throw new SQLException(ee.toString());
        }
    }
    
public java.sql.SavepointsetSavepoint()

    throw new SQLException("not supported");
    
public java.sql.SavepointsetSavepoint(java.lang.String name)

    throw new SQLException("not supported");
    
public voidsetTransactionIsolation(int level)

    if (level != TRANSACTION_SERIALIZABLE) {
        throw new SQLException("not supported");
    }
    
public voidsetTypeMap(java.util.Map map)

    throw new SQLException("not supported");