Package org.datanucleus.metadata

Examples of org.datanucleus.metadata.MetaDataManager


                StringUtils.objectArrayToString(types)));
        }

        // Check if classes are detachable
        NucleusContext nucleusCtxSource = ((JDOPersistenceManagerFactory)pmfSource).getNucleusContext();
        MetaDataManager mmgr = nucleusCtxSource.getMetaDataManager();
        ClassLoaderResolver clr = nucleusCtxSource.getClassLoaderResolver(null);
        for (int i=0;i<types.length;i++)
        {
            AbstractClassMetaData cmd = mmgr.getMetaDataForClass(types[i], clr);
            if (!cmd.isDetachable())
            {
                throw new JDOUserException("Class " + types[i] + " is not detachable so cannot replicate");
            }
        }

        Object[] detachedObjects = null;

        // Detach from datastore 1
        if (NucleusLogger.PERSISTENCE.isDebugEnabled())
        {
            NucleusLogger.PERSISTENCE.debug(LOCALISER_JDO.msg("012053"));
        }
        PersistenceManager pm1 = pmfSource.getPersistenceManager();
        Transaction tx1 = pm1.currentTransaction();
        if (getBooleanProperty("datanucleus.replicateObjectGraph"))
        {
            pm1.getFetchPlan().setGroup(javax.jdo.FetchPlan.ALL);
            pm1.getFetchPlan().setMaxFetchDepth(-1);
        }
        try
        {
            tx1.begin();

            ArrayList objects = new ArrayList();
            for (int i=0;i<types.length;i++)
            {
                AbstractClassMetaData cmd = mmgr.getMetaDataForClass(types[i], clr);
                if (!cmd.isEmbeddedOnly())
                {
                    Extent ex = pm1.getExtent(types[i]);
                    Iterator iter = ex.iterator();
                    while (iter.hasNext())
View Full Code Here


                StringUtils.objectArrayToString(classNames)));
        }

        // Check if classes are detachable
        NucleusContext nucleusCtxSource = ((JDOPersistenceManagerFactory)pmfSource).getNucleusContext();
        MetaDataManager mmgr = nucleusCtxSource.getMetaDataManager();
        ClassLoaderResolver clr = nucleusCtxSource.getClassLoaderResolver(null);
        for (int i=0;i<classNames.length;i++)
        {
            AbstractClassMetaData cmd = mmgr.getMetaDataForClass(classNames[i], clr);
            if (!cmd.isDetachable())
            {
                throw new JDOUserException("Class " + classNames[i] + " is not detachable so cannot replicate");
            }
        }

        Object[] detachedObjects = null;

        // Detach from datastore 1
        if (NucleusLogger.PERSISTENCE.isDebugEnabled())
        {
            NucleusLogger.PERSISTENCE.debug(LOCALISER_JDO.msg("012053"));
        }
        PersistenceManager pm1 = pmfSource.getPersistenceManager();
        Transaction tx1 = pm1.currentTransaction();
        if (getBooleanProperty("datanucleus.replicateObjectGraph"))
        {
            pm1.getFetchPlan().setGroup(javax.jdo.FetchPlan.ALL);
            pm1.getFetchPlan().setMaxFetchDepth(-1);
        }
        try
        {
            tx1.begin();

            clr = ((JDOPersistenceManager)pm1).getObjectManager().getClassLoaderResolver();
            ArrayList objects = new ArrayList();
            for (int i=0;i<classNames.length;i++)
            {
                Class cls = clr.classForName(classNames[i]);
                AbstractClassMetaData cmd = mmgr.getMetaDataForClass(cls, clr);
                if (!cmd.isEmbeddedOnly())
                {
                    Extent ex = pm1.getExtent(cls);
                    Iterator iter = ex.iterator();
                    while (iter.hasNext())
View Full Code Here

     * Method to perform the replication for all objects registered in the pmf source.
     */
    public void replicateRegisteredClasses()
    {
        ClassLoaderResolver clr = ((JDOPersistenceManager)pmfSource.getPersistenceManager()).getObjectManager().getClassLoaderResolver();
        MetaDataManager mmgr = ((JDOPersistenceManagerFactory)pmfSource).getNucleusContext().getMetaDataManager();
        Collection classNames = mmgr.getClassesWithMetaData();
        ArrayList arrayTypes = new ArrayList();

        Iterator iterator = classNames.iterator();
        while (iterator.hasNext())
        {
            String className = (String) iterator.next();
            AbstractClassMetaData cmd = mmgr.getMetaDataForClass(className, clr);
            if (!cmd.isEmbeddedOnly()) // Omit embedded-only classes since can't replicate those
            {
                arrayTypes.add(clr.classForName(className));
            }
        }
View Full Code Here

public class MetaDataValidatorTest extends JDOTestCase {

  public void testIgnorableMapping_NoConfig() {
    setIgnorableMetaDataBehavior(null);
    NucleusContext nucContext = ((JDOPersistenceManagerFactory)pmf).getNucleusContext();
    MetaDataManager mdm = nucContext.getMetaDataManager();
    final String[] loggedMsg = {null};
    AbstractClassMetaData acmd =
        mdm.getMetaDataForClass(Flight.class, nucContext.getClassLoaderResolver(getClass().getClassLoader()));
    MetaDataValidator mdv = new MetaDataValidator((DatastoreManager) nucContext.getStoreManager(), mdm, null) {
      @Override
      void warn(String msg) {
        loggedMsg[0] = msg;
      }
View Full Code Here

  }

  public void testIgnorableMapping_NoneConfig() {
    setIgnorableMetaDataBehavior(MetaDataValidator.IgnorableMetaDataBehavior.NONE.name());
    NucleusContext nucContext = ((JDOPersistenceManagerFactory)pmf).getNucleusContext();
    MetaDataManager mdm = nucContext.getMetaDataManager();
    MetaDataValidator mdv = new MetaDataValidator((DatastoreManager) nucContext.getStoreManager(), mdm, null) {
      @Override
      void warn(String msg) {
        fail("shouldn't have been called");
      }
View Full Code Here

  }

  public void testIgnorableMapping_WarningConfig() {
    setIgnorableMetaDataBehavior(MetaDataValidator.IgnorableMetaDataBehavior.WARN.name());
    NucleusContext nucContext = ((JDOPersistenceManagerFactory)pmf).getNucleusContext();
    MetaDataManager mdm = nucContext.getMetaDataManager();
    final String[] loggedMsg = {null};
    AbstractClassMetaData acmd =
        mdm.getMetaDataForClass(Flight.class, nucContext.getClassLoaderResolver(getClass().getClassLoader()));
    MetaDataValidator mdv = new MetaDataValidator((DatastoreManager) nucContext.getStoreManager(), mdm, null) {
      @Override
      void warn(String msg) {
        loggedMsg[0] = msg;
      }
View Full Code Here

  }

  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

        // 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

    }
  }

  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

        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

TOP

Related Classes of org.datanucleus.metadata.MetaDataManager

Copyright © 2018 www.massapicom. 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.