Package org.eclipse.persistence.internal.jpa

Examples of org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl


        if (name == null){
            name = "";
        }

        JPAInitializer initializer = initializationHelper.getInitializer(classLoader, nonNullProperties);
        EntityManagerSetupImpl emSetupImpl = null;

        try {
            Enumeration<URL> resources = classLoader.getResources("META-INF/persistence.xml");
            boolean initialized = false;
            while (resources.hasMoreElements()) {
                String puName = PersistenceUnitProcessor.buildPersistenceUnitName(PersistenceUnitProcessor.computePURootURL(resources.nextElement()), name);

                synchronized (EntityManagerFactoryProvider.persistenceUnits) {
                    PersistenceUnitInfo puInfo = EntityManagerFactoryProvider.getPersistenceUnitInfo(puName);
                    if (puInfo == null) {
                        if (!initialized) {
                            initializer.initialize(nonNullProperties, initializationHelper);
                            initialized = true;
                        }
                        puInfo = EntityManagerFactoryProvider.getPersistenceUnitInfo(puName);
                    }
                    if (puInfo != null) {
                        String esiName = puName;
                        if (nonNullProperties.get(PersistenceUnitProperties.SESSION_NAME) != null) {
                            esiName = puName + nonNullProperties.get(PersistenceUnitProperties.SESSION_NAME);
                        } else {
                            if (puInfo.getProperties().get(PersistenceUnitProperties.SESSION_NAME) != null) {
                                esiName = puName + puInfo.getProperties().get(PersistenceUnitProperties.SESSION_NAME);
                            }
                        }
                        emSetupImpl = EntityManagerFactoryProvider.getEntityManagerSetupImpl(esiName);
                        if (emSetupImpl == null) {
                            initializer.callPredeploy(puInfo, nonNullProperties, initializationHelper);
                            emSetupImpl = EntityManagerFactoryProvider.getEntityManagerSetupImpl(esiName);
                        }
                    }

                    // We found a match, stop looking.
                    if (emSetupImpl != null) {
                        break;
                    }
                }
            }
        } catch (Exception e) {
            throw PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(classLoader, e);
        }

        //gf bug 854  Returns null if EntityManagerSetupImpl for the name doesn't exist (e.g. a non-existent PU)
        if (emSetupImpl == null) {
            return null;
        }
           
        if (!initializer.isPersistenceProviderSupported(emSetupImpl.getPersistenceUnitInfo().getPersistenceProviderClassName())){
            return null;
        }

        // synchronized to prevent overriding of the class loader
        // and also calls to predeploy and undeploy by other threads -
        // the latter may alter result of shouldRedeploy method.
        synchronized(emSetupImpl) {
            if(emSetupImpl.shouldRedeploy()) {
                SEPersistenceUnitInfo persistenceInfo = (SEPersistenceUnitInfo)emSetupImpl.getPersistenceUnitInfo();
                persistenceInfo.setClassLoader(initializationHelper.getClassLoader(emName, properties));
                if (emSetupImpl.isUndeployed()){
                    persistenceInfo.setNewTempClassLoader(initializationHelper.getClassLoader(emName, properties));
                }
            }
           
            // 253701: cache a reference to (this) PersistenceProvider's initializer for later use during undeploy()
            emSetupImpl.setPersistenceInitializationHelper(this.initializationHelper);
           
            // call predeploy
            // this will just increment the factory count since we should already be deployed
            emSetupImpl.predeploy(emSetupImpl.getPersistenceUnitInfo(), nonNullProperties);
        }
           
        EntityManagerFactoryImpl factory = null;
        try {
            factory = new EntityManagerFactoryImpl(emSetupImpl, nonNullProperties);
       
            // This code has been added to allow validation to occur without actually calling createEntityManager
            if (emSetupImpl.shouldGetSessionOnCreateFactory(nonNullProperties)) {
                factory.getServerSession();
            }
            return factory;
        } catch (RuntimeException ex) {
            if(factory != null) {
                factory.close();
            } else {
                emSetupImpl.undeploy();
            }
            throw ex;
        }
    }
View Full Code Here


     * by the persistence provider.
     */
    public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties){
            Map nonNullProperties = (properties == null) ? new HashMap() : properties;
       
        EntityManagerSetupImpl emSetupImpl = null;
            boolean isNew = false;
            ClassTransformer transformer = null;
        synchronized (EntityManagerFactoryProvider.emSetupImpls) {
            String puName = PersistenceUnitProcessor.buildPersistenceUnitName(info.getPersistenceUnitRootUrl(), info.getPersistenceUnitName());
            String esiName = puName;
            if (nonNullProperties.get(PersistenceUnitProperties.SESSION_NAME) != null) {
                esiName = puName + nonNullProperties.get(PersistenceUnitProperties.SESSION_NAME);
            } else {
                if (info.getProperties().get(PersistenceUnitProperties.SESSION_NAME) != null) {
                    esiName = puName + info.getProperties().get(PersistenceUnitProperties.SESSION_NAME);
                }
            }
            emSetupImpl = EntityManagerFactoryProvider.getEntityManagerSetupImpl(esiName);
            if (emSetupImpl == null){
                emSetupImpl = new EntityManagerSetupImpl();
                    isNew = true;
                emSetupImpl.setIsInContainerMode(true);       
                    // if predeploy fails then emSetupImpl shouldn't be added to FactoryProvider
                    transformer = emSetupImpl.predeploy(info, nonNullProperties);
                EntityManagerFactoryProvider.addEntityManagerSetupImpl(esiName, emSetupImpl);
            }
        }
           
            if(!isNew && !emSetupImpl.isDeployed()) {
            transformer = emSetupImpl.predeploy(info, nonNullProperties);
        }
        if (transformer != null){
            info.addTransformer(transformer);
        }
        // When EntityManagerFactory is created, the session is only partially created
        // When the factory is actually accessed, the emSetupImpl will be used to complete the session construction
        EntityManagerFactoryImpl factory = new EntityManagerFactoryImpl(emSetupImpl, nonNullProperties);

        // This code has been added to allow validation to occur without actually calling createEntityManager
        if (emSetupImpl.shouldGetSessionOnCreateFactory(nonNullProperties)) {
            factory.getServerSession();
        }
        return factory;
    }
View Full Code Here

                sessionName = (String)persistenceUnitInfo.getProperties().get(PersistenceUnitProperties.SESSION_NAME);
            }
            if (sessionName == null) sessionName = "";
            String emName = PersistenceUnitProcessor.buildPersistenceUnitName(persistenceUnitInfo.getPersistenceUnitRootUrl(),persistenceUnitInfo.getPersistenceUnitName()) + sessionName;
           
            EntityManagerSetupImpl emSetupImpl = EntityManagerFactoryProvider.getEntityManagerSetupImpl(emName);
            // if we already have an EntityManagerSetupImpl this PU has already been processed.  Use the existing one
            if (emSetupImpl != null && !emSetupImpl.isUndeployed()){
                return false;
            }
            Set tempLoaderSet = PersistenceUnitProcessor.buildClassSet(persistenceUnitInfo, Thread.currentThread().getContextClassLoader());
            AbstractSessionLog.getLog().log(SessionLog.FINER, "cmp_init_invoke_predeploy", persistenceUnitInfo.getPersistenceUnitName());
            Map mergedProperties = EntityManagerFactoryProvider.mergeMaps(m, persistenceUnitInfo.getProperties());
            // Bug#4452468  When globalInstrumentation is null, there is no weaving
            checkWeaving(mergedProperties);
           
            if (persistenceUnitInfo instanceof SEPersistenceUnitInfo){
                // Create the temp loader that will not cache classes for entities in our persistence unit
                ClassLoader tempLoader = createTempLoader(tempLoaderSet);
                ((SEPersistenceUnitInfo)persistenceUnitInfo).setNewTempClassLoader(tempLoader);
                ((SEPersistenceUnitInfo)persistenceUnitInfo).setClassLoader(persistenceHelper.getClassLoader(persistenceUnitInfo.getPersistenceUnitName(), m));
            }
            if (emSetupImpl == null){
                emSetupImpl = new EntityManagerSetupImpl();
                // Bug 210280/215865: use the decoded URL path + PU name as the key in the EMSetup map - to handle paths with spaces
                EntityManagerFactoryProvider.addEntityManagerSetupImpl(emName, emSetupImpl);
                ++ EntityManagerFactoryProvider.PUIUsageCount;
            }
          
   
            // A call to predeploy will partially build the session we will use
            final ClassTransformer transformer = emSetupImpl.predeploy(persistenceUnitInfo, mergedProperties);
   
            registerTransformer(transformer, persistenceUnitInfo);
            return true;
        }
        return false;
View Full Code Here

        }
        if (!checkForProviderProperty(nonNullProperties)){
            //not EclipseLink so return null;
            return null;
        }
        EntityManagerSetupImpl emSetupImpl = null;
        boolean isNew = false;
        // the name that uniquely defines persistence unit
        String uniqueName = null;
        String sessionName = null;
        JPAInitializer initializer = getInitializer(emName, nonNullProperties);
        try {
            SEPersistenceUnitInfo puInfo = initializer.findPersistenceUnitInfo(name, nonNullProperties);
            // either persistence unit not found or provider not supported
            if(puInfo == null) {
                return null;
            }
           
            if(EntityManagerSetupImpl.mustBeCompositeMember(puInfo)) {
                // persistence unit cannot be used standalone (only as a composite member).
                // still the factory will be created but attempt to createEntityManager would cause an exception.
                emSetupImpl = new EntityManagerSetupImpl(name, name);
                // predeploy assigns puInfo and does not do anything else.
                // the session is not created, no need to add emSetupImpl to the global map.
                emSetupImpl.predeploy(puInfo, nonNullProperties);
                isNew = true;
            } else {
                if(initializer.isPersistenceUnitUniquelyDefinedByName()) {
                    uniqueName = name;
                } else {
                    uniqueName = initializer.createUniquePersistenceUnitName(puInfo);
                }
                   
                sessionName = EntityManagerSetupImpl.getOrBuildSessionName(nonNullProperties, puInfo, uniqueName);
                synchronized (EntityManagerFactoryProvider.emSetupImpls) {
                    emSetupImpl = EntityManagerFactoryProvider.getEntityManagerSetupImpl(sessionName);
                    if(emSetupImpl == null) {
                        // there may be initial emSetupImpl cached in Initializer - remove it and use.
                        emSetupImpl = initializer.extractInitialEmSetupImpl(name);
                        if(emSetupImpl != null) {
                            // change the name
                            emSetupImpl.changeSessionName(sessionName);
                        } else {
                            // create and predeploy a new emSetupImpl
                            emSetupImpl = initializer.callPredeploy(puInfo, nonNullProperties, uniqueName, sessionName);
                        }
                        // emSetupImpl has been already predeployed, predeploy will just increment factoryCount.
                        emSetupImpl.predeploy(emSetupImpl.getPersistenceUnitInfo(), nonNullProperties);
                        EntityManagerFactoryProvider.addEntityManagerSetupImpl(sessionName, emSetupImpl);
                        isNew = true;
                    }
                }
            }
        } catch (Exception e) {
            throw PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(initializer.getInitializationClassLoader(), e);
        }

        if(!isNew) {
            if(!uniqueName.equals(emSetupImpl.getPersistenceUnitUniqueName())) {
                throw PersistenceUnitLoadingException.sessionNameAlreadyInUse(sessionName, uniqueName, emSetupImpl.getPersistenceUnitUniqueName());
            }
           
            // synchronized to prevent undeploying by other threads.
            boolean undeployed = false;
            synchronized(emSetupImpl) {
                if(emSetupImpl.isUndeployed()) {
                    undeployed = true;
                }
               
                // emSetupImpl has been already predeployed, predeploy will just increment factoryCount.
                emSetupImpl.predeploy(emSetupImpl.getPersistenceUnitInfo(), nonNullProperties);
            }
            if(undeployed) {
                // after the emSetupImpl has been obtained from emSetupImpls
                // it has been undeployed by factory.close() in another thread - start all over again.
                return createEntityManagerFactory(emName, properties);
            }
        }
           
        EntityManagerFactoryImpl factory = null;
        try {
            factory = new EntityManagerFactoryImpl(emSetupImpl, nonNullProperties);
       
            // This code has been added to allow validation to occur without actually calling createEntityManager
            if (emSetupImpl.shouldGetSessionOnCreateFactory(nonNullProperties)) {
                factory.getDatabaseSession();
            }
            return factory;
        } catch (RuntimeException ex) {
            if(factory != null) {
                factory.close();
            } else {
                emSetupImpl.undeploy();
            }
            throw ex;
        }
    }
View Full Code Here

        // Record that we are inside a JEE container to allow weaving for non managed persistence units.
        JavaSECMPInitializer.setIsInContainer(true);
       
        Map nonNullProperties = (properties == null) ? new HashMap() : properties;
       
        EntityManagerSetupImpl emSetupImpl = null;
        if (EntityManagerSetupImpl.mustBeCompositeMember(info)) {
            // persistence unit cannot be used standalone (only as a composite member).
            // still the factory will be created but attempt to createEntityManager would cause an exception.
            emSetupImpl = new EntityManagerSetupImpl(info.getPersistenceUnitName(), info.getPersistenceUnitName());
            // predeploy assigns puInfo and does not do anything else.
            // the session is not created, no need to add emSetupImpl to the global map.
            emSetupImpl.predeploy(info, nonNullProperties);
        } else {
            boolean isNew = false;
            ClassTransformer transformer = null;
            String uniqueName = PersistenceUnitProcessor.buildPersistenceUnitName(info.getPersistenceUnitRootUrl(), info.getPersistenceUnitName());
            String sessionName = EntityManagerSetupImpl.getOrBuildSessionName(nonNullProperties, info, uniqueName);
            synchronized (EntityManagerFactoryProvider.emSetupImpls) {
                emSetupImpl = EntityManagerFactoryProvider.getEntityManagerSetupImpl(sessionName);
                if (emSetupImpl == null){
                    emSetupImpl = new EntityManagerSetupImpl(uniqueName, sessionName);
                    isNew = true;
                    emSetupImpl.setIsInContainerMode(true);       
                    // if predeploy fails then emSetupImpl shouldn't be added to FactoryProvider
                    transformer = emSetupImpl.predeploy(info, nonNullProperties);
                    EntityManagerFactoryProvider.addEntityManagerSetupImpl(sessionName, emSetupImpl);
                }
            }
               
            if(!isNew) {
                if(!uniqueName.equals(emSetupImpl.getPersistenceUnitUniqueName())) {
                    throw PersistenceUnitLoadingException.sessionNameAlreadyInUse(sessionName, uniqueName, emSetupImpl.getPersistenceUnitUniqueName());
                }
                // synchronized to prevent undeploying by other threads.
                boolean undeployed = false;
                synchronized(emSetupImpl) {
                    if(emSetupImpl.isUndeployed()) {
                        undeployed = true;
                    }
                   
                    // emSetupImpl has been already predeployed, predeploy will just increment factoryCount.
                    transformer = emSetupImpl.predeploy(emSetupImpl.getPersistenceUnitInfo(), nonNullProperties);
                }
                if(undeployed) {
                    // after the emSetupImpl has been obtained from emSetupImpls
                    // it has been undeployed by factory.close() in another thread - start all over again.
                    return createContainerEntityManagerFactory(info, properties);
                }
            }
            if (transformer != null){
                info.addTransformer(transformer);
            }
        }

        EntityManagerFactoryImpl factory = null;
        try {
            factory = new EntityManagerFactoryImpl(emSetupImpl, nonNullProperties);
       
            // This code has been added to allow validation to occur without actually calling createEntityManager
            if (emSetupImpl.shouldGetSessionOnCreateFactory(nonNullProperties)) {
                factory.getDatabaseSession();
            }
            return factory;
        } catch (RuntimeException ex) {
            if(factory != null) {
                factory.close();
            } else {
                emSetupImpl.undeploy();
            }
            throw ex;
        }
    }
View Full Code Here

     * @return load status of the attribute
     */
    public LoadState isLoadedWithReference(Object entity, String attributeName){
        Iterator<EntityManagerSetupImpl> setups = EntityManagerFactoryProvider.getEmSetupImpls().values().iterator();
        while (setups.hasNext()){
            EntityManagerSetupImpl setup = setups.next();
            if (setup.isDeployed()){
                Boolean isLoaded = EntityManagerFactoryImpl.isLoaded(entity, setup.getSession());
                if (isLoaded != null){
                    if (isLoaded.booleanValue() && attributeName != null){
                        isLoaded = EntityManagerFactoryImpl.isLoaded(entity, attributeName, setup.getSession());
                    }
                    if (isLoaded != null){
                        return isLoaded.booleanValue() ? LoadState.LOADED : LoadState.NOT_LOADED;
                    }
                }
View Full Code Here

        // we will only attempt to deploy when EclipseLink is specified as the provider or the provider is unspecified
        String providerClassName = persistenceUnitInfo.getPersistenceProviderClassName();
        if (isPersistenceProviderSupported(providerClassName)){
            // Bug 210280/215865: this decoded URL path + PU name [puName] must be used as the key in the EMSetup map below
            String puName = PersistenceUnitProcessor.buildPersistenceUnitName(persistenceUnitInfo.getPersistenceUnitRootUrl(),persistenceUnitInfo.getPersistenceUnitName());
            EntityManagerSetupImpl emSetupImpl = EntityManagerFactoryProvider.getEntityManagerSetupImpl(puName);
            // if we already have an EntityManagerSetupImpl this PU has already been processed.  Use the existing one
            if (emSetupImpl != null && !emSetupImpl.isUndeployed()){
                return false;
            }
            Set tempLoaderSet = PersistenceUnitProcessor.buildClassSet(persistenceUnitInfo, Thread.currentThread().getContextClassLoader());
            AbstractSessionLog.getLog().log(SessionLog.FINER, "cmp_init_invoke_predeploy", persistenceUnitInfo.getPersistenceUnitName());
            Map mergedProperties = EntityManagerFactoryProvider.mergeMaps(m, persistenceUnitInfo.getProperties());
            // Bug#4452468  When globalInstrumentation is null, there is no weaving
            checkWeaving(mergedProperties);

            // Create the temp loader that will not cache classes for entities in our persistence unit
            ClassLoader tempLoader = createTempLoader(tempLoaderSet);
            persistenceUnitInfo.setNewTempClassLoader(tempLoader);
            if (emSetupImpl == null){
                emSetupImpl = new EntityManagerSetupImpl();
                // Bug 210280/215865: use the decoded URL path + PU name as the key in the EMSetup map - to handle paths with spaces
                EntityManagerFactoryProvider.addEntityManagerSetupImpl(puName, emSetupImpl);
            }
          
            persistenceUnitInfo.setClassLoader(persistenceHelper.getClassLoader(persistenceUnitInfo.getPersistenceUnitName(), m));
   
            // A call to predeploy will partially build the session we will use
            final ClassTransformer transformer = emSetupImpl.predeploy(persistenceUnitInfo, mergedProperties);
   
            registerTransformer(transformer, persistenceUnitInfo);
            return true;
        }
        return false;
View Full Code Here

        }
        if (!checkForProviderProperty(nonNullProperties)){
            //not EclipseLink so return null;
            return null;
        }
        EntityManagerSetupImpl emSetupImpl = null;
        boolean isNew = false;
        // the name that uniquely defines persistence unit
        String uniqueName = null;
        String sessionName = null;
        JPAInitializer initializer = getInitializer(emName, nonNullProperties);
        try {
            SEPersistenceUnitInfo puInfo = initializer.findPersistenceUnitInfo(name, nonNullProperties);
            // either persistence unit not found or provider not supported
            if(puInfo == null) {
                return null;
            }
           
            if(EntityManagerSetupImpl.mustBeCompositeMember(puInfo)) {
                // persistence unit cannot be used standalone (only as a composite member).
                // still the factory will be created but attempt to createEntityManager would cause an exception.
                emSetupImpl = new EntityManagerSetupImpl(name, name);
                // predeploy assigns puInfo and does not do anything else.
                // the session is not created, no need to add emSetupImpl to the global map.
                emSetupImpl.predeploy(puInfo, nonNullProperties);
                isNew = true;
            } else {
                if(initializer.isPersistenceUnitUniquelyDefinedByName()) {
                    uniqueName = name;
                } else {
                    uniqueName = initializer.createUniquePersistenceUnitName(puInfo);
                }
                   
                sessionName = EntityManagerSetupImpl.getOrBuildSessionName(nonNullProperties, puInfo, uniqueName);
                synchronized (EntityManagerFactoryProvider.emSetupImpls) {
                    emSetupImpl = EntityManagerFactoryProvider.getEntityManagerSetupImpl(sessionName);
                    if(emSetupImpl == null) {
                        // there may be initial emSetupImpl cached in Initializer - remove it and use.
                        emSetupImpl = initializer.extractInitialEmSetupImpl(name);
                        if(emSetupImpl != null) {
                            // change the name
                            emSetupImpl.changeSessionName(sessionName);
                        } else {
                            // create and predeploy a new emSetupImpl
                            emSetupImpl = initializer.callPredeploy(puInfo, nonNullProperties, uniqueName, sessionName);
                        }
                        // emSetupImpl has been already predeployed, predeploy will just increment factoryCount.
                        emSetupImpl.predeploy(emSetupImpl.getPersistenceUnitInfo(), nonNullProperties);
                        EntityManagerFactoryProvider.addEntityManagerSetupImpl(sessionName, emSetupImpl);
                        isNew = true;
                    }
                }
            }
        } catch (Exception e) {
            throw PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(initializer.getInitializationClassLoader(), e);
        }

        if(!isNew) {
            if(!uniqueName.equals(emSetupImpl.getPersistenceUnitUniqueName())) {
                throw PersistenceUnitLoadingException.sessionNameAlreadyInUse(sessionName, uniqueName, emSetupImpl.getPersistenceUnitUniqueName());
            }
           
            // synchronized to prevent undeploying by other threads.
            boolean undeployed = false;
            synchronized(emSetupImpl) {
                if(emSetupImpl.isUndeployed()) {
                    undeployed = true;
                }
               
                // emSetupImpl has been already predeployed, predeploy will just increment factoryCount.
                emSetupImpl.predeploy(emSetupImpl.getPersistenceUnitInfo(), nonNullProperties);
            }
            if(undeployed) {
                // after the emSetupImpl has been obtained from emSetupImpls
                // it has been undeployed by factory.close() in another thread - start all over again.
                return createEntityManagerFactory(emName, properties);
            }
        }
           
        EntityManagerFactoryImpl factory = null;
        try {
            factory = new EntityManagerFactoryImpl(emSetupImpl, nonNullProperties);
       
            // This code has been added to allow validation to occur without actually calling createEntityManager
            if (emSetupImpl.shouldGetSessionOnCreateFactory(nonNullProperties)) {
                factory.getDatabaseSession();
            }
            return factory;
        } catch (RuntimeException ex) {
            if(factory != null) {
                factory.close();
            } else {
                emSetupImpl.undeploy();
            }
            throw ex;
        }
    }
View Full Code Here

        // Record that we are inside a JEE container to allow weaving for non managed persistence units.
        JavaSECMPInitializer.setIsInContainer(true);
       
        Map nonNullProperties = (properties == null) ? new HashMap() : properties;
       
        EntityManagerSetupImpl emSetupImpl = null;
        if (EntityManagerSetupImpl.mustBeCompositeMember(info)) {
            // persistence unit cannot be used standalone (only as a composite member).
            // still the factory will be created but attempt to createEntityManager would cause an exception.
            emSetupImpl = new EntityManagerSetupImpl(info.getPersistenceUnitName(), info.getPersistenceUnitName());
            // predeploy assigns puInfo and does not do anything else.
            // the session is not created, no need to add emSetupImpl to the global map.
            emSetupImpl.predeploy(info, nonNullProperties);
        } else {
            boolean isNew = false;
            ClassTransformer transformer = null;
            String uniqueName = PersistenceUnitProcessor.buildPersistenceUnitName(info.getPersistenceUnitRootUrl(), info.getPersistenceUnitName());
            String sessionName = EntityManagerSetupImpl.getOrBuildSessionName(nonNullProperties, info, uniqueName);
            synchronized (EntityManagerFactoryProvider.emSetupImpls) {
                emSetupImpl = EntityManagerFactoryProvider.getEntityManagerSetupImpl(sessionName);
                if (emSetupImpl == null){
                    emSetupImpl = new EntityManagerSetupImpl(uniqueName, sessionName);
                    isNew = true;
                    emSetupImpl.setIsInContainerMode(true);       
                    // if predeploy fails then emSetupImpl shouldn't be added to FactoryProvider
                    transformer = emSetupImpl.predeploy(info, nonNullProperties);
                    EntityManagerFactoryProvider.addEntityManagerSetupImpl(sessionName, emSetupImpl);
                }
            }
               
            if(!isNew) {
                if(!uniqueName.equals(emSetupImpl.getPersistenceUnitUniqueName())) {
                    throw PersistenceUnitLoadingException.sessionNameAlreadyInUse(sessionName, uniqueName, emSetupImpl.getPersistenceUnitUniqueName());
                }
                // synchronized to prevent undeploying by other threads.
                boolean undeployed = false;
                synchronized(emSetupImpl) {
                    if(emSetupImpl.isUndeployed()) {
                        undeployed = true;
                    }
                   
                    // emSetupImpl has been already predeployed, predeploy will just increment factoryCount.
                    transformer = emSetupImpl.predeploy(emSetupImpl.getPersistenceUnitInfo(), nonNullProperties);
                }
                if(undeployed) {
                    // after the emSetupImpl has been obtained from emSetupImpls
                    // it has been undeployed by factory.close() in another thread - start all over again.
                    return createContainerEntityManagerFactory(info, properties);
                }
            }
            if (transformer != null){
                info.addTransformer(transformer);
            }
        }

        EntityManagerFactoryImpl factory = null;
        try {
            factory = new EntityManagerFactoryImpl(emSetupImpl, nonNullProperties);
       
            // This code has been added to allow validation to occur without actually calling createEntityManager
            if (emSetupImpl.shouldGetSessionOnCreateFactory(nonNullProperties)) {
                factory.getDatabaseSession();
            }
            return factory;
        } catch (RuntimeException ex) {
            if(factory != null) {
                factory.close();
            } else {
                emSetupImpl.undeploy();
            }
            throw ex;
        }
    }
View Full Code Here

     * @return load status of the attribute
     */
    public LoadState isLoadedWithReference(Object entity, String attributeName){
        Iterator<EntityManagerSetupImpl> setups = EntityManagerFactoryProvider.getEmSetupImpls().values().iterator();
        while (setups.hasNext()){
            EntityManagerSetupImpl setup = setups.next();
            if (setup.isDeployed()){
                Boolean isLoaded = EntityManagerFactoryImpl.isLoaded(entity, setup.getSession());
                if (isLoaded != null){
                    if (isLoaded.booleanValue() && attributeName != null){
                        isLoaded = EntityManagerFactoryImpl.isLoaded(entity, attributeName, setup.getSession());
                    }
                    if (isLoaded != null){
                        return isLoaded.booleanValue() ? LoadState.LOADED : LoadState.NOT_LOADED;
                    }
                }
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl

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.