本文整理汇总了Java中org.springframework.orm.jpa.persistenceunit.SmartPersistenceUnitInfo类的典型用法代码示例。如果您正苦于以下问题:Java SmartPersistenceUnitInfo类的具体用法?Java SmartPersistenceUnitInfo怎么用?Java SmartPersistenceUnitInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SmartPersistenceUnitInfo类属于org.springframework.orm.jpa.persistenceunit包,在下文中一共展示了SmartPersistenceUnitInfo类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPersistenceUnit
import org.springframework.orm.jpa.persistenceunit.SmartPersistenceUnitInfo; //导入依赖的package包/类
private PersistenceUnitInfo createPersistenceUnit(PersistenceUnitInfo mPui) throws IllegalArgumentException, SecurityException {
InvocationHandler jpa2PersistenceUnitInfoDecorator = null;
Class<?>[] classes = getClass().getSuperclass().getDeclaredClasses();
for (Class<?> clz : classes) {
if ("org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager$Jpa2PersistenceUnitInfoDecorator".equals(clz.getName())) {
Constructor<?> constructor;
try {
constructor = clz.getConstructor(Class.forName("org.springframework.orm.jpa.persistenceunit.SpringPersistenceUnitInfo"));
constructor.setAccessible(true);
jpa2PersistenceUnitInfoDecorator = (InvocationHandler) constructor.newInstance(mPui);
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
break;
}
}
PersistenceUnitInfo puiToStore = (PersistenceUnitInfo) Proxy.newProxyInstance(SmartPersistenceUnitInfo.class.getClassLoader(),
new Class[] { SmartPersistenceUnitInfo.class }, jpa2PersistenceUnitInfoDecorator);
return puiToStore;
}
示例2: generateSchema
import org.springframework.orm.jpa.persistenceunit.SmartPersistenceUnitInfo; //导入依赖的package包/类
public void generateSchema() throws MojoFailureException
{
final Map<String, Object> cfg = buildCfg();
String[] allBasePackages = this.getBasePackages();
getLog().info("Using base packages " + StringUtils.arrayToDelimitedString(allBasePackages, ", "));
final PersistenceProvider provider = new PersistenceProvider();
final DefaultPersistenceUnitManager manager = new DefaultPersistenceUnitManager();
manager.setDefaultPersistenceUnitRootLocation(null);
manager.setDefaultPersistenceUnitName("default");
manager.setPackagesToScan(allBasePackages);
manager.setPersistenceXmlLocations(new String[0]);
manager.afterPropertiesSet();
final SmartPersistenceUnitInfo puInfo = (SmartPersistenceUnitInfo) manager.obtainDefaultPersistenceUnitInfo();
puInfo.setPersistenceProviderPackageName(provider.getClass().getName());
getLog().info("Entities found : " + puInfo.getManagedClassNames().size());
getLog().debug("Managed class names:\n * " + StringUtils.collectionToDelimitedString(puInfo.getManagedClassNames(), "\n * "));
puInfo.getProperties().putAll(cfg);
provider.generateSchema(new DelegatingPuInfo(puInfo), cfg);
}
示例3: createContainerEntityManagerFactory
import org.springframework.orm.jpa.persistenceunit.SmartPersistenceUnitInfo; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) {
Ejb3Configuration cfg = new Ejb3Configuration();
if (info instanceof SmartPersistenceUnitInfo) {
for (String managedPackage : ((SmartPersistenceUnitInfo) info).getManagedPackages()) {
cfg.addPackage(managedPackage);
}
}
Ejb3Configuration configured = cfg.configure(info, properties);
return (configured != null ? configured.buildEntityManagerFactory() : null);
}
示例4: createContainerEntityManagerFactory
import org.springframework.orm.jpa.persistenceunit.SmartPersistenceUnitInfo; //导入依赖的package包/类
@Override
@SuppressWarnings("rawtypes")
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) {
final List<String> mergedClassesAndPackages = new ArrayList<String>(info.getManagedClassNames());
if (info instanceof SmartPersistenceUnitInfo) {
mergedClassesAndPackages.addAll(((SmartPersistenceUnitInfo) info).getManagedPackages());
}
return new EntityManagerFactoryBuilderImpl(
new PersistenceUnitInfoDescriptor(info) {
@Override
public List<String> getManagedClassNames() {
return mergedClassesAndPackages;
}
}, properties).build();
}
示例5: generate
import org.springframework.orm.jpa.persistenceunit.SmartPersistenceUnitInfo; //导入依赖的package包/类
private void generate() throws Exception {
Map<String, Object> map = JpaSchemaGeneratorUtils.buildProperties(this);
if (getVendor() == null) {
// with persistence.xml
Persistence.generateSchema(this.persistenceUnitName, map);
} else {
PersistenceProvider provider = getProviderClass().newInstance();
List<String> packages = getPackageToScan();
if (packages.isEmpty()) {
throw new IllegalArgumentException("packageToScan is required on xml-less mode.");
}
DefaultPersistenceUnitManager manager = new DefaultPersistenceUnitManager();
manager.setDefaultPersistenceUnitName(getPersistenceUnitName());
manager.setPackagesToScan(packages.toArray(new String[packages.size()]));
// issue #22
Field persistenceXmlLocations = manager.getClass().getDeclaredField("persistenceXmlLocations");
persistenceXmlLocations.setAccessible(true);
persistenceXmlLocations.set(manager, new String[0]);
manager.afterPropertiesSet();
SmartPersistenceUnitInfo info = (SmartPersistenceUnitInfo) manager.obtainDefaultPersistenceUnitInfo();
info.setPersistenceProviderPackageName(provider.getClass().getName());
info.getProperties().putAll(map);
// Path persistenceXml = null;
/* @formatter:off */
// if (Vendor.datanucleus.equals(getVendor())) {
// // datanucleus must need persistence.xml
// Path path = Paths.get(project.getBuild().getOutputDirectory(), "META-INF");
// persistenceXml = Files.createTempFile(path, "persistence-", ".xml");
// try (BufferedWriter writer = Files.newBufferedWriter(persistenceXml, StandardCharsets.UTF_8)) {
// PrintWriter out = new PrintWriter(writer);
// out.println("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
// out.println("<persistence version=\"2.1\"");
// out.println(" xmlns=\"http://xmlns.jcp.org/xml/ns/persistence\"
// xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
// out.println(" xsi:schemaLocation=\"http://xmlns.jcp.org/xml/ns/persistence
// http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/persistence_2_1.xsd\">");
// out.printf(" <persistence-unit name=\"%s\" transaction-type=\"RESOURCE_LOCAL\">\n",
// info.getPersistenceUnitName());
// out.println(" <provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>");
// out.println(" <exclude-unlisted-classes>false</exclude-unlisted-classes>");
// out.println(" </persistence-unit>");
// out.println("</persistence>");
// }
// map.put(PropertyNames.PROPERTY_PERSISTENCE_XML_FILENAME, persistenceXml.toAbsolutePath().toString());
// // datanucleus does not support execution order...
// map.remove(PersistenceUnitProperties.SCHEMA_GENERATION_CREATE_SOURCE);
// map.remove(PersistenceUnitProperties.SCHEMA_GENERATION_DROP_SOURCE);
// }
/* @formatter:on */
try {
provider.generateSchema(info, map);
} finally {
// if (persistenceXml != null) {
// Files.delete(persistenceXml);
// }
}
}
}