本文整理汇总了Java中org.eclipse.persistence.sessions.DatabaseRecord类的典型用法代码示例。如果您正苦于以下问题:Java DatabaseRecord类的具体用法?Java DatabaseRecord怎么用?Java DatabaseRecord使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DatabaseRecord类属于org.eclipse.persistence.sessions包,在下文中一共展示了DatabaseRecord类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fireSQL
import org.eclipse.persistence.sessions.DatabaseRecord; //导入依赖的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);
}
示例2: assertSQL
import org.eclipse.persistence.sessions.DatabaseRecord; //导入依赖的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);
}
示例3: queryIndexOf
import org.eclipse.persistence.sessions.DatabaseRecord; //导入依赖的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;
}