当前位置: 首页>>代码示例>>Java>>正文


Java EntityManagerFactory.createEntityManager方法代码示例

本文整理汇总了Java中javax.persistence.EntityManagerFactory.createEntityManager方法的典型用法代码示例。如果您正苦于以下问题:Java EntityManagerFactory.createEntityManager方法的具体用法?Java EntityManagerFactory.createEntityManager怎么用?Java EntityManagerFactory.createEntityManager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.persistence.EntityManagerFactory的用法示例。


在下文中一共展示了EntityManagerFactory.createEntityManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPermission

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
/**
 * retrieves the <code>RolesPermission</code> by the role.
 * 
 * @param role
 *            the role
 * @return userPermissions the list of permissions of the user
 * 
 */
public static Set<String> getPermission(String role) {
	EntityManagerFactory emf = Persistence.createEntityManagerFactory("userData");
	EntityManager em = emf.createEntityManager();
	EntityTransaction tx = em.getTransaction();
	tx.begin();
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<RolePermission> q = cb.createQuery(RolePermission.class);
	Root<RolePermission> c = q.from(RolePermission.class);
	q.select(c).where(cb.equal(c.get("roleName"), role));
	TypedQuery<RolePermission> query = em.createQuery(q);
	List<RolePermission> permissions = query.getResultList();
	Set<String> userPermissions = new HashSet<String>();
	for (RolePermission permission : permissions)
		userPermissions.add(permission.getPermission());
	tx.commit();
	em.close();
	return userPermissions;
}
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:27,代码来源:RolePermissionDAO.java

示例2: jpa_with_parent_and_active_span_only

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
@Test
public void jpa_with_parent_and_active_span_only() {

  try (Scope ignored = mockTracer.buildSpan("parent").startActive(true)) {
    EntityManagerFactory entityManagerFactory = Persistence
        .createEntityManagerFactory("jpa_active_span_only");

    EntityManager entityManager = entityManagerFactory.createEntityManager();

    entityManager.getTransaction().begin();
    entityManager.persist(new Employee());
    entityManager.persist(new Employee());
    entityManager.getTransaction().commit();
    entityManager.close();
    entityManagerFactory.close();
  }

  List<MockSpan> spans = mockTracer.finishedSpans();
  assertEquals(11, spans.size());
  checkSameTrace(spans);
  assertNull(mockTracer.activeSpan());
}
 
开发者ID:opentracing-contrib,项目名称:java-jdbc,代码行数:23,代码来源:HibernateTest.java

示例3: retrieveAuthor

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
/**
   * gets an author from the database by determining the type of the provided id. if no author is present it builds one from the id.
   * @param id the author identifier
   * @return the author retrieved from the database or build with the identifier
* @throws JDOMException thrown upon parsing the source response
* @throws IOException thrown upon reading profiles from disc
* @throws SAXException thrown when parsing the files from disc
 */
  public PublicationAuthor retrieveAuthor(String id) throws JDOMException, IOException, SAXException {
      typeOfID = determineID(id);
      LOGGER.info("given ID: " + id + " is of type " + typeOfID);
      EntityManagerFactory emf = Persistence.createEntityManagerFactory("publicationAuthors");
      EntityManager em = emf.createEntityManager();
      CriteriaBuilder cb = em.getCriteriaBuilder();
      CriteriaQuery<PublicationAuthor> q = cb.createQuery(PublicationAuthor.class);
      Root<PublicationAuthor> c = q.from(PublicationAuthor.class);
      List<Predicate> predicates = new ArrayList<>();
      if (typeOfID.equals("surname")) {
          if (id.contains(",")) {
              predicates.add(cb.equal(c.get("surname"),id.substring(0,id.indexOf(","))));
              predicates.add(cb.equal(c.get("firstname"),id.substring(id.indexOf(",")+1)));
              LOGGER.info("retriving surname, firstname from database for " + id);
          } else if (id.contains(" ")) {
              predicates.add(cb.equal(c.get("firstname"),id.substring(0,id.indexOf(" "))));
              predicates.add(cb.equal(c.get("surname"),id.substring(id.indexOf(" ")+1)));
              LOGGER.info("retrieving firstname surname from database for " + id);
          } else {
              predicates.add(cb.equal(c.get("surname"), id));
              LOGGER.info("retrieving surname from database for " + id);
          }
      }
      predicates.add(cb.equal(c.get(typeOfID), id));
      q.select(c).where(cb.equal(c.get(typeOfID), id));
      TypedQuery<PublicationAuthor> query = em.createQuery(q);
      List<PublicationAuthor> authors = query.getResultList();
      em.close();
      if (authors.size() == 1) {
          LOGGER.info("found author in database");
          this.author = authors.get(0);
          return author;
      }
      LOGGER.info("no match in database");
      return buildAuthor(id);
  }
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:45,代码来源:AuthorBuilder.java

示例4: getEntityManager

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
private synchronized EntityManager getEntityManager(final PersistenceUnitInfo unit) {
    if (entityManagers.containsKey(unit.getPersistenceUnitName())) {
        return entityManagers.get(unit.getPersistenceUnitName());
    }
    final String providerClassName = unit.getPersistenceProviderClassName();
    try {
        final PersistenceProvider provider = (PersistenceProvider) Class.forName(providerClassName).newInstance();
        final EntityManagerFactory emf = provider.createContainerEntityManagerFactory(unit, new HashMap());
        final EntityManager entityManager = emf.createEntityManager();
        entityManagers.put(unit.getPersistenceUnitName(), entityManager);
        entityManager.getTransaction().begin();
        return entityManager;
    } catch (final IllegalAccessException | InstantiationException | ClassNotFoundException e) {
        throw new TestEEfiException("Failed to load persistence provider class " + providerClassName, e);
    }
}
 
开发者ID:dajudge,项目名称:testee.fi,代码行数:17,代码来源:JpaInjectionServicesImpl.java

示例5: getRoles

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
/**
 * retrieves the list of roles for a given username.
 * 
 * @param username
 *            the username
 * @return userRoles the roles
 * 
 */
public static Set<String> getRoles(String username) {
	EntityManagerFactory emf = Persistence.createEntityManagerFactory("userData");
	EntityManager em = emf.createEntityManager();
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<UserRole> q = cb.createQuery(UserRole.class);
	Root<UserRole> c = q.from(UserRole.class);
	q.select(c).where(cb.equal(c.get("username"), username));
	TypedQuery<UserRole> query = em.createQuery(q);
	List<UserRole> roles = query.getResultList();
	Set<String> userRoles = new HashSet<String>();
	em.close();
	for (UserRole role : roles)
		userRoles.add(role.getRoleName());
	return userRoles;
}
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:24,代码来源:UserRoleDAO.java

示例6: btn_silActionPerformed

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
private void btn_silActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_silActionPerformed
    // TODO add your handling code here:
    if (tbl_arkadaslistesi.getSelectedRow() < 0) {
        JOptionPane.showMessageDialog(rootPane, "Bir kullanıcı Seçmelisiniz");
        return;
    }

    int id = (int) dtm2.getValueAt(tbl_arkadaslistesi.getSelectedRow(), 0);

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("SosyalMedyaAppWithDatabasePU");
    EntityManager em = emf.createEntityManager();

    Query q = em.createQuery("DELETE FROM ARKADASLIK u WHERE u.idUserKabul=:kabulid AND U.idUserIstek=:istekid");
    q.setParameter("istekid", id);
    q.setParameter("kabulid", Frm_Login.loginuser.getId());

    em.getTransaction().begin();
    q.executeUpdate();
    em.getTransaction().commit();
    
    
}
 
开发者ID:sametkaya,项目名称:Java_Swing_Programming,代码行数:23,代码来源:Frm_KullaniciSayfasi.java

示例7: btn_degistirActionPerformed

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
private void btn_degistirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_degistirActionPerformed
    // TODO add your handling code here:
       // UPDATE
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("BP2_LAB2PU");
    EntityManager em = emf.createEntityManager();

    Query q = em.createQuery("UPDATE Hasta h SET h.adi=:ad,h.soyadi=:soyad, h.idDoktor=:did  WHERE h.id=:id");
    q.setParameter("ad", txt_hastaadi.getText());
    q.setParameter("soyad", txt_hastasoyadi.getText());
    q.setParameter("did", doktorlar.get(cmb_doktorlar.getSelectedIndex()).getId());
    q.setParameter("id", tbl_hastalar.getValueAt(tbl_hastalar.getSelectedRow(), 0));
    em.getTransaction().begin();
    q.executeUpdate();
    em.getTransaction().commit();
    ///
    dtm.setRowCount(0);
    q = em.createQuery("SELECT h FROM Hasta h");

    List<Hasta> hastalar = q.getResultList();
    for (Hasta hs : hastalar) {
        dtm.addRow(new Object[]{hs.getId(), hs.getAdi(), hs.getSoyadi(), hs.getIdDoktor()});
    }
    tbl_hastalar.setModel(dtm);


}
 
开发者ID:sametkaya,项目名称:Java_Swing_Programming,代码行数:27,代码来源:Soru1.java

示例8: generateRosters

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
private static List<Roster> generateRosters() {
    EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("optashift-employee-rostering-persistence-unit");
    EntityManager entityManager = entityManagerFactory.createEntityManager();
    RosterGenerator rosterGenerator = new RosterGenerator(entityManager);

    List<Roster> rosterList = new ArrayList<>();
    rosterList.add(rosterGenerator.generateRoster(10, 7, false));
    rosterList.add(rosterGenerator.generateRoster(80, (28 * 4), false));

    entityManager.close();
    entityManagerFactory.close();
    return rosterList;
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:14,代码来源:OptaShiftEmployeeRosteringBenchmarkApp.java

示例9: getCategoryById

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
@Override
public Category getCategoryById(int id) {
	EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("pl.edu.bogdan.training.db.entity");
	EntityManager em = entityManagerFactory.createEntityManager();
	
	// begining of transaction
	em.getTransaction().begin();
	
	return em.find(Category.class, id);
}
 
开发者ID:PawelBogdan,项目名称:BecomeJavaHero,代码行数:11,代码来源:JPACategoryService.java

示例10: btn_girisActionPerformed

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
private void btn_girisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_girisActionPerformed
    // TODO add your handling code here:
    String kullaniciad = txt_kullaniciAdi.getText();
    String sifre = String.copyValueOf(txtp_sifre.getPassword());
    boolean girisyap = false;
    USER_1 login=null;
    
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("SosyalMedyaAppWithDatabasePU");
    EntityManager em = emf.createEntityManager();

    Query q = em.createQuery("SELECT u FROM USER_1 u WHERE u.kullaniciAdi=:kad AND u.sifre=:sif");
    
    q.setParameter("kad", kullaniciad);
    q.setParameter("sif", sifre);
    
    login=(USER_1)q.getSingleResult();
    
    if(login!=null)
    {
       loginuser=login;
      Frm_KullaniciSayfasi newkullanicisayfasi = new Frm_KullaniciSayfasi();
        newkullanicisayfasi.setVisible(true);
        this.dispose();
    
    }
    else
    {
      JOptionPane.showMessageDialog(rootPane, "Kullanici Adi ya da Şifre Geçersiz! ");
    }
  
}
 
开发者ID:sametkaya,项目名称:Java_Swing_Programming,代码行数:32,代码来源:Frm_Login.java

示例11: createEmSupplier

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
private EmSupplier createEmSupplier(EntityManagerFactory emf) {
    final EntityManager em = emf.createEntityManager();
    EmSupplier emSupplier = new EmSupplier() {
        public void preCall() {
        }

        public EntityManager get() {
            return em;
        }

        public void postCall() {
        }
    };
    return emSupplier;
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:16,代码来源:TaskServiceImplTest.java

示例12: getAuthors

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
public static List<PublicationAuthor> getAuthors() {
	EntityManagerFactory emf = Persistence.createEntityManagerFactory("publicationAuthors");
	EntityManager em = emf.createEntityManager();
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<PublicationAuthor> q = cb.createQuery(PublicationAuthor.class);
	Root<PublicationAuthor> c = q.from(PublicationAuthor.class);
	q.select(c).where(cb.like(c.<String>get("surname"), "%"));
	TypedQuery<PublicationAuthor> query = em.createQuery(q);
	List<PublicationAuthor> authors = query.getResultList();
	em.close();
	return authors;
}
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:13,代码来源:PublicationAuthorDAO.java

示例13: listUsers

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
/**
 * retrieves the list of user emails registered.
 * 
 * @return users the list of user emails
 * 
 */
public static List<String> listUsers() {
	EntityManagerFactory emf = Persistence.createEntityManagerFactory("userData");
	EntityManager em = emf.createEntityManager();
	Query query = em.createQuery("SELECT username FROM User");
	@SuppressWarnings("unchecked")
	List<String> users = query.getResultList();
	em.close();
	return users;
}
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:16,代码来源:UserDAO.java

示例14: jButton3ActionPerformed

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
         EntityManagerFactory emf=Persistence.createEntityManagerFactory("BP2_LAB2PU");
         EntityManager em=emf.createEntityManager();
         Query q=em.createQuery("SELECT k FROM Personel k");
         List<Personel>personeller=q.getResultList();
      //   ArrayList<String> paths=new ArrayList();
         for (Personel personel : personeller) {
             try {
                 //   paths.add(personel.getAdi());
                 Path p =Paths.get(personel.getAdi());
                 p.toRealPath();
             } catch (IOException ex) {
                 Logger.getLogger(Soru2.class.getName()).log(Level.SEVERE, null, ex);
             }
        }
//         
//         for (String path : paths) {
//             try {
//                 Path p=Paths.get(path);
//                 p.toRealPath();
//             } catch (IOException ex) {
//                 System.out.println(path+" Müşterisine Ait Bilgi Bulunamadı.");
//             }
//        }
         
         
    }
 
开发者ID:sametkaya,项目名称:Java_Swing_Programming,代码行数:29,代码来源:Soru2.java

示例15: btn_ekleActionPerformed

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
private void btn_ekleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_ekleActionPerformed
    // TODO add your handling code here:
    if (tbl_kisiliste.getSelectedRow() < 0) {
        JOptionPane.showMessageDialog(rootPane, "Bir kullanıcı Seçmelisiniz");
        return;
    }
    int id = (int) dtm1.getValueAt(tbl_kisiliste.getSelectedRow(), 0);

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("SosyalMedyaAppWithDatabasePU");
    EntityManager em = emf.createEntityManager();

    Query q = em.createQuery("SELECT u FROM USER_1 u WHERE u.id=:id");
    q.setParameter("id", id);

    USER_1 gelen = (USER_1) q.getSingleResult();
    if (gelen == null) {

        return;
    }

    ARKADASLIK yeni = new ARKADASLIK();
    yeni.setId(3);
    yeni.setIdUserIstek(Frm_Login.loginuser.getId());
    yeni.setIdUserKabul(gelen.getId());
    yeni.setKabulDurumu(false);
    em.getTransaction().begin();
    em.persist(yeni);
    em.getTransaction().commit();


}
 
开发者ID:sametkaya,项目名称:Java_Swing_Programming,代码行数:32,代码来源:Frm_KullaniciSayfasi.java


注:本文中的javax.persistence.EntityManagerFactory.createEntityManager方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。