Package org.apache.openjpa.meta

Examples of org.apache.openjpa.meta.MetaDataRepository


  public void testPreloadBasic() {
    OpenJPAEntityManagerFactorySPI emf = null;
    try {
      emf = createNamedEMF(PU_NAME, "openjpa.MetaDataRepository",
          "Preload=true");
      MetaDataRepository mdr = emf.getConfiguration()
          .getMetaDataRepositoryInstance();

      // Check that there is cached metadata in the repo
      ClassMetaData metadata = mdr.getCachedMetaData(MdrTestEntity.class);
      assertNotNull(metadata);

      // Make sure that there is an alias registered
      // int numEntities =
      // mdr.getPersistentTypeNames(false,
      // AccessController.doPrivileged(J2DoPrivHelper.getContextClassLoaderAction())).size();
      Collection<String> aliases = mdr.getAliasNames();
      assertTrue(aliases.contains("MdrTestEntity"));

      // assertTrue(aliases.size() == numEntities);

      QueryMetaData query = mdr.getCachedQueryMetaData("query");
      assertNotNull(query);
    } finally {
      closeEMF(emf);
    }
  }
View Full Code Here


  }
 
  public void testPreloadCleanUp() {
        OpenJPAEntityManagerFactorySPI emf = null;
        emf = createNamedEMF(PU_NAME, "openjpa.MetaDataRepository", "Preload=true");
        MetaDataRepository repo = emf.getConfiguration().getMetaDataRepositoryInstance();
        emf.createEntityManager();
        closeEMF(emf);
        assertFalse("The PCRegistry should no longer reference the MetaDataRepository.", PCRegistry
            .removeRegisterClassListener(repo));
    }
View Full Code Here

        OpenJPAEntityManagerFactorySPI emf = null;
        try {
            emf =
                createNamedEMF("test", "openjpa.MetaDataRepository", "Preload=true", Customer.class,
                    Customer.CustomerKey.class, Order.class, EAddress.class);
            MetaDataRepository mdr = emf.getConfiguration().getMetaDataRepositoryInstance();

            assertNotNull(mdr.getCachedXMLMetaData(Address.class));
            assertNull(mdr.getCachedXMLMetaData(Order.class));
           

        } finally {
            closeEMF(emf);
        }
View Full Code Here

     * Returns the repository for this parser. If none has been set,
     * create a new repository and sets it.
     */
    public MetaDataRepository getRepository() {
        if (_repos == null) {
            MetaDataRepository repos = _conf.newMetaDataRepositoryInstance();
            MetaDataFactory mdf = repos.getMetaDataFactory();
            if (mdf instanceof DelegatingMetaDataFactory)
                mdf = ((DelegatingMetaDataFactory) mdf).getInnermostDelegate();
            if (mdf instanceof PersistenceMetaDataFactory)
                ((PersistenceMetaDataFactory) mdf).setAnnotationParser(this);
            _repos = repos;
View Full Code Here

            }
        }
    }

    private FetchPlan getFetchPlan(OpenJPAEntityManagerSPI em) {
        MetaDataRepository mdr = em.getConfiguration().getMetaDataRepositoryInstance();
        FetchPlan fp = em.pushFetchPlan();
        fp.removeFetchGroups(fp.getFetchGroups());
        for (Class<?> cls : new Class<?>[] { OptSelectEntity.class }) {
            ClassMetaData cmd = mdr.getMetaData(cls, null, true);
            for (FieldMetaData fmd : cmd.getFields()) {
                fp.addField(cls, fmd.getName());
            }
        }
        return fp;
View Full Code Here

        return getClassMetaData(schemaName, true);
    }

    private ClassMetaData getClassMetaData(String alias, boolean assertValid) {
        ClassLoader loader = getClassLoader();
        MetaDataRepository repos = resolver.getConfiguration().
            getMetaDataRepositoryInstance();

        // first check for the alias
        ClassMetaData cmd = repos.getMetaData(alias, loader, false);

        if (cmd != null)
            return cmd;

        // now check for the class name; this is not technically permitted
        // by the JPA spec, but is required in order to be able to execute
        // JPQL queries from other facades (like JDO) that do not have
        // the concept of entity names or aliases
        Class<?> c = resolver.classForName(alias, null);
        if (c != null)
            cmd = repos.getMetaData(c, loader, assertValid);
        else if (assertValid)
            cmd = repos.getMetaData(alias, loader, false);

        if (cmd == null && assertValid) {
            String close = repos.getClosestAliasName(alias);
            if (close != null)
                throw parseException(EX_USER, "not-schema-name-hint",
                    new Object[]{ alias, close, repos.getAliasNames() }, null);
            else
                throw parseException(EX_USER, "not-schema-name",
                    new Object[]{ alias, repos.getAliasNames() }, null);
        }

        return cmd;
    }
View Full Code Here

            // setup transient state
            setup();

            // register the metdata repository to auto-load persistent types
            // and make sure types are enhanced
            MetaDataRepository repos = _conf.getMetaDataRepositoryInstance();
            repos.setValidate(MetaDataRepository.VALIDATE_RUNTIME, true);
            repos.setResolve(MetaDataModes.MODE_MAPPING_INIT, true);
            PCRegistry.addRegisterClassListener(repos);

            // freeze underlying configuration and eagerly initialize to
            // avoid synchronization
            _conf.setReadOnly(Configuration.INIT_STATE_FREEZING);
View Full Code Here

        // Don't get a MetaDataRepository yet if not preloading because it is possible that someone has extended the MDR
        // and the extension hasn't been plugged in yet.
        if (MetaDataRepository.needsPreload(_conf) == true) {
            // Don't catch any exceptions here because we want to fail-fast if something bad happens when we're
            // preloading.
            MetaDataRepository mdr = _conf.getMetaDataRepositoryInstance();
            mdr.setValidate(MetaDataRepository.VALIDATE_RUNTIME, true);
            mdr.setResolve(MetaDataRepository.MODE_MAPPING_INIT, true);

            // Load persistent classes and hook in subclasser
            loadPersistentTypes((ClassLoader) AccessController.doPrivileged(J2DoPrivHelper
                .getContextClassLoaderAction()));
            mdr.preload();
        }

        // Get a DataCacheManager instance up front to avoid threading concerns on first call.
        // _conf.getDataCacheManagerInstance();
View Full Code Here

        OpenJPAEntityManager kem = OpenJPAPersistence.cast (em);
        JDBCConfiguration conf =
            (JDBCConfiguration) ((OpenJPAEntityManagerSPI) kem)
            .getConfiguration();

        MetaDataRepository repos = conf.getMappingRepositoryInstance();
        ClassMetaData meta;
        for (int i = 0; i < clss.length; i++) {
            meta = repos.getMetaData(clss[i], null, true);
            detachedStateFields[i] = meta.getDetachedState();
            meta.setDetachedState(null);

           deleteAll(clss[i]);
        }

        try {
            attachTest();
        } finally {
            // set detached state back
            for (int i = 0; i < clss.length; i++)
                repos.getMetaData(clss[i], null, true).setDetachedState
                    (detachedStateFields[i]);
        }
    }
View Full Code Here

     */
    public ApplicationIdTool(OpenJPAConfiguration conf, Class type) {
        _log = conf.getLog(OpenJPAConfiguration.LOG_ENHANCE);
        _type = type;

        MetaDataRepository repos = conf.newMetaDataRepositoryInstance();
        repos.setValidate(repos.VALIDATE_NONE);
        repos.setSourceMode(repos.MODE_MAPPING, false);
        loadObjectIds(repos, true);
        _meta = repos.getMetaData(type, null, false);
        if (_meta != null) {
            _abstract = Modifier.isAbstract(_meta.getDescribedType().
                getModifiers());
            _fields = getDeclaredPrimaryKeyFields(_meta);
        }
View Full Code Here

TOP

Related Classes of org.apache.openjpa.meta.MetaDataRepository

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.