本文整理汇总了Java中com.sleepycat.bind.serial.SerialBinding类的典型用法代码示例。如果您正苦于以下问题:Java SerialBinding类的具体用法?Java SerialBinding怎么用?Java SerialBinding使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SerialBinding类属于com.sleepycat.bind.serial包,在下文中一共展示了SerialBinding类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getChildren
import com.sleepycat.bind.serial.SerialBinding; //导入依赖的package包/类
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.getLogger(Scaffold.class.getName()).log(Level.SEVERE, "Scaffold entry insertion error!", ex);
}
return null;
}
示例2: getParents
import com.sleepycat.bind.serial.SerialBinding; //导入依赖的package包/类
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.getLogger(Scaffold.class.getName()).log(Level.SEVERE, "Scaffold entry insertion error!", ex);
}
return null;
}
示例3: getVertex
import com.sleepycat.bind.serial.SerialBinding; //导入依赖的package包/类
@Override
public AbstractVertex getVertex(String vertexHash) {
AbstractVertex vertex = null;
Integer vertexID = hashToID.get(vertexHash);
try
{
// Instantiate class catalog
StoredClassCatalog vertexCatalog = new StoredClassCatalog(annotationsDatabase);
// Create the binding
EntryBinding vertexBinding = new SerialBinding<>(vertexCatalog, AbstractVertex.class);
// Create DatabaseEntry for the key
DatabaseEntry key = new DatabaseEntry(vertexID.toString().getBytes("UTF-8"));
// Create the DatabaseEntry for the data.
DatabaseEntry data = new DatabaseEntry();
annotationsDatabase.get(null, key, data, LockMode.DEFAULT);
// Recreate the MyData object from the retrieved DatabaseEntry using
// the EntryBinding created above
vertex = (AbstractVertex) vertexBinding.entryToObject(data);
}
catch (UnsupportedEncodingException ex)
{
Logger.getLogger(BerkeleyDB.class.getName()).log(Level.WARNING, null, ex);
}
return vertex;
}
示例4: run
import com.sleepycat.bind.serial.SerialBinding; //导入依赖的package包/类
private void run(String args[])
throws DatabaseException {
// Parse the arguments list
parseArgs(args);
myDbEnv.setup(myDbEnvPath, // path to the environment home
true); // is this environment read-only?
// Setup our bindings.
inventoryBinding = new InventoryBinding();
vendorBinding =
new SerialBinding(myDbEnv.getClassCatalog(),
Vendor.class);
if (locateItem != null) {
showItem();
} else {
showAllInventory();
}
}
示例5: setUp
import com.sleepycat.bind.serial.SerialBinding; //导入依赖的package包/类
public void setUp()
throws Exception {
DbTestUtil.printTestName(getName());
env = testEnv.open(makeTestName(testEnv), false);
runner = new TransactionRunner(env);
catalog = new StoredClassCatalog(openDb(CATALOG_FILE, false));
catalog2 = new StoredClassCatalog(openDb("catalog2.db", true));
SerialBinding keyBinding = new SerialBinding(catalog,
String.class);
SerialBinding valueBinding = new SerialBinding(catalog,
TestSerial.class);
store = openDb(STORE_FILE, false);
map = new StoredMap(store, keyBinding, valueBinding, true);
}
示例6: setUp
import com.sleepycat.bind.serial.SerialBinding; //导入依赖的package包/类
public void setUp()
throws Exception {
DbTestUtil.printTestName(getName());
env = testEnv.open(StoredClassCatalogTest.makeTestName(testEnv));
runner = new TransactionRunner(env);
catalog = new StoredClassCatalog(openDb(CATALOG_FILE));
SerialBinding keyBinding = new SerialBinding(catalog, String.class);
SerialBinding valueBinding =
new SerialBinding(catalog, TestSerial.class);
store = openDb(STORE_FILE);
map = new StoredMap(store, keyBinding, valueBinding, true);
}
示例7: primitiveBindingTest
import com.sleepycat.bind.serial.SerialBinding; //导入依赖的package包/类
private void primitiveBindingTest(Object val) {
Class cls = val.getClass();
SerialBinding binding = new SerialBinding(catalog, cls);
binding.objectToEntry(val, buffer);
assertTrue(buffer.getSize() > 0);
Object val2 = binding.entryToObject(buffer);
assertSame(cls, val2.getClass());
assertEquals(val, val2);
Object valWithWrongCls = (cls == String.class)
? ((Object) new Integer(0)) : ((Object) new String(""));
try {
binding.objectToEntry(valWithWrongCls, buffer);
} catch (IllegalArgumentException expected) {}
}
示例8: testSerialSerialBinding
import com.sleepycat.bind.serial.SerialBinding; //导入依赖的package包/类
public void testSerialSerialBinding() {
SerialBinding keyBinding = new SerialBinding(catalog, String.class);
SerialBinding valueBinding = new SerialBinding(catalog, String.class);
EntityBinding binding = new MySerialSerialBinding(keyBinding,
valueBinding);
String val = "key#value?indexKey";
binding.objectToData(val, buffer);
assertTrue(buffer.getSize() > 0);
binding.objectToKey(val, keyBuffer);
assertTrue(keyBuffer.getSize() > 0);
Object result = binding.entryToObject(keyBuffer, buffer);
assertEquals(val, result);
}
示例9: testTupleSerialMarshalledBinding
import com.sleepycat.bind.serial.SerialBinding; //导入依赖的package包/类
public void testTupleSerialMarshalledBinding() {
SerialBinding valueBinding = new SerialBinding(catalog,
MarshalledObject.class);
EntityBinding binding =
new TupleSerialMarshalledBinding(valueBinding);
MarshalledObject val = new MarshalledObject("abc", "primary",
"index1", "index2");
binding.objectToData(val, buffer);
assertTrue(buffer.getSize() > 0);
binding.objectToKey(val, keyBuffer);
assertEquals(val.expectedKeyLength(), keyBuffer.getSize());
Object result = binding.entryToObject(keyBuffer, buffer);
assertTrue(result instanceof MarshalledObject);
val = (MarshalledObject) result;
assertEquals("abc", val.getData());
assertEquals("primary", val.getPrimaryKey());
assertEquals("index1", val.getIndexKey1());
assertEquals("index2", val.getIndexKey2());
}
示例10: testClassloaderOverride
import com.sleepycat.bind.serial.SerialBinding; //导入依赖的package包/类
/**
* Tests that overriding SerialBinding.getClassLoader is possible. This is
* a crude test because to create a truly working class loader is a large
* undertaking.
*/
public void testClassloaderOverride()
throws Exception {
DatabaseEntry entry = new DatabaseEntry();
SerialBinding binding = new CustomLoaderBinding
(catalog, null, new FailureClassLoader());
try {
binding.objectToEntry(new MyClass(), entry);
binding.entryToObject(entry);
fail();
} catch (RuntimeException e) {
assertTrue(e.getMessage().startsWith("expect failure"));
}
}
示例11: run
import com.sleepycat.bind.serial.SerialBinding; //导入依赖的package包/类
private void run(String args[])
throws DatabaseException {
// Parse the arguments list
parseArgs(args);
myDbs.setup(myDbsPath);
// Setup our bindings.
inventoryBinding = new InventoryBinding();
vendorBinding =
new SerialBinding(myDbs.getClassCatalog(),
Vendor.class);
if (locateItem != null) {
showItem();
} else {
showAllInventory();
}
}
示例12: setUp
import com.sleepycat.bind.serial.SerialBinding; //导入依赖的package包/类
public void setUp()
throws Exception {
SharedTestUtils.printTestName(getName());
env = testEnv.open(makeTestName(testEnv), false);
runner = new TransactionRunner(env);
catalog = new StoredClassCatalog(openDb(CATALOG_FILE, false));
catalog2 = new StoredClassCatalog(openDb("catalog2.db", true));
SerialBinding keyBinding = new SerialBinding(catalog,
String.class);
SerialBinding valueBinding = new SerialBinding(catalog,
TestSerial.class);
store = openDb(STORE_FILE, false);
map = new StoredMap(store, keyBinding, valueBinding, true);
}
示例13: setUp
import com.sleepycat.bind.serial.SerialBinding; //导入依赖的package包/类
public void setUp()
throws Exception {
SharedTestUtils.printTestName(getName());
env = testEnv.open(StoredClassCatalogTest.makeTestName(testEnv));
runner = new TransactionRunner(env);
catalog = new StoredClassCatalog(openDb(CATALOG_FILE));
SerialBinding keyBinding = new SerialBinding(catalog, String.class);
SerialBinding valueBinding =
new SerialBinding(catalog, TestSerial.class);
store = openDb(STORE_FILE);
map = new StoredMap(store, keyBinding, valueBinding, true);
}
示例14: ClassCatalog
import com.sleepycat.bind.serial.SerialBinding; //导入依赖的package包/类
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;
}
};
}
示例15: putData
import com.sleepycat.bind.serial.SerialBinding; //导入依赖的package包/类
/**
*
* Put key and value into file BD. If key is same the old value will be rewrited
*
* @param key
* @param value
*/
public void putData(String[] key, Object value) {
String keyString = ConvertToKey(key);
DataListRow valueListRow = new DataListRow();
valueListRow.getKeys().addAll(Arrays.asList(key));
valueListRow.getValue().add(value);
StoredClassCatalog classCatalog = berkeleyDbEnv.getClassCatalog();
EntryBinding<DataListRow> dataBinding = new SerialBinding<DataListRow>(classCatalog, DataListRow.class);
TupleBinding<String> integerBinding = TupleBinding.getPrimitiveBinding(String.class);
DatabaseEntry keyEntry = new DatabaseEntry();
DatabaseEntry valueEntry = new DatabaseEntry();
integerBinding.objectToEntry(keyString, keyEntry);
dataBinding.objectToEntry(valueListRow, valueEntry);
berkeleyDbEnv.getDataDB().put(null, keyEntry, valueEntry);
}