Exemplo n.º 1
0
  /** Create the data bindings and collection views. */
  public SampleViews(SampleDatabase db) {

    // In this sample, the stored key and data entries are used directly
    // rather than mapping them to separate objects. Therefore, no binding
    // classes are defined here and the SerialBinding class is used.
    //
    ClassCatalog catalog = db.getClassCatalog();
    EntryBinding partKeyBinding = new SerialBinding(catalog, PartKey.class);
    EntryBinding partDataBinding = new SerialBinding(catalog, PartData.class);
    EntryBinding supplierKeyBinding = new SerialBinding(catalog, SupplierKey.class);
    EntryBinding supplierDataBinding = new SerialBinding(catalog, SupplierData.class);
    EntryBinding shipmentKeyBinding = new SerialBinding(catalog, ShipmentKey.class);
    EntryBinding shipmentDataBinding = new SerialBinding(catalog, ShipmentData.class);

    // 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
    // useful ordering.
    //
    partMap = new StoredMap(db.getPartDatabase(), partKeyBinding, partDataBinding, true);
    supplierMap =
        new StoredMap(db.getSupplierDatabase(), supplierKeyBinding, supplierDataBinding, true);
    shipmentMap =
        new StoredMap(db.getShipmentDatabase(), shipmentKeyBinding, shipmentDataBinding, true);
  }
Exemplo n.º 2
0
  /** Create the data bindings and collection views. */
  public SampleViews(SampleDatabase db) {

    // Create the data bindings.
    // In this sample, EntityBinding classes are used to bind the stored
    // key/data entry pair to a combined data 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
    // EntryBinding classes to bind the stored tuple entry to a key Object.
    //
    ClassCatalog catalog = db.getClassCatalog();
    EntryBinding partKeyBinding = new PartKeyBinding();
    EntityBinding partDataBinding = new PartBinding(catalog, Part.class);
    EntryBinding supplierKeyBinding = new SupplierKeyBinding();
    EntityBinding supplierDataBinding = new SupplierBinding(catalog, Supplier.class);
    EntryBinding shipmentKeyBinding = new ShipmentKeyBinding();
    EntityBinding shipmentDataBinding = new ShipmentBinding(catalog, Shipment.class);
    EntryBinding cityKeyBinding = TupleBinding.getPrimitiveBinding(String.class);

    // Create map views for all stores and indices.
    // StoredSortedMap is used since the stores and indices are ordered
    // (they use the DB_BTREE access method).
    //
    partMap = new StoredSortedMap(db.getPartDatabase(), partKeyBinding, partDataBinding, true);
    supplierMap =
        new StoredSortedMap(
            db.getSupplierDatabase(), supplierKeyBinding, supplierDataBinding, true);
    shipmentMap =
        new StoredSortedMap(
            db.getShipmentDatabase(), shipmentKeyBinding, shipmentDataBinding, true);
    shipmentByPartMap =
        new StoredSortedMap(
            db.getShipmentByPartDatabase(), partKeyBinding, shipmentDataBinding, true);
    shipmentBySupplierMap =
        new StoredSortedMap(
            db.getShipmentBySupplierDatabase(), supplierKeyBinding, shipmentDataBinding, true);
    supplierByCityMap =
        new StoredSortedMap(
            db.getSupplierByCityDatabase(), cityKeyBinding, supplierDataBinding, true);
  }
Exemplo n.º 3
0
  /**
   * Run two transactions to populate and print the database. A TransactionRunner is used to ensure
   * consistent handling of transactions, including deadlock retries. But the best transaction
   * handling mechanism to use depends on the application.
   */
  private void run() throws Exception {

    TransactionRunner runner = new TransactionRunner(db.getEnvironment());
    runner.run(new PopulateDatabase());
    runner.run(new PrintDatabase());
  }
Exemplo n.º 4
0
  /** Close the database cleanly. */
  private void close() throws DatabaseException {

    db.close();
  }