本文整理匯總了Java中org.apache.ignite.binary.BinaryObjectBuilder類的典型用法代碼示例。如果您正苦於以下問題:Java BinaryObjectBuilder類的具體用法?Java BinaryObjectBuilder怎麽用?Java BinaryObjectBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BinaryObjectBuilder類屬於org.apache.ignite.binary包,在下文中一共展示了BinaryObjectBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createKeyObject
import org.apache.ignite.binary.BinaryObjectBuilder; //導入依賴的package包/類
/**
* Converting entity key to cache key
*
* @param key entity key
* @return string key
*/
public Object createKeyObject(EntityKey key) {
Object result = null;
if ( key.getColumnValues().length == 1 ) {
IgniteCache<Object, BinaryObject> entityCache = getEntityCache( key.getMetadata() );
CacheConfiguration cacheConfig = entityCache.getConfiguration( CacheConfiguration.class );
result = toValidKeyObject( key.getColumnValues()[0], cacheConfig.getKeyType() );
}
else {
BinaryObjectBuilder builder = createBinaryObjectBuilder( findKeyType( key.getMetadata() ) );
for ( int i = 0; i < key.getColumnNames().length; i++ ) {
builder.setField( StringHelper.stringAfterPoint( key.getColumnNames()[i] ), key.getColumnValues()[i] );
}
result = builder.build();
}
return result;
}
示例2: createAssociationKeyObject
import org.apache.ignite.binary.BinaryObjectBuilder; //導入依賴的package包/類
public Object createAssociationKeyObject( RowKey rowKey, AssociationKeyMetadata keyMetadata ) {
Object result = null;
if ( IgniteAssociationSnapshot.isThirdTableAssociation( keyMetadata ) ) {
result = UUID.randomUUID().toString();
}
else {
String associationKeyColumns[] = keyMetadata.getAssociatedEntityKeyMetadata().getAssociationKeyColumns();
if ( associationKeyColumns.length == 1 ) {
result = rowKey.getColumnValue( associationKeyColumns[0] );
}
else {
BinaryObjectBuilder builder = createBinaryObjectBuilder( findKeyType( keyMetadata.getAssociatedEntityKeyMetadata().getEntityKeyMetadata() ) );
for ( int i = 0; i < associationKeyColumns.length; i++ ) {
builder.setField( StringHelper.stringAfterPoint( associationKeyColumns[i] ), rowKey.getColumnValue( associationKeyColumns[i] ) );
}
result = builder.build();
}
}
return result;
}
示例3: createPerson
import org.apache.ignite.binary.BinaryObjectBuilder; //導入依賴的package包/類
/**
*
*/
Object createPerson(int id, String name) {
if (!isBinaryMarshaller()) {
Person p = new Person(id);
p.name = name;
return p;
}
else {
BinaryObjectBuilder o = grid(0).binary().builder("Person");
o.setField("id", id);
o.setField("name", name);
return o.build();
}
}
示例4: createPerson2
import org.apache.ignite.binary.BinaryObjectBuilder; //導入依賴的package包/類
/**
*
*/
Object createPerson2(int id, String name, int valFld) {
if (!isBinaryMarshaller()) {
Person2 p = new Person2(id);
p.name = name;
p.IntVal = valFld;
return p;
}
else {
BinaryObjectBuilder o = grid(0).binary().builder("Person2");
o.setField("id", id);
o.setField("name", name);
o.setField("IntVal", valFld);
return o.build();
}
}
示例5: prepareAffinityField
import org.apache.ignite.binary.BinaryObjectBuilder; //導入依賴的package包/類
/**
* Prepare affinity field for builder (if possible).
*
* @param buider Builder.
*/
public void prepareAffinityField(BinaryObjectBuilder buider) {
assert binaryMarshaller();
assert buider instanceof BinaryObjectBuilderImpl;
BinaryObjectBuilderImpl builder0 = (BinaryObjectBuilderImpl)buider;
if (!customAffinityMapper()) {
CacheDefaultBinaryAffinityKeyMapper mapper =
(CacheDefaultBinaryAffinityKeyMapper)cacheObjCtx.defaultAffMapper();
BinaryField field = mapper.affinityKeyField(builder0.typeId());
if (field != null) {
String fieldName = field.name();
builder0.affinityFieldName(fieldName);
}
}
}
示例6: setField
import org.apache.ignite.binary.BinaryObjectBuilder; //導入依賴的package包/類
/** {@inheritDoc} */
@Override public BinaryObjectBuilder setField(String name, Object val0) {
Object val = assignedValues().get(name);
if (val instanceof BinaryValueWithType)
((BinaryValueWithType)val).value(val0);
else {
Class valCls = (val == null) ? Object.class : val.getClass();
val = val0 == null ? new BinaryValueWithType(BinaryUtils.typeByClass(valCls), null) : val0;
}
assignedValues().put(name, val);
return this;
}
示例7: buildBinaryObject
import org.apache.ignite.binary.BinaryObjectBuilder; //導入依賴的package包/類
/**
* Construct binary object from query result.
*
* @param typeName Type name.
* @param fields Fields descriptors.
* @param loadColIdxs Select query columns index.
* @param rs ResultSet.
* @return Constructed binary object.
* @throws CacheLoaderException If failed to construct binary object.
*/
protected Object buildBinaryObject(String typeName, JdbcTypeField[] fields, Map<String, Integer> loadColIdxs, ResultSet rs) throws CacheLoaderException {
try {
BinaryObjectBuilder builder = ignite.binary().builder(typeName);
for (JdbcTypeField field : fields) {
Integer colIdx = columnIndex(loadColIdxs, field.getDatabaseFieldName());
Object colVal = transformer.getColumnValue(rs, colIdx, field.getJavaFieldType());
builder.setField(field.getJavaFieldName(), colVal, (Class<Object>)field.getJavaFieldType());
}
return builder.build();
}
catch (SQLException e) {
throw new CacheException("Failed to read binary object: " + typeName, e);
}
}
示例8: newBinaryObject
import org.apache.ignite.binary.BinaryObjectBuilder; //導入依賴的package包/類
/**
* @param builder Builder.
* @param desc Descriptor with parameters of BinaryObject to build.
* @return BinaryObject built by provided description
*/
private static BinaryObject newBinaryObject(BinaryObjectBuilder builder, BinaryUpdateDescription desc) {
builder.setField(SEQ_NUM_FLD, desc.itemId + 1);
switch (desc.fieldType) {
case NUMBER:
builder.setField(desc.fieldName, getNumberFieldVal());
break;
case STRING:
builder.setField(desc.fieldName, getStringFieldVal());
break;
case ARRAY:
builder.setField(desc.fieldName, getArrayFieldVal());
break;
case OBJECT:
builder.setField(desc.fieldName, new Object());
}
return builder.build();
}
示例9: testCrossFormatObjectsIdentity
import org.apache.ignite.binary.BinaryObjectBuilder; //導入依賴的package包/類
/**
*
*/
@SuppressWarnings("unchecked")
public void testCrossFormatObjectsIdentity() {
IgniteCache c = binKeysCache();
c.put(new ComplexBinaryFieldsListHashedKey(), "zzz");
// Now let's build an identical key for get
BinaryObjectBuilder bldr = grid(0).binary().builder(ComplexBinaryFieldsListHashedKey.class.getName());
bldr.setField("firstField", 1);
bldr.setField("secondField", "value");
bldr.setField("thirdField", 0x1020304050607080L);
BinaryObject binKey = bldr.build();
assertEquals("zzz", c.get(binKey));
}
示例10: checkProperty
import org.apache.ignite.binary.BinaryObjectBuilder; //導入依賴的package包/類
/**
* @param expTypeName Type name.
* @throws Exception If failed.
*/
private void checkProperty(String expTypeName) throws Exception {
String marshBackup = GridTestProperties.getProperty(MARSH_CLASS_NAME);
try {
GridTestProperties.setProperty(MARSH_CLASS_NAME, BinaryMarshaller.class.getName());
IgniteBinary binary = startGrid().binary();
BinaryObjectBuilder builder = binary.builder("org.ignite.test.TestClass");
BinaryObject bObj = builder.build();
assertEquals(expTypeName, bObj.type().typeName());
}
finally {
if (marshBackup != null)
GridTestProperties.setProperty(MARSH_CLASS_NAME, marshBackup);
}
}
示例11: testCollectionField
import org.apache.ignite.binary.BinaryObjectBuilder; //導入依賴的package包/類
/**
* @throws Exception If failed.
*/
public void testCollectionField() throws Exception {
BinaryObjectBuilder builder = builder("Class");
builder.setField("collectionField", Arrays.asList(new Value(1), new Value(2)));
builder.setField("collectionField2", Arrays.asList(new Value(1), new Value(2)), Collection.class);
BinaryObject po = builder.build();
assertEquals(expectedHashCode("Class"), po.type().typeId());
assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode());
List<Value> list = po.field("collectionField");
assertEquals(2, list.size());
assertEquals(1, list.get(0).i);
assertEquals(2, list.get(1).i);
List<BinaryObject> list2 = po.field("collectionField2");
assertEquals(2, list2.size());
assertEquals(1, list2.get(0).<Value>deserialize().i);
assertEquals(2, list2.get(1).<Value>deserialize().i);
}
示例12: testDontBrokeCyclicDependency
import org.apache.ignite.binary.BinaryObjectBuilder; //導入依賴的package包/類
/**
* @throws IgniteCheckedException If any error occurs.
*/
public void testDontBrokeCyclicDependency() throws IgniteCheckedException {
GridBinaryTestClasses.TestObjectOuter outer = new GridBinaryTestClasses.TestObjectOuter();
outer.inner = new GridBinaryTestClasses.TestObjectInner();
outer.inner.outer = outer;
outer.foo = "a";
BinaryObjectBuilder builder = builder(toBinary(outer));
builder.setField("foo", "b");
GridBinaryTestClasses.TestObjectOuter res = builder.build().deserialize();
assertEquals("b", res.foo);
assertSame(res, res.inner.outer);
}
示例13: testSameBinaryKey
import org.apache.ignite.binary.BinaryObjectBuilder; //導入依賴的package包/類
/**
* @throws Exception If failed.
*/
public void testSameBinaryKey() throws Exception {
IgniteCache<BinaryObject, BinaryObject> replicatedCache =
jcache(0).withKeepBinary();
IgniteCache<BinaryObject, BinaryObject> partitionedCache =
jcache(0, "partitioned").withKeepBinary();
BinaryObjectBuilder keyBuilder = ignite(0).binary().builder("keyType")
.setField("F1", "V1");
BinaryObjectBuilder valBuilder = ignite(0).binary().builder("valueType")
.setField("F2", "V2")
.setField("F3", "V3");
BinaryObject key = keyBuilder.build();
BinaryObject val = valBuilder.build();
replicatedCache.put(key, val);
partitionedCache.put(key, val);
assertNotNull(replicatedCache.get(key));
assertNotNull(partitionedCache.get(key));
}
示例14: testEnum
import org.apache.ignite.binary.BinaryObjectBuilder; //導入依賴的package包/類
/**
* Checks correct serialization/deserialization of enums in builder.
*
* @throws Exception If failed.
*/
public void testEnum() throws Exception {
BinaryObjectBuilder builder = newWrapper("TestType");
final TestEnum exp = TestEnum.A;
final TestEnum[] expArr = {TestEnum.A, TestEnum.B};
BinaryObject enumObj = builder.setField("testEnum", exp).setField("testEnumArr", expArr).build();
assertEquals(exp, ((BinaryObject)enumObj.field("testEnum")).deserialize());
Assert.assertArrayEquals(expArr, (Object[])deserializeEnumBinaryArray(enumObj.field("testEnumArr")));
builder = newWrapper(enumObj.type().typeName());
enumObj = builder.setField("testEnum", (Object)enumObj.field("testEnum"))
.setField("testEnumArr", (Object)enumObj.field("testEnumArr")).build();
assertEquals(exp, ((BinaryObject)enumObj.field("testEnum")).deserialize());
Assert.assertArrayEquals(expArr, (Object[])deserializeEnumBinaryArray(enumObj.field("testEnumArr")));
}
示例15: testBuilderReusage
import org.apache.ignite.binary.BinaryObjectBuilder; //導入依賴的package包/類
/**
* @throws Exception If fails
*/
public void testBuilderReusage() throws Exception {
// Check: rewrite null field value.
BinaryObjectBuilder builder = newWrapper("SimpleCls1");
builder.setField("f1", null, Object.class);
assertNull(builder.build().field("f1"));
builder.setField("f1", "val1");
assertEquals("val1", builder.build().field("f1"));
// Check: rewrite non-null field value to null and back.
builder = newWrapper("SimpleCls2");
builder.setField("f1", "val1", String.class);
assertEquals("val1", builder.build().field("f1"));
builder.setField("f1", null);
assertNull(builder.build().field("f1"));
builder.setField("f1", "val2");
assertEquals("val2", builder.build().field("f1"));
}