Package com.sleepycat.db

Examples of com.sleepycat.db.Db


        // method and no duplicate keys allowed.  Although the DB_BTREE method
        // provides ordered keys, the ordering of serialized key objects
        // is not very useful. Duplicate keys are not allowed for any entity
        // with indexes or foreign key relationships.
        //
        Db partDb = new Db(env, 0);
        partDb.open(null, PART_STORE, null, Db.DB_BTREE, flags, 0);
        partStore = new DataStore(partDb, partKeyFormat,
                                  partValueFormat, null);

        Db supplierDb = new Db(env, 0);
        supplierDb.open(null, SUPPLIER_STORE, null, Db.DB_BTREE, flags, 0);
        supplierStore = new DataStore(supplierDb, supplierKeyFormat,
                                      supplierValueFormat, null);

        Db shipmentDb = new Db(env, 0);
        shipmentDb.open(null, SHIPMENT_STORE, null, Db.DB_BTREE, flags, 0);
        shipmentStore = new DataStore(shipmentDb, shipmentKeyFormat,
                                      shipmentValueFormat, null);

        // 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
        // ForeignKeyIndex, for the part and supplier indices of the shipment
        // store.
        // In this sample, the indices are opened with the DB_BTREE access
        // method and sorted duplicate keys.  Although the DB_BTREE method
        // provides ordered keys, the ordering of serialized key objects
        // is not very useful. Duplicate keys are allowed since more than one
        // shipment may exist for the same supplier or part. For indices, if
        // duplicates are allowed they should always be sorted to allow for
        // efficient joins.
        //
        Db cityIndexDb = new Db(env, 0);
        cityIndexDb.setFlags(Db.DB_DUPSORT);
        cityIndexDb.open(null, SUPPLIER_CITY_INDEX, null, Db.DB_BTREE,
                         flags, 0);
        supplierByCityIndex = new DataIndex(supplierStore, cityIndexDb,
                                            cityKeyFormat, cityExtractor);

        Db partIndexDb = new Db(env, 0);
        partIndexDb.setFlags(Db.DB_DUPSORT);
        partIndexDb.open(null, SHIPMENT_PART_INDEX, null, Db.DB_BTREE,
                         flags, 0);
        shipmentByPartIndex = new ForeignKeyIndex(shipmentStore, partIndexDb,
                                            partExtractor, partStore,
                                            ForeignKeyIndex.ON_DELETE_CASCADE);

        Db supplierIndexDb = new Db(env, 0);
        supplierIndexDb.setFlags(Db.DB_DUPSORT);
        supplierIndexDb.open(null, SHIPMENT_SUPPLIER_INDEX, null, Db.DB_BTREE,
                             flags, 0);
        shipmentBySupplierIndex = new ForeignKeyIndex(shipmentStore,
                                        supplierIndexDb,
                                        supplierExtractor, supplierStore,
                                        ForeignKeyIndex.ON_DELETE_CASCADE);
View Full Code Here


        if (txn != null)
            openFlags &= ~Db.DB_AUTO_COMMIT;

        // open the catalog database

        Db db = new Db(env, 0);
        db.open(txn, file, database, Db.DB_BTREE, openFlags, 0);
        this.db = new DataDb(db);

        // create the class format and class info maps; note that these are not
        // synchronized, and therefore the methods that use them are
        // synchronized
View Full Code Here

        // method and no duplicate keys allowed.  The DB_BTREE method is used
        // to provide ordered keys, since ordering is meaningful when the tuple
        // data format is used.  Duplicate keys are not allowed for any entity
        // with indexes or foreign key relationships.
        //
        Db partDb = new Db(env, 0);
        partDb.open(null, PART_STORE, null, Db.DB_BTREE, flags, 0);
        partStore = new DataStore(partDb, partKeyFormat,
                                  partValueFormat, null);

        Db supplierDb = new Db(env, 0);
        supplierDb.open(null, SUPPLIER_STORE, null, Db.DB_BTREE, flags, 0);
        supplierStore = new DataStore(supplierDb, supplierKeyFormat,
                                      supplierValueFormat, null);

        Db shipmentDb = new Db(env, 0);
        shipmentDb.open(null, SHIPMENT_STORE, null, Db.DB_BTREE, flags, 0);
        shipmentStore = new DataStore(shipmentDb, shipmentKeyFormat,
                                      shipmentValueFormat, null);

        // 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
        // ForeignKeyIndex, for the part and supplier indices of the shipment
        // store.
        // In this sample, the indices are opened with the DB_BTREE access
        // method and sorted duplicate keys.  The DB_BTREE method is used to
        // provide ordered keys, since ordering is meaningful when the tuple
        // data format is used.  Duplicate keys are allowed since more than one
        // shipment may exist for the same supplier or part. For indices, if
        // duplicates are allowed they should always be sorted to allow for
        // efficient joins.
        //
        Db cityIndexDb = new Db(env, 0);
        cityIndexDb.setFlags(Db.DB_DUPSORT);
        cityIndexDb.open(null, SUPPLIER_CITY_INDEX, null,
                         Db.DB_BTREE, flags, 0);
        supplierByCityIndex = new DataIndex(supplierStore, cityIndexDb,
                                            cityKeyFormat, cityExtractor);

        Db partIndexDb = new Db(env, 0);
        partIndexDb.setFlags(Db.DB_DUPSORT);
        partIndexDb.open(null, SHIPMENT_PART_INDEX, null,
                         Db.DB_BTREE, flags, 0);
        shipmentByPartIndex = new ForeignKeyIndex(shipmentStore, partIndexDb,
                                            partExtractor, partStore,
                                            ForeignKeyIndex.ON_DELETE_CASCADE);

        Db supplierIndexDb = new Db(env, 0);
        supplierIndexDb.setFlags(Db.DB_DUPSORT);
        supplierIndexDb.open(null, SHIPMENT_SUPPLIER_INDEX, null,
                             Db.DB_BTREE, flags, 0);
        shipmentBySupplierIndex = new ForeignKeyIndex(shipmentStore,
                                            supplierIndexDb,
                                            supplierExtractor, supplierStore,
                                            ForeignKeyIndex.ON_DELETE_CASCADE);
View Full Code Here

        SerialFormat valueFormat =
            new SerialFormat(catalog, String.class);
        SerialBinding valueBinding = new SerialBinding(valueFormat);

        // open a BTREE (sorted) data store
        Db db = new Db(env, 0);
        db.open(null, "data.db", null, Db.DB_BTREE, dbFlags, 0);
        this.store = new DataStore(db, keyFormat, valueFormat, null);

        // create a map view of the data store
        this.map = new StoredSortedMap(store, keyBinding, valueBinding, true);
    }
View Full Code Here

        // method and no duplicate keys allowed.  Although the DB_BTREE method
        // provides ordered keys, the ordering of serialized key objects
        // is not very useful. Duplicate keys are not allowed for any entity
        // with indexes or foreign key relationships.
        //
        Db partDb = new Db(env, 0);
        partDb.open(null, PART_STORE, null, Db.DB_BTREE, flags, 0);
        partStore = new DataStore(partDb, partKeyFormat, partValueFormat,
                                  null);

        Db supplierDb = new Db(env, 0);
        supplierDb.open(null, SUPPLIER_STORE, null, Db.DB_BTREE, flags, 0);
        supplierStore = new DataStore(supplierDb, supplierKeyFormat,
                                      supplierValueFormat, null);

        Db shipmentDb = new Db(env, 0);
        shipmentDb.open(null, SHIPMENT_STORE, null, Db.DB_BTREE, flags, 0);
        shipmentStore = new DataStore(shipmentDb, shipmentKeyFormat,
                                      shipmentValueFormat, null);
    }
View Full Code Here

        // method and no duplicate keys allowed.  The DB_BTREE method is used
        // to provide ordered keys, since ordering is meaningful when the tuple
        // data format is used.  Duplicate keys are not allowed for any entity
        // with indexes or foreign key relationships.
        //
        Db partDb = new Db(env, 0);
        partDb.open(null, PART_STORE, null, Db.DB_BTREE, flags, 0);
        partStore = new DataStore(partDb, partKeyFormat,
                                  partValueFormat, null);

        Db supplierDb = new Db(env, 0);
        supplierDb.open(null, SUPPLIER_STORE, null, Db.DB_BTREE, flags, 0);
        supplierStore = new DataStore(supplierDb, supplierKeyFormat,
                                      supplierValueFormat, null);

        Db shipmentDb = new Db(env, 0);
        shipmentDb.open(null, SHIPMENT_STORE, null, Db.DB_BTREE, flags, 0);
        shipmentStore = new DataStore(shipmentDb, shipmentKeyFormat,
                                      shipmentValueFormat, null);

        // 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);

        // Open the Berkeley DB database, along with the associated
        // ForeignKeyIndex, for the part and supplier indices of the shipment
        // store.
        // In this sample, the indices are opened with the DB_BTREE access
        // method and sorted duplicate keys.  The DB_BTREE method is used to
        // provide ordered keys, since ordering is meaningful when the tuple
        // data format is used.  Duplicate keys are allowed since more than one
        // shipment may exist for the same supplier or part. For indices, if
        // duplicates are allowed they should always be sorted to allow for
        // efficient joins.
        //
        Db cityIndexDb = new Db(env, 0);
        cityIndexDb.setFlags(Db.DB_DUPSORT);
        cityIndexDb.open(null, SUPPLIER_CITY_INDEX, null, Db.DB_BTREE,
                         flags, 0);
        supplierByCityIndex = new DataIndex(supplierStore, cityIndexDb,
                                            cityKeyFormat, cityExtractor);

        Db partIndexDb = new Db(env, 0);
        partIndexDb.setFlags(Db.DB_DUPSORT);
        partIndexDb.open(null, SHIPMENT_PART_INDEX, null, Db.DB_BTREE,
                         flags, 0);
        shipmentByPartIndex = new ForeignKeyIndex(shipmentStore, partIndexDb,
                                            partExtractor, partStore,
                                            ForeignKeyIndex.ON_DELETE_CASCADE);

        Db supplierIndexDb = new Db(env, 0);
        supplierIndexDb.setFlags(Db.DB_DUPSORT);
        supplierIndexDb.open(null, SHIPMENT_SUPPLIER_INDEX, null, Db.DB_BTREE,
                             flags, 0);
        shipmentBySupplierIndex = new ForeignKeyIndex(shipmentStore,
                                        supplierIndexDb,
                                        supplierExtractor, supplierStore,
                                        ForeignKeyIndex.ON_DELETE_CASCADE);
View Full Code Here

        // method and no duplicate keys allowed.  Although the DB_BTREE method
        // provides ordered keys, the ordering of serialized key objects
        // is not very useful.  Duplicate keys are not allowed for any entity
        // with indexes or foreign key relationships.
        //
        Db partDb = new Db(env, 0);
        partDb.open(null, PART_STORE, null, Db.DB_BTREE, flags, 0);
        partStore = new DataStore(partDb, partKeyFormat, partValueFormat,
                                  null);

        Db supplierDb = new Db(env, 0);
        supplierDb.open(null, SUPPLIER_STORE, null, Db.DB_BTREE, flags, 0);
        supplierStore = new DataStore(supplierDb, supplierKeyFormat,
                                      supplierValueFormat, null);

        Db shipmentDb = new Db(env, 0);
        shipmentDb.open(null, SHIPMENT_STORE, null, Db.DB_BTREE, flags, 0);
        shipmentStore = new DataStore(shipmentDb, shipmentKeyFormat,
                                      shipmentValueFormat, null);

        // 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
        // ForeignKeyIndex, for the part and supplier indices of the shipment
        // store.
        // In this sample, the indices are opened with the DB_BTREE access
        // method and sorted duplicate keys.  Although the DB_BTREE method
        // provides ordered keys, the ordering of serialized key objects
        // is not very useful. Duplicate keys are allowed since more than one
        // shipment may exist for the same supplier or part. For indices, if
        // duplicates are allowed they should always be sorted to allow for
        // efficient joins.
        //
        Db cityIndexDb = new Db(env, 0);
        cityIndexDb.setFlags(Db.DB_DUPSORT);
        cityIndexDb.open(null, SUPPLIER_CITY_INDEX, null,
                         Db.DB_BTREE, flags, 0);
        supplierByCityIndex = new DataIndex(supplierStore, cityIndexDb,
                                        cityKeyFormat, cityExtractor);

        Db partIndexDb = new Db(env, 0);
        partIndexDb.setFlags(Db.DB_DUPSORT);
        partIndexDb.open(null, SHIPMENT_PART_INDEX, null,
                         Db.DB_BTREE, flags, 0);
        shipmentByPartIndex = new ForeignKeyIndex(shipmentStore, partIndexDb,
                                        partExtractor, partStore,
                                        ForeignKeyIndex.ON_DELETE_CASCADE);

        Db supplierIndexDb = new Db(env, 0);
        supplierIndexDb.setFlags(Db.DB_DUPSORT);
        supplierIndexDb.open(null, SHIPMENT_SUPPLIER_INDEX, null,
                             Db.DB_BTREE, flags, 0);
        shipmentBySupplierIndex = new ForeignKeyIndex(shipmentStore,
                                        supplierIndexDb,
                                        supplierExtractor, supplierStore,
                                        ForeignKeyIndex.ON_DELETE_CASCADE);
View Full Code Here

        // DataStore, for the part, supplier and shipment stores.
        // In this sample, the stores are opened as sorted and no duplicate
        // keys allowed.  Duplicate keys are not allowed for any entity
        // with indexes or foreign key relationships.
        //
        Db partDb = new Db(env, 0);
        partDb.open(null, PART_STORE, null, Db.DB_BTREE, flags, 0);
        partStore = factory.newDataStore(partDb, Part.class, null);

        Db supplierDb = new Db(env, 0);
        supplierDb.open(null, SUPPLIER_STORE, null, Db.DB_BTREE, flags, 0);
        supplierStore = factory.newDataStore(supplierDb, Supplier.class, null);

        Db shipmentDb = new Db(env, 0);
        shipmentDb.open(null, SHIPMENT_STORE, null, Db.DB_BTREE, flags, 0);
        shipmentStore = factory.newDataStore(shipmentDb, Shipment.class, null);

        // Open the ForeignKeyIndex, along with the associated the Berkeley
        // DB database, for the part and supplier indices of the shipment
        // store.
        // In this sample, the indices are opened with sorted duplicate
        // keys.  Duplicate keys are allowed since more than one shipment
        // may exist for the same supplier or part.
        //
        Db cityIndexDb = new Db(env, 0);
        cityIndexDb.setFlags(Db.DB_DUPSORT);
        cityIndexDb.open(null, SUPPLIER_CITY_INDEX, null, Db.DB_BTREE,
                         flags, 0);
        supplierByCityIndex = factory.newDataIndex(supplierStore,
                                            cityIndexDb, Supplier.CITY_KEY,
                                            false, true);

        Db partIndexDb = new Db(env, 0);
        partIndexDb.setFlags(Db.DB_DUPSORT);
        partIndexDb.open(null, SHIPMENT_PART_INDEX, null, Db.DB_BTREE,
                         flags, 0);
        shipmentByPartIndex = factory.newForeignKeyIndex(shipmentStore,
                                            partIndexDb, Shipment.PART_KEY,
                                            false, true, partStore,
                                            ForeignKeyIndex.ON_DELETE_CASCADE);

        Db supplierIndexDb = new Db(env, 0);
        supplierIndexDb.setFlags(Db.DB_DUPSORT);
        supplierIndexDb.open(null, SHIPMENT_SUPPLIER_INDEX, null, Db.DB_BTREE,
                             flags, 0);
        shipmentBySupplierIndex = factory.newForeignKeyIndex(shipmentStore,
                                            supplierIndexDb,
                                            Shipment.SUPPLIER_KEY,
                                            false, true, supplierStore,
View Full Code Here

        // method and no duplicate keys allowed.  The DB_BTREE method is used
        // to provide ordered keys, since ordering is meaningful when the tuple
        // data format is used.  Duplicate keys are not allowed for any entity
        // with indexes or foreign key relationships.
        //
        Db partDb = new Db(env, 0);
        partDb.open(null, PART_STORE, null, Db.DB_BTREE, flags, 0);
        partStore = new DataStore(partDb, partKeyFormat,
                                  partValueFormat, null);

        Db supplierDb = new Db(env, 0);
        supplierDb.open(null, SUPPLIER_STORE, null, Db.DB_BTREE, flags, 0);
        supplierStore = new DataStore(supplierDb, supplierKeyFormat,
                                      supplierValueFormat, null);

        Db shipmentDb = new Db(env, 0);
        shipmentDb.open(null, SHIPMENT_STORE, null, Db.DB_BTREE, flags, 0);
        shipmentStore = new DataStore(shipmentDb, shipmentKeyFormat,
                                      shipmentValueFormat, null);

        // 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
        // ForeignKeyIndex, for the part and supplier indices of the shipment
        // store.
        // In this sample, the indices are opened with the DB_BTREE access
        // method and sorted duplicate keys.  The DB_BTREE method is used to
        // provide ordered keys, since ordering is meaningful when the tuple
        // data format is used.  Duplicate keys are allowed since more than one
        // shipment may exist for the same supplier or part. For indices, if
        // duplicates are allowed they should always be sorted to allow for
        // efficient joins.
        //
        Db cityIndexDb = new Db(env, 0);
        cityIndexDb.setFlags(Db.DB_DUPSORT);
        cityIndexDb.open(null, SUPPLIER_CITY_INDEX, null, Db.DB_BTREE,
                         flags, 0);
        supplierByCityIndex = new DataIndex(supplierStore, cityIndexDb,
                                            cityKeyFormat, cityExtractor);

        Db partIndexDb = new Db(env, 0);
        partIndexDb.setFlags(Db.DB_DUPSORT);
        partIndexDb.open(null, SHIPMENT_PART_INDEX, null, Db.DB_BTREE,
                         flags, 0);
        shipmentByPartIndex = new ForeignKeyIndex(shipmentStore, partIndexDb,
                                            partExtractor, partStore,
                                            ForeignKeyIndex.ON_DELETE_CASCADE);

        Db supplierIndexDb = new Db(env, 0);
        supplierIndexDb.setFlags(Db.DB_DUPSORT);
        supplierIndexDb.open(null, SHIPMENT_SUPPLIER_INDEX, null, Db.DB_BTREE,
                             flags, 0);
        shipmentBySupplierIndex = new ForeignKeyIndex(shipmentStore,
                                            supplierIndexDb,
                                            supplierExtractor, supplierStore,
                                            ForeignKeyIndex.ON_DELETE_CASCADE);
View Full Code Here

        return env;
    }

    public static Db open(DbEnv environment, String name, boolean isQueue) throws FileNotFoundException, DbException, JMSException {
        int flags = Db.DB_CREATE; // | Db.DB_AUTO_COMMIT
        Db db = new Db(environment, 0);

        if (isQueue) {
            db.setFlags(Db.DB_RENUMBER);
        }
        //  only use Db.DB_RECNUM for list tables as its a performance hog
        int type = Db.DB_BTREE;
        if (isQueue) {
            type = Db.DB_RECNO;
        }
        String databaseName = null;
        DbTxn transaction = createTransaction(environment);
        try {
            db.open(transaction, name, databaseName, type, flags, 0);
            transaction = commitTransaction(transaction);
        }
        finally {
            rollbackTransaction(transaction);
        }
View Full Code Here

TOP

Related Classes of com.sleepycat.db.Db

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.