Ejemplo n.º 1
0
  /**
   * Method to remove an element from the List
   *
   * @param element The Element to remove
   * @return Whether it was removed successfully.
   */
  public boolean remove(Object element, boolean allowCascadeDelete) {
    boolean success = delegate.remove(element);
    if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations()) {
      ownerOP
          .getExecutionContext()
          .getRelationshipManager(ownerOP)
          .relationRemove(ownerMmd.getAbsoluteFieldNumber(), element);
    }

    if (ownerOP != null && allowCascadeDelete) {
      // Cascade delete
      if (SCOUtils.useQueuedUpdate(ownerOP)) {
        // Queue the cascade delete
        ownerOP
            .getExecutionContext()
            .addOperationToQueue(
                new CollectionRemoveOperation(
                    ownerOP, ownerMmd.getAbsoluteFieldNumber(), element, allowCascadeDelete));
      } else if (SCOUtils.hasDependentElement(ownerMmd)) {
        // Perform the cascade delete
        ownerOP.getExecutionContext().deleteObjectInternal(element);
      }
    }

    if (success) {
      makeDirty();
      if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
      }
    }

    return success;
  }
Ejemplo n.º 2
0
 /**
  * Method to add a collection to the LinkedHashSet.
  *
  * @param elements The collection
  * @return Whether it was added ok.
  */
 public boolean addAll(Collection elements) {
   boolean success = delegate.addAll(elements);
   if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations()) {
     // Relationship management
     Iterator iter = elements.iterator();
     while (iter.hasNext()) {
       ownerOP
           .getExecutionContext()
           .getRelationshipManager(ownerOP)
           .relationAdd(ownerMmd.getAbsoluteFieldNumber(), iter.next());
     }
   }
   if (success) {
     if (SCOUtils.useQueuedUpdate(ownerOP)) {
       for (Object element : elements) {
         ownerOP
             .getExecutionContext()
             .addOperationToQueue(
                 new CollectionAddOperation(ownerOP, ownerMmd.getAbsoluteFieldNumber(), element));
       }
     }
     makeDirty();
     if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
       ownerOP.getExecutionContext().processNontransactionalUpdate();
     }
   }
   return success;
 }
  /* (non-Javadoc)
   * @see org.datanucleus.store.rdbms.sql.method.SQLMethod#getExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression, java.util.List)
   */
  public SQLExpression getExpression(SQLExpression expr, List<SQLExpression> args) {
    if (args == null || args.size() == 0 || args.size() > 1) {
      throw new NucleusException(Localiser.msg("060016", "containsValue", "MapExpression", 1));
    }

    MapExpression mapExpr = (MapExpression) expr;
    SQLExpression valExpr = args.get(0);

    if (valExpr.isParameter()) {
      // Value is a parameter so make sure its type is set
      AbstractMemberMetaData mmd = mapExpr.getJavaTypeMapping().getMemberMetaData();
      if (mmd != null && mmd.getMap() != null) {
        Class valCls =
            stmt.getQueryGenerator()
                .getClassLoaderResolver()
                .classForName(mmd.getMap().getValueType());
        stmt.getQueryGenerator().bindParameter(valExpr.getParameterName(), valCls);
      }
    }

    if (mapExpr instanceof MapLiteral) {
      MapLiteral lit = (MapLiteral) mapExpr;
      Map map = (Map) lit.getValue();
      if (map == null || map.size() == 0) {
        return new BooleanLiteral(stmt, expr.getJavaTypeMapping(), Boolean.FALSE);
      }

      // TODO If valExpr is a parameter and mapExpr is derived from a parameter ?
      MapValueLiteral mapValueLiteral = lit.getValueLiteral();
      BooleanExpression bExpr = null;
      List<SQLExpression> elementExprs = mapValueLiteral.getValueExpressions();
      for (int i = 0; i < elementExprs.size(); i++) {
        if (bExpr == null) {
          bExpr = (elementExprs.get(i)).eq(valExpr);
        } else {
          bExpr = bExpr.ior((elementExprs.get(i)).eq(valExpr));
        }
      }
      if (bExpr != null) {
        bExpr.encloseInParentheses();
      }
      return bExpr;
    }

    if (stmt.getQueryGenerator().getCompilationComponent() == CompilationComponent.FILTER) {
      boolean needsSubquery = getNeedsSubquery();

      // TODO Check if *this* "containsValue" is negated, not any of them (and remove above check)
      if (needsSubquery) {
        NucleusLogger.QUERY.debug(
            "map.containsValue on " + mapExpr + "(" + valExpr + ") using SUBQUERY");
        return containsAsSubquery(mapExpr, valExpr);
      }
      NucleusLogger.QUERY.debug(
          "map.containsValue on " + mapExpr + "(" + valExpr + ") using INNERJOIN");
      return containsAsInnerJoin(mapExpr, valExpr);
    }
    return containsAsSubquery(mapExpr, valExpr);
  }
 /**
  * Convenience method to unload a field/property.
  *
  * @param fieldName Name of the field/property
  * @throws NucleusUserException if the object managed by this StateManager is embedded
  */
 public void unloadField(String fieldName) {
   if (objectType == ObjectProvider.PC) {
     // Mark as not loaded
     AbstractMemberMetaData mmd = getClassMetaData().getMetaDataForMember(fieldName);
     loadedFields[mmd.getAbsoluteFieldNumber()] = false;
   } else {
     throw new NucleusUserException("Cannot unload field/property of embedded object");
   }
 }
Ejemplo n.º 5
0
 /**
  * Convenience method for whether a PK is required for the join table. Makes use of the extension
  * "primary-key" (within &lt;join&gt;) to allow turning off PK generation.
  *
  * @return Whether a PK is required
  */
 protected boolean requiresPrimaryKey() {
   boolean pkRequired = true;
   if (mmd.getJoinMetaData() != null
       && mmd.getJoinMetaData().hasExtension("primary-key")
       && mmd.getJoinMetaData().getValueForExtension("primary-key").equalsIgnoreCase("false")) {
     pkRequired = false;
   }
   return pkRequired;
 }
  /**
   * Method called when a method of the class is visited.
   *
   * @param access Access for the method
   * @param name Name of the method
   * @param desc Descriptor
   * @param signature Signature
   * @param exceptions Exceptions that this method is declared to throw
   * @return Visitor to visit this (or null if not wanting to visit it)
   */
  public MethodVisitor visitMethod(
      int access, String name, String desc, String signature, String[] exceptions) {
    if (name.equals("<init>") && desc != null && desc.equals("()V")) {
      // Check for default constructor
      hasDefaultConstructor = true;
    }
    if (name.equals("writeObject")
        && desc != null
        && desc.equals("(Ljava/io/ObjectOutputStream;)V")) {
      // Has writeObject() for use in serialisation
      hasWriteObject = true;
    }
    if (name.equals("<clinit>") && desc != null && desc.equals("()V")) {
      hasStaticInitialisation = true;
    }

    MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions);
    if (mv == null) {
      return null;
    }

    if (name.equals("jdoPreClear") || name.equals("jdoPostLoad")) {
      // jdoPreClear/jdoPostLoad should not be enhanced (JDO2 spec [10.1, 10.3]
      return mv;
    } else if (name.equals("readObject")
        && (desc.equals("(Ljava/io/ObjectOutputStream;)V")
            || desc.equals("(Ljava/io/ObjectInputStream;)V"))) {
      // readObject(ObjectInputStream), readObject(ObjectOutputStream) should not be enhanced (JDO2
      // spec [21.6])
      return mv;
    }

    String propGetterName = ClassUtils.getFieldNameForJavaBeanGetter(name);
    String propSetterName = ClassUtils.getFieldNameForJavaBeanSetter(name);
    if (propGetterName != null) {
      AbstractMemberMetaData mmd = enhancer.getClassMetaData().getMetaDataForMember(propGetterName);
      if (mmd != null
          && mmd instanceof PropertyMetaData
          && mmd.getPersistenceModifier() != FieldPersistenceModifier.NONE) {
        // Property getter method "getXXX" - generated dnGetXXX
        return new EnhancerPropertyGetterAdapter(mv, enhancer, name, desc, mmd, cv);
      }
    } else if (propSetterName != null) {
      AbstractMemberMetaData mmd = enhancer.getClassMetaData().getMetaDataForMember(propSetterName);
      if (mmd != null
          && mmd instanceof PropertyMetaData
          && mmd.getPersistenceModifier() != FieldPersistenceModifier.NONE) {
        // Property setter method "setXXX" - generates dnSetXXX
        return new EnhancerPropertySetterAdapter(mv, enhancer, name, desc, mmd, cv);
      }
    }

    // normal method, so just enhance it
    return new EnhancerMethodAdapter(mv, enhancer, name, desc);
  }
Ejemplo n.º 7
0
  /**
   * Accessor for the primary key for this table. Overrides the method in TableImpl to add on any
   * specification of PK name in the &lt;join&gt; metadata.
   *
   * @return The primary key.
   */
  public PrimaryKey getPrimaryKey() {
    PrimaryKey pk = super.getPrimaryKey();
    if (mmd.getJoinMetaData() != null) {
      PrimaryKeyMetaData pkmd = mmd.getJoinMetaData().getPrimaryKeyMetaData();
      if (pkmd != null && pkmd.getName() != null) {
        pk.setName(pkmd.getName());
      }
    }

    return pk;
  }
Ejemplo n.º 8
0
  /**
   * 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();
    }
  }
Ejemplo n.º 9
0
  /**
   * Utility to add the mapping for a field/property to the managed list.
   *
   * @param fieldMapping The mapping for the field/property
   */
  protected void addMemberMapping(JavaTypeMapping fieldMapping) {
    AbstractMemberMetaData mmd = fieldMapping.getMemberMetaData();
    logMapping(mmd.getFullFieldName(), fieldMapping);
    memberMappingsMap.put(mmd, fieldMapping);

    // Update highest field number if this is higher
    int absoluteFieldNumber = mmd.getAbsoluteFieldNumber();
    if (absoluteFieldNumber > highestMemberNumber) {
      highestMemberNumber = absoluteFieldNumber;
    }
  }
Ejemplo n.º 10
0
 /**
  * Accessor for the JavaTypeMapping that is handling the member of the specified name. Returns the
  * first one that matches.
  *
  * @param memberName Name of the field/property
  * @return The java type mapping
  */
 protected JavaTypeMapping getMappingForMemberName(String memberName) {
   Iterator<Map.Entry<AbstractMemberMetaData, JavaTypeMapping>> memberMapEntryIter =
       memberMappingsMap.entrySet().iterator();
   while (memberMapEntryIter.hasNext()) {
     Map.Entry<AbstractMemberMetaData, JavaTypeMapping> memberMapEntry = memberMapEntryIter.next();
     AbstractMemberMetaData mmd = memberMapEntry.getKey();
     if (mmd.getFullFieldName().equals(memberName)) {
       return memberMapEntry.getValue();
     }
   }
   return null;
 }
Ejemplo n.º 11
0
  /**
   * Constructor, using the ObjectProvider of the "owner" and the field name.
   *
   * @param op The owner ObjectProvider
   * @param mmd Metadata for the member
   */
  public Map(ObjectProvider op, AbstractMemberMetaData mmd) {
    super(op, mmd);

    // Set up our "delegate"
    this.delegate = new java.util.HashMap();

    ExecutionContext ec = ownerOP.getExecutionContext();
    allowNulls = SCOUtils.allowNullsInContainer(allowNulls, mmd);
    useCache = SCOUtils.useContainerCache(ownerOP, mmd);

    if (!SCOUtils.mapHasSerialisedKeysAndValues(mmd)
        && mmd.getPersistenceModifier() == FieldPersistenceModifier.PERSISTENT) {
      ClassLoaderResolver clr = ec.getClassLoaderResolver();
      this.backingStore =
          (MapStore)
              ((BackedSCOStoreManager) ownerOP.getStoreManager())
                  .getBackingStoreForField(clr, mmd, java.util.Map.class);
    }

    if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
      NucleusLogger.PERSISTENCE.debug(
          SCOUtils.getContainerInfoMessage(
              ownerOP,
              ownerMmd.getName(),
              this,
              useCache,
              allowNulls,
              SCOUtils.useCachedLazyLoading(ownerOP, ownerMmd)));
    }
  }
Ejemplo n.º 12
0
  /**
   * Constructor, using the ObjectProvider of the "owner" and the field name.
   *
   * @param op The owner ObjectProvider
   * @param mmd Metadata for the member
   */
  public ArrayList(ObjectProvider op, AbstractMemberMetaData mmd) {
    super(op, mmd);

    // Set up our delegate
    this.delegate = new java.util.ArrayList();

    ExecutionContext ec = op.getExecutionContext();
    allowNulls = SCOUtils.allowNullsInContainer(allowNulls, mmd);
    queued = ec.isDelayDatastoreOperationsEnabled();
    useCache = SCOUtils.useContainerCache(op, mmd);

    if (!SCOUtils.collectionHasSerialisedElements(mmd)
        && mmd.getPersistenceModifier() == FieldPersistenceModifier.PERSISTENT) {
      ClassLoaderResolver clr = ec.getClassLoaderResolver();
      this.backingStore =
          (ListStore)
              ((BackedSCOStoreManager) op.getStoreManager())
                  .getBackingStoreForField(clr, mmd, java.util.ArrayList.class);
    }

    if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
      NucleusLogger.PERSISTENCE.debug(
          SCOUtils.getContainerInfoMessage(
              op,
              ownerMmd.getName(),
              this,
              useCache,
              queued,
              allowNulls,
              SCOUtils.useCachedLazyLoading(op, ownerMmd)));
    }
  }
Ejemplo n.º 13
0
  /**
   * Provide the mappings to the consumer for all non primary-key fields mapped to this table.
   *
   * @param consumer Consumer for the mappings
   */
  public final void provideNonPrimaryKeyMappings(MappingConsumer consumer) {
    consumer.preConsumeMapping(highestMemberNumber + 1);

    Iterator<Map.Entry<AbstractMemberMetaData, JavaTypeMapping>> memberMapEntryIter =
        memberMappingsMap.entrySet().iterator();
    while (memberMapEntryIter.hasNext()) {
      Map.Entry<AbstractMemberMetaData, JavaTypeMapping> memberMapEntry = memberMapEntryIter.next();
      AbstractMemberMetaData mmd = memberMapEntry.getKey();
      JavaTypeMapping memberMapping = memberMapEntry.getValue();
      if (memberMapping != null) {
        if (!mmd.isPrimaryKey()) {
          consumer.consumeMapping(memberMapping, mmd);
        }
      }
    }
  }
Ejemplo n.º 14
0
 /**
  * Convenience logging method to output the mapping information for an element, key, value field
  *
  * @param mapping The mapping
  */
 protected void debugMapping(JavaTypeMapping mapping) {
   if (NucleusLogger.DATASTORE.isDebugEnabled()) {
     // Provide field->column mapping debug message
     StringBuffer columnsStr = new StringBuffer();
     for (int i = 0; i < mapping.getNumberOfDatastoreMappings(); i++) {
       if (i > 0) {
         columnsStr.append(",");
       }
       columnsStr.append(mapping.getDatastoreMapping(i).getDatastoreField());
     }
     if (mapping.getNumberOfDatastoreMappings() == 0) {
       columnsStr.append("[none]");
     }
     StringBuffer datastoreMappingTypes = new StringBuffer();
     for (int i = 0; i < mapping.getNumberOfDatastoreMappings(); i++) {
       if (i > 0) {
         datastoreMappingTypes.append(',');
       }
       datastoreMappingTypes.append(mapping.getDatastoreMapping(i).getClass().getName());
     }
     NucleusLogger.DATASTORE.debug(
         LOCALISER.msg(
             "057010",
             mmd.getFullFieldName(),
             columnsStr.toString(),
             mapping.getClass().getName(),
             datastoreMappingTypes.toString()));
   }
 }
Ejemplo n.º 15
0
 /** Utility to mark the object as dirty */
 public void makeDirty() {
   if (ownerOP != null) {
     ownerOP.makeDirty(ownerMmd.getAbsoluteFieldNumber());
     if (!ownerOP.getExecutionContext().getTransaction().isActive()) {
       ownerOP.getExecutionContext().processNontransactionalUpdate();
     }
   }
 }
Ejemplo n.º 16
0
  /**
   * 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;
  }
Ejemplo n.º 17
0
  /**
   * Constructor, taking the meta data for the field, and the table it is mapped to.
   *
   * @param mmd MetaData for the field.
   * @param table Table definition
   */
  public RDBMSStoreData(AbstractMemberMetaData mmd, Table table) {
    super(mmd.getFullFieldName(), mmd, SCO_TYPE, null);

    if (table == null) {
      throw new NullPointerException("table should not be null");
    }
    this.table = table;
    this.tableName = table.toString();
    this.tableOwner = true;
    this.tableIdentifier = table.getIdentifier();

    String interfaceName =
        (table.getStoreManager().getMetaDataManager().isPersistentInterface(mmd.getType().getName())
            ? mmd.getType().getName()
            : null);
    if (interfaceName != null) {
      this.interfaceName = interfaceName;
    }
  }
Ejemplo n.º 18
0
  /**
   * Method to remove all elements from the collection from the LinkedHashSet.
   *
   * @param elements The collection of elements to remove
   * @return Whether it was removed ok.
   */
  public boolean removeAll(java.util.Collection elements) {
    boolean success = delegate.removeAll(elements);
    if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations()) {
      // Relationship management
      Iterator iter = elements.iterator();
      RelationshipManager relMgr = ownerOP.getExecutionContext().getRelationshipManager(ownerOP);
      while (iter.hasNext()) {
        relMgr.relationRemove(ownerMmd.getAbsoluteFieldNumber(), iter.next());
      }
    }

    if (ownerOP != null && elements != null && !elements.isEmpty()) {
      // Cascade delete
      if (SCOUtils.useQueuedUpdate(ownerOP)) {
        // Queue the cascade delete
        Iterator iter = elements.iterator();
        while (iter.hasNext()) {
          ownerOP
              .getExecutionContext()
              .addOperationToQueue(
                  new CollectionRemoveOperation(
                      ownerOP, ownerMmd.getAbsoluteFieldNumber(), iter.next(), true));
        }
      } else if (SCOUtils.hasDependentElement(ownerMmd)) {
        // Perform the cascade delete
        Iterator iter = elements.iterator();
        while (iter.hasNext()) {
          ownerOP.getExecutionContext().deleteObjectInternal(iter.next());
        }
      }
    }

    if (success) {
      makeDirty();
      if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
      }
    }

    return success;
  }
Ejemplo n.º 19
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)));
   }
 }
  /* (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);
  }
Ejemplo n.º 21
0
 private static void addColumnsToScanForEmbeddedMember(
     Scan scan, List<AbstractMemberMetaData> embMmds, Table table, ExecutionContext ec) {
   AbstractMemberMetaData lastMmd = embMmds.get(embMmds.size() - 1);
   ClassLoaderResolver clr = ec.getClassLoaderResolver();
   AbstractClassMetaData embCmd =
       ec.getMetaDataManager().getMetaDataForClass(lastMmd.getTypeName(), clr);
   int[] embMmdPosns = embCmd.getAllMemberPositions();
   for (int i = 0; i < embMmdPosns.length; i++) {
     AbstractMemberMetaData embMmd = embCmd.getMetaDataForManagedMemberAtAbsolutePosition(i);
     List<AbstractMemberMetaData> subEmbMmds = new ArrayList<AbstractMemberMetaData>(embMmds);
     subEmbMmds.add(embMmd);
     RelationType relationType = embMmd.getRelationType(clr);
     MemberColumnMapping mapping = table.getMemberColumnMappingForEmbeddedMember(subEmbMmds);
     if (RelationType.isRelationSingleValued(relationType)) {
       addColumnsToScanForEmbeddedMember(scan, subEmbMmds, table, ec);
     } else {
       String familyName = HBaseUtils.getFamilyNameForColumn(mapping.getColumn(0));
       String qualifName = HBaseUtils.getQualifierNameForColumn(mapping.getColumn(0));
       scan.addColumn(familyName.getBytes(), qualifName.getBytes());
     }
   }
 }
Ejemplo n.º 22
0
 /**
  * Method to add an element to the LinkedHashSet.
  *
  * @param element The new element
  * @return Whether it was added ok.
  */
 public boolean add(E element) {
   boolean success = delegate.add(element);
   if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations()) {
     // Relationship management
     ownerOP
         .getExecutionContext()
         .getRelationshipManager(ownerOP)
         .relationAdd(ownerMmd.getAbsoluteFieldNumber(), element);
   }
   if (success) {
     if (SCOUtils.useQueuedUpdate(ownerOP)) {
       ownerOP
           .getExecutionContext()
           .addOperationToQueue(
               new CollectionAddOperation(ownerOP, ownerMmd.getAbsoluteFieldNumber(), element));
     }
     makeDirty();
     if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
       ownerOP.getExecutionContext().processNontransactionalUpdate();
     }
   }
   return success;
 }
Ejemplo n.º 23
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)));
   }
 }
Ejemplo n.º 24
0
 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)));
   }
 }
Ejemplo n.º 25
0
 /**
  * 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)));
   }
 }
Ejemplo n.º 26
0
  /**
   * Method to retain a Collection of elements (and remove all others).
   *
   * @param c The collection to retain
   * @return Whether they were retained successfully.
   */
  public boolean retainAll(java.util.Collection c) {
    if (c == null) {
      throw new NullPointerException("Input collection was null");
    }
    Collection collToRemove = new java.util.LinkedHashSet();
    for (Object o : delegate) {
      if (!c.contains(o)) {
        collToRemove.add(o);
      }
    }

    boolean success = delegate.retainAll(c);
    if (success) {
      makeDirty();
      if (SCOUtils.useQueuedUpdate(ownerOP)) {
        // Queue any cascade delete
        Iterator iter = collToRemove.iterator();
        while (iter.hasNext()) {
          ownerOP
              .getExecutionContext()
              .addOperationToQueue(
                  new CollectionRemoveOperation(
                      ownerOP, ownerMmd.getAbsoluteFieldNumber(), iter.next(), true));
        }
      } else if (SCOUtils.hasDependentElement(ownerMmd)) {
        // Perform the cascade delete
        Iterator iter = collToRemove.iterator();
        while (iter.hasNext()) {
          ownerOP.getExecutionContext().deleteObjectInternal(iter.next());
        }
      }

      if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
      }
    }
    return success;
  }
Ejemplo n.º 27
0
  /** 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();
  }
Ejemplo n.º 28
0
 /**
  * Accessor for the field name
  *
  * @return The field name
  */
 public String getFieldName() {
   return ownerMmd.getName();
 }
Ejemplo n.º 29
0
 /** Utility to mark the object as dirty */
 public void makeDirty() {
   if (ownerOP != null) {
     ownerOP.makeDirty(ownerMmd.getAbsoluteFieldNumber());
   }
 }
 public boolean useBackedSCOWrapperForMember(AbstractMemberMetaData mmd, ExecutionContext ec) {
   // Use backed SCO wrapper on relation field (to support legacy), and use simple SCO wrapper on
   // others
   return (mmd.getRelationType(ec.getClassLoaderResolver()) == RelationType.NONE ? false : true);
 }