@Override public void execute(SqlJetDb database) throws SqlJetException { ISqlJetSchema schema = database.getSchema(); if (schema.getTable(STATE_TABLE) == null) { database.createTable(CREATE_STATE_SQL); } else if (Boolean.getBoolean(StateManager.CLEAR_LOCAL_STATE)) { database.getTable(STATE_TABLE).clear(); } } };
/** * @param file * @param write * @param fsName * @return SqlJetDb object for opened database * @throws SqlJetException */ public static SqlJetDb open(File file, boolean write, final String fsName) throws SqlJetException { final SqlJetDb db = new SqlJetDb(file, write, fsName); db.open(); return db; }
public void close() throws SqlJetException { db.close(); }
private void createStructure(SqlJetDb db) throws SqlJetException { db.beginTransaction(SqlJetTransactionMode.WRITE); try { db.createTable("CREATE TABLE states (full_name TEXT NOT NULL PRIMARY KEY, version TEXT NULL)"); db.createIndex("CREATE INDEX full_name_index ON states(full_name)"); } finally { db.commit(); } }
@Override public void insert(State state) { try { db.beginTransaction(SqlJetTransactionMode.WRITE); try { ISqlJetTable table = db.getTable(StateTable.TABLE_NAME); table.insert(getData(state)); } finally { db.commit(); } } catch (Throwable e) { logger.error("unable to insert: " + state, e); } }
case TABLE: if (stmt.isDrop()) { if (db.getSchema().getTableNames().contains(stmt.getName())) { db.dropTable(stmt.getSql()); if (db.getSchema().getTableNames().contains(stmt.getName())) { db.dropTable(stmt.getName()); db.createTable(stmt.getSql()); if (db.getSchema().getIndexNames().contains(stmt.getName())) { db.dropIndex(stmt.getSql()); if (db.getSchema().getIndexNames().contains(stmt.getName())) { db.dropIndex(stmt.getName()); db.createIndex(stmt.getSql()); db.createIndex(stmt.getSql()); case VIEW: if (stmt.isDrop()) { if (db.getSchema().getViewNames().contains(stmt.getName())) { db.dropView(stmt.getSql()); if (db.getSchema().getViewNames().contains(stmt.getName())) { db.dropView(stmt.getName()); db.createView(stmt.getSql());
public SVNFSFSRevPropSet(SVNSqlJetDb sDb) throws SqlJetException { super(sDb); table = sDb.getDb().getTable(FSFS.REVISION_PROPERTIES_TABLE); }
public static void createRepresentationCache(File path) throws SVNException { SqlJetDb db = null; try { db = SqlJetDb.open(path, true); checkFormat(db); } catch (SqlJetException e) { SVNErrorManager.error(FSRepresentationCacheManager.convertError(e), SVNLogType.FSFS); } finally { if (db != null) { try { db.close(); } catch (SqlJetException e) { SVNDebugLog.getDefaultLog().logFine(SVNLogType.FSFS, e); } } } }
public Object run(SqlJetDb db) throws SqlJetException { db.createTable("create table revprop (revision integer UNIQUE not null, " + "properties BLOB not null);"); db.createIndex("create index i_revision on revprop (revision);"); db.getOptions().setUserVersion(1); return null; } });
public Object runWithLock(SqlJetDb db) throws SqlJetException { int version = db.getOptions().getUserVersion(); if (version < REP_CACHE_DB_FORMAT) { db.getOptions().setAutovacuum(true); db.runWriteTransaction(new ISqlJetTransaction() { public Object run(SqlJetDb db) throws SqlJetException { db.getOptions().setUserVersion(REP_CACHE_DB_FORMAT); db.createTable(FSRepresentationCacheManager.REP_CACHE_DB_SQL); return null; } }); } else if (version > REP_CACHE_DB_FORMAT) { throw new SqlJetException("Schema format " + version + " not recognized"); } return null; } });
public static FSRepresentationCacheManager openRepresentationCache(FSFS fsfs) throws SVNException { final FSRepresentationCacheManager cacheObj = new FSRepresentationCacheManager(); try { cacheObj.myRepCacheDB = SqlJetDb.open(fsfs.getRepositoryCacheFile(), true); checkFormat(cacheObj.myRepCacheDB); cacheObj.myTable = cacheObj.myRepCacheDB.getTable(REP_CACHE_TABLE); } catch (SqlJetException e) { SVNErrorManager.error(convertError(e), SVNLogType.FSFS); } return cacheObj; }
/** * Creates trigger from SQL clause. * * @param sql * CREATE TRIGGER ... sentence. * @return definition of the trigger being created. */ public ISqlJetTriggerDef createTrigger(final String sql) throws SqlJetException { checkOpen(); return (ISqlJetTriggerDef) runWriteTransaction(new ISqlJetTransaction() { public Object run(SqlJetDb db) throws SqlJetException { return getSchemaInternal().createTrigger(sql); } }); }
public static IFSRepresentationCacheManager openRepresentationCache(FSFS fsfs) throws SVNException { final FSRepresentationCacheManager cacheObj = new FSRepresentationCacheManager(); try { cacheObj.myRepCacheDB = SqlJetDb.open(fsfs.getRepositoryCacheFile(), true); cacheObj.myRepCacheDB.setSafetyLevel(SqlJetSafetyLevel.OFF); checkFormat(cacheObj.myRepCacheDB); cacheObj.myTable = cacheObj.myRepCacheDB.getTable(REP_CACHE_TABLE); } catch (SqlJetException e) { SVNDebugLog.getDefaultLog().logError(SVNLogType.FSFS, e); return new FSEmptyRepresentationCacheManager(); } return cacheObj; }
sDb.getDb().createTable("CREATE TABLE EXTERNALS ( " + " wc_id INTEGER NOT NULL REFERENCES WCROOT (id), " + " local_relpath TEXT NOT NULL, " + " PRIMARY KEY (wc_id, local_relpath) " + "); "); sDb.getDb().createIndex("CREATE INDEX I_EXTERNALS_PARENT ON EXTERNALS (wc_id, parent_relpath);"); sDb.getDb().createIndex("CREATE UNIQUE INDEX I_EXTERNALS_DEFINED ON EXTERNALS (wc_id, def_local_relpath, local_relpath);"); } catch (SqlJetException e) { SVNSqlJetDb.createSqlJetError(e); if (sDb.getDb().getSchema().getTriggerNames().contains("nodes_update_checksum_trigger")) { sDb.getDb().dropTrigger("nodes_update_checksum_trigger"); if (sDb.getDb().getSchema().getTriggerNames().contains("nodes_insert_trigger")) { sDb.getDb().dropTrigger("nodes_insert_trigger"); if (sDb.getDb().getSchema().getTriggerNames().contains("nodes_delete_trigger")) { sDb.getDb().dropTrigger("nodes_delete_trigger"); sDb.getDb().createTrigger("CREATE TRIGGER nodes_update_checksum_trigger AFTER UPDATE OF checksum ON nodes WHEN NEW.checksum IS NOT OLD.checksum BEGIN UPDATE pristine SET refcount = refcount + 1 WHERE checksum = NEW.checksum; UPDATE pristine SET refcount = refcount - 1 WHERE checksum = OLD.checksum; END;"); sDb.getDb().createTrigger("CREATE TRIGGER nodes_insert_trigger AFTER INSERT ON nodes WHEN NEW.checksum IS NOT NULL BEGIN UPDATE pristine SET refcount = refcount + 1 WHERE checksum = NEW.checksum; END;"); sDb.getDb().createTrigger("CREATE TRIGGER nodes_delete_trigger AFTER DELETE ON nodes WHEN OLD.checksum IS NOT NULL BEGIN UPDATE pristine SET refcount = refcount - 1 WHERE checksum = OLD.checksum; END;"); } catch (SqlJetException e) { SVNSqlJetDb.createSqlJetError(e);
public void statementCompleted(SqlJetDb db, SqlJetException error) throws SqlJetException { if (error == null) { this.db.getDb().getTemporaryDatabase().commit(); } else { this.db.getDb().getTemporaryDatabase().rollback(); } }
@Override public void execute(SqlJetDb database) throws SqlJetException { ISqlJetSchema schema = database.getSchema(); if (schema.getTable(INVOCATION_TABLE) == null) { database.createTable(CREATE_INVOCATION_SQL); } if (schema.getTable(INVOKER_TABLE) == null) { database.createTable(CREATE_INVOKER_SQL); database.createIndex(CREATE_INVOKER_INDEX); } } };
public void bumpTo(SVNWCDb db, SVNSqlJetDb sDb, File wcRootAbsPath) throws SVNException { try { if (sDb.getDb().getSchema().getTable("NODES").getColumn("inherited_props") == null) { sDb.getDb().createIndex("CREATE UNIQUE INDEX IF NOT EXISTS I_NODES_MOVED ON NODES (wc_id, moved_to, op_depth);"); sDb.getDb().createIndex("CREATE INDEX IF NOT EXISTS I_PRISTINE_MD5 ON PRISTINE (md5_checksum);"); final ISqlJetCursor actulaNode = sDb.getDb().getTable("ACTUAL_NODE").open(); while(!actulaNode.eof()) { final String conflictOld = actulaNode.getString(ACTUAL_NODE__Fields.conflict_old.toString());
/** * {@inheritDoc} * @see net.sf.hajdbc.pool.PoolProvider#create() */ @Override public synchronized SqlJetDb create() throws SqlJetException { boolean exists = this.file.exists(); SqlJetDb db = SqlJetDb.open(this.file, true); if (!exists) { db.getOptions().setAutovacuum(true); db.getOptions().setIncrementalVacuum(true); } return db; }
public ISqlJetCursor open() throws SqlJetException { return (ISqlJetCursor) db.runWithLock(new ISqlJetRunnableWithLock() { public Object runWithLock(SqlJetDb db) throws SqlJetException { return new SqlJetTableDataCursor(new SqlJetBtreeDataTable(btree, tableName, write), db); } }); }