/** Calculate and set the default data source in given <code>pud</code> **/ private void calculateDefaultDataSource(PersistenceUnitDescriptor pud) { String jtaDataSourceName = calculateJtaDataSourceName(pud.getTransactionType(), pud.getJtaDataSource(), pud.getNonJtaDataSource(), pud.getName()); String nonJtaDataSourceName = calculateNonJtaDataSourceName(pud.getJtaDataSource(), pud.getNonJtaDataSource()); pud.setJtaDataSource(jtaDataSourceName); pud.setNonJtaDataSource(nonJtaDataSourceName); }
/** * @return the absolute path of the root of this persistence unit * @see #getPuRoot() * @see PersistenceUnitsDescriptor#getAbsolutePuRoot() */ public String getAbsolutePuRoot() { return getParent().getAbsolutePuRoot(); }
/** * This method does not do any validation like checking for unique names * of PersistenceUnits. * @param pud the PersistenceUnitDescriptor to be added. */ public void addPersistenceUnitDescriptor(PersistenceUnitDescriptor pud){ persistenceUnitDescriptors.add(pud); pud.setParent(this); }
/** * Returns unique identifier for this pu within application * @param pud The given pu * @return Absolute pu root + pu name */ private static String getUniquePuIdentifier(PersistenceUnitDescriptor pud) { return pud.getAbsolutePuRoot() + pud.getName(); }
/** * Record the Data Source specified in PUD. */ private void parseResources(PersistenceUnitDescriptor pu, JndiNameEnvironment env, AppResources appResources) { String jtaDataSourceName = pu.getJtaDataSource(); String nonJtaDataSourceName = pu.getNonJtaDataSource(); if (jtaDataSourceName != null && jtaDataSourceName.length() > 0) appResources.store(new AppResource(pu.getName(), jtaDataSourceName, "javax.sql.DataSource", env, true)); if (nonJtaDataSourceName != null && nonJtaDataSourceName.length() > 0) appResources.store(new AppResource(pu.getName(), nonJtaDataSourceName, "javax.sql.DataSource", env, true)); }
helper.setProcessorType("JPA", pud.getName()); // NOI18N helper.setDropTablesValue(userDropTables, pud.getName()); helper.setCreateTablesValue(userCreateTables && !ddlMode.equals(DDL_SQL_SCRIPT_GENERATION), pud.getName()); (PersistenceUnitTransactionType.JTA == PersistenceUnitTransactionType.valueOf(pud.getTransactionType())) ? pud.getJtaDataSource() : pud.getNonJtaDataSource(); helper.setJndiName(dataSourceName, pud.getName()); constructJdbcFileNames(pud); if (logger.isLoggable(Level.FINE)) { logger.fine("Processing request to create files - create file: " + //NOI18N helper.getCreateJdbcFileName(pud.getName()) + ", drop file: " + //NOI18N helper.getDropJdbcFileName(pud.getName()));
String providerClassName = pud.getProvider(); logger.log(Level.INFO, "puloader.defaulting.provider.on.upgrade", new Object[] {pud.getName(), defaultProvider}); pud.setProvider(defaultProvider); upgradeTopLinkEssentialsProperties = true; Properties properties = pud.getProperties(); for (Map.Entry entry : properties.entrySet()) { String key = (String) entry.getKey(); if(key.startsWith(TOPLINK) ) { String translatedKey = ECLIPSELINK + key.substring(TOPLINK.length()); pud.addProperty(translatedKey, entry.getValue());
protected static PersistenceUnitDescriptor findReferencedPUViaEMRef(EntityManagerReference emRef) { final String unitName = emRef.getUnitName(); final BundleDescriptor bundle = emRef.getReferringBundleDescriptor(); PersistenceUnitDescriptor pu = bundle.findReferencedPU(unitName); if (pu == null) { throw new RuntimeException(localStrings.getLocalString( "enterprise.deployment.exception-unresolved-pc-ref", "xxx", // NOI18N new Object[]{emRef.getName(), bundle.getName()}) ); } if ("RESOURCE_LOCAL".equals(pu.getTransactionType())) { // NOI18N throw new RuntimeException(localStrings.getLocalString( "enterprise.deployment.exception-non-jta-container-managed-em", "xxx", // NOI18N new Object[]{emRef.getName(), bundle.getName(), pu.getName()}) ); } return pu; }
/** * This method calculates the absolute path of the root of a PU. * Absolute path is not the path with regards to root of file system. * It is the path from the root of the Java EE application this * persistence unit belongs to. * Returned path always uses '/' as path separator. * @return the absolute path of the root of this persistence unit */ private String getAbsolutePuRootWithinApplication() { // TODO shift this into PersistenceUnitDescriptor to better encapsulate RootDeploymentDescriptor rootDD = persistenceUnitDescriptor.getParent(). getParent(); String puRoot = persistenceUnitDescriptor.getPuRoot(); if(rootDD.isApplication()){ return puRoot; } else { ModuleDescriptor module = BundleDescriptor.class.cast(rootDD). getModuleDescriptor(); if(module.isStandalone()) { return puRoot; } else { // The module is embedded in an ear (an ejb jar or war) final String moduleLocation = // Would point to the directory where module is expanded. For example myejb_jar DeploymentUtils.getRelativeEmbeddedModulePath( providerContainerContractInfo.getApplicationLocation(), module.getArchiveUri()); return moduleLocation + '/' + puRoot; // see we always '/' } } }
Java2DBProcessorHelper.getDDLNamePrefix(parBundle.getParent().getParent()); createJdbcFileName = filePrefix + DatabaseConstants.NAME_SEPARATOR + parBundle.getName() + DatabaseConstants.CREATE_DDL_JDBC_FILE_SUFFIX; dropJdbcFileName = filePrefix + DatabaseConstants.NAME_SEPARATOR + parBundle.getName() + DatabaseConstants.DROP_DDL_JDBC_FILE_SUFFIX; helper.setCreateJdbcFileName(createJdbcFileName, parBundle.getName()); helper.setDropJdbcFileName(dropJdbcFileName, parBundle.getName());
/** * {@inheritDoc} */ public String getPersistenceUnitName() { return persistenceUnitDescriptor.getName(); }
public PersistenceUnitInfoImpl( PersistenceUnitDescriptor persistenceUnitDescriptor, ProviderContainerContractInfo providerContainerContractInfo) { this.persistenceUnitDescriptor = persistenceUnitDescriptor; this.providerContainerContractInfo = providerContainerContractInfo; jarFiles = _getJarFiles(); String jtaDataSourceName = persistenceUnitDescriptor.getJtaDataSource(); String nonJtaDataSourceName = persistenceUnitDescriptor.getNonJtaDataSource(); try { jtaDataSource = jtaDataSourceName == null ? null : providerContainerContractInfo.lookupDataSource(jtaDataSourceName); nonJtaDataSource = nonJtaDataSourceName == null ? null : providerContainerContractInfo.lookupNonTxDataSource(nonJtaDataSourceName); } catch (NamingException e) { throw new RuntimeException(e); } }
@Override public void startElement( XMLElement element, Attributes attributes) { if (PersistenceTagNames.PROPERTY.equals(element.getQName())) { assert(attributes.getLength() == 2); assert(attributes.getIndex(PersistenceTagNames.PROPERTY_NAME) != -1); assert(attributes.getIndex(PersistenceTagNames.PROPERTY_VALUE) != -1); PersistenceUnitDescriptor persistenceUnitDescriptor = (PersistenceUnitDescriptor) getDescriptor(); String propName = attributes.getValue( PersistenceTagNames.PROPERTY_NAME); String propValue = attributes.getValue( PersistenceTagNames.PROPERTY_VALUE); persistenceUnitDescriptor.addProperty(propName, propValue); return; } super.startElement(element, attributes); }
/** * {@inheritDoc} */ public PersistenceUnitTransactionType getTransactionType() { return PersistenceUnitTransactionType.valueOf( persistenceUnitDescriptor.getTransactionType()); }
/** * @return true if given <code>pud</code> is using scoped resource */ private boolean hasScopedResource(PersistenceUnitDescriptor pud) { boolean hasScopedResource = false; String jtaDataSource = pud.getJtaDataSource(); if(jtaDataSource != null && jtaDataSource.startsWith("java:")){ hasScopedResource = true; } return hasScopedResource; }
protected static PersistenceUnitDescriptor findReferencedPUViaEMRef(EntityManagerReference emRef) { final String unitName = emRef.getUnitName(); final BundleDescriptor bundle = emRef.getReferringBundleDescriptor(); PersistenceUnitDescriptor pu = bundle.findReferencedPU(unitName); if (pu == null) { throw new RuntimeException(localStrings.getLocalString( "enterprise.deployment.exception-unresolved-pc-ref", "xxx", // NOI18N new Object[]{emRef.getName(), bundle.getName()}) ); } if ("RESOURCE_LOCAL".equals(pu.getTransactionType())) { // NOI18N throw new RuntimeException(localStrings.getLocalString( "enterprise.deployment.exception-non-jta-container-managed-em", "xxx", // NOI18N new Object[]{emRef.getName(), bundle.getName(), pu.getName()}) ); } return pu; }
if(fineMsgLoggable) { logger.fine("Loading persistence unit for application: \"" + applicationLocation + "\"pu Root is: " + pud.getPuRoot()); logger.fine("PersistenceInfo for this pud is :\n" + pInfo); // NOI18N PersistenceUnitsDescriptor parent = pud.getParent(); RootDeploymentDescriptor containingBundle = parent.getParent(); providerContainerContractInfo.registerEMF(pInfo.getPersistenceUnitName(), pud.getPuRoot(), containingBundle, emf);
private void addSchemaGenerationPropertiesToOverrides(PersistenceUnitDescriptor puDescriptor, Map<String, Object> overrides) { addPropertyToOverride(puDescriptor, overrides, providerPropertyNamesHolder.appLocation, helper.getGeneratedLocation(puDescriptor.getName())); addPropertyToOverride(puDescriptor, overrides, providerPropertyNamesHolder.createJdbcDdlFile, helper.getCreateJdbcFileName(puDescriptor.getName())); addPropertyToOverride(puDescriptor, overrides, providerPropertyNamesHolder.dropJdbcDdlFile, helper.getDropJdbcFileName(puDescriptor.getName())); // The puDescriptor might not have this property if schema generation is triggered by deployment CLI override addPropertyToOverride(puDescriptor, overrides, providerPropertyNamesHolder.ddlGeneration, DROP_AND_CREATE); // If we are doing schema generation, we want DDL scripts to be generated addPropertyToOverride(puDescriptor, overrides, providerPropertyNamesHolder.ddlGenerationOutputMode, DDL_SQL_SCRIPT_GENERATION); }