Package com.sleepycat.bdb.bind

Examples of com.sleepycat.bdb.bind.DataBinding


    private void primitiveBindingTest(Object val)
        throws IOException {

        Class cls = val.getClass();
        SerialFormat format = new SerialFormat(catalog, cls);
        DataBinding binding = new SerialBinding(format);
        assertSame(format, binding.getDataFormat());

        binding.objectToData(val, buffer);
        assertTrue(buffer.getDataLength() > 0);

        Object val2 = binding.dataToObject(buffer);
        assertSame(cls, val2.getClass());
        assertEquals(val, val2);

        Object valWithWrongCls = (cls == String.class)
                      ? ((Object) new Integer(0)) : ((Object) new String(""));
        try {
            binding.objectToData(valWithWrongCls, buffer);
        } catch (IllegalArgumentException expected) {}
    }
View Full Code Here


                        (SerialFormat) store.getValueFormat());
    }

    private DataBinding getKeyBinding(Class keyClass) {

        DataBinding binding = TupleBinding.getPrimitiveBinding(keyClass,
                                                               TUPLE_FORMAT);
        if (binding == null) {
            binding = new TupleMarshalledBinding(TUPLE_FORMAT, keyClass);
        }
        return binding;
View Full Code Here

    private void primitiveBindingTest(Object val, int byteSize)
        throws IOException {

        Class cls = val.getClass();
        DataBinding binding = TupleBinding.getPrimitiveBinding(cls, format);
        assertSame(format, binding.getDataFormat());

        binding.objectToData(val, buffer);
        assertEquals(byteSize, buffer.getDataLength());

        Object val2 = binding.dataToObject(buffer);
        assertSame(cls, val2.getClass());
        assertEquals(val, val2);

        Object valWithWrongCls = (cls == String.class)
                      ? ((Object) new Integer(0)) : ((Object) new String(""));
        try {
            binding.objectToData(valWithWrongCls, buffer);
        }
        catch (ClassCastException expected) {}
    }
View Full Code Here

    }

    public void testTupleInputBinding()
        throws IOException {

        DataBinding binding = new TupleInputBinding(format);
        assertSame(format, binding.getDataFormat());

        TupleOutput out = new TupleOutput();
        out.writeString("abc");
        binding.objectToData(new TupleInput(out), buffer);
        assertEquals(4, buffer.getDataLength());

        Object result = binding.dataToObject(buffer);
        assertTrue(result instanceof TupleInput);
        TupleInput in = (TupleInput) result;
        assertEquals("abc", in.readString());
        assertEquals(0, in.available());
    }
View Full Code Here

    // also tests TupleBinding since TupleMarshalledBinding extends it
    public void testTupleMarshalledBinding()
        throws IOException {

        DataBinding binding =
            new TupleMarshalledBinding(format, MarshalledObject.class);
        assertSame(format, binding.getDataFormat());

        MarshalledObject val = new MarshalledObject("abc", "", "", "");
        binding.objectToData(val, buffer);
        assertEquals(val.expectedDataLength(), buffer.getDataLength());

        Object result = binding.dataToObject(buffer);
        assertTrue(result instanceof MarshalledObject);
        val = (MarshalledObject) result;
        assertEquals("abc", val.getData());
    }
View Full Code Here

        // key/value data pair to a combined value object; a "tricky" binding
        // that uses transient fields is used--see PartBinding, etc, for
        // details.  For keys, a one-to-one binding is implemented with
        // DataBinding classes to bind the stored tuple data to a key Object.
        //
        DataBinding partKeyBinding =
            new PartKeyBinding(db.getPartKeyFormat());
        EntityBinding partValueBinding =
            new PartBinding(db.getPartKeyFormat(), db.getPartValueFormat());
        DataBinding supplierKeyBinding =
            new SupplierKeyBinding(db.getSupplierKeyFormat());
        EntityBinding supplierValueBinding =
            new SupplierBinding(db.getSupplierKeyFormat(),
                                db.getSupplierValueFormat());
        DataBinding shipmentKeyBinding =
            new ShipmentKeyBinding(db.getShipmentKeyFormat());
        EntityBinding shipmentValueBinding =
            new ShipmentBinding(db.getShipmentKeyFormat(),
                                db.getShipmentValueFormat());
        DataBinding cityKeyBinding =
            TupleBinding.getPrimitiveBinding(String.class,
                                             db.getCityKeyFormat());

        // Create map views for all stores and indices.
        // StoredSortedMap is used since the stores and indices are ordered
View Full Code Here

        // In this sample, EntityBinding classes are used to bind the stored
        // key/value data pair to a combined value object.  For keys, however,
        // the stored data is used directly via a SerialBinding and no
        // special binding class is needed.
        //
        DataBinding partKeyBinding =
            new SerialBinding(db.getPartKeyFormat());
        EntityBinding partValueBinding =
            new PartBinding(db.getPartKeyFormat(), db.getPartValueFormat());
        DataBinding supplierKeyBinding =
            new SerialBinding(db.getSupplierKeyFormat());
        EntityBinding supplierValueBinding =
            new SupplierBinding(db.getSupplierKeyFormat(),
                                db.getSupplierValueFormat());
        DataBinding shipmentKeyBinding =
            new SerialBinding(db.getShipmentKeyFormat());
        EntityBinding shipmentValueBinding =
            new ShipmentBinding(db.getShipmentKeyFormat(),
                                db.getShipmentValueFormat());
        DataBinding cityKeyBinding =
            new SerialBinding(db.getCityKeyFormat());

        // Create map views for all stores and indices.
        // StoredSortedMap is not used since the stores and indices are
        // ordered by serialized key objects, which do not provide a very
View Full Code Here

        // In this sample, EntityBinding classes are used to bind the stored
        // key/value data pair to a combined value object.  For keys, a
        // one-to-one binding is implemented with DataBinding classes to bind
        // the stored tuple data to a key Object.
        //
        DataBinding partKeyBinding =
            new PartKeyBinding(db.getPartKeyFormat());
        EntityBinding partValueBinding =
            new PartBinding(db.getPartKeyFormat(), db.getPartValueFormat());
        DataBinding supplierKeyBinding =
            new SupplierKeyBinding(db.getSupplierKeyFormat());
        EntityBinding supplierValueBinding =
            new SupplierBinding(db.getSupplierKeyFormat(),
                                db.getSupplierValueFormat());
        DataBinding shipmentKeyBinding =
            new ShipmentKeyBinding(db.getShipmentKeyFormat());
        EntityBinding shipmentValueBinding =
            new ShipmentBinding(db.getShipmentKeyFormat(),
                                db.getShipmentValueFormat());
        DataBinding cityKeyBinding =
            TupleBinding.getPrimitiveBinding(String.class,
                                             db.getCityKeyFormat());

        // Create map views for all stores and indices.
        // StoredSortedMap is used since the stores and indices are ordered
View Full Code Here

        // Create the data bindings.
        // In this sample, the stored keys and values are used directly rather
        // than mapping them to separate objects. Therefore, no binding classes
        // are defined here and the SerialBinding class is used.
        //
        DataBinding partKeyBinding =
            new SerialBinding(db.getPartKeyFormat());
        DataBinding partValueBinding =
            new SerialBinding(db.getPartValueFormat());
        DataBinding supplierKeyBinding =
            new SerialBinding(db.getSupplierKeyFormat());
        DataBinding supplierValueBinding =
            new SerialBinding(db.getSupplierValueFormat());
        DataBinding shipmentKeyBinding =
            new SerialBinding(db.getShipmentKeyFormat());
        DataBinding shipmentValueBinding =
            new SerialBinding(db.getShipmentValueFormat());

        // Create map views for all stores and indices.
        // StoredSortedMap is not used since the stores and indices are
        // ordered by serialized key objects, which do not provide a very
View Full Code Here

        // key/value data pair to a combined value object; a "tricky" binding
        // that uses transient fields is used--see PartBinding, etc, for
        // details.  For keys, a one-to-one binding is implemented with
        // DataBinding classes to bind the stored tuple data to a key Object.
        //
        DataBinding partKeyBinding =
            new MarshalledKeyBinding(db.getPartKeyFormat(), PartKey.class);
        EntityBinding partValueBinding =
            new MarshalledEntityBinding(db.getPartKeyFormat(),
                                        db.getPartValueFormat(),
                                        Part.class);
        DataBinding supplierKeyBinding =
            new MarshalledKeyBinding(db.getSupplierKeyFormat(),
                                     SupplierKey.class);
        EntityBinding supplierValueBinding =
            new MarshalledEntityBinding(db.getSupplierKeyFormat(),
                                        db.getSupplierValueFormat(),
                                        Supplier.class);
        DataBinding shipmentKeyBinding =
            new MarshalledKeyBinding(db.getShipmentKeyFormat(),
                                     ShipmentKey.class);
        EntityBinding shipmentValueBinding =
            new MarshalledEntityBinding(db.getShipmentKeyFormat(),
                                        db.getShipmentValueFormat(),
                                        Shipment.class);
        DataBinding cityKeyBinding =
            TupleBinding.getPrimitiveBinding(String.class,
                                             db.getCityKeyFormat());

        // Create map views for all stores and indices.
        // StoredSortedMap is used since the stores and indices are ordered
View Full Code Here

TOP

Related Classes of com.sleepycat.bdb.bind.DataBinding

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.