Examples of JPAInitializer


Examples of org.eclipse.persistence.internal.jpa.deployment.JPAInitializer

                // try to build the passed-in initializer.  If it is available, we will build it otherwise
                // we will assume generic OSGI
                Class initializerClass = Class.forName(this.initializerClassName);
                Class[] argTypes = new Class[]{ClassLoader.class, Map.class, PersistenceInitializationHelper.class};
                Object[] args = new Object[]{classLoader, m, this};
                JPAInitializer initializer = (JPAInitializer)initializerClass.getConstructor(argTypes).newInstance(args);
                return initializer;
            } catch (Exception exception) {
                AbstractSessionLog.getLog().log(SessionLog.WARNING,
                        LoggingLocalization.buildMessage("osgi_initializer_failed", new Object[]{this.initializerClassName, exception}));
                AbstractSessionLog.getLog().logThrowable(SessionLog.WARNING, exception);
View Full Code Here

Examples of org.eclipse.persistence.internal.jpa.deployment.JPAInitializer

     * Here we will attempt to build an EquinoxInitializer.  It will only be available if the org.eclipse.persistence.jpa.equinox
     * fragment is available.  Else, we will return a standard OSGi initializer.
     */
    public JPAInitializer getInitializer(String emName, Map m){
        ClassLoader classLoader = getClassLoader(emName, m);
        JPAInitializer initializer;
        if (this.initializerClassName != null) {
            try {
                // try to build the passed-in initializer.  If it is available, we will build it otherwise
                // we will assume generic OSGI
                Class initializerClass = Class.forName(this.initializerClassName);
                Class[] argTypes = new Class[]{ClassLoader.class, Map.class};
                Object[] args = new Object[]{classLoader, m};
                initializer = (JPAInitializer)initializerClass.getConstructor(argTypes).newInstance(args);
                initializer.initialize(m);
                return initializer;
            } catch (Exception exception) {
                AbstractSessionLog.getLog().log(SessionLog.WARNING,
                        LoggingLocalization.buildMessage("osgi_initializer_failed", new Object[]{this.initializerClassName, exception}));
                AbstractSessionLog.getLog().logThrowable(SessionLog.WARNING, exception);
            }
        }
        initializer = new OSGiInitializer(classLoader);
        initializer.initialize(m);
        return initializer;
    }
View Full Code Here

Examples of org.eclipse.persistence.internal.jpa.deployment.JPAInitializer

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

        JPAInitializer initializer = initializationHelper.getInitializer(classLoader, nonNullProperties);
        EntityManagerSetupImpl emSetupImpl = null;
        // get a class loader to use with this specific EM
        ClassLoader currentLoader = initializationHelper.getClassLoader(emName, nonNullProperties);

        try {
            Enumeration<URL> resources = currentLoader.getResources("META-INF/persistence.xml");
            boolean initialized = false;
            while (resources.hasMoreElements()) {
                String puName = PersistenceUnitProcessor.buildPersistenceUnitName(PersistenceUnitProcessor.computePURootURL(resources.nextElement()), name);
               
                synchronized (EntityManagerFactoryProvider.emSetupImpls){
                    emSetupImpl = EntityManagerFactoryProvider.getEntityManagerSetupImpl(puName);
                    if (emSetupImpl == null || emSetupImpl.isUndeployed()){
                        if (!initialized){                          
                            initializer.initialize(nonNullProperties, initializationHelper);
                            initialized = true;
                        }
                        emSetupImpl = EntityManagerFactoryProvider.getEntityManagerSetupImpl(puName);
                    }
                }

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

        //gf bug 854  Returns null if EntityManagerSetupImpl for the name doesn't exist (e.g. a non-existant 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 -
View Full Code Here

Examples of org.eclipse.persistence.internal.jpa.deployment.JPAInitializer

        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());
View Full Code Here

Examples of org.eclipse.persistence.internal.jpa.deployment.JPAInitializer

            boolean isNew = false;
            String uniqueName = null; // the name the uniquely defines the pu
            String sessionName = null;
            EntityManagerSetupImpl emSetupImpl = null;
            String puName = puInfo.getPersistenceUnitName();
            JPAInitializer initializer = getInitializer(puInfo.getPersistenceUnitName(), properties);
           
            try {
                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(puName, puName);
                    // 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, properties);
                    isNew = true;
                } else {
                    if (initializer.isPersistenceUnitUniquelyDefinedByName()) {
                        uniqueName = puName;
                    } else {
                        uniqueName = initializer.createUniquePersistenceUnitName(puInfo);
                    }
                   
                    sessionName = EntityManagerSetupImpl.getOrBuildSessionName(properties, 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(puName);
                           
                            if (emSetupImpl != null) {
                                // change the name
                                emSetupImpl.changeSessionName(sessionName);
                            } else {
                                // create and predeploy a new emSetupImpl
                                emSetupImpl = initializer.callPredeploy((SEPersistenceUnitInfo) puInfo, properties, uniqueName, sessionName);
                            }
                           
                            // emSetupImpl has been already predeployed, predeploy will just increment factoryCount.
                            emSetupImpl.predeploy(emSetupImpl.getPersistenceUnitInfo(), properties);
                            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());
View Full Code Here

Examples of org.eclipse.persistence.internal.jpa.deployment.JPAInitializer

    public EntityManagerFactory createEntityManagerFactory(String emName, Map properties){
        Map nonNullProperties = (properties == null) ? new HashMap() : properties;

        if (checkForProviderProperty(nonNullProperties)){
            String name = (emName == null) ? "" : emName;
            JPAInitializer initializer = getInitializer(name, nonNullProperties);
            return createEntityManagerFactoryImpl(initializer.findPersistenceUnitInfo(name, nonNullProperties), nonNullProperties, true);
        }

        // Not EclipseLink so return null;
        return null;
    }
View Full Code Here

Examples of org.eclipse.persistence.internal.jpa.deployment.JPAInitializer

        String puName = (persistenceUnitName == null) ? "" : persistenceUnitName;
        Map nonNullProperties = (properties == null) ? new HashMap() : properties;
       
        // If not EclipseLink, do nothing.
        if (checkForProviderProperty(nonNullProperties)) {
            JPAInitializer initializer = getInitializer(puName, nonNullProperties);
            SEPersistenceUnitInfo puInfo = initializer.findPersistenceUnitInfo(puName, nonNullProperties);
           
            if (puInfo != null) {
                generateSchema(puInfo, nonNullProperties);
                return true;
            }
View Full Code Here

Examples of org.eclipse.persistence.internal.jpa.deployment.JPAInitializer

     * Here we will attempt to build an EquinoxInitializer.  It will only be available if the org.eclipse.persistence.jpa.equinox
     * fragment is available.  Else, we will return a standard OSGi initializer.
     */
    public JPAInitializer getInitializer(String emName, Map m){
        ClassLoader classLoader = getClassLoader(emName, m);
        JPAInitializer initializer;
        if (this.initializerClassName != null) {
            try {
                // try to build the passed-in initializer.  If it is available, we will build it otherwise
                // we will assume generic OSGI
                Class initializerClass = Class.forName(this.initializerClassName);
                Class[] argTypes = new Class[]{ClassLoader.class, Map.class};
                Object[] args = new Object[]{classLoader, m};
                initializer = (JPAInitializer)initializerClass.getConstructor(argTypes).newInstance(args);
                initializer.initialize(m);
                return initializer;
            } catch (Exception exception) {
                AbstractSessionLog.getLog().log(SessionLog.WARNING,
                        LoggingLocalization.buildMessage("osgi_initializer_failed", new Object[]{this.initializerClassName, exception}));
                AbstractSessionLog.getLog().logThrowable(SessionLog.WARNING, exception);
            }
        }
        initializer = new OSGiInitializer(classLoader);
        initializer.initialize(m);
        return initializer;
    }
View Full Code Here

Examples of org.eclipse.persistence.internal.jpa.deployment.JPAInitializer

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

        JPAInitializer initializer = initializationHelper.getInitializer(classLoader, nonNullProperties);
        EntityManagerSetupImpl emSetupImpl = null;
        boolean isNew = false;
        // the name that uniquely defines persistence unit
        String uniqueName;
        String sessionName;
        try {           
            SEPersistenceUnitInfo puInfo;
            puInfo = initializer.findPersistenceUnitInfo(name, nonNullProperties, initializationHelper);
            // either persistence unit not found or provider not supported
            if(puInfo == null) {
                return null;
            }
           
            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) {
                    if(EntityManagerFactoryProvider.initialEmSetupImpls != null) {
                        // there may be initial emSetupImpl (possible only in SE that uses agent) remove it and use.
                        emSetupImpl = EntityManagerFactoryProvider.initialEmSetupImpls.remove(uniqueName);
                        if(emSetupImpl != null) {
                            // change the name
                            emSetupImpl.changeSessionName(sessionName);
                            //  make sure we grab the classloader that may have
                            // been provided by the user. I.E. a DynamicClassLoader
                            puInfo.setClassLoader(classLoader);
                        }
                    }
                    if(emSetupImpl == null) {
                        // create and predeploy a new emSetupImpl
                        emSetupImpl = initializer.callPredeploy(puInfo, nonNullProperties, initializationHelper, uniqueName, sessionName);
                    }
                    // emSetupImpl has been already predeployed, predeploy will just increment factoryCount.
                    emSetupImpl.predeploy(emSetupImpl.getPersistenceUnitInfo(), nonNullProperties);
                    EntityManagerFactoryProvider.addEntityManagerSetupImpl(sessionName, emSetupImpl);
                    isNew = true;
View Full Code Here

Examples of org.eclipse.persistence.internal.jpa.deployment.JPAInitializer

        String name = emName;
        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 -
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.