Example #1
0
 /**
  * public void bdbSetField(Object o, int field, int superLevel, boolean isSecField, Object value)
  * { if (superLevel > 0) { // if has superclass: super.bdbSetField (o, field, superLevel - 1,
  * isSecField, value); } else if (isSecField) { switch (field) { case 0: f2 = ((Integer)
  * value).intValue(); case 1: f3 = (String) value; case 2: f4 = (String) value; } } else { switch
  * (field) { case 0: f5 = ((Integer) value).intValue(); case 1: f6 = (String) value; case 2: f7 =
  * (String) value; } } }
  */
 private void genBdbSetField() {
   MethodVisitor mv =
       cv.visitMethod(
           ACC_PUBLIC, "bdbSetField", "(Ljava/lang/Object;IIZLjava/lang/Object;)V", null, null);
   mv.visitCode();
   mv.visitVarInsn(ILOAD, 3);
   Label l0 = new Label();
   mv.visitJumpInsn(IFLE, l0);
   if (hasPersistentSuperclass) {
     mv.visitVarInsn(ALOAD, 0);
     mv.visitVarInsn(ALOAD, 1);
     mv.visitVarInsn(ILOAD, 2);
     mv.visitVarInsn(ILOAD, 3);
     mv.visitInsn(ICONST_1);
     mv.visitInsn(ISUB);
     mv.visitVarInsn(ILOAD, 4);
     mv.visitVarInsn(ALOAD, 5);
     mv.visitMethodInsn(
         INVOKESPECIAL, className, "bdbSetField", "(Ljava/lang/Object;IIZLjava/lang/Object;)V");
   }
   mv.visitInsn(RETURN);
   mv.visitLabel(l0);
   mv.visitVarInsn(ILOAD, 4);
   Label l2 = new Label();
   mv.visitJumpInsn(IFEQ, l2);
   Label l1 = new Label();
   genSetFieldSwitch(mv, secKeyFields, l1);
   mv.visitLabel(l2);
   genSetFieldSwitch(mv, nonKeyFields, l1);
   mv.visitLabel(l1);
   mv.visitInsn(RETURN);
   mv.visitMaxs(2, 6);
   mv.visitEnd();
 }
Example #2
0
 /**
  * public void bdbWriteNonKeyFields(EntityOutput output) { super.bdbWriteNonKeyFields(output); //
  * if has super output.writeInt(nonKeyField1); output.writeObject(nonKeyField2, null); // etc }
  */
 private void genBdbWriteNonKeyFields() {
   MethodVisitor mv =
       cv.visitMethod(
           ACC_PUBLIC,
           "bdbWriteNonKeyFields",
           "(Lcom/sleepycat/persist/impl/EntityOutput;)V",
           null,
           null);
   mv.visitCode();
   if (hasPersistentSuperclass) {
     mv.visitVarInsn(ALOAD, 0);
     mv.visitVarInsn(ALOAD, 1);
     mv.visitMethodInsn(
         INVOKESPECIAL,
         superclassName,
         "bdbWriteNonKeyFields",
         "(Lcom/sleepycat/persist/impl/EntityOutput;)V");
   }
   if (isCompositeKey) {
     for (FieldInfo field : nonKeyFields) {
       genWriteSimpleKeyField(mv, field);
       /* Ignore non-simple (illegal) types for composite key. */
     }
   } else {
     for (FieldInfo field : nonKeyFields) {
       genWriteField(mv, field);
     }
   }
   mv.visitInsn(RETURN);
   mv.visitMaxs(2, 2);
   mv.visitEnd();
 }
Example #3
0
 /**
  * public void bdbWriteSecKeyFields(EntityOutput output) {
  * output.registerPriKeyObject(priKeyField); // if an object
  * super.bdbWriteSecKeyFields(EntityOutput output); // if has super output.writeInt(secKeyField1);
  * output.writeObject(secKeyField2, null); // etc }
  */
 private void genBdbWriteSecKeyFields() {
   MethodVisitor mv =
       cv.visitMethod(
           ACC_PUBLIC,
           "bdbWriteSecKeyFields",
           "(Lcom/sleepycat/persist/impl/EntityOutput;)V",
           null,
           null);
   mv.visitCode();
   if (priKeyField != null && isRefType(priKeyField.type)) {
     genRegisterPrimaryKey(mv, false);
   }
   if (hasPersistentSuperclass) {
     mv.visitVarInsn(ALOAD, 0);
     mv.visitVarInsn(ALOAD, 1);
     mv.visitMethodInsn(
         INVOKESPECIAL,
         superclassName,
         "bdbWriteSecKeyFields",
         "(Lcom/sleepycat/persist/impl/EntityOutput;)V");
   }
   for (FieldInfo field : secKeyFields) {
     genWriteField(mv, field);
   }
   mv.visitInsn(RETURN);
   mv.visitMaxs(2, 2);
   mv.visitEnd();
 }
Example #4
0
 /**
  * public boolean bdbIsPriKeyFieldNullOrZero() { return theField == null; // or zero or false, as
  * appropriate // or if no primary key but has superclass: return
  * super.bdbIsPriKeyFieldNullOrZero(); }
  */
 private void genBdbIsPriKeyFieldNullOrZero() {
   MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "bdbIsPriKeyFieldNullOrZero", "()Z", null, null);
   mv.visitCode();
   if (priKeyField != null) {
     mv.visitVarInsn(ALOAD, 0);
     mv.visitFieldInsn(GETFIELD, className, priKeyField.name, priKeyField.type.getDescriptor());
     Label l0 = new Label();
     if (isRefType(priKeyField.type)) {
       mv.visitJumpInsn(IFNONNULL, l0);
     } else {
       genBeforeCompareToZero(mv, priKeyField.type);
       mv.visitJumpInsn(IFNE, l0);
     }
     mv.visitInsn(ICONST_1);
     Label l1 = new Label();
     mv.visitJumpInsn(GOTO, l1);
     mv.visitLabel(l0);
     mv.visitInsn(ICONST_0);
     mv.visitLabel(l1);
   } else if (hasPersistentSuperclass) {
     mv.visitVarInsn(ALOAD, 0);
     mv.visitMethodInsn(INVOKESPECIAL, superclassName, "bdbIsPriKeyFieldNullOrZero", "()Z");
   } else {
     mv.visitInsn(ICONST_0);
   }
   mv.visitInsn(IRETURN);
   mv.visitMaxs(1, 1);
   mv.visitEnd();
 }
Example #5
0
 /**
  * public Object bdbNewArray(int len) { return new TheClass[len]; // or if abstract: return null;
  * }
  */
 private void genBdbNewArray() {
   MethodVisitor mv =
       cv.visitMethod(ACC_PUBLIC, "bdbNewArray", "(I)Ljava/lang/Object;", null, null);
   mv.visitCode();
   if (isAbstract) {
     mv.visitInsn(ACONST_NULL);
     mv.visitInsn(ARETURN);
     mv.visitMaxs(1, 2);
   } else {
     mv.visitVarInsn(ILOAD, 1);
     mv.visitTypeInsn(ANEWARRAY, className);
     mv.visitInsn(ARETURN);
     mv.visitMaxs(1, 2);
     mv.visitEnd();
   }
 }
Example #6
0
 /** public Object bdbNewInstance() { return new TheClass(); // or if abstract: return null; } */
 private void genBdbNewInstance() {
   MethodVisitor mv =
       cv.visitMethod(ACC_PUBLIC, "bdbNewInstance", "()Ljava/lang/Object;", null, null);
   mv.visitCode();
   if (isAbstract) {
     mv.visitInsn(ACONST_NULL);
     mv.visitInsn(ARETURN);
     mv.visitMaxs(1, 1);
   } else {
     mv.visitTypeInsn(NEW, className);
     mv.visitInsn(DUP);
     mv.visitMethodInsn(INVOKESPECIAL, className, "<init>", "()V");
     mv.visitInsn(ARETURN);
     mv.visitMaxs(2, 1);
   }
   mv.visitEnd();
 }
Example #7
0
 /**
  * public void bdbReadSecKeyFields(EntityInput input, int startField, int endField, int
  * superLevel) { input.registerPriKeyObject(priKeyField); // if an object // if has super: if
  * (superLevel != 0) { super.bdbReadSecKeyFields(..., superLevel - 1); } if (superLevel <= 0) {
  * switch (startField) { case 0: secKeyField1 = input.readInt(); if (endField == 0) break; case 1:
  * secKeyField2 = (String) input.readObject(); if (endField == 1) break; case 2: secKeyField3 =
  * input.readInt(); } } }
  */
 private void genBdbReadSecKeyFields() {
   MethodVisitor mv =
       cv.visitMethod(
           ACC_PUBLIC,
           "bdbReadSecKeyFields",
           "(Lcom/sleepycat/persist/impl/EntityInput;III)V",
           null,
           null);
   mv.visitCode();
   if (priKeyField != null && isRefType(priKeyField.type)) {
     genRegisterPrimaryKey(mv, true);
   }
   genReadSuperKeyFields(mv, true);
   genReadFieldSwitch(mv, secKeyFields);
   mv.visitInsn(RETURN);
   mv.visitMaxs(5, 5);
   mv.visitEnd();
 }
Example #8
0
 /**
  * public void bdbReadNonKeyFields(EntityInput input, int startField, int endField, int
  * superLevel) { // if has super: if (superLevel != 0) { super.bdbReadNonKeyFields(..., superLevel
  * - 1); } nonKeyField1 = input.readInt(); nonKeyField2 = (String) input.readObject(); // etc //
  * or like bdbReadSecKeyFields if not a composite key class }
  */
 private void genBdbReadNonKeyFields() {
   MethodVisitor mv =
       cv.visitMethod(
           ACC_PUBLIC,
           "bdbReadNonKeyFields",
           "(Lcom/sleepycat/persist/impl/EntityInput;III)V",
           null,
           null);
   mv.visitCode();
   if (isCompositeKey) {
     for (FieldInfo field : nonKeyFields) {
       genReadSimpleKeyField(mv, field);
       /* Ignore non-simple (illegal) types for composite key. */
     }
   } else {
     genReadSuperKeyFields(mv, false);
     genReadFieldSwitch(mv, nonKeyFields);
   }
   mv.visitInsn(RETURN);
   mv.visitMaxs(5, 5);
   mv.visitEnd();
 }
Example #9
0
 /**
  * Outputs code in a static block to register the prototype instance:
  *
  * <p>static { EnhancedAccessor.registerClass(TheClassName, new TheClass()); // or for an abstract
  * class: EnhancedAccessor.registerClass(TheClassName, null); }
  */
 private void genStaticBlock() {
   MethodVisitor mv = cv.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null);
   mv.visitCode();
   if (staticBlockMethod != null) {
     mv.visitMethodInsn(INVOKESTATIC, className, staticBlockMethod, "()V");
   }
   mv.visitLdcInsn(className.replace('/', '.'));
   if (isAbstract) {
     mv.visitInsn(ACONST_NULL);
   } else {
     mv.visitTypeInsn(NEW, className);
     mv.visitInsn(DUP);
     mv.visitMethodInsn(INVOKESPECIAL, className, "<init>", "()V");
   }
   mv.visitMethodInsn(
       INVOKESTATIC,
       "com/sleepycat/persist/impl/EnhancedAccessor",
       "registerClass",
       "(Ljava/lang/String;Lcom/sleepycat/persist/impl/Enhanced;)V");
   mv.visitInsn(RETURN);
   mv.visitMaxs(3, 0);
   mv.visitEnd();
 }
Example #10
0
 /**
  * public void bdbReadPriKeyField(EntityInput input, Format format) { theField = (TheFieldClass)
  * input.readKeyObject(format); // or theField = input.readInt(); // and other simple types // or
  * if no primary key but has superclass: super.bdbReadPriKeyField(input, format); }
  */
 private void genBdbReadPriKeyField() {
   MethodVisitor mv =
       cv.visitMethod(
           ACC_PUBLIC,
           "bdbReadPriKeyField",
           "(Lcom/sleepycat/persist/impl/EntityInput;" + "Lcom/sleepycat/persist/impl/Format;)V",
           null,
           null);
   mv.visitCode();
   if (priKeyField != null) {
     if (!genReadSimpleKeyField(mv, priKeyField)) {
       /* For a non-simple type, call EntityInput.readKeyObject. */
       mv.visitVarInsn(ALOAD, 0);
       mv.visitVarInsn(ALOAD, 1);
       mv.visitVarInsn(ALOAD, 2);
       mv.visitMethodInsn(
           INVOKEINTERFACE,
           "com/sleepycat/persist/impl/EntityInput",
           "readKeyObject",
           "(Lcom/sleepycat/persist/impl/Format;)" + "Ljava/lang/Object;");
       mv.visitTypeInsn(CHECKCAST, getTypeInstName(priKeyField.type));
       mv.visitFieldInsn(PUTFIELD, className, priKeyField.name, priKeyField.type.getDescriptor());
     }
   } else if (hasPersistentSuperclass) {
     mv.visitVarInsn(ALOAD, 0);
     mv.visitVarInsn(ALOAD, 1);
     mv.visitVarInsn(ALOAD, 2);
     mv.visitMethodInsn(
         INVOKESPECIAL,
         superclassName,
         "bdbReadPriKeyField",
         "(Lcom/sleepycat/persist/impl/EntityInput;" + "Lcom/sleepycat/persist/impl/Format;)V");
   }
   mv.visitInsn(RETURN);
   mv.visitMaxs(3, 3);
   mv.visitEnd();
 }