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


Java JpaEntityManager类代码示例

本文整理汇总了Java中org.eclipse.persistence.jpa.JpaEntityManager的典型用法代码示例。如果您正苦于以下问题:Java JpaEntityManager类的具体用法?Java JpaEntityManager怎么用?Java JpaEntityManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: extractIdPropertyNames

import org.eclipse.persistence.jpa.JpaEntityManager; //导入依赖的package包/类
@Override
public String[] extractIdPropertyNames(Object entity)
{
    final EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager(emf);
    final ClassDescriptor desc = em.unwrap(JpaEntityManager.class).getServerSession().getClassDescriptor(entity);
    if (desc != null)
    {
   	    final Collection<DatabaseMapping> fieldNames = desc.getMappings();
   	    final List<DatabaseMapping> tmp = new LinkedList<>();
   	    for (DatabaseMapping m : fieldNames)
   	    {
   	        if (m.isPrimaryKeyMapping())
   	        {
   	            tmp.add(m);
   	        }
   	    }
   	    final String[] retVal = new String[tmp.size()];
   	    for (int i = 0; i < retVal.length; i++)
   	    {
   	        retVal[i] = tmp.get(i).getAttributeName();
   	    }
   	    return retVal;
    }
    
    return null;
}
 
开发者ID:ethlo,项目名称:dachs,代码行数:27,代码来源:EclipselinkLazyIdExtractor.java

示例2: fireSQL

import org.eclipse.persistence.jpa.JpaEntityManager; //导入依赖的package包/类
private void fireSQL(TypedQuery<T> q, EntityManager em){
    String sql;

    // warning!!! highly unportable detection method
    if (em.getProperties().containsKey("org.hibernate.flushMode")){ // hibernate
        sql = q.unwrap(org.hibernate.Query.class).getQueryString();
    }
    else{ // eclipselink
        Session session = em.unwrap(JpaEntityManager.class).getActiveSession();
        DatabaseQuery databaseQuery = ((EJBQueryImpl)q).getDatabaseQuery();
        databaseQuery.prepareCall(session, new DatabaseRecord());
        sql = databaseQuery.getSQLString();
    }

    eventBus.fire(sql);
}
 
开发者ID:sasa7812,项目名称:jfbdemo,代码行数:17,代码来源:LazyLoadServiceImpl.java

示例3: getDBConnection

import org.eclipse.persistence.jpa.JpaEntityManager; //导入依赖的package包/类
private Connection getDBConnection(EntityManager em) {
    UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl) ((JpaEntityManager) em.getDelegate()).getActiveSession();
    unitOfWork.beginEarlyTransaction();
    Accessor accessor = unitOfWork.getAccessor();
    accessor.incrementCallCount(unitOfWork.getParent());
    accessor.decrementCallCount();
    return accessor.getConnection();

}
 
开发者ID:SECQME,项目名称:watchoverme-server,代码行数:10,代码来源:DefaultDatabaseUtil.java

示例4: copyInstance

import org.eclipse.persistence.jpa.JpaEntityManager; //导入依赖的package包/类
/**
    * {@inheritDoc}
    */
   @Override
   @Transactional
public <T> T copyInstance(final T dataObject, CopyOption... options) {
	final CopyGroup copyGroup = new CopyGroup();
	if (ArrayUtils.contains(options, CopyOption.RESET_PK_FIELDS)) {
		copyGroup.setShouldResetPrimaryKey(true);
	}
	final boolean shouldResetVersionNumber = ArrayUtils.contains(options, CopyOption.RESET_VERSION_NUMBER);
	if (shouldResetVersionNumber) {
		copyGroup.setShouldResetVersion(true);
	}
	final boolean shouldResetObjectId = ArrayUtils.contains(options, CopyOption.RESET_OBJECT_ID);
       return doWithExceptionTranslation(new Callable<T>() {
		@SuppressWarnings("unchecked")
		@Override
           public T call() {
			T copiedObject = (T) sharedEntityManager.unwrap(JpaEntityManager.class).getDatabaseSession()
					.copy(dataObject, copyGroup);
			if (shouldResetObjectId) {
				clearObjectIdOnUpdatableObjects(copiedObject, new HashSet<Object>());
			}
			if (shouldResetVersionNumber) {
			    clearVersionNumberOnUpdatableObjects(copiedObject, new HashSet<Object>());
			}
			return copiedObject;
           }
       });
   }
 
开发者ID:kuali,项目名称:kc-rice,代码行数:32,代码来源:JpaPersistenceProvider.java

示例5: testVariousGetters

import org.eclipse.persistence.jpa.JpaEntityManager; //导入依赖的package包/类
/**
 * Just tests some of the getters to ensure they are delegating down to the internal factory bean and the
 * PersistenceUnitManager appropriately.
 */
@Test
public void testVariousGetters() throws Exception {
    loadContext(getClass().getSimpleName() +  "_LoadTimeWeaving.xml");
    KradEclipseLinkEntityManagerFactoryBean factoryBean =
            context.getBean(KradEclipseLinkEntityManagerFactoryBean.class);
    assertNotNull(factoryBean);

    assertEquals(2, factoryBean.getPersistenceUnitPostProcessors().length);
    EntityManagerFactory entityManagerFactory = factoryBean.getNativeEntityManagerFactory();
    assertTrue(entityManagerFactory instanceof EntityManagerFactoryImpl);
    assertEquals(factoryBean.getBeanClassLoader(), getClass().getClassLoader());
    assertEquals(JpaEntityManager.class, factoryBean.getEntityManagerInterface());

}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:19,代码来源:KradEclipseLinkEntityManagerFactoryBeanTest.java

示例6: allActive

import org.eclipse.persistence.jpa.JpaEntityManager; //导入依赖的package包/类
/**
 * Return all active vertices.
 */
@SuppressWarnings("unchecked")
public synchronized List<Vertex> allActive() {
	UnitOfWork unitOfWork = this.entityManager.unwrap(JpaEntityManager.class).getUnitOfWork();
	try {
		return unitOfWork.getIdentityMapAccessor().getAllFromIdentityMap(null, BasicVertex.class, null, null);
	} catch (Exception exception) {
		return new ArrayList<Vertex>();
	}
}
 
开发者ID:BotLibre,项目名称:BotLibre,代码行数:13,代码来源:DatabaseNetwork.java

示例7: assertSQL

import org.eclipse.persistence.jpa.JpaEntityManager; //导入依赖的package包/类
protected void assertSQL(TypedQuery<Employee> tq, String expected){
    Session session = em.unwrap(JpaEntityManager.class).getActiveSession();
    DatabaseQuery databaseQuery = ((EJBQueryImpl)tq).getDatabaseQuery();
    databaseQuery.prepareCall(session, new DatabaseRecord());
    String actual = databaseQuery.getSQLString();
    //String actual = tq.unwrap(EJBQueryImpl.class).getDatabaseQuery().getSQLString();
    assertEquals(expected, actual);
}
 
开发者ID:sasa7812,项目名称:jfbdemo,代码行数:9,代码来源:FilterCriteriaBuilderEclipseLinkTest.java

示例8: getEntityManagerInterface

import org.eclipse.persistence.jpa.JpaEntityManager; //导入依赖的package包/类
@Override
public Class<? extends EntityManager> getEntityManagerInterface() {
	return JpaEntityManager.class;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:5,代码来源:EclipseLinkJpaVendorAdapter.java

示例9: testCanCastSharedEntityManagerProxyToEclipseLinkEntityManager

import org.eclipse.persistence.jpa.JpaEntityManager; //导入依赖的package包/类
public void testCanCastSharedEntityManagerProxyToEclipseLinkEntityManager() {
	assertTrue(sharedEntityManager instanceof JpaEntityManager);
	JpaEntityManager eclipselinkEntityManager = (JpaEntityManager) sharedEntityManager;
	assertNotNull(eclipselinkEntityManager.getActiveSession());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:6,代码来源:EclipseLinkEntityManagerFactoryIntegrationTests.java

示例10: beginTransaction

import org.eclipse.persistence.jpa.JpaEntityManager; //导入依赖的package包/类
@Override
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition) throws PersistenceException, SQLException, TransactionException {
    Object result = super.beginTransaction(entityManager, definition);
    Preconditions.checkState(result == null, "Transactional data should be null for EclipseLink dialect");

    // Read default timeout every time - may be somebody wants to change it on the fly
    int defaultTimeout = 0;
    String defaultTimeoutProp = AppContext.getProperty("cuba.defaultQueryTimeoutSec");
    if (!"0".equals(defaultTimeoutProp) && !StringUtils.isBlank(defaultTimeoutProp)) {
        try {
            defaultTimeout = Integer.parseInt(defaultTimeoutProp);
        } catch (NumberFormatException e) {
            log.error("Invalid cuba.defaultQueryTimeoutSec value", e);
        }
    }

    int timeoutSec = 0;
    if (definition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT)
        timeoutSec = definition.getTimeout();
    else if (defaultTimeout != 0)
        timeoutSec = defaultTimeout;

    if (timeoutSec != 0) {
        log.trace("Applying query timeout " + timeoutSec + "sec");
        if (entityManager instanceof JpaEntityManager) {
            UnitOfWork unitOfWork = ((JpaEntityManager) entityManager).getUnitOfWork();
            if (unitOfWork != null) {
                //setup delay in seconds on unit of work
                unitOfWork.setQueryTimeoutDefault(timeoutSec);
            }
        }

        String s = DbmsSpecificFactory.getDbmsFeatures().getTransactionTimeoutStatement();
        if (s != null) {
            Connection connection = entityManager.unwrap(Connection.class);
            try (Statement statement = connection.createStatement()) {
                statement.execute(String.format(s, timeoutSec * 1000));
            }
        }
    }

    return new CubaEclipseLinkTransactionData(entityManager);
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:44,代码来源:CubaEclipseLinkJpaDialect.java

示例11: unwrap

import org.eclipse.persistence.jpa.JpaEntityManager; //导入依赖的package包/类
/**
 * Tests unwrapping the underlaying EclipseLink JpaEntityManager
 */
@Test
   public void unwrap() {
	JpaEntityManager jpaEntityManager = repository.unwrap(JpaEntityManager.class);
	assertNotNull(jpaEntityManager);
   }
 
开发者ID:Appverse,项目名称:appverse-server,代码行数:9,代码来源:TestEclipseLinkRepositoryIntegrationTests.java

示例12: getSession

import org.eclipse.persistence.jpa.JpaEntityManager; //导入依赖的package包/类
/**
 * Get a traditional EclipseLink Session from the given EntityManager.
 */
protected Session getSession(EntityManager em) {
	JpaEntityManager emi = (JpaEntityManager) em;
	return emi.getActiveSession();
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:8,代码来源:EclipseLinkJpaDialect.java

示例13: testCanCastSharedEntityManagerProxyToTopLinkEntityManager

import org.eclipse.persistence.jpa.JpaEntityManager; //导入依赖的package包/类
public void testCanCastSharedEntityManagerProxyToTopLinkEntityManager() {
	assertTrue(sharedEntityManager instanceof JpaEntityManager);
	JpaEntityManager eclipselinkEntityManager = (JpaEntityManager) sharedEntityManager;
	assertNotNull(eclipselinkEntityManager.getActiveSession());
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:6,代码来源:EclipseLinkEntityManagerFactoryIntegrationTests.java

示例14: getUpdateSource

import org.eclipse.persistence.jpa.JpaEntityManager; //导入依赖的package包/类
@Override
public SynchronizedUpdateSource getUpdateSource(
		ExtendedSearchIntegrator searchIntegrator,
		Map<Class<?>, RehashedTypeMetadata> rehashedTypeMetadataPerIndexRoot,
		Map<Class<?>, List<Class<?>>> containedInIndexOf,
		Properties properties,
		EntityManagerFactory emf,
		TransactionManager transactionManager,
		Set<Class<?>> indexRelevantEntities) {
	JpaEntityManager entityManager = (JpaEntityManager) emf.createEntityManager();
	try {
		Session session = entityManager.getServerSession();

		IndexUpdater indexUpdater = new IndexUpdater(
				rehashedTypeMetadataPerIndexRoot,
				containedInIndexOf,
				new DummyReusableEntityProvider(),
				searchIntegrator
		);

		EclipseLinkUpdateSource eclipseLinkUpdateSource = new EclipseLinkUpdateSource(
				indexUpdater,
				indexRelevantEntities,
				rehashedTypeMetadataPerIndexRoot,
				containedInIndexOf,
				transactionManager
		);
		for ( Class<?> entity : indexRelevantEntities ) {
			if ( session.getDescriptor( entity ) == null ) {
				//no JPA entity
				continue;
			}
			session.getDescriptor( entity )
					.getDescriptorEventManager()
					.addListener( eclipseLinkUpdateSource.descriptorEventAspect );
		}
		if(transactionManager == null) {
			//equivalent to resource local tx
			session.getEventManager().addListener( eclipseLinkUpdateSource.sessionEventAspect );
		}
		return eclipseLinkUpdateSource;
	}
	finally {
		entityManager.close();
	}
}
 
开发者ID:Hotware,项目名称:Hibernate-Search-GenericJPA,代码行数:47,代码来源:EclipseLinkSynchronizedUpdateSourceProvider.java

示例15: queryIndexOf

import org.eclipse.persistence.jpa.JpaEntityManager; //导入依赖的package包/类
private Integer queryIndexOf(final JpaEntityItem<TEntityType> item) {
        final EntityManager em = lookup(EntityManager.class);
        final CriteriaBuilder cb = em.getCriteriaBuilder();
        final CriteriaQuery query = cb.createQuery();
        final Root<TEntityType> root = query.from(entityClass);

        // Добавляем фильтр контейнера
        final List<Predicate> predicates = createContainerFilterPredicates(cb, query, root);
        if (!predicates.isEmpty()) {
            query.where(CollectionUtil.toArray(Predicate.class, predicates));
        }

        // Добавляем сортировку
        final List<JpaSortBy> sortByList = sortBySupplier.get();
        if (!sortByList.isEmpty()) {
            final List<Order> orders = newArrayListWithCapacity(sortByList.size());
            for (final JpaSortBy sortBy : sortByList)
                orders.add(translateSortBy(sortBy, cb, root));
            query.orderBy(orders);
        }

        final Path<String> idPath = root.get(IdentifiedObject_.id);
        query.select(idPath).distinct(true);

        final TypedQuery<Long> tq = em.createQuery(query);
        final DatabaseQuery databaseQuery = tq.unwrap(JpaQuery.class).getDatabaseQuery();
        final DatabaseRecord translationRow = new DatabaseRecord();
        final JpaEntityManager jpaEm = em.unwrap(JpaEntityManager.class);
        databaseQuery.prepareCall(jpaEm.getSession(), translationRow);
        final String querySql = databaseQuery.getTranslatedSQLString(jpaEm.getSession(), translationRow);
        final String itemId = item.getBean().getId();
        final Query nativeQuery = em.createNativeQuery(
                MessageFormat.format(
                        "SELECT q.rownum AS indx " +
                                "FROM (SELECT s.{2} AS id, (@rownum:[email protected] + 1) - 1 AS rownum " +
                                "           FROM (SELECT @rownum:=0) i, ({0}) s) q " +
                                "WHERE q.id = ''{1}''", querySql, itemId, IdentifiedObject_.id.getName()));
//            nativeQuery.unwrap(JpaQuery.class).getDatabaseQuery().setTranslationRow(translationRow);
        final Object result;
        try {
            result = nativeQuery.getSingleResult();
        } catch (final NoResultException e) {
            return -1;
        }

        return result != null /*&& result instanceof Number*/ ? ((Number) result).intValue() : -1;
    }
 
开发者ID:ExtaSoft,项目名称:extacrm,代码行数:48,代码来源:JpaLazyItemList.java


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