Package com.sleepycat.bdb.bind

Examples of com.sleepycat.bdb.bind.KeyExtractor


        SerialFormat keyFormat = new SerialFormat(catalog, String.class);
        SerialFormat valueFormat = new SerialFormat(catalog, String.class);
        SerialFormat indexKeyFormat = new SerialFormat(catalog, String.class);
        EntityBinding binding = new MySerialSerialBinding(keyFormat,
                                                          valueFormat);
        KeyExtractor extractor = new MySerialSerialExtractor(keyFormat,
                                                             valueFormat,
                                                             indexKeyFormat);
        assertSame(keyFormat, extractor.getPrimaryKeyFormat());
        assertSame(valueFormat, extractor.getValueFormat());
        assertSame(indexKeyFormat, extractor.getIndexKeyFormat());

        String val = "key#value?indexKey";
        binding.objectToValue(val, buffer);
        binding.objectToKey(val, keyBuffer);

        extractor.extractIndexKey(keyBuffer, buffer, indexKeyBuffer);
        assertEquals("indexKey", indexKeyFormat.dataToObject(indexKeyBuffer));

        extractor.clearIndexKey(buffer);
        extractor.extractIndexKey(keyBuffer, buffer, indexKeyBuffer);
        assertEquals(0, indexKeyBuffer.getDataLength());
    }
View Full Code Here


                                                    MarshalledObject.class);
        TupleFormat indexKeyFormat = new TupleFormat();
        TupleSerialMarshalledBinding binding =
            new TupleSerialMarshalledBinding(keyFormat, valueFormat);

        KeyExtractor extractor =
            new TupleSerialMarshalledKeyExtractor(binding, indexKeyFormat, "1",
                                                  false, true);
        assertSame(valueFormat, extractor.getValueFormat());
        assertNull(extractor.getPrimaryKeyFormat());
        assertSame(indexKeyFormat, extractor.getIndexKeyFormat());

        MarshalledObject val = new MarshalledObject("abc", "primary",
                                                    "index1", "index2");
        binding.objectToValue(val, buffer);
        binding.objectToKey(val, keyBuffer);

        extractor.extractIndexKey(keyBuffer, buffer, indexKeyBuffer);
        TupleInput in = indexKeyFormat.dataToInput(indexKeyBuffer);
        assertEquals("index1", in.readString());

        extractor.clearIndexKey(buffer);
        extractor.extractIndexKey(keyBuffer, buffer, indexKeyBuffer);
        assertEquals(0, indexKeyBuffer.getDataLength());
    }
View Full Code Here

                throw new UnsupportedOperationException(
                    "null key, null index, and null entity binding");
            }
            entityBinding.objectToKey(value, keyThang);
        } else {
            KeyExtractor extractor = index.getKeyExtractor();
            DataThang primaryKeyThang = null;
            DataThang valueThang = null;
            if (entityBinding != null) {
                if (extractor.getPrimaryKeyFormat() != null) {
                    primaryKeyThang = new DataThang();
                    entityBinding.objectToKey(value, primaryKeyThang);
                }
                if (extractor.getValueFormat() != null) {
                    valueThang = new DataThang();
                    entityBinding.objectToValue(value, valueThang);
                }
            } else {
                if (extractor.getPrimaryKeyFormat() != null) {
                    throw new IllegalStateException(
                        "primary key needed by index extractor");
                }
                if (extractor.getValueFormat() != null) {
                    valueThang = new DataThang();
                    valueBinding.objectToData(value, valueThang);
                }
            }
            extractor.extractIndexKey(primaryKeyThang, valueThang, keyThang);
        }
        if (checkRange != null) {
            return checkRange.check(keyThang) ? 0 : Db.DB_NOTFOUND;
        } else {
            return 0;
View Full Code Here

    public boolean canDeriveKeyFromValue() {

        if (index == null) {
            return (entityBinding != null);
        } else {
            KeyExtractor extractor = index.getKeyExtractor();
            if (extractor.getPrimaryKeyFormat() != null &&
                entityBinding == null) {
                return false;
            } else if (extractor.getValueFormat() != null &&
                     entityBinding == null && valueBinding == null) {
                return false;
            } else {
                return true;
            }
View Full Code Here

        throws IOException {

        TupleTupleMarshalledBinding binding =
            new TupleTupleMarshalledBinding(keyFormat, format,
                                            MarshalledObject.class);
        KeyExtractor extractor =
            new TupleTupleMarshalledKeyExtractor(binding, indexKeyFormat, "1",
                                                 false, true);
        assertSame(format, extractor.getValueFormat());
        assertNull(extractor.getPrimaryKeyFormat());
        assertSame(indexKeyFormat, extractor.getIndexKeyFormat());

        MarshalledObject val = new MarshalledObject("abc", "primary",
                                                    "index1", "index2");
        binding.objectToValue(val, buffer);
        binding.objectToKey(val, keyBuffer);

        extractor.extractIndexKey(keyBuffer, buffer, indexKeyBuffer);
        TupleInput in = indexKeyFormat.dataToInput(indexKeyBuffer);
        assertEquals("index1", in.readString());

        extractor.clearIndexKey(buffer);
        extractor.extractIndexKey(keyBuffer, buffer, indexKeyBuffer);
        assertEquals(0, indexKeyBuffer.getDataLength());
    }
View Full Code Here

        // Create the KeyExtractor objects for the part and supplier
        // indices of the shipment store.  Each key extractor object defines
        // its associated index, since it is responsible for mapping between
        // the indexed value and the index key.
        //
        KeyExtractor cityExtractor = new SupplierByCityExtractor(
                                                    supplierKeyFormat,
                                                    supplierValueFormat,
                                                    cityKeyFormat);
        KeyExtractor partExtractor = new ShipmentByPartExtractor(
                                                    shipmentKeyFormat,
                                                    shipmentValueFormat,
                                                    partKeyFormat);
        KeyExtractor supplierExtractor = new ShipmentBySupplierExtractor(
                                                    shipmentKeyFormat,
                                                    shipmentValueFormat,
                                                    supplierKeyFormat);

        // Open the Berkeley DB database, along with the associated
View Full Code Here

        // Create the KeyExtractor objects for the part and supplier
        // indices of the shipment store.  Each key extractor object defines
        // its associated index, since it is responsible for mapping between
        // the indexed value and the index key.
        //
        KeyExtractor cityExtractor = new MarshalledKeyExtractor(
                                                    supplierKeyFormat,
                                                    supplierValueFormat,
                                                    cityKeyFormat,
                                                    Supplier.CITY_KEY);
        KeyExtractor partExtractor = new MarshalledKeyExtractor(
                                                    shipmentKeyFormat,
                                                    shipmentValueFormat,
                                                    partKeyFormat,
                                                    Shipment.PART_KEY);
        KeyExtractor supplierExtractor = new MarshalledKeyExtractor(
                                                    shipmentKeyFormat,
                                                    shipmentValueFormat,
                                                    supplierKeyFormat,
                                                    Shipment.SUPPLIER_KEY);
View Full Code Here

        // Create the KeyExtractor objects for the three indices.
        // Each key extractor object defines its associated index, since it is
        // responsible for mapping between the indexed value and the index key.
        //
        KeyExtractor cityExtractor = new SupplierByCityExtractor(
                                                    supplierKeyFormat,
                                                    supplierValueFormat,
                                                    cityKeyFormat);
        KeyExtractor partExtractor = new ShipmentByPartExtractor(
                                                    shipmentKeyFormat,
                                                    shipmentValueFormat,
                                                    partKeyFormat);
        KeyExtractor supplierExtractor = new ShipmentBySupplierExtractor(
                                                    shipmentKeyFormat,
                                                    shipmentValueFormat,
                                                    supplierKeyFormat);

        // Open the Berkeley DB database, along with the associated
View Full Code Here

        // Create the KeyExtractor objects for the part and supplier
        // indices of the shipment store.  Each key extractor object defines
        // its associated index, since it is responsible for mapping between
        // the indexed value and the index key.
        //
        KeyExtractor cityExtractor = new SupplierByCityExtractor(
                                                    supplierKeyFormat,
                                                    supplierValueFormat,
                                                    cityKeyFormat);
        KeyExtractor partExtractor = new ShipmentByPartExtractor(
                                                    shipmentKeyFormat,
                                                    shipmentValueFormat,
                                                    partKeyFormat);
        KeyExtractor supplierExtractor = new ShipmentBySupplierExtractor(
                                                    shipmentKeyFormat,
                                                    shipmentValueFormat,
                                                    supplierKeyFormat);

        // Open the Berkeley DB database, along with the associated
View Full Code Here

        // Create the KeyExtractor objects for the part and supplier
        // indices of the shipment store.  Each key extractor object defines
        // its associated index, since it is responsible for mapping between
        // the indexed value and the index key.
        //
        KeyExtractor cityExtractor = new SupplierByCityExtractor(
                                                    supplierKeyFormat,
                                                    supplierValueFormat,
                                                    cityKeyFormat);
        KeyExtractor partExtractor = new ShipmentByPartExtractor(
                                                    shipmentKeyFormat,
                                                    shipmentValueFormat,
                                                    partKeyFormat);
        KeyExtractor supplierExtractor = new ShipmentBySupplierExtractor(
                                                    shipmentKeyFormat,
                                                    shipmentValueFormat,
                                                    supplierKeyFormat);

        // Open the Berkeley DB database, along with the associated
View Full Code Here

TOP

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

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.