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;
  
 import java.util.List;
 import java.util.Map;
 
Implements Accessor for a complex persistent class.

Author(s):
Mark Hayes
 
 public class EnhancedAccessor implements Accessor {
 
     private static final Map<StringEnhancedclassRegistry =
         Collections.synchronizedMap(new HashMap<StringEnhanced>());
 
     /* Is public for unit tests. */
     public static final boolean EXPECT_ENHANCED =
         "true".equals(System.getProperty("expectEnhanced"));
 
     private Enhanced prototype;
     private Format priKeyFormat;
     private Format[] compositeKeyFormats
     private Class type;

    
Registers a prototype instance, and should be called during initialization of the prototype class. The prototype may be null for an abstract class.
 
     public static void registerClass(String classNameEnhanced prototype) {
         .put(classNameprototype);
     }

    
Returns whether a given class is a (registered) enhanced class.
 
     static boolean isEnhanced(Class type) {
         boolean enhanced = .containsKey(type.getName());
         if (!enhanced && ) {
             throw new IllegalStateException
                 ("Test was run with expectEnhanced=true but class " +
                  type.getName() + " is not enhanced");
         }
         return enhanced;
     }
 
     private EnhancedAccessor(Class type) {
         this. = type;
          = .get(type.getName());
         assert  != null || Modifier.isAbstract(type.getModifiers());
     }

    
Creates an accessor for a complex type.
 
     EnhancedAccessor(Catalog catalogClass typeComplexFormat format) {
         this(type);
 
         /*
          * Find the primary key format for this format or one of its superclass
          * formats.
          */
         ComplexFormat declaringFormat = format;
         while (declaringFormat != null) {
             FieldInfo priKeyField = declaringFormat.getPriKeyFieldInfo();
             if (priKeyField != null) {
                  = catalog.getFormat(priKeyField.getClassName());
                 break;
             } else {
                 declaringFormat = declaringFormat.getComplexSuper();
             }
         }
     }

    
Creates an accessor for a composite key type.
 
     EnhancedAccessor(Catalog catalogClass typeList<FieldInfofieldInfos) {
         this(type);
         final int nFields = fieldInfos.size();
          = new Format[nFields];
         for (int i = 0; i < nFieldsi += 1) {
             [i] =
                 catalog.getFormat(fieldInfos.get(i).getClassName());
         }
     }
    public Object newInstance() {
        if ( == null) {
            /* Abstract class -- internal error. */
            throw DbCompat.unexpectedState();
        }
        return .bdbNewInstance();
    }
    public Object newArray(int len) {
        if ( == null) {
            /* Abstract class -- use reflection for now. */
            return Array.newInstance(len);
        }
        return .bdbNewArray(len);
    }
    public boolean isPriKeyFieldNullOrZero(Object o) {
        if ( == null) {
            throw DbCompat.unexpectedState
                ("No primary key: " + o.getClass().getName());
        }
        return ((Enhancedo).bdbIsPriKeyFieldNullOrZero();
    }
    public void writePriKeyField(Object oEntityOutput output)
        throws RefreshException {
        if ( == null) {
            throw DbCompat.unexpectedState
                ("No primary key: " + o.getClass().getName());
        }
        ((Enhancedo).bdbWritePriKeyField(output);
    }
    public void readPriKeyField(Object oEntityInput input)
        throws RefreshException {
        if ( == null) {
            throw DbCompat.unexpectedState
                ("No primary key: " + o.getClass().getName());
        }
        ((Enhancedo).bdbReadPriKeyField(input);
    }
    public void writeSecKeyFields(Object oEntityOutput output)
        throws RefreshException {
        ((Enhancedo).bdbWriteSecKeyFields(output);
    }
    public void readSecKeyFields(Object o,
                                 EntityInput input,
                                 int startField,
                                 int endField,
                                 int superLevel)
        throws RefreshException {
        ((Enhancedo).bdbReadSecKeyFields
            (inputstartFieldendFieldsuperLevel);
    }
    public void writeNonKeyFields(Object oEntityOutput output)
        throws RefreshException {
        ((Enhancedo).bdbWriteNonKeyFields(output);
    }
    public void readNonKeyFields(Object o,
                                 EntityInput input,
                                 int startField,
                                 int endField,
                                 int superLevel)
        throws RefreshException {
        ((Enhancedo).bdbReadNonKeyFields
            (inputstartFieldendFieldsuperLevel);
    }
    public void writeCompositeKeyFields(Object oEntityOutput output)
        throws RefreshException {
    }
    public void readCompositeKeyFields(Object oEntityInput input)
        throws RefreshException {
    }
    public Object getField(Object o,
                           int field,
                           int superLevel,
                           boolean isSecField) {
        return ((Enhancedo).bdbGetField(ofieldsuperLevelisSecField);
    }
    public void setField(Object o,
                         int field,
                         int superLevel,
                         boolean isSecField,
                         Object value) {
        ((Enhancedo).bdbSetField(ofieldsuperLevelisSecFieldvalue);
    }
    
    public void setPriField(Object oObject value) {
        ((Enhancedo).bdbSetPriField(ovalue);
    }
New to GrepCode? Check out our FAQ X