/**
   * Constructor.
   *
   * @param tableName The Table SQL identifier
   * @param mmd Member meta data for the owner field/property
   * @param storeMgr Manager for the datastore.
   */
  protected JoinTable(
      DatastoreIdentifier tableName, AbstractMemberMetaData mmd, RDBMSStoreManager storeMgr) {
    super(tableName, storeMgr);

    this.mmd = mmd;
    this.ownerType = mmd.getClassName(true);

    if (mmd.getPersistenceModifier() == FieldPersistenceModifier.NONE) {
      throw new NucleusException(Localiser.msg("057006", mmd.getName())).setFatal();
    }
  }
Beispiel #2
0
 /** Method to initialise the SCO for use. */
 public void initialise() {
   initialiseDelegate();
   if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
     NucleusLogger.PERSISTENCE.debug(
         LOCALISER.msg(
             "023003",
             ownerOP.getObjectAsPrintable(),
             ownerMmd.getName(),
             "" + size(),
             SCOUtils.getSCOWrapperOptionsMessage(true, false, false, false)));
   }
 }
 public void initialise(java.util.LinkedHashSet c) {
   if (c != null) {
     delegate = c;
   } else {
     delegate = new java.util.LinkedHashSet();
   }
   if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
     NucleusLogger.PERSISTENCE.debug(
         Localiser.msg(
             "023003",
             this.getClass().getName(),
             ownerOP.getObjectAsPrintable(),
             ownerMmd.getName(),
             "" + size(),
             SCOUtils.getSCOWrapperOptionsMessage(true, false, true, false)));
   }
 }
Beispiel #4
0
 /**
  * Method to initialise the SCO from an existing value.
  *
  * @param o Object to set value using.
  * @param forInsert Whether the object needs inserting in the datastore with this value
  * @param forUpdate Whether to update the datastore with this value
  */
 public void initialise(Object o, boolean forInsert, boolean forUpdate) {
   java.util.Map m = (java.util.Map) o;
   if (m != null) {
     delegate = (java.util.HashMap) m;
   } else {
     delegate = new java.util.HashMap();
   }
   if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
     NucleusLogger.PERSISTENCE.debug(
         LOCALISER.msg(
             "023003",
             ownerOP.getObjectAsPrintable(),
             ownerMmd.getName(),
             "" + size(),
             SCOUtils.getSCOWrapperOptionsMessage(true, false, true, false)));
   }
 }
 /**
  * Method to initialise the SCO from an existing value.
  *
  * @param c The object to set from
  * @param forInsert Whether the object needs inserting in the datastore with this value
  * @param forUpdate Whether to update the datastore with this value
  */
 public void initialise(java.util.PriorityQueue c, boolean forInsert, boolean forUpdate) {
   if (c != null) {
     initialiseDelegate();
     delegate.addAll(c);
   } else {
     initialiseDelegate();
   }
   if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
     NucleusLogger.PERSISTENCE.debug(
         Localiser.msg(
             "023003",
             ownerOP.getObjectAsPrintable(),
             ownerMmd.getName(),
             "" + size(),
             SCOUtils.getSCOWrapperOptionsMessage(true, false, false, false)));
   }
 }
  /**
   * Constructor.
   *
   * @param enhancer ClassEnhancer
   * @param fmd MetaData for the field we are generating for
   */
  public JdoSetViaCheck(ClassEnhancer enhancer, AbstractMemberMetaData fmd) {
    super(
        enhancer,
        enhancer.getNamer().getSetMethodPrefixMethodName() + fmd.getName(),
        (fmd.isPublic() ? Opcodes.ACC_PUBLIC : 0)
            | (fmd.isProtected() ? Opcodes.ACC_PROTECTED : 0)
            | (fmd.isPrivate() ? Opcodes.ACC_PRIVATE : 0)
            | Opcodes.ACC_STATIC,
        null,
        null,
        null);

    // Set the arg types/names
    argTypes = new Class[] {getClassEnhancer().getClassBeingEnhanced(), fmd.getType()};
    argNames = new String[] {"objPC", "val"};

    this.fmd = fmd;
  }
  /* (non-Javadoc)
   * @see org.datanucleus.store.fieldmanager.AbstractFieldManager#fetchObjectField(int)
   */
  @Override
  public Object fetchObjectField(int fieldNumber) {
    ClassLoaderResolver clr = ec.getClassLoaderResolver();
    AbstractMemberMetaData mmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber);
    RelationType relationType = mmd.getRelationType(clr);
    EmbeddedMetaData embmd = mmds.get(0).getEmbeddedMetaData();
    if (mmds.size() == 1
        && embmd != null
        && embmd.getOwnerMember() != null
        && embmd.getOwnerMember().equals(mmd.getName())) {
      // Special case of this being a link back to the owner. TODO Repeat this for nested and their
      // owners
      ObjectProvider[] ownerOps = ec.getOwnersForEmbeddedObjectProvider(op);
      return (ownerOps != null && ownerOps.length > 0 ? ownerOps[0].getObject() : null);
    }

    if (relationType != RelationType.NONE
        && MetaDataUtils.getInstance()
            .isMemberEmbedded(ec.getMetaDataManager(), clr, mmd, relationType, null)) {
      // Embedded field
      if (RelationType.isRelationSingleValued(relationType)) {
        // TODO Cater for null value detection

        List<AbstractMemberMetaData> embMmds = new ArrayList<AbstractMemberMetaData>(mmds);
        embMmds.add(mmd);

        AbstractClassMetaData embCmd =
            ec.getMetaDataManager().getMetaDataForClass(mmd.getType(), clr);
        ObjectProvider embOP =
            ec.getNucleusContext()
                .getObjectProviderFactory()
                .newForEmbedded(ec, embCmd, op, fieldNumber);
        FieldManager ffm = new FetchEmbeddedFieldManager(embOP, result, embMmds, table);
        embOP.replaceFields(embCmd.getAllMemberPositions(), ffm);
        return embOP.getObject();
      }
    }

    return fetchNonEmbeddedObjectField(mmd, relationType, clr);
  }
  /** Method to add the contents of the class method. */
  public void execute() {
    visitor.visitCode();

    String fieldTypeDesc = Type.getDescriptor(fmd.getType());

    Label startLabel = new Label();
    visitor.visitLabel(startLabel);

    // "if (objPC.jdoFlags != 0 && objPC.jdoStateManager != null)"
    visitor.visitVarInsn(Opcodes.ALOAD, 0);
    visitor.visitFieldInsn(
        Opcodes.GETFIELD,
        getClassEnhancer().getASMClassName(),
        getNamer().getFlagsFieldName(),
        "B");
    Label l1 = new Label();
    visitor.visitJumpInsn(Opcodes.IFEQ, l1);
    visitor.visitVarInsn(Opcodes.ALOAD, 0);
    visitor.visitFieldInsn(
        Opcodes.GETFIELD,
        getClassEnhancer().getASMClassName(),
        getNamer().getStateManagerFieldName(),
        "L" + getNamer().getStateManagerAsmClassName() + ";");
    visitor.visitJumpInsn(Opcodes.IFNULL, l1);

    // "objPC.jdoStateManager.setYYYField(objPC, 8, objPC.ZZZ, val);"
    visitor.visitVarInsn(Opcodes.ALOAD, 0);
    visitor.visitFieldInsn(
        Opcodes.GETFIELD,
        getClassEnhancer().getASMClassName(),
        getNamer().getStateManagerFieldName(),
        "L" + getNamer().getStateManagerAsmClassName() + ";");
    visitor.visitVarInsn(Opcodes.ALOAD, 0);
    EnhanceUtils.addBIPUSHToMethod(visitor, fmd.getFieldId());
    if (enhancer.getClassMetaData().getPersistenceCapableSuperclass() != null) {
      visitor.visitFieldInsn(
          Opcodes.GETSTATIC,
          getClassEnhancer().getASMClassName(),
          getNamer().getInheritedFieldCountFieldName(),
          "I");
      visitor.visitInsn(Opcodes.IADD);
    }
    visitor.visitVarInsn(Opcodes.ALOAD, 0);
    visitor.visitFieldInsn(
        Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), fmd.getName(), fieldTypeDesc);
    EnhanceUtils.addLoadForType(visitor, fmd.getType(), 1);
    String jdoMethodName = "set" + EnhanceUtils.getTypeNameForJDOMethod(fmd.getType()) + "Field";
    String argTypeDesc = fieldTypeDesc;
    if (jdoMethodName.equals("setObjectField")) {
      argTypeDesc = EnhanceUtils.CD_Object;
    }
    visitor.visitMethodInsn(
        Opcodes.INVOKEINTERFACE,
        getNamer().getStateManagerAsmClassName(),
        jdoMethodName,
        "(L" + getNamer().getPersistableAsmClassName() + ";I" + argTypeDesc + argTypeDesc + ")V");
    Label l3 = new Label();
    visitor.visitJumpInsn(Opcodes.GOTO, l3);

    // "objPC.text = val;"
    visitor.visitLabel(l1);
    if (JavaUtils.useStackMapFrames()) {
      visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    }

    visitor.visitVarInsn(Opcodes.ALOAD, 0);
    EnhanceUtils.addLoadForType(visitor, fmd.getType(), 1);
    visitor.visitFieldInsn(
        Opcodes.PUTFIELD, getClassEnhancer().getASMClassName(), fmd.getName(), fieldTypeDesc);

    if (enhancer.getClassMetaData().isDetachable()) {
      // "if (objPC.jdoIsDetached() == true)  ((BitSet) objPC.jdoDetachedState[3]).set(8);"
      visitor.visitVarInsn(Opcodes.ALOAD, 0);
      visitor.visitMethodInsn(
          Opcodes.INVOKEVIRTUAL,
          getClassEnhancer().getASMClassName(),
          getNamer().getIsDetachedMethodName(),
          "()Z");
      visitor.visitJumpInsn(Opcodes.IFEQ, l3);
      visitor.visitVarInsn(Opcodes.ALOAD, 0);
      visitor.visitFieldInsn(
          Opcodes.GETFIELD,
          getClassEnhancer().getASMClassName(),
          getNamer().getDetachedStateFieldName(),
          "[Ljava/lang/Object;");
      visitor.visitInsn(Opcodes.ICONST_3);
      visitor.visitInsn(Opcodes.AALOAD);
      visitor.visitTypeInsn(Opcodes.CHECKCAST, "java/util/BitSet");
      EnhanceUtils.addBIPUSHToMethod(visitor, fmd.getFieldId());
      if (enhancer.getClassMetaData().getPersistenceCapableSuperclass() != null) {
        visitor.visitFieldInsn(
            Opcodes.GETSTATIC,
            getClassEnhancer().getASMClassName(),
            getNamer().getInheritedFieldCountFieldName(),
            "I");
        visitor.visitInsn(Opcodes.IADD);
      }
      visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/BitSet", "set", "(I)V");
    }

    visitor.visitLabel(l3);
    if (JavaUtils.useStackMapFrames()) {
      visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    }
    visitor.visitInsn(Opcodes.RETURN);

    Label endLabel = new Label();
    visitor.visitLabel(endLabel);
    visitor.visitLocalVariable(
        argNames[0], getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
    visitor.visitLocalVariable(argNames[1], fieldTypeDesc, null, startLabel, endLabel, 1);
    visitor.visitMaxs(5, 2);

    visitor.visitEnd();
  }
Beispiel #9
0
 /**
  * Accessor for the field name
  *
  * @return The field name
  */
 public String getFieldName() {
   return ownerMmd.getName();
 }
  /** Method to add the contents of the class method. */
  public void execute() {
    visitor.visitCode();

    Label startLabel = new Label();
    visitor.visitLabel(startLabel);

    ClassMetaData cmd = enhancer.getClassMetaData();
    if (cmd.getIdentityType() == IdentityType.APPLICATION) {
      // application identity
      if (!cmd.isInstantiable()) {
        // Application identity but mapped-superclass with no PK defined, so throw exception
        visitor.visitTypeInsn(
            Opcodes.NEW, getClassEnhancer().getNamer().getFatalInternalExceptionAsmClassName());
        visitor.visitInsn(Opcodes.DUP);
        visitor.visitLdcInsn("This class has no identity");
        visitor.visitMethodInsn(
            Opcodes.INVOKESPECIAL,
            getClassEnhancer().getNamer().getFatalInternalExceptionAsmClassName(),
            "<init>",
            "(Ljava/lang/String;)V");
        visitor.visitInsn(Opcodes.ATHROW);
        Label endLabel = new Label();
        visitor.visitLabel(endLabel);
        visitor.visitLocalVariable(
            "this", getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
        visitor.visitMaxs(3, 1);
      } else {
        String objectIdClass = cmd.getObjectidClass();
        int[] pkFieldNums = cmd.getPKMemberPositions();
        if (enhancer
            .getMetaDataManager()
            .getApiAdapter()
            .isSingleFieldIdentityClass(objectIdClass)) {
          // SingleFieldIdentity
          String ACN_objectIdClass = objectIdClass.replace('.', '/');
          AbstractMemberMetaData fmd =
              cmd.getMetaDataForManagedMemberAtAbsolutePosition(pkFieldNums[0]);

          visitor.visitTypeInsn(Opcodes.NEW, ACN_objectIdClass);
          visitor.visitInsn(Opcodes.DUP);
          visitor.visitVarInsn(Opcodes.ALOAD, 0);
          visitor.visitMethodInsn(
              Opcodes.INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;");
          visitor.visitVarInsn(Opcodes.ALOAD, 0);
          if (fmd instanceof PropertyMetaData) {
            // Persistent property so use jdoGetXXX()
            visitor.visitMethodInsn(
                Opcodes.INVOKEVIRTUAL,
                getClassEnhancer().getASMClassName(),
                getNamer().getGetMethodPrefixMethodName() + fmd.getName(),
                "()" + Type.getDescriptor(fmd.getType()));
          } else {
            // Persistent field so use xxx
            visitor.visitFieldInsn(
                Opcodes.GETFIELD,
                getClassEnhancer().getASMClassName(),
                fmd.getName(),
                Type.getDescriptor(fmd.getType()));
          }
          Class primitiveType = ClassUtils.getPrimitiveTypeForType(fmd.getType());
          if (primitiveType != null) {
            // Using object wrapper of primitive so use wrapper constructor
            visitor.visitMethodInsn(
                Opcodes.INVOKESPECIAL,
                ACN_objectIdClass,
                "<init>",
                "(Ljava/lang/Class;" + Type.getDescriptor(fmd.getType()) + ")V");
          } else {
            visitor.visitMethodInsn(
                Opcodes.INVOKESPECIAL,
                ACN_objectIdClass,
                "<init>",
                "(Ljava/lang/Class;"
                    + getNamer().getTypeDescriptorForSingleFieldIdentityGetKey(objectIdClass)
                    + ")V");
          }

          visitor.visitInsn(Opcodes.ARETURN);

          Label endLabel = new Label();
          visitor.visitLabel(endLabel);
          visitor.visitLocalVariable(
              "this", getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
          visitor.visitMaxs(4, 1);
        } else {
          // User-provided app identity, and compound identity
          String ACN_objectIdClass = objectIdClass.replace('.', '/');

          visitor.visitTypeInsn(Opcodes.NEW, ACN_objectIdClass);
          visitor.visitInsn(Opcodes.DUP);
          visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, ACN_objectIdClass, "<init>", "()V");
          visitor.visitInsn(Opcodes.ARETURN);

          Label endLabel = new Label();
          visitor.visitLabel(endLabel);
          visitor.visitLocalVariable(
              "this", getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
          visitor.visitMaxs(2, 1);
        }
      }
    } else {
      // datastore/nondurable identity
      visitor.visitInsn(Opcodes.ACONST_NULL);
      visitor.visitInsn(Opcodes.ARETURN);

      Label endLabel = new Label();
      visitor.visitLabel(endLabel);
      visitor.visitLocalVariable(
          "this", getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
      visitor.visitMaxs(1, 1);
    }

    visitor.visitEnd();
  }