本文整理了Java中javax.persistence.Persistence
类的一些代码示例,展示了Persistence
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Persistence
类的具体详情如下:
包路径:javax.persistence.Persistence
类名称:Persistence
[英]Bootstrap class that is used to obtain an EntityManagerFactoryin Java SE environments. It may also be used to cause schema generation to occur.
The Persistence
class is available in a Java EE container environment as well; however, support for the Java SE bootstrapping APIs is not required in container environments.
The Persistence
class is used to obtain a javax.persistence.PersistenceUtil instance in both Java EE and Java SE environments.
[中]用于在Java SE环境中获取EntityManagerFactory的引导类。它还可用于生成模式。Persistence
类也可以在JavaEE容器环境中使用;但是,在容器环境中不需要支持JavaSE引导API。Persistence
类用于获取javax。坚持不懈Java EE和Java SE环境中的PersistenceUtil实例。
代码示例来源:origin: kiegroup/jbpm
@Before
public void beforeThis() {
emf = Persistence.createEntityManagerFactory("org.jbpm.logging.jta");
logService = new JPAAuditLogService(emf);
}
代码示例来源:origin: Impetus/Kundera
@Before
public void setUp() throws Exception
{
emf = Persistence.createEntityManagerFactory("hbaseTest");
em = emf.createEntityManager();
}
代码示例来源:origin: Impetus/Kundera
@Test
public void validConstructorTest() throws Exception {
emf = Persistence.createEntityManagerFactory("patest");
em = emf.createEntityManager();
BookEntity book = new BookEntity();
book.setBookId(1);
book.setTitle("The Complete Reference");
book.setAuthor("Herbert Schildt");
book.setPages(500);
em.persist(book);
em.clear();
BookEntity book1 = em.find(BookEntity.class, 1);
Assert.assertNotNull(book1);
Assert.assertEquals(1, book1.getBookId());
Assert.assertEquals("The Complete Reference", book1.getTitle());
Assert.assertEquals("Herbert Schildt", book1.getAuthor());
Assert.assertEquals(500, book1.getPages());
em.remove(book1);
BookEntity book2 = em.find(BookEntity.class, 1);
Assert.assertNull(book2);
em.close();
emf.close();
}
代码示例来源:origin: Impetus/Kundera
@Before
public void setUp() throws Exception
{
emf = Persistence.createEntityManagerFactory(persistenceUnit);
em = emf.createEntityManager();
em.getDelegate();
}
代码示例来源:origin: kiegroup/jbpm
@BeforeClass
public static void configure() {
pds = setupPoolingDataSource();
emf = Persistence.createEntityManagerFactory( "org.jbpm.services.task" );
hackTheDatabaseMetadataLoggerBecauseTheresALogbackXmlInTheClasspath();
}
代码示例来源:origin: Impetus/Kundera
@Test
public void onLimit()
emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT);
EntityManager em = emf.createEntityManager();
Map<String, Client> clients = (Map<String, Client>) em.getDelegate();
Client client = clients.get(PERSISTENCE_UNIT);
((CassandraClientBase) client).setCqlVersion(CassandraConstants.CQL_VERSION_3_0);
user1.setTweetBody("my first tweet");
user1.setTweetDate(currentDate);
em.persist(user1);
user2.setTweetBody("my first tweet");
user2.setTweetDate(currentDate);
em.persist(user2);
Query q = em.createQuery(noClause);
List<PrimeUser> results = q.getResultList();
Assert.assertNotNull(results);
Assert.assertEquals(3, results.size());
q = em.createQuery(noClause);
q.setMaxResults(2);
results = q.getResultList();
Assert.assertNotNull(results);
Assert.assertEquals(2, results.size());
代码示例来源:origin: Impetus/Kundera
/**
* Setup.
*/
@Before
public void setup()
{
emf = Persistence.createEntityManagerFactory("es-refresh-indexes-pu");
em = emf.createEntityManager();
/*
* This property will force ES to refresh indexes on all the nodes after
* insert, update and delete operations.
*
*/
em.setProperty("es.refresh.indexes", true);
}
代码示例来源:origin: Impetus/Kundera
/**
* Sets the up before class.
*
* @throws Exception
* the exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception
{
emf = Persistence.createEntityManagerFactory(_PU);
em = emf.createEntityManager();
}
代码示例来源:origin: Impetus/Kundera
@Test
public void testShowQueryDisabled()
emf = Persistence.createEntityManagerFactory(SHOW_QUERY_DISABLED_PU, puProperties);
em = emf.createEntityManager();
try
Query q = em.createQuery("Select p.personName from UserInformation p where p.personId = 2");
q.getResultList();
System.setOut(printStream);
q = em.createQuery("Select p.personName from UserInformation p where p.personId < 3");
q.getResultList();
System.setOut(printStream);
q = em.createQuery("Select p.personName from UserInformation p where p.personId >= 1 and p.personId < 3");
q.getResultList();
System.setOut(printStream);
Assert.assertEquals(isFileEmpty, true);
em.close();
emf.close();
代码示例来源:origin: Impetus/Kundera
EntityManagerFactory emfLucene = Persistence.createEntityManagerFactory("hbaseTest", puProperties);
EntityManager emLucene = emfLucene.createEntityManager();
emLucene.persist(p1);
emLucene.persist(p2);
emLucene.persist(p3);
Query q = emLucene.createQuery("Select p from PersonHBase p where p.personName = vivek1 OR p.age= 10");
List<PersonHBase> results = q.getResultList();
Assert.assertNotNull(results);
Assert.assertFalse(results.isEmpty());
Assert.assertEquals(1, results.size());
Assert.assertNotNull(results.get(0).getPersonId());
Assert.assertEquals("vivek", results.get(0).getPersonName());
.createQuery("Select p.personId, p.personName from PersonHBase p where p.personName = vivek1 OR p.age= 10");
results = q.getResultList();
Assert.assertNotNull(results);
Assert.assertFalse(results.isEmpty());
emLucene.close();
emfLucene.close();
代码示例来源:origin: Impetus/Kundera
@Test
public void testShowQueryDisabled()
emf = Persistence.createEntityManagerFactory(SHOW_QUERY_DISABLED_PU, puProperties);
em = emf.createEntityManager();
try
Query findQuery = em.createQuery("Select s from UserInformation s", UserInformation.class);
findQuery.getResultList();
expectedQuery[0] = "SELECT * FROM \"USER\" LIMIT 100";
System.setOut(printStream);
findQuery = em.createQuery("Select s from UserInformation s where s.name = vivek");
findQuery.getResultList();
expectedQuery[1] = "SELECT * FROM \"USER\" WHERE \"name\" = 'vivek' LIMIT 100 ALLOW FILTERING";
System.setOut(printStream);
findQuery = em.createQuery("Select s.age from UserInformation s where s.name = vivek");
findQuery.getResultList();
expectedQuery[2] = "SELECT \"age\" FROM \"USER\" WHERE \"name\" = 'vivek' LIMIT 100 ALLOW FILTERING";
System.setOut(printStream);
Assert.assertTrue(actualQuery.indexOf(expectedQuery[0]) == -1
&& actualQuery.indexOf(expectedQuery[1]) == -1 && actualQuery.indexOf(expectedQuery[2]) == -1);
em.close();
emf.close();
代码示例来源:origin: Impetus/Kundera
+ " \"tweetDate\" timestamp, PRIMARY KEY(\"userId\",\"tweetId\",\"timeLineId\"))";
executeScript(cql_Query);
emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT);
EntityManager em = emf.createEntityManager();
user2.setNickName(NickName.KK);
em.persist(user1);
em.persist(user2);
em.clear();
Query query = em.createQuery(noClause);
List<PrimeUser> results = query.getResultList();
Assert.assertNotNull(results);
Assert.assertEquals(2, results.size());
Assert.assertNotSame(results.get(0).getKey(), results.get(1).getKey());
Assert.assertEquals(results.get(0).getKey().getUserId(), results.get(1).getKey().getUserId());
Assert.assertNotSame(results.get(0).getKey().getTimeLineId(), results.get(1).getKey().getTimeLineId());
em.createQuery(deleteQuery).executeUpdate();
query = em.createQuery(noClause);
results = query.getResultList();
Assert.assertTrue(results.isEmpty());
代码示例来源:origin: Impetus/Kundera
@Test
public void testMetadataQueries()
EntityManagerFactory emf = Persistence.createEntityManagerFactory("dsscalar");
EntityManager entityManager = emf.createEntityManager();
String useNativeSql = "SELECT keyspace_name,table_name,column_name,kind,type FROM system_schema.columns"
+ " WHERE keyspace_name = 'KunderaExamples' AND table_name = 'PERSON'";
Query q = entityManager.createNativeQuery(useNativeSql);
List<Object[]> results = q.getResultList();
Assert.assertNotNull(results);
Assert.assertEquals(6, results.size());
q = entityManager.createNativeQuery(useNativeSql);
results = q.getResultList();
Assert.assertNotNull(results);
q = entityManager.createNativeQuery(useNativeSql);
final List<Object> resultsSingle = q.getResultList();
Assert.assertNotNull(results);
entityManager.close();
emf.close();
代码示例来源:origin: Impetus/Kundera
@Test
public void testShowQueryDisabled()
emf = Persistence.createEntityManagerFactory(REDIS_PU);
em = emf.createEntityManager();
Query findQuery = em.createQuery("Select s from UserInformation s");
findQuery.getResultList();
System.setOut(printStream);
findQuery = em.createQuery("Select p from UserInformation p where p.id=\"PK_1\"");
findQuery.getResultList();
System.setOut(printStream);
findQuery = em.createQuery("Select p from UserInformation p where p.id=\"Shahid\"");
findQuery.getResultList();
System.setOut(printStream);
Assert.assertEquals(isFileEmpty, true);
代码示例来源:origin: hibernate/hibernate-orm
doInJPA( this::entityManagerFactory, entityManager -> {
Session session = entityManager.unwrap( Session.class );
SessionImplementor sessionImplementor = entityManager.unwrap( SessionImplementor.class );
SessionFactory sessionFactory = entityManager.getEntityManagerFactory().unwrap( SessionFactory.class );
entityManager.createQuery( "delete from Book" ).executeUpdate();
entityManager.createQuery( "delete from Person" ).executeUpdate();
doInJPA( this::entityManagerFactory, entityManager -> {
Session session = entityManager.unwrap( Session.class );
entityManager.createQuery( "delete from Book" ).executeUpdate();
entityManager.createQuery( "delete from Person" ).executeUpdate();
PersistenceUnitUtil persistenceUnitUtil = entityManager.getEntityManagerFactory().getPersistenceUnitUtil();
PersistenceUtil persistenceUnitUtil = Persistence.getPersistenceUtil();
代码示例来源:origin: Impetus/Kundera
@Test
public void compositeKeytest()
{
emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT, puProperties);
em = emf.createEntityManager();
UUID timeLineId = UUID.randomUUID();
CassandraCompoundKey key = new CassandraCompoundKey("shahid", 1, timeLineId);
CassandraPrimeUser user = new CassandraPrimeUser(key);
user.setTweetBody("my first tweet");
user.setTweetDate(currentDate);
em.persist(user);
CassandraPrimeUser user2 = new CassandraPrimeUser(key);
user2.setTweetBody("my second tweet");
user2.setTweetDate(currentDate);
em.flush(); // optional,just to clear persistence cache.
em.clear();
CassandraPrimeUser u = em.find(CassandraPrimeUser.class, key);
Assert.assertEquals("my first tweet", u.getTweetBody());
em.merge(user2);
u = em.find(CassandraPrimeUser.class, key);
Assert.assertEquals("my second tweet", u.getTweetBody());
em.remove(user2);
}
代码示例来源:origin: Impetus/Kundera
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception
{
emf = Persistence.createEntityManagerFactory(PU);
em = emf.createEntityManager();
Map<String, Client> clients = (Map<String, Client>) em.getDelegate();
client = (Neo4JClient) clients.get(PU);
}
代码示例来源:origin: Impetus/Kundera
@Test
public void onBatchInsert()
{
emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT);
EntityManager em = emf.createEntityManager();
UUID timeLineId = UUID.randomUUID();
for (int i = 0; i < 500; i++)
{
UserTimeLine key = new UserTimeLine("mevivs", i, timeLineId);
Map<String, Client> clients = (Map<String, Client>) em.getDelegate();
Client client = clients.get(PERSISTENCE_UNIT);
((CassandraClientBase) client).setCqlVersion(CassandraConstants.CQL_VERSION_3_0);
PrimeUser user = new PrimeUser(key);
user.setTweetBody("my first tweet");
user.setTweetDate(currentDate);
em.persist(user);
}
em.clear();
PrimeUser u = em.find(PrimeUser.class, new UserTimeLine("mevivs", 499, timeLineId));
Assert.assertNotNull(u);
}
代码示例来源:origin: Impetus/Kundera
@Test
public void testCreate()
{
Map<String, Object> props = new HashMap<String, Object>();
props.put(PersistenceProperties.KUNDERA_DDL_AUTO_PREPARE, "create");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("metaDataTest", props);
Assert.assertTrue(CoreSchemaManager.validateAction("create"));
emf.close();
Assert.assertTrue(CoreSchemaManager.validateAction("create"));
Assert.assertFalse(CoreSchemaManager.validateAction("drop"));
}
代码示例来源:origin: Impetus/Kundera
@Test
public void testUUID()
{
EntityManagerFactory emf = Persistence.createEntityManagerFactory("cass_pu");
UUID key = UUID.randomUUID();
CassandraUUIDEntity entity = new CassandraUUIDEntity();
entity.setAge(10);
entity.setName("vivek");
entity.setUuidKey(key);
EntityManager em = emf.createEntityManager();
em.persist(entity);
CassandraUUIDEntity result = em.find(CassandraUUIDEntity.class, key);
Assert.assertNotNull(result);
Assert.assertEquals(key, result.getUuidKey());
Assert.assertEquals("vivek", result.getName());
Assert.assertEquals(new Integer(10), result.getAge());
}
内容来源于网络,如有侵权,请联系作者删除!