com.sleepycat.bind.EntryBinding Java Examples
The following examples show how to use
com.sleepycat.bind.EntryBinding.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BdbWrapper.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
public List<String> dump(String prefix, int start, int count, LockMode lockMode) { EntryBinding<String> binder = TupleBinding.getPrimitiveBinding(String.class); DatabaseEntry key = new DatabaseEntry(); binder.objectToEntry(prefix, key); DatabaseEntry value = new DatabaseEntry(); Cursor cursor = database.openCursor(null, null); OperationStatus status = cursor.getSearchKeyRange(key, value, LockMode.READ_UNCOMMITTED); List<String> result = new ArrayList<>(); int index = 0; while (status == OperationStatus.SUCCESS && index < (start + count)) { if (index >= start) { result.add( binder.entryToObject(key) + " -> " + binder.entryToObject(value) ); } index++; status = cursor.getNext(key, value, LockMode.READ_UNCOMMITTED); } cursor.close(); return result; }
Example #2
Source File: BdbNonPersistentEnvironmentCreator.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
@Override public <KeyT, ValueT> BdbWrapper<KeyT, ValueT> getDatabase(String userId, String dataSetId, String databaseName, boolean allowDuplicates, EntryBinding<KeyT> keyBinder, EntryBinding<ValueT> valueBinder, IsCleanHandler<KeyT, ValueT> isCleanHandler) throws BdbDbCreationException { try { DatabaseConfig config = new DatabaseConfig(); config.setAllowCreate(true); config.setDeferredWrite(true); config.setSortedDuplicates(allowDuplicates); String environmentKey = environmentKey(userId, dataSetId); File envHome = new File(dbHome, environmentKey); envHome.mkdirs(); Environment dataSetEnvironment = new Environment(envHome, configuration); Database database = dataSetEnvironment.openDatabase(null, databaseName, config); databases.put(environmentKey + "_" + databaseName, database); environmentMap.put(environmentKey, dataSetEnvironment); return new BdbWrapper<>(dataSetEnvironment, database, config, keyBinder, valueBinder, isCleanHandler); } catch (DatabaseException e) { throw new BdbDbCreationException(e); } }
Example #3
Source File: BerkeleyDB.java From SPADE with GNU General Public License v3.0 | 5 votes |
@Override public Set<String> getChildren(String parentHash) { try { // Instantiate class catalog StoredClassCatalog neighborCatalog = new StoredClassCatalog(neighborDatabase); // Create the binding EntryBinding<Neighbors> neighborBinding = new SerialBinding<>(neighborCatalog, Neighbors.class); // Create DatabaseEntry for the key DatabaseEntry key = new DatabaseEntry(parentHash.getBytes("UTF-8")); // Create the DatabaseEntry for the data. DatabaseEntry data = new DatabaseEntry(); // query database to get the key-value OperationStatus operationStatus = scaffoldDatabase.get(null, key, data, LockMode.DEFAULT); if(operationStatus != OperationStatus.NOTFOUND) { Neighbors neighbors = neighborBinding.entryToObject(data); return neighbors.children; } } catch (UnsupportedEncodingException ex) { logger.log(Level.SEVERE, "Scaffold entry insertion error!", ex); } return null; }
Example #4
Source File: BerkeleyDB.java From SPADE with GNU General Public License v3.0 | 5 votes |
@Override public Set<String> getParents(String childHash) { try { // Instantiate class catalog StoredClassCatalog neighborCatalog = new StoredClassCatalog(neighborDatabase); // Create the binding EntryBinding<Neighbors> neighborBinding = new SerialBinding<>(neighborCatalog, Neighbors.class); // Create DatabaseEntry for the key DatabaseEntry key = new DatabaseEntry(childHash.getBytes("UTF-8")); // Create the DatabaseEntry for the data. DatabaseEntry data = new DatabaseEntry(); // query database to get the key-value OperationStatus operationStatus = scaffoldDatabase.get(null, key, data, LockMode.DEFAULT); if(operationStatus != OperationStatus.NOTFOUND) { Neighbors neighbors = neighborBinding.entryToObject(data); return neighbors.parents; } } catch (UnsupportedEncodingException ex) { logger.log(Level.SEVERE, "Scaffold entry insertion error!", ex); } return null; }
Example #5
Source File: BerkeleyDB.java From SPADE with GNU General Public License v3.0 | 5 votes |
/** * This function inserts the given edge into the underlying storage(s) and * updates the cache(s) accordingly. * * @param incomingEdge edge to insert into the storage * @return returns true if the insertion is successful. Insertion is considered * not successful if the edge is already present in the storage. */ @Override public boolean putEdge(AbstractEdge incomingEdge) { String hash = incomingEdge.getChildVertex().bigHashCode() + incomingEdge.getParentVertex().bigHashCode(); try { // Instantiate class catalog StoredClassCatalog edgeCatalog = new StoredClassCatalog(edgeDatabase); // Create the binding EntryBinding<AbstractEdge> edgeBinding = new SerialBinding<>(edgeCatalog, AbstractEdge.class); // Create DatabaseEntry for the key DatabaseEntry key = new DatabaseEntry(hash.getBytes("UTF-8")); // Create the DatabaseEntry for the data. DatabaseEntry data = new DatabaseEntry(); edgeBinding.objectToEntry(incomingEdge, data); // Insert it in database myDatabase.put(null, key, data); return true; } catch (UnsupportedEncodingException ex) { Logger.getLogger(BerkeleyDB.class.getName()).log(Level.WARNING, null, ex); } return false; }
Example #6
Source File: BerkeleyDB.java From SPADE with GNU General Public License v3.0 | 5 votes |
/** * This function inserts the given vertex into the underlying storage(s) and * updates the cache(s) accordingly. * * @param incomingVertex vertex to insert into the storage * @return returns true if the insertion is successful. Insertion is considered * not successful if the vertex is already present in the storage. */ @Override public boolean putVertex(AbstractVertex incomingVertex) { try { // Instantiate class catalog StoredClassCatalog vertexCatalog = new StoredClassCatalog(vertexDatabase); // Create the binding EntryBinding<AbstractVertex> vertexBinding = new SerialBinding<>(vertexCatalog, AbstractVertex.class); // Create DatabaseEntry for the key DatabaseEntry key = new DatabaseEntry(incomingVertex.bigHashCode().getBytes("UTF-8")); // Create the DatabaseEntry for the data. DatabaseEntry data = new DatabaseEntry(); vertexBinding.objectToEntry(incomingVertex, data); // Insert it in database myDatabase.put(null, key, data); return true; } catch (UnsupportedEncodingException ex) { Logger.getLogger(BerkeleyDB.class.getName()).log(Level.WARNING, null, ex); } return false; }
Example #7
Source File: BdbWrapper.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
public BdbWrapper(Environment dbEnvironment, Database database, DatabaseConfig databaseConfig, EntryBinding<KeyT> keyBinder, EntryBinding<ValueT> valueBinder, IsCleanHandler<KeyT, ValueT> isCleanHandler) { this.dbEnvironment = dbEnvironment; this.database = database; this.databaseConfig = databaseConfig; this.keyBinder = keyBinder; this.valueBinder = valueBinder; this.isCleanHandler = isCleanHandler; }
Example #8
Source File: DatabaseGetter.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
DatabaseGetter(EntryBinding<KeyT> keyBinder, EntryBinding<ValueT> valueBinder, DatabaseFunction initializer, DatabaseFunction iterator, Database database, Map<Cursor, String> cursors, DatabaseEntry key, DatabaseEntry value) { this.keyBinder = keyBinder; this.valueBinder = valueBinder; this.initializer = initializer; this.iterator = iterator; this.database = database; this.cursors = cursors; this.key = key; this.value = value; }
Example #9
Source File: DatabaseGetter.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
public static <KeyT, ValueT> Builder<KeyT, ValueT> databaseGetter(EntryBinding<KeyT> keyBinder, EntryBinding<ValueT> valueBinder, Database database, Map<Cursor, String> cursors, KeyT keyToIgnore, ValueT valueToIgnore) { return new DatabaseGetterBuilderImpl<>(keyBinder, valueBinder, database, cursors, keyToIgnore, valueToIgnore); }
Example #10
Source File: DatabaseGetter.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
public DatabaseGetterBuilderImpl(EntryBinding<KeyT> keyBinder, EntryBinding<ValueT> valueBinder, Database database, Map<Cursor, String> cursors, KeyT keyToIgnore, ValueT valueToIgnore) { this.keyBinder = keyBinder; this.valueBinder = valueBinder; this.database = database; this.cursors = cursors; this.keyToIgnore = keyToIgnore; this.valueToIgnore = valueToIgnore; }
Example #11
Source File: BerkeleyDB.java From SPADE with GNU General Public License v3.0 | 4 votes |
@Override public Map<String, Set<String>> getLineage(String hash, String direction, int maxDepth) { try { // Instantiate class catalog StoredClassCatalog neighborCatalog = new StoredClassCatalog(neighborDatabase); // Create the binding EntryBinding<Neighbors> neighborBinding = new SerialBinding<>(neighborCatalog, Neighbors.class); // Create DatabaseEntry for the key DatabaseEntry key = new DatabaseEntry(hash.getBytes("UTF-8")); // Create the DatabaseEntry for the data. DatabaseEntry data = new DatabaseEntry(); // query database to get the key-value OperationStatus operationStatus = scaffoldDatabase.get(null, key, data, LockMode.DEFAULT); if(operationStatus != OperationStatus.NOTFOUND) { Set<String> remainingVertices = new HashSet<>(); Set<String> visitedVertices = new HashSet<>(); Map<String, Set<String>> lineageMap = new HashMap<>(); remainingVertices.add(hash); int current_depth = 0; while(!remainingVertices.isEmpty() && current_depth < maxDepth) { visitedVertices.addAll(remainingVertices); Set<String> currentSet = new HashSet<>(); for(String current_hash: remainingVertices) { Set<String> neighbors = null; if(DIRECTION_ANCESTORS.startsWith(direction.toLowerCase())) neighbors = getParents(current_hash); else if(DIRECTION_DESCENDANTS.startsWith(direction.toLowerCase())) neighbors = getChildren(current_hash); if(neighbors != null) { lineageMap.put(current_hash, neighbors); for(String vertexHash: neighbors) { if(!visitedVertices.contains(vertexHash)) { currentSet.addAll(neighbors); } } } } remainingVertices.clear(); remainingVertices.addAll(currentSet); current_depth++; } return lineageMap; } } catch(UnsupportedEncodingException ex) { logger.log(Level.SEVERE, "Scaffold Get Lineage error!", ex); } return null; }
Example #12
Source File: BDBFrontier.java From codes-scratch-crawler with Apache License 2.0 | 4 votes |
public BDBFrontier(String homeDirectory) { super(homeDirectory); EntryBinding keyBinding = new SerialBinding(javaCatalog, String.class); EntryBinding valueBinding = new SerialBinding(javaCatalog, CrawlUrl.class); pendingUrisDB = new StoredMap(database, keyBinding, valueBinding, true); }
Example #13
Source File: RelDatabase.java From Rel with Apache License 2.0 | 4 votes |
public EntryBinding<ValueTuple> getTupleBinding() { return classCatalog.getTupleBinding(); }
Example #14
Source File: ClassCatalog.java From Rel with Apache License 2.0 | 4 votes |
EntryBinding<RelvarMetadata> getRelvarMetadataBinding() { return relvarMetadataBinding; }
Example #15
Source File: BdbEnvironmentCreator.java From timbuctoo with GNU General Public License v3.0 | 4 votes |
<KeyT, ValueT> BdbWrapper<KeyT, ValueT> getDatabase(String userId, String dataSetName, String databaseName, boolean allowDuplicates, EntryBinding<KeyT> keyBinder, EntryBinding<ValueT> valueBinder, IsCleanHandler<KeyT, ValueT> cleanHandler) throws BdbDbCreationException;
Example #16
Source File: DatabaseGetter.java From timbuctoo with GNU General Public License v3.0 | 4 votes |
DatabaseFunction make(DatabaseEntry keyEntry, DatabaseEntry valueEntry, DatabaseFunction iterator, EntryBinding<KeyT> keyBinder, EntryBinding<ValueT> valueBinder);