Search in sources :

Example 21 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class BinaryObjectBuilderDefaultMappersSelfTest method testNullField.

/**
     * @throws Exception If failed.
     */
public void testNullField() throws Exception {
    BinaryObjectBuilder builder = builder("Class");
    builder.setField("objField", (Object) null);
    builder.setField("otherField", "value");
    BinaryObject obj = builder.build();
    assertNull(obj.field("objField"));
    assertEquals("value", obj.field("otherField"));
    assertEquals(BinaryArrayIdentityResolver.instance().hashCode(obj), obj.hashCode());
    builder = builder(obj);
    builder.setField("objField", "value", Object.class);
    builder.setField("otherField", (Object) null);
    obj = builder.build();
    assertNull(obj.field("otherField"));
    assertEquals("value", obj.field("objField"));
    assertEquals(BinaryArrayIdentityResolver.instance().hashCode(obj), obj.hashCode());
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 22 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class BinaryObjectBuilderDefaultMappersSelfTest method testStringArrayField.

/**
     * @throws Exception If failed.
     */
public void testStringArrayField() throws Exception {
    BinaryObjectBuilder builder = builder("Class");
    builder.setField("stringArrayField", new String[] { "str1", "str2", "str3" });
    BinaryObject po = builder.build();
    assertEquals(expectedHashCode("Class"), po.type().typeId());
    assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode());
    assertTrue(Arrays.equals(new String[] { "str1", "str2", "str3" }, po.<String[]>field("stringArrayField")));
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 23 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class BinaryObjectBuilderDefaultMappersSelfTest method testGetFromCopiedObj.

/**
     *
     */
public void testGetFromCopiedObj() {
    BinaryObject objStr = builder(GridBinaryTestClasses.TestObjectAllTypes.class.getName()).setField("str", "aaa").build();
    BinaryObjectBuilderImpl builder = builder(objStr);
    assertEquals("aaa", builder.getField("str"));
    builder.setField("str", "bbb");
    assertEquals("bbb", builder.getField("str"));
    assertNull(builder.getField("i_"));
    TestCase.assertEquals("bbb", builder.build().<GridBinaryTestClasses.TestObjectAllTypes>deserialize().str);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilderImpl(org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl)

Example 24 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class BinaryObjectBuilderDefaultMappersSelfTest method testLongArrayField.

/**
     * @throws Exception If failed.
     */
public void testLongArrayField() throws Exception {
    BinaryObjectBuilder builder = builder("Class");
    builder.setField("longArrayField", new long[] { 1, 2, 3 });
    BinaryObject po = builder.build();
    assertEquals(expectedHashCode("Class"), po.type().typeId());
    assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode());
    assertTrue(Arrays.equals(new long[] { 1, 2, 3 }, po.<long[]>field("longArrayField")));
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 25 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class BinaryObjectBuilderDefaultMappersSelfTest method testDecimalField.

/**
     * @throws Exception If failed.
     */
public void testDecimalField() throws Exception {
    BinaryObjectBuilder builder = builder("Class");
    builder.setField("decimalField", BigDecimal.TEN);
    BinaryObject po = builder.build();
    assertEquals(expectedHashCode("Class"), po.type().typeId());
    assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode());
    assertEquals(BigDecimal.TEN, po.<BigDecimal>field("decimalField"));
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Aggregations

BinaryObject (org.apache.ignite.binary.BinaryObject)173 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)54 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)24 IgniteCache (org.apache.ignite.IgniteCache)21 Ignite (org.apache.ignite.Ignite)19 HashMap (java.util.HashMap)14 Map (java.util.Map)14 LinkedHashMap (java.util.LinkedHashMap)13 ArrayList (java.util.ArrayList)12 Cache (javax.cache.Cache)12 BinaryObjectBuilderImpl (org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl)10 GridBinaryTestClasses (org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)9 List (java.util.List)8 UUID (java.util.UUID)8 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)8 BigInteger (java.math.BigInteger)7 Date (java.util.Date)6 BinaryType (org.apache.ignite.binary.BinaryType)6 IgniteEx (org.apache.ignite.internal.IgniteEx)6 Transaction (org.apache.ignite.transactions.Transaction)6