本文整理汇总了Java中org.eclipse.persistence.jpa.PersistenceProvider类的典型用法代码示例。如果您正苦于以下问题:Java PersistenceProvider类的具体用法?Java PersistenceProvider怎么用?Java PersistenceProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PersistenceProvider类属于org.eclipse.persistence.jpa包,在下文中一共展示了PersistenceProvider类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createEntityManagerFactory
import org.eclipse.persistence.jpa.PersistenceProvider; //导入依赖的package包/类
private void createEntityManagerFactory(String pid, Dictionary<String, ?> configs) {
EntityManagerFactory emf = null;
try {
String unitName = (String) configs.get("unitName");
LOGGER.info("Creating EntityManagerFactory for PersistenceUnit: [{}]", unitName);
emf = new PersistenceProvider().createEntityManagerFactory(unitName, this.jpaProperties(configs));
if (emf == null) {
LOGGER.warn("Could not initialize EntityManagerFactory, Most probably persistence.xml not found!!");
} else {
LOGGER.info("EntityManagerFactory [{}] created for PersistenceUnit: [{}]", emf, unitName);
this.pidVsUnitNameMapping.put(pid, unitName);
this.unitNameVsEMFMapping.put(unitName, emf);
this.repositoryManager.registerJpaCrudRepository(unitName, emf);
if (LOGGER.isDebugEnabled()) {
emf.getMetamodel()
.getEntities()
.forEach(type -> LOGGER.debug("EntityType: [{}]", type.getName()));
}
}
} catch (Exception ex) { // NOSONAR
LOGGER.error("Exception occurred while creating EntityManagerFactory!!", ex);
if (emf != null) {
emf.close();
}
}
}
开发者ID:AdeptJ,项目名称:adeptj-modules,代码行数:27,代码来源:EntityManagerFactoryProvider.java
示例2: generateSchema
import org.eclipse.persistence.jpa.PersistenceProvider; //导入依赖的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);
}
开发者ID:ethlo,项目名称:eclipselink-maven-plugin,代码行数:21,代码来源:EclipselinkDdlGenerationMojo.java
示例3: entityManagerFactory
import org.eclipse.persistence.jpa.PersistenceProvider; //导入依赖的package包/类
@Bean
public FactoryBean<EntityManagerFactory> entityManagerFactory(DataSource dataSource) {
LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
emf.setDataSource(dataSource);
emf.setPersistenceUnitName("PU");
emf.setPackagesToScan("org.teavm.flavour.example.model");
emf.setPersistenceProviderClass(PersistenceProvider.class);
Map<String, String> properties = new HashMap<>();
properties.put("eclipselink.weaving", "false");
properties.put("eclipselink.ddl-generation", "create-or-extend-tables");
emf.setJpaPropertyMap(properties);
return emf;
}
开发者ID:konsoletyper,项目名称:teavm-flavour,代码行数:16,代码来源:ApplicationConfiguration.java
示例4: connect
import org.eclipse.persistence.jpa.PersistenceProvider; //导入依赖的package包/类
private void connect() {
log.trace("connect to database: {}", url);
Map<Object, Object> map = new HashMap<>();
map.put("javax.persistence.jdbc.url", url);
map.put("javax.persistence.jdbc.driver",
"org.apache.derby.jdbc.EmbeddedDriver");
map.put("eclipselink.classloader", getClass().getClassLoader());
map.put("eclipselink.target-database", "Derby");
entityFactory = new PersistenceProvider().createEntityManagerFactory(
"openLCA", map);
initConnectionPool();
}
开发者ID:GreenDelta,项目名称:olca-modules,代码行数:13,代码来源:DerbyDatabase.java
示例5: connect
import org.eclipse.persistence.jpa.PersistenceProvider; //导入依赖的package包/类
private void connect() {
log.trace("Connect to database mysql: {} @ {}", user, url);
Map<Object, Object> map = new HashMap<>();
map.put("javax.persistence.jdbc.url", url);
map.put("javax.persistence.jdbc.user", user);
map.put("javax.persistence.jdbc.password", password);
map.put("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver");
map.put("eclipselink.classloader", getClass().getClassLoader());
map.put("eclipselink.target-database", "MySQL");
entityFactory = new PersistenceProvider().createEntityManagerFactory(
persistenceUnit, map);
initConnectionPool();
}
开发者ID:GreenDelta,项目名称:olca-modules,代码行数:14,代码来源:MySQLDatabase.java
示例6: EclipseLinkProvider
import org.eclipse.persistence.jpa.PersistenceProvider; //导入依赖的package包/类
public EclipseLinkProvider(String version){
super(PersistenceProvider.class.getName(), version); //NOI18N
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:4,代码来源:EclipseLinkProvider.java
示例7: connectToDatabase
import org.eclipse.persistence.jpa.PersistenceProvider; //导入依赖的package包/类
private void connectToDatabase() {
Job connectDatabaseJob = new Job("Connecting to Timekeeper database") {
@Override
protected IStatus run(IProgressMonitor monitor) {
Map<String, Object> props = new HashMap<String, Object>();
// default, default location
String jdbc_url = "jdbc:h2:~/.timekeeper/h2db";
try {
String location = Platform.getPreferencesService().getString(BUNDLE_ID, DATABASE_LOCATION, DATABASE_LOCATION_SHARED,new IScopeContext[] { InstanceScope.INSTANCE });
switch (location){
case DATABASE_LOCATION_SHARED:
jdbc_url = getSharedLocation();
// Fix https://github.com/turesheim/eclipse-timekeeper/issues/107
System.setProperty("h2.bindAddress", "localhost");
break;
case DATABASE_LOCATION_WORKSPACE:
jdbc_url = getWorkspaceLocation();
break;
case DATABASE_LOCATION_URL:
jdbc_url = getSpecifiedLocation();
break;
}
// baseline the database
Flyway flyway = new Flyway();
flyway.setDataSource(jdbc_url, "sa", "");
flyway.setLocations("classpath:/db/");
flyway.setBaselineOnMigrate(true);
flyway.migrate();
// https://www.eclipse.org/forums/index.php?t=msg&goto=541155&
props.put(PersistenceUnitProperties.CLASSLOADER, TimekeeperPlugin.class.getClassLoader());
// ensure only a in-memory database is used when testing
if (Thread.currentThread().getName().equals("WorkbenchTestable")) {
jdbc_url = "jdbc:h2:mem:test_mem";
}
props.put(PersistenceUnitProperties.JDBC_URL, jdbc_url);
props.put(PersistenceUnitProperties.JDBC_DRIVER, "org.h2.Driver");
props.put(PersistenceUnitProperties.JDBC_USER, "sa");
props.put(PersistenceUnitProperties.JDBC_PASSWORD, "");
props.put(PersistenceUnitProperties.LOGGING_LEVEL, "fine");
// we want Flyway to create the database, it gives us better control over migrating
props.put(PersistenceUnitProperties.DDL_GENERATION, "none");
entityManager = new PersistenceProvider()
.createEntityManagerFactory("net.resheim.eclipse.timekeeper.db", props)
.createEntityManager();
} catch (Exception e) {
return new Status(IStatus.ERROR, BUNDLE_ID,
"Could not connect to Timekeeper database at " + jdbc_url, e);
}
cleanTaskActivities();
notifyListeners();
return Status.OK_STATUS; }
};
connectDatabaseJob.setSystem(false);
connectDatabaseJob.schedule();
}
开发者ID:turesheim,项目名称:eclipse-timekeeper,代码行数:60,代码来源:TimekeeperPlugin.java
示例8: main
import org.eclipse.persistence.jpa.PersistenceProvider; //导入依赖的package包/类
public static void main(String[] args) {
try {
Map<Object, Object> config = new HashMap<>();
// set the connection data to the database
// you should already have an existing database (in this case
// olca_test_db)
String url = "jdbc:mysql://localhost:3306/olca_test_db";
String user = "root";
String pw = "";
config.put("javax.persistence.jdbc.url", url);
config.put("javax.persistence.jdbc.user", user);
config.put("javax.persistence.jdbc.password", pw);
// change the driver and database type if you want to create the
// database schema for another database type than MySQL
config.put("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver");
config.put("eclipselink.target-database", "MySQL");
// specify the location where the schema files should be written
String folder = Files.createTempDir().getAbsolutePath();
String createDllFile = "olca_schema_create.sql";
String dropDllFile = "olca_schema_drop.sql";
// see
// http://eclipse.org/eclipselink/documentation/2.4/jpa/extensions/p_ddl_generation_output_mode.htm
// for more configuration details
config.put("eclipselink.ddl-generation", "drop-and-create-tables");
config.put("eclipselink.ddl-generation.output-mode", "both");
config.put("eclipselink.create-ddl-jdbc-file-name", createDllFile);
config.put("eclipselink.drop-ddl-jdbc-file-name", dropDllFile);
config.put("eclipselink.application-location", folder);
// now we create an entity manager which will generate the database
// schema
new PersistenceProvider()
.createEntityManagerFactory("openLCA", config)
.createEntityManager().close();
System.out.println("DDL files should be created now in: " + folder);
} catch (Exception e) {
e.printStackTrace();
}
}
开发者ID:GreenDelta,项目名称:olca-modules,代码行数:49,代码来源:DatabaseSchemaGeneration.java
注:本文中的org.eclipse.persistence.jpa.PersistenceProvider类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论