com.sleepycat.bind.serial.StoredClassCatalog Java Examples

The following examples show how to use com.sleepycat.bind.serial.StoredClassCatalog. 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: AbstractFrontier.java    From codes-scratch-crawler with Apache License 2.0 6 votes vote down vote up
public AbstractFrontier(String homeDirectory) {
  EnvironmentConfig envConfig = new EnvironmentConfig();
  envConfig.setTransactional(true);
  envConfig.setAllowCreate(true);
  env = new Environment(new File(homeDirectory), envConfig);
  // 设置databaseconfig
  DatabaseConfig dbConfig = new DatabaseConfig();
  dbConfig.setTransactional(true);
  dbConfig.setAllowCreate(true);
  // 打开
  catalogdatabase = env.openDatabase(null, CLASS_CATALOG, dbConfig);
  javaCatalog = new StoredClassCatalog(catalogdatabase);
  // 设置databaseconfig
  DatabaseConfig dbConfig0 = new DatabaseConfig();
  dbConfig0.setTransactional(true);
  dbConfig0.setAllowCreate(true);
  database = env.openDatabase(null, "URL", dbConfig0);
}
 
Example #2
Source File: ClassCatalog.java    From Rel with Apache License 2.0 6 votes vote down vote up
ClassCatalog(String directory, EnvironmentConfig environmentConfig, DatabaseConfig dbConfig) {
	// This should be main database directory
	dirClassLoader = new DirClassLoader(directory);
	
    // Open the environment in subdirectory of the above
	String classesDir = directory + java.io.File.separator + "classes";
	RelDatabase.mkdir(classesDir);
    environment = new Environment(new File(classesDir), environmentConfig);
    
    // Open the class catalog db. This is used to optimize class serialization.
    classCatalogDb = environment.openDatabase(null, "_ClassCatalog", dbConfig);

    // Create our class catalog
    classCatalog = new StoredClassCatalog(classCatalogDb);
    
    // Need a serial binding for metadata
    relvarMetadataBinding = new SerialBinding<RelvarMetadata>(classCatalog, RelvarMetadata.class);
    
    // Need serial binding for data
    tupleBinding = new SerialBinding<ValueTuple>(classCatalog, ValueTuple.class) {
    	public ClassLoader getClassLoader() {
    		return dirClassLoader;
    	}
    };   	
}
 
Example #3
Source File: BerkeleyDB.java    From SPADE with GNU General Public License v3.0 5 votes vote down vote up
@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 vote down vote up
@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 vote down vote up
/**
 * 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 vote down vote up
/**
 * 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: BerkeleyDB.java    From SPADE with GNU General Public License v3.0 4 votes vote down vote up
@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 #8
Source File: RelDatabase.java    From Rel with Apache License 2.0 4 votes vote down vote up
StoredClassCatalog getClassCatalog() {
	return classCatalog.getStoredClassCatalog();
}
 
Example #9
Source File: ClassCatalog.java    From Rel with Apache License 2.0 4 votes vote down vote up
public StoredClassCatalog getStoredClassCatalog() {
	return classCatalog;
}