Examples of MetadataManager


Examples of org.datanucleus.metadata.MetaDataManager

  }

  public void testIgnorableMapping_ErrorConfig() {
    setIgnorableMetaDataBehavior(MetaDataValidator.IgnorableMetaDataBehavior.ERROR.name());
    NucleusContext nucContext = ((JDOPersistenceManagerFactory)pmf).getNucleusContext();
    MetaDataManager mdm = nucContext.getMetaDataManager();
    AbstractClassMetaData acmd =
        mdm.getMetaDataForClass(Flight.class, nucContext.getClassLoaderResolver(getClass().getClassLoader()));
    MetaDataValidator mdv = new MetaDataValidator((DatastoreManager) nucContext.getStoreManager(), mdm, null) {
      @Override
      void warn(String msg) {
        fail("shouldn't have been called");
      }
View Full Code Here

Examples of org.datanucleus.metadata.MetaDataManager

        // PERSISTENT INTERFACE : allow for the value (impl) not be directly assignable from the superclass impl
        // e.g If we have interface "Base" with impl "BaseImpl", and sub-interface "Sub1" with impl "Sub1Impl"
        // So if the mapping is of type BaseImpl and the value is Sub1Impl then they don't come up as "assignable"
        // but they are
        Class mappingJavaType = null;
        MetaDataManager mmgr = storeMgr.getNucleusContext().getMetaDataManager();
        boolean isPersistentInterface = mmgr.isPersistentInterface(getType());
        if (isPersistentInterface)
        {
            // Field is declared as a "persistent-interface" type so all impls of that type should match
            mappingJavaType = clr.classForName(getType());
        }
        else if (mmd != null && mmd.getFieldTypes() != null && mmd.getFieldTypes().length == 1)
        {
            isPersistentInterface = mmgr.isPersistentInterface(mmd.getFieldTypes()[0]);
            if (isPersistentInterface)
            {
                // Field is declared as interface and accepts "persistent-interface" value, so all impls should match
                mappingJavaType = clr.classForName(mmd.getFieldTypes()[0]);
            }
View Full Code Here

Examples of org.datanucleus.metadata.MetaDataManager

    }
  }

  protected String kindForClass(Class<?> clazz) {
    ExecutionContext om = getExecutionContext();
    MetaDataManager mdm = om.getMetaDataManager();
    return EntityUtils.determineKind(
        mdm.getMetaDataForClass(clazz, om.getClassLoaderResolver()), om);
  }
View Full Code Here

Examples of org.datanucleus.metadata.MetaDataManager

        new com.google.appengine.api.datastore.Query(kind)).countEntities();
  }

  protected String kindForClass(Class<?> clazz) {
    ExecutionContext om = getExecutionContext();
    MetaDataManager mdm = om.getMetaDataManager();
    return EntityUtils.determineKind(
        mdm.getMetaDataForClass(clazz, om.getClassLoaderResolver()), om);
  }
View Full Code Here

Examples of org.datanucleus.metadata.MetaDataManager

    return ds.prepare(new Query(kind)).countEntities();
  }

  protected String kindForClass(Class<?> clazz) {
    NucleusContext nucContext = ((JPAEntityManagerFactory)emf).getNucleusContext();
    MetaDataManager mdm = nucContext.getMetaDataManager();
    MappedStoreManager storeMgr = (MappedStoreManager) nucContext.getStoreManager();
    ClassLoaderResolver clr = nucContext.getClassLoaderResolver(getClass().getClassLoader());
    return EntityUtils.determineKind(
        mdm.getMetaDataForClass(
            clazz,
            nucContext.getClassLoaderResolver(getClass().getClassLoader())),
            storeMgr,
            clr);
  }
View Full Code Here

Examples of org.datanucleus.metadata.MetaDataManager

    }
  }

  protected String kindForClass(Class<?> clazz) {
    NucleusContext nucContext = ((JPAEntityManagerFactory)emf).getNucleusContext();
    MetaDataManager mdm = nucContext.getMetaDataManager();
    MappedStoreManager storeMgr = (MappedStoreManager) nucContext.getStoreManager();
    ClassLoaderResolver clr = nucContext.getClassLoaderResolver(getClass().getClassLoader());
    return EntityUtils.determineKind(
        mdm.getMetaDataForClass(
            clazz,
            nucContext.getClassLoaderResolver(getClass().getClassLoader())),
            storeMgr,
            clr);
  }
View Full Code Here

Examples of org.datanucleus.metadata.MetaDataManager

        this.emd = emd;
        this.typeName = typeName;
        this.objectType = (short) objectType;

        // Find the MetaData for the embedded PC class
        MetaDataManager mmgr = datastoreContainer.getStoreManager().getMetaDataManager();
        AbstractClassMetaData rootEmbCmd = mmgr.getMetaDataForClass(typeName, clr);
        if (rootEmbCmd == null)
        {
            // Not found so must be an interface
            if (fmd != null)
            {
                // Try using the fieldTypes on the field/property - we support it if only 1 implementation
                String[] fieldTypes = fmd.getFieldTypes();
                if (fieldTypes != null && fieldTypes.length == 1)
                {
                    rootEmbCmd = mmgr.getMetaDataForClass(fieldTypes[0], clr);
                }
                else if (fieldTypes != null && fieldTypes.length > 1)
                {
                    // TODO Cater for multiple implementations
                    throw new NucleusUserException("Field " + fmd.getFullFieldName() +
                        " is a reference field that is embedded with multiple possible implementations. " +
                        "DataNucleus doesnt support embedded reference fields that have more than 1 implementation");
                }
            }

            if (rootEmbCmd == null)
            {
                // Try a persistent interface
                rootEmbCmd = mmgr.getMetaDataForInterface(clr.classForName(typeName), clr);
                if (rootEmbCmd == null && fmd.getFieldTypes() != null && fmd.getFieldTypes().length == 1)
                {
                    // No MetaData for the type so try "fieldType" specified on the field
                    rootEmbCmd = mmgr.getMetaDataForInterface(clr.classForName(fmd.getFieldTypes()[0]), clr);
                }
            }
        }

        embCmd = rootEmbCmd;

        AbstractMemberMetaData[] embFmds;
        if (emd == null && rootEmbCmd.isEmbeddedOnly())
        {
            // No <embedded> block yet the class is defined as embedded-only so just use its own definition of fields
            embFmds = rootEmbCmd.getManagedMembers();
        }
        else
        {
            // <embedded> block so use those field definitions
            embFmds = emd.getMemberMetaData();
        }

        String[] subclasses = mmgr.getSubclassesForClass(rootEmbCmd.getFullClassName(), true);
        if (subclasses != null && subclasses.length > 0)
        {
            if (rootEmbCmd.hasDiscriminatorStrategy())
            {
                discrimMetaData = new DiscriminatorMetaData();
View Full Code Here

Examples of org.datanucleus.metadata.MetaDataManager

    if (!allowSubclasses) {
      return false;
    }

    MetaDataManager mdm = ec.getMetaDataManager();
    // see if the key kind is a subclass of the requested kind
    String[] subclasses = mdm.getSubclassesForClass(cls.getName(), true);
    if (subclasses != null) {
      for (String subclass : subclasses) {
        AbstractClassMetaData subAcmd = mdm.getMetaDataForClass(subclass, ec.getClassLoaderResolver());
        if (key.getKind().equals(determineKind(subAcmd, ec))) {
          return true;
        }
      }
    }
View Full Code Here

Examples of org.datanucleus.metadata.MetaDataManager

      if (managesField(fmd.getFullFieldName())) {
        if (!fmd.getClassName(true).equals(curCmd.getFullClassName())) {
          throw new UnsupportedOperationException("Overrides not currently supported.");
        }
      } else {
        MetaDataManager mmgr = storeMgr.getMetaDataManager();

        // Manage the field if not already managed (may already exist if overriding a superclass field)
        JavaTypeMapping mapping = null;
        if (fmd.getPersistenceModifier() == FieldPersistenceModifier.PERSISTENT) {
          boolean isPrimary = true;
          if (fmd.getTable() != null && fmd.getJoinMetaData() == null) {
            // Field has a table specified and is not a 1-N with join table so is mapped to a secondary table
            isPrimary = false;
          }

          if (isPrimary) {
            // Add the field to this table
            mapping = dba.getMappingManager(storeMgr).getMapping(this, fmd, clr, FieldRole.ROLE_FIELD);
            addFieldMapping(mapping);
            embeddedFieldMappingsMap.put(fmd, fieldMappingsMap.get(fmd));
          } else {
            throw new UnsupportedOperationException("No support for secondary tables.");
          }
        } else if (fmd.getPersistenceModifier() != FieldPersistenceModifier.TRANSACTIONAL) {
          throw new NucleusException("Invalid persistence-modifier for field ").setFatal();
        }

        // Calculate if we need a FK adding due to a 1-N relationship TODO Remove this when no longer supporting old storageVersion
        // Note that we ignore any "join" setting since we don't use join tables
        boolean needsFKToContainerOwner = false;
        RelationType relationType = fmd.getRelationType(clr);
        if (relationType == RelationType.ONE_TO_MANY_BI) {
          /*AbstractMemberMetaData[] relatedMmds = fmd.getRelatedMemberMetaData(clr);
          if (fmd.getJoinMetaData() == null && relatedMmds[0].getJoinMetaData() == null) {*/
            needsFKToContainerOwner = true;
          /*}*/
        } else if (relationType == RelationType.ONE_TO_MANY_UNI) {
          /*if (fmd.getJoinMetaData() == null) {*/
            needsFKToContainerOwner = true;
          /*}*/
        } else if (relationType == RelationType.ONE_TO_ONE_BI) {
          if (fmd.getMappedBy() != null && MetaDataUtils.isOwnedRelation(fmd, storeMgr)) {
            // This element type has a many-to-one pointing back.
            // We assume that our pk is part of the pk of the element type.
            DatastoreTable dt = storeMgr.getDatastoreClass(fmd.getAbstractClassMetaData().getFullClassName(), clr);
            dt.runCallBacks();
            dt.markFieldAsParentKeyProvider(fmd.getName());
          }
        } else if (relationType == RelationType.MANY_TO_ONE_BI) {
        }

        if (needsFKToContainerOwner) {
          // 1-N uni/bidirectional using FK, so update the element side with a FK
          if ((fmd.getCollection() != null && !SCOUtils.collectionHasSerialisedElements(fmd)) ||
              (fmd.getArray() != null && !SCOUtils.arrayIsStoredInSingleColumn(fmd, mmgr))) {
            // 1-N ForeignKey collection/array, so add FK to element table
            AbstractClassMetaData elementCmd;
            if (fmd.hasCollection()) {
              // Collection
              elementCmd = mmgr.getMetaDataForClass(fmd.getCollection().getElementType(), clr);
            } else {
              // Array
              elementCmd = mmgr.getMetaDataForClass(fmd.getType().getComponentType(), clr);
            }
            if (elementCmd == null) {
              // Elements that are reference types or non-PC will come through here
            } else {
              AbstractClassMetaData[] elementCmds;
              // TODO : Cater for interface elements, and get the metadata for the implementation classes here
              if (elementCmd.getInheritanceMetaData().getStrategy() == InheritanceStrategy.SUBCLASS_TABLE) {
                elementCmds = storeMgr.getClassesManagingTableForClass(elementCmd, clr);
              } else {
                elementCmds = new ClassMetaData[1];
                elementCmds[0] = elementCmd;
              }

              // Run callbacks for each of the element classes.
              for (AbstractClassMetaData elementCmd1 : elementCmds) {
                callbacks.put(elementCmd1.getFullClassName(), new CallBack(fmd, cmd.getFullClassName()));
                DatastoreTable dt =
                    (DatastoreTable) storeMgr.getDatastoreClass(elementCmd1.getFullClassName(), clr);
                dt.runCallBacks();
                if (fmd.getMappedBy() != null && MetaDataUtils.isOwnedRelation(fmd, storeMgr)) {
                  // This element type has a many-to-one pointing back.
                  // We assume that our pk is part of the pk of the element type.
                  dt.markFieldAsParentKeyProvider(fmd.getMappedBy());
                }
              }
            }
          } else if (fmd.getMap() != null && !SCOUtils.mapHasSerialisedKeysAndValues(fmd)) {
            // 1-N ForeignKey map, so add FK to value table
            if (fmd.getKeyMetaData() != null && fmd.getKeyMetaData().getMappedBy() != null) {
              // Key is stored in the value table so add the FK to the value table
              AbstractClassMetaData valueCmd = mmgr.getMetaDataForClass(fmd.getMap().getValueType(), clr);
              if (valueCmd == null) {
                // Interface elements will come through here and java.lang.String and others as well
              }
            } else if (fmd.getValueMetaData() != null
                       && fmd.getValueMetaData().getMappedBy() != null) {
              // Value is stored in the key table so add the FK to the key table
              AbstractClassMetaData keyCmd = mmgr.getMetaDataForClass(fmd.getMap().getKeyType(), clr);
              if (keyCmd == null) {
                // Interface elements will come through here and java.lang.String and others as well
              } else {
              }
            }
View Full Code Here

Examples of org.jpox.metadata.MetaDataManager

        this.emd = emd;
        this.typeName = typeName;
        this.objectType = objectType;

        // Find the MetaData for the embedded PC class
        MetaDataManager mmgr = fmd.getAbstractClassMetaData().getMetaDataManager();
        AbstractClassMetaData pcCmd = mmgr.getMetaDataForClass(typeName, clr);
        if (pcCmd == null)
        {
            // Not found so must be an interface
            if (fmd != null)
            {
                // Try using the fieldTypes on the field/property - we support it if only 1 implementation
                String[] fieldTypes = fmd.getFieldTypes();
                if (fieldTypes != null && fieldTypes.length == 1)
                {
                    pcCmd = mmgr.getMetaDataForClass(fieldTypes[0], clr);
                }
                else if (fieldTypes != null && fieldTypes.length > 1)
                {
                    // TODO Cater for multiple implementations
                    throw new JPOXUserException("Field " + fmd.getFullFieldName() + " is a reference field that is embedded. " +
                        "JPOX doesnt support embedded reference fields that have more than 1 implementation");
                }
            }

            if (pcCmd == null)
            {
                // Try a persistent interface
                pcCmd = mmgr.getMetaDataForInterface(clr.classForName(typeName), clr);
                if (pcCmd == null && fmd.getFieldTypes() != null && fmd.getFieldTypes().length == 1)
                {
                    // No MetaData for the type so try "fieldType" specified on the field
                    pcCmd = mmgr.getMetaDataForInterface(clr.classForName(fmd.getFieldTypes()[0]), clr);
                }
            }
        }

        embCmd = pcCmd;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.