Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*-
   * See the file LICENSE for redistribution information.
   *
   * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
   *
   */
  
  package com.sleepycat.persist.impl;
  
A persistence key binding for a given key class.

Author(s):
Mark Hayes
 
 public class PersistKeyBinding implements EntryBinding {
 
     /* See Store.refresh for an explanation of the use of volatile fields. */
     volatile Catalog catalog;
     volatile Format keyFormat;
     final boolean rawAccess;

    
Creates a key binding for a given key class.
 
     public PersistKeyBinding(Catalog catalogParam,
                              String clsName,
                              boolean rawAccess) {
          = catalogParam;
         try {
              = PersistEntityBinding.getOrCreateFormat
                 (clsNamerawAccess);
         } catch (RefreshException e) {
             /* Must assign catalog field in constructor. */
              = e.refresh();
             try {
                  = PersistEntityBinding.getOrCreateFormat
                     (clsNamerawAccess);
             } catch (RefreshException e2) {
                 throw DbCompat.unexpectedException(e2);
             }
         }
         if (!.isSimple() &&
             !.isEnum() &&
             !(.getClassMetadata() != null &&
               .getClassMetadata().getCompositeKeyFields() != null)) {
             throw new IllegalArgumentException
                 ("Key class is not a simple type, an enum, or a composite " +
                  "key class (composite keys must include @KeyField " +
                  "annotations): " +
                  clsName);
         }
         this. = rawAccess;
     }

    
Creates a key binding dynamically for use by PersistComparator. Formats are created from scratch rather than using a shared catalog.
 
     PersistKeyBinding(final Catalog catalog,
                       final Class cls,
                       final String[] compositeFieldOrder) {
         this. = catalog;
          = new CompositeKeyFormat(catalogclscompositeFieldOrder);
         .initializeIfNeeded(catalognull /*model*/);
          = false;
     }

    
Binds bytes to an object for use by PersistComparator as well as entryToObject.
 
     Object bytesToObject(byte[] bytesint offsetint length)
         throws RefreshException {
 
         return readKey(bytesoffsetlength);
     }

    
Binds bytes to an object for use by PersistComparator as well as entryToObject.
 
     static Object readKey(Format keyFormat,
                           Catalog catalog,
                           byte[] bytes,
                           int offset,
                           int length,
                           boolean rawAccess)
         throws RefreshException {
 
         EntityInput input = new RecordInput
             (catalograwAccessnull, 0, bytesoffsetlength);
         return input.readKeyObject(keyFormat);
     }
 
    public Object entryToObject(DatabaseEntry entry) {
        try {
            return entryToObjectInternal(entry);
        } catch (RefreshException e) {
            e.refresh();
            try {
                return entryToObjectInternal(entry);
            } catch (RefreshException e2) {
                throw DbCompat.unexpectedException(e2);
            }
        }
    }
        throws RefreshException {
        return bytesToObject
            (entry.getData(), entry.getOffset(), entry.getSize());
    }
    public void objectToEntry(Object objectDatabaseEntry entry) {
        try {
            objectToEntryInternal(objectentry);
        } catch (RefreshException e) {
            e.refresh();
            try {
                objectToEntryInternal(objectentry);
            } catch (RefreshException e2) {
                throw DbCompat.unexpectedException(e2);
            }
        }
    }
    private void objectToEntryInternal(Object objectDatabaseEntry entry)
        throws RefreshException {
        RecordOutput output = new RecordOutput();
        output.writeKeyObject(object);
        TupleBase.outputToEntry(outputentry);
    }

    
See Store.refresh.
    void refresh(final PersistCatalog newCatalog) {
         = newCatalog;
    }
New to GrepCode? Check out our FAQ X