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


Java EntityManager.unwrap方法代码示例

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


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

示例1: getColumnNameToIndexMap

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static Map<String, Integer> getColumnNameToIndexMap(final String queryString, final EntityManager em) throws SQLException {

        final Session session = em.unwrap(Session.class); // ATTENTION! This is Hibernate-specific!
        final AtomicReference<ResultSetMetaData> msRef = new AtomicReference<>();
        session.doWork((c) -> {
            try (final PreparedStatement statement = create(c, queryString)) {
                // I'm not setting parameters here, because I just want to find out about the return values' column names
                msRef.set(statement.getMetaData());
            }
        });
        final ResultSetMetaData metaData = msRef.get();
        // LinkedHashmap preserves order of insertion:
        final Map<String, Integer> columnNameToColumnIndex = new LinkedHashMap<>();
        for (int t = 0; t < metaData.getColumnCount(); ++t) {
            // important, first index in the metadata is "1", the first index for the result array must be "0"
            columnNameToColumnIndex.put(metaData.getColumnName(t + 1), t);
        }
        return columnNameToColumnIndex;
    }
 
开发者ID:napstr,项目名称:SqlSauce,代码行数:20,代码来源:DbUtils.java

示例2: getJdbcConnection

import javax.persistence.EntityManager; //导入方法依赖的package包/类
@Override
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
		throws PersistenceException, SQLException {

	Connection con = entityManager.unwrap(Connection.class);
	return (con != null ? new SimpleConnectionHandle(con) : null);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:EclipseLinkJpaDialect.java

示例3: getDB

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static org.jpos.ee.DB getDB(EntityManager entityManager, Context ctx)
{
    ProxyFactory factory = new ProxyFactory();
    factory.setSuperclass(org.jpos.ee.DB.class);
    Class aClass = factory.createClass();
    final org.jpos.ee.DB newInstance;
    try
    {
        newInstance = (org.jpos.ee.DB) aClass.newInstance();
    }
    catch (InstantiationException | IllegalAccessException e)
    {
        throw new IllegalStateException("Could not create proxy", e);
    }

    MethodHandler methodHandler = (self, overridden, proceed, args) ->
    {
        if (overridden.getName().equals("session"))
        {
            return entityManager.unwrap(Session.class);
        }
        if (overridden.getName().equals("save"))
        {
            entityManager.persist(args[0]);
            return null;
        }
        if (overridden.getName().equals("saveOrUpdate"))
        {
            return entityManager.merge(args[0]);
        }
        if (overridden.getName().equals("delete"))
        {
            entityManager.remove(args[0]);
            return null;
        }
        else if (Arrays.asList(validMethods).contains(overridden.getName()))
        {
            return proceed.invoke(newInstance, args);
        }
        else
        {
            throw new IllegalStateException(
                "Method " + overridden.getName() + " cannot be accessed from Transaction " +
                "Participant");
        }
    };

    ((ProxyObject) newInstance).setHandler(methodHandler);
    return newInstance;
}
 
开发者ID:vmantek,项目名称:chimera,代码行数:51,代码来源:HibernateUtil.java

示例4: getDatabaseMetaData

import javax.persistence.EntityManager; //导入方法依赖的package包/类
private DatabaseMetaData getDatabaseMetaData(EntityManager entityManager) throws SQLException {
    SessionImplementor sessionImplementor = entityManager.unwrap(SessionImplementor.class);
    DatabaseMetaData metaData = sessionImplementor.connection().getMetaData();
    entityManager.close();
    return metaData;
}
 
开发者ID:infobip,项目名称:infobip-spring-data-jpa-querydsl,代码行数:7,代码来源:SimpleExtendedQueryDslJpaRepository.java

示例5: getSession

import javax.persistence.EntityManager; //导入方法依赖的package包/类
protected Session getSession(EntityManager em) {
	return em.unwrap(Session.class);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:4,代码来源:HibernateJpaDialect.java

示例6: createQuery

import javax.persistence.EntityManager; //导入方法依赖的package包/类
private <X> TypedQuery<X> createQuery(EntityManager entityManager, Class<X> clazz, boolean pagedCount)
{
	StrQLBuilder oThis = this;
	while (oThis.unionParent != null)
	{
		log.warn("Warning: you are trying to execute a query over an auxiliar instance -used to build union union queries-. Use .endUnion() to remove this message.");
		oThis = oThis.unionParent;
	}
	String sql = oThis.build(pagedCount);
	Map<String, Object> parametersMap = oThis.getParametersMap();

	AbstractEntityManagerImpl abstractEntityManager = entityManager.unwrap(AbstractEntityManagerImpl.class);
	try
	{
		QueryTranslator translator = null;
		boolean fixJpqlCountQuery = !isNative && pagedCount;
		if (fixJpqlCountQuery)
		{
			translator = translator(sql, entityManager);
			sql = "select count(*) from (" + translator.getSQLString() + ") x";
		}
		Query q = createQuery(sql, abstractEntityManager, fixJpqlCountQuery);
		TypedQueryImpl<X> typedQuery = new TypedQueryImpl<X>(q, abstractEntityManager);
		if (fixJpqlCountQuery)
		{
			typedQuery.setPositionParameters(getPositionParametersMap(translator, parametersMap));
		}
		else
		{
			typedQuery.setParameters(parametersMap);
		}
		typedQuery.setAlias(oThis.select.getAliases());
		typedQuery.setTargetClass(clazz);

		return typedQuery;
	}
	catch (HibernateException he)
	{
		throw abstractEntityManager.convert(he);
	}
}
 
开发者ID:iaunzu,项目名称:strqlbuilder,代码行数:42,代码来源:StrQLBuilder.java


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