/** * 构造函数 */ public WebGraph(String dbDir) throws DatabaseException { File envDir = new File(dbDir); EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setTransactional(false); envConfig.setAllowCreate(true); Environment env = new Environment(envDir, envConfig); StoreConfig storeConfig = new StoreConfig(); storeConfig.setAllowCreate(true); storeConfig.setTransactional(false); store = new EntityStore(env, "classDb", storeConfig); outLinkIndex = store.getPrimaryIndex(String.class, Link.class); inLinkIndex = store.getSecondaryIndex(outLinkIndex, String.class, "toURL"); }
public void close () throws DatabaseException { gcSem.acquireUninterruptibly(); gcTask.cancel(false); while (!gcTask.isDone()) { try { Thread.sleep(500L); } catch (InterruptedException ignored) { } } store.close (); dbe.close(); }
public void close() throws Exception { if (!diskQuotaEnabled) { return; } open = false; log.info("Requesting to close quota store..."); transactionRunner.shutdown(); try { transactionRunner.awaitTermination(30 * 1000, TimeUnit.MILLISECONDS); } catch (InterruptedException ie) { log.error( "Time out shutting down quota store write thread, trying to " + "close the entity store as is.", ie); Thread.currentThread().interrupt(); } finally { Environment environment = entityStore.getEnvironment(); entityStore.close(); environment.close(); } log.info("Quota store closed."); }
private void configure(final File storeDirectory) throws InterruptedException { // todo: make config persistent? or just rely on je.properties (I guess so) PageStoreConfig config = new PageStoreConfig(); EntityStoreBuilder builder = new EntityStoreBuilder(config); EntityStore entityStore = builder.buildEntityStore(storeDirectory, null); this.entityStore = entityStore; tileSetById = entityStore.getPrimaryIndex(String.class, TileSet.class); pageById = entityStore.getPrimaryIndex(Long.class, TilePage.class); pageStatsById = entityStore.getPrimaryIndex(Long.class, PageStats.class); usedQuotaById = entityStore.getPrimaryIndex(Integer.class, Quota.class); pageByKey = entityStore.getSecondaryIndex(pageById, String.class, "page_key"); pagesByTileSetId = entityStore.getSecondaryIndex(pageById, String.class, "tileset_id_fk"); tileSetsByLayer = entityStore.getSecondaryIndex(tileSetById, String.class, "layer"); pageStatsByLRU = entityStore.getSecondaryIndex(pageStatsById, Float.class, "LRU"); pageStatsByLFU = entityStore.getSecondaryIndex(pageStatsById, Float.class, "LFU"); usedQuotaByTileSetId = entityStore.getSecondaryIndex(usedQuotaById, String.class, "tileset_id"); pageStatsByPageId = entityStore.getSecondaryIndex(pageStatsById, Long.class, "page_stats_by_page_id"); }
store = new EntityStore(myEnv, "ScientificSpeciesNameEntityStore", storeConfig); index = store.getPrimaryIndex(Integer.class, Entry.class);
/** * Returns a {@link MetaDataEntity} object with the metadata of the vector with the given internal id or * null if the internal id does not exist. Accesses the BDB store! * * @param iid * The internal id of the vector * @return The metadata mapped to the given internal id or null if the internal id does not exist */ public MetaDataEntity getMetadata(int iid) throws Exception { if (iid < 0 || iid > loadCounter) { System.out.println("Internal id " + iid + " is out of range!"); return null; } PrimaryIndex<Integer, MetaDataEntity> primaryIndex = iidToMetadataDB.getPrimaryIndex(Integer.class, MetaDataEntity.class); return primaryIndex.get(null, iid, null); }
entryById = store.getSecondaryIndex(entryByKey, Long.class, "entryId");
config.setModel(new DiskQuotaEntityModel()); EntityStore entityStore = new EntityStore(env, storeName, config); return entityStore;
public Void call() throws Exception { final Transaction transaction = entityStore.getEnvironment().beginTransaction(null, null); try { createLayer(layerName, transaction); transaction.commit(); } catch (RuntimeException e) { transaction.abort(); } return null; } });
store = new EntityStore(myEnv, "EntityStore", storeConfig); index = store.getPrimaryIndex(String.class, Entry.class);
/** * This method is used to set the metadata of a previously indexed vector. If the metadata is already set, * this methods replaces it. * * @param iid * The internal id of the vector * @param metaData * A java object of any class with the @persistent annotation * @return true if metadata is successfully set, false otherwise */ public boolean setMetadata(int iid, Object metaData) { if (iid < 0 || iid > loadCounter) { System.out.println("Internal id " + iid + " is out of range!"); return false; } MetaDataEntity mde = new MetaDataEntity(iid, metaData); PrimaryIndex<Integer, MetaDataEntity> primaryIndex = iidToMetadataDB.getPrimaryIndex(Integer.class, MetaDataEntity.class); if (primaryIndex.contains(iid)) { primaryIndex.put(null, mde); return true; } else { return false; } }
entryById = store.getSecondaryIndex(entryByKey, Long.class, "entryId");
public Void call() throws Exception { Transaction transaction = entityStore.getEnvironment().beginTransaction(null, null); try { call(transaction); transaction.commit(); } catch (RuntimeException e) { transaction.abort(); throw e; } return null; }
storeConfig.setTransactional(false); storeConfig.setReadOnly(isReadOnly); store = new EntityStore(env, DATABASE_NAME, storeConfig); pageById = store.getPrimaryIndex(Long.class, WiktionaryPage.class); pageByTitle = store.getSecondaryIndex(pageById, String.class, "title"); pageByNormalizedTitle = store.getSecondaryIndex(pageById, String.class, "normalizedTitle"); entryByKey = store.getPrimaryIndex(String.class, WiktionaryEntryProxy.class); entryById = store.getSecondaryIndex(entryByKey, Long.class, "entryId"); senseByKey = store.getPrimaryIndex(String.class, WiktionarySenseProxy.class);
/** Hotspot for closing the connection. * @throws WiktionaryException if the connection could not be closed. */ protected void doClose() { if (store == null) return; // DB already closed. try { openCursors.forEach(EntityCursor::close); openCursors.clear(); store.close(); env.close(); env = null; store = null; } catch (DatabaseException e) { throw new WiktionaryException("Unable to close database", e); } }
public Void call() throws Exception { final Transaction transaction = entityStore.getEnvironment().beginTransaction(null, null); try { if (null
storeConfig.setTransactional(false); storeConfig.setReadOnly(isReadOnly); store = new EntityStore(env, DATABASE_NAME, storeConfig); pageById = store.getPrimaryIndex(Long.class, WiktionaryPage.class); pageByTitle = store.getSecondaryIndex(pageById, String.class, "title"); pageByNormalizedTitle = store.getSecondaryIndex(pageById, String.class, "normalizedTitle"); entryByKey = store.getPrimaryIndex(String.class, WiktionaryEntryProxy.class); entryById = store.getSecondaryIndex(entryByKey, Long.class, "entryId"); senseByKey = store.getPrimaryIndex(String.class, WiktionarySenseProxy.class);
/** Hotspot for closing the connection. * @throws WiktionaryException if the connection could not be closed. */ protected void doClose() { if (store == null) return; // DB already closed. try { for (EntityCursor<?> cursor : openCursors) cursor.close(); openCursors.clear(); store.close(); env.close(); env = null; store = null; } catch (DatabaseException e) { throw new WiktionaryException("Unable to close database", e); } }
/** * Copy over old {@link TileSet}s, used {@link Quota}s and {@link TilePage}s from * oldLayerName to newLayerName and delete the old ones * * @see java.util.concurrent.Callable#call() */ public Void call() throws Exception { Transaction transaction = entityStore.getEnvironment().beginTransaction(null, null); try { copyTileSets(transaction); Deleter deleteCommand = new Deleter(oldLayerName, ts -> true); deleteCommand.call(transaction); transaction.commit(); } catch (RuntimeException e) { transaction.abort(); throw e; } return null; }
public JESpace(String name, String params) throws SpaceError { super(); try { EnvironmentConfig envConfig = new EnvironmentConfig(); StoreConfig storeConfig = new StoreConfig(); String[] p = ISOUtil.commaDecode(params); String path = p[0]; envConfig.setAllowCreate (true); envConfig.setTransactional(true); envConfig.setLockTimeout(getParam("lock.timeout", p, DEFAULT_LOCK_TIMEOUT), TimeUnit.MILLISECONDS); envConfig.setTxnTimeout(getParam("txn.timeout", p, DEFAULT_TXN_TIMEOUT), TimeUnit.MILLISECONDS); storeConfig.setAllowCreate (true); storeConfig.setTransactional (true); File dir = new File(path); dir.mkdirs(); dbe = new Environment (dir, envConfig); store = new EntityStore (dbe, name, storeConfig); pIndex = store.getPrimaryIndex (Long.class, Ref.class); gcpIndex = store.getPrimaryIndex (Long.class, GCRef.class); sIndex = store.getSecondaryIndex (pIndex, String.class, "key"); gcsIndex = store.getSecondaryIndex (gcpIndex, Long.class, "expires"); gcTask = SpaceFactory.getGCExecutor().scheduleAtFixedRate(this, GC_DELAY, GC_DELAY, TimeUnit.MILLISECONDS); } catch (Exception e) { throw new SpaceError (e); } }