use of org.eclipse.persistence.internal.jpa.deployment.SEPersistenceUnitInfo in project eclipselink by eclipse-ee4j.
the class EntityManagerSetupImpl method updateCompositeMembersProperties.
/*
* Overide composite member properties' map with a new one, which
* has (possibly empty but non-null) properties for each composite member,
* for required properties overrides values with those from composite properties.
* Parameter compositePuInfo indicates whether compositeMemberPreoperties should be merged (overriding) with its puInfo properties
* (false for predeploy, true for deploy).
*/
protected void updateCompositeMembersProperties(Set<SEPersistenceUnitInfo> compositePuInfos, Map compositeProperties) {
// Don't log these properties - may contain passwords. The properties will be logged by contained persistence units.
Map compositeMemberMapOfProperties = (Map) getConfigProperty(PersistenceUnitProperties.COMPOSITE_UNIT_PROPERTIES, compositeProperties);
Map newCompositeMemberMapOfProperties;
if (compositeMemberMapOfProperties == null) {
newCompositeMemberMapOfProperties = new HashMap<>(compositePuInfos.size());
} else {
// Don't alter user-supplied properties' map - create a copy instead
newCompositeMemberMapOfProperties = new HashMap<>(compositeMemberMapOfProperties);
}
for (SEPersistenceUnitInfo compositePuInfo : compositePuInfos) {
String compositeMemberPuName = compositePuInfo.getPersistenceUnitName();
Map compositeMemberProperties = (Map) newCompositeMemberMapOfProperties.get(compositeMemberPuName);
Map newCompositeMemberProperties;
if (compositeMemberProperties == null) {
newCompositeMemberProperties = new HashMap<>();
} else {
// Don't alter user-supplied properties - create a copy instead
newCompositeMemberProperties = new HashMap<>(compositeMemberProperties);
}
overrideMemberProperties(newCompositeMemberProperties, compositeProperties);
newCompositeMemberProperties = mergeMaps(newCompositeMemberProperties, compositePuInfo.getProperties());
translateOldProperties(newCompositeMemberProperties, session);
newCompositeMemberMapOfProperties.put(compositeMemberPuName, newCompositeMemberProperties);
}
// set the new COMPOSITE_PROPERTIES into compositeProperties
compositeProperties.put(PersistenceUnitProperties.COMPOSITE_UNIT_PROPERTIES, newCompositeMemberMapOfProperties);
}
use of org.eclipse.persistence.internal.jpa.deployment.SEPersistenceUnitInfo in project eclipselink by eclipse-ee4j.
the class PersistenceContentHandler method startElement.
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
if (NS_URI.equals(namespaceURI) || NAMESPACE_URI.equals(namespaceURI) || NAMESPACE_URI_OLD.equals(namespaceURI)) {
if (ELEMENT_PERSISTENCE_UNIT.equals(localName)) {
persistenceUnitInfo = new SEPersistenceUnitInfo();
persistenceUnitInfo.setPersistenceUnitName(atts.getValue(ATTRIBUTE_NAME));
String transactionType = atts.getValue(ATTRIBUTE_TRANSACTION_TYPE);
if (transactionType != null) {
persistenceUnitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(transactionType));
}
return;
} else if (ELEMENT_PROPERTY.equals(localName)) {
String name = atts.getValue(ATTRIBUTE_NAME);
String value = atts.getValue(ATTRIBUTE_VALUE);
persistenceUnitInfo.getProperties().setProperty(name, value);
} else if (ELEMENT_PROVIDER.equals(localName)) {
readCharacters = true;
return;
} else if (ELEMENT_JTA_DATA_SOURCE.equals(localName)) {
readCharacters = true;
return;
} else if (ELEMENT_NON_JTA_DATA_SOURCE.equals(localName)) {
readCharacters = true;
return;
} else if (ELEMENT_MAPPING_FILE.equals(localName)) {
readCharacters = true;
return;
} else if (ELEMENT_JAR_FILE.equals(localName)) {
readCharacters = true;
return;
} else if (ELEMENT_EXCLUDE_UNLISTED_CLASSES.equals(localName)) {
readCharacters = true;
return;
} else if (ELEMENT_CACHING.equals(localName)) {
readCharacters = true;
return;
} else if (ELEMENT_VALIDATION_MODE.equals(localName)) {
readCharacters = true;
return;
} else if (ELEMENT_CLASS.equals(localName)) {
readCharacters = true;
return;
}
}
}
use of org.eclipse.persistence.internal.jpa.deployment.SEPersistenceUnitInfo in project eclipselink by eclipse-ee4j.
the class StaticWeaveClassTransformer method buildClassTransformers.
/**
* The method creates classtransformer list corresponding to each persistence unit.
*/
private void buildClassTransformers(URL inputArchiveURL, String persistenceXMLLocation, ClassLoader aclassloader) throws URISyntaxException, IOException {
if (classTransformers != null) {
return;
} else {
classTransformers = new ArrayList<ClassTransformer>();
}
Archive archive = null;
try {
archive = (new ArchiveFactoryImpl()).createArchive(inputArchiveURL, persistenceXMLLocation == null ? PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML_DEFAULT : persistenceXMLLocation, null);
List<SEPersistenceUnitInfo> persistenceUnitsList = PersistenceUnitProcessor.processPersistenceArchive(archive, aclassloader);
if (persistenceUnitsList == null) {
throw PersistenceUnitLoadingException.couldNotGetUnitInfoFromUrl(inputArchiveURL);
}
Map<Object, Object> emptyMap = new HashMap<>(0);
Iterator<SEPersistenceUnitInfo> persistenceUnitsIterator = persistenceUnitsList.iterator();
while (persistenceUnitsIterator.hasNext()) {
SEPersistenceUnitInfo unitInfo = persistenceUnitsIterator.next();
// build class transformer.
String puName = unitInfo.getPersistenceUnitName();
String sessionName = (String) unitInfo.getProperties().get(PersistenceUnitProperties.SESSION_NAME);
if (sessionName == null) {
sessionName = puName;
}
EntityManagerSetupImpl emSetupImpl = new EntityManagerSetupImpl(puName, sessionName);
// indicates that predeploy is used for static weaving, also passes logging parameters
emSetupImpl.setStaticWeaveInfo(this.info);
ClassTransformer transformer = emSetupImpl.predeploy(unitInfo, emptyMap);
if (transformer != null) {
classTransformers.add(transformer);
}
}
} catch (ZipException e) {
throw StaticWeaveException.exceptionOpeningArchive(inputArchiveURL, e);
} finally {
if (archive != null) {
archive.close();
}
}
}
use of org.eclipse.persistence.internal.jpa.deployment.SEPersistenceUnitInfo in project eclipselink by eclipse-ee4j.
the class PersistenceProvider method generateSchema.
/**
* Create database schemas and/or tables and/or create DDL scripts as
* determined by the supplied properties.
* <p>
* Called by the Persistence class when schema generation is to occur as a
* separate phase from creation of the entity manager factory.
*
* @param persistenceUnitName the name of the persistence unit
* @param properties properties for schema generation; these may also
* contain provider-specific properties. The value of these
* properties override any values that may have been configured
* elsewhere.
* @throws PersistenceException if insufficient or inconsistent
* configuration information is provided of if schema generation
* otherwise fails
*
* @since Java Persistence 2.1
*/
@Override
public boolean generateSchema(String persistenceUnitName, Map properties) {
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 && checkForProviderProperty(properties)) {
// Will cause a login if necessary, generate the DDL and then close.
// The false indicates that we do not require a connection if
// generating only to script. Since the user may have connected with
// specific database credentials for DDL generation or even provided
// a specific connection, close the emf once we're done.
createEntityManagerFactoryImpl(puInfo, properties, false).close();
return true;
}
}
return false;
}
use of org.eclipse.persistence.internal.jpa.deployment.SEPersistenceUnitInfo in project eclipselink by eclipse-ee4j.
the class PersistenceProvider method createEntityManagerFactoryImpl.
/**
* Internal method to return the entity manager factory.
*/
protected EntityManagerFactoryImpl createEntityManagerFactoryImpl(PersistenceUnitInfo puInfo, Map properties, boolean requiresConnection) {
if (puInfo != null) {
boolean isNew = false;
// the name the uniquely defines the pu
String uniqueName = null;
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());
}
// synchronized to prevent undeploying by other threads.
boolean undeployed = false;
synchronized (emSetupImpl) {
if (emSetupImpl.isUndeployed()) {
undeployed = true;
} else {
// emSetupImpl has been already predeployed, predeploy will just increment factoryCount.
emSetupImpl.predeploy(emSetupImpl.getPersistenceUnitInfo(), properties);
}
}
if (undeployed) {
// it has been undeployed by factory.close() in another thread - start all over again.
return (EntityManagerFactoryImpl) createEntityManagerFactory(puName, properties);
}
}
EntityManagerFactoryImpl factory = null;
try {
factory = new EntityManagerFactoryImpl(emSetupImpl, properties);
emSetupImpl.setRequiresConnection(requiresConnection);
emSetupImpl.preInitializeCanonicalMetamodel(factory);
if (emSetupImpl.shouldGetSessionOnCreateFactory(properties)) {
factory.getDatabaseSession();
}
return factory;
} catch (RuntimeException ex) {
if (factory != null) {
factory.close();
} else {
emSetupImpl.undeploy();
}
throw ex;
}
}
return null;
}
Aggregations