public FileResource<?> setup(String unitName, Project project, JPADataSource dataSource, boolean configureMetadata)
{
FileResource<?> result = null;
if (project != null)
{
PersistenceFacet facet = facetFactory.install(project, PersistenceFacet.class);
PersistenceContainer container = dataSource.getContainer();
PersistenceProvider provider = dataSource.getProvider();
PersistenceDescriptor config = facet.getConfig();
PersistenceUnit<PersistenceDescriptor> unit = config.createPersistenceUnit();
unit.name(unitName).description(DEFAULT_UNIT_DESC);
unit.transactionType(container.isJTASupported() ? PersistenceUnitTransactionType._JTA
: PersistenceUnitTransactionType._RESOURCE_LOCAL);
unit.provider(provider.getProvider());
container.setupConnection(unit, dataSource);
provider.configure(unit, dataSource);
facet.saveConfig(config);
result = facet.getConfigFile();
}
if (configureMetadata)
{
facetFactory.install(project, PersistenceMetaModelFacet.class);
}