本文整理匯總了Java中org.hibernate.transform.Transformers類的典型用法代碼示例。如果您正苦於以下問題:Java Transformers類的具體用法?Java Transformers怎麽用?Java Transformers使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Transformers類屬於org.hibernate.transform包,在下文中一共展示了Transformers類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getStatisticsBySession
import org.hibernate.transform.Transformers; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public List<VoteStatsDTO> getStatisticsBySession(Long toolContentId) {
SQLQuery query = getSession().createSQLQuery(GET_STATISTICS);
query.addScalar("sessionUid", LongType.INSTANCE).addScalar("sessionName", StringType.INSTANCE)
.addScalar("countUsersComplete", IntegerType.INSTANCE).setLong("contentId", toolContentId)
.setResultTransformer(Transformers.aliasToBean(VoteStatsDTO.class));
return query.list();
}
示例2: pageByHql
import org.hibernate.transform.Transformers; //導入依賴的package包/類
@SuppressWarnings({"unchecked"})
public <T> Pagination<T> pageByHql(Class<T> clazz, CharSequence queryString, int pageIndex,
int pageSize, Object... params) {
Query query = getSession().createQuery(queryString.toString());
if ((pageSize > 0) && (pageIndex > 0)) {
query.setFirstResult((pageIndex - 1) * pageSize);
query.setMaxResults(pageIndex * pageSize);
}
setParameter(query, params);
query.setResultTransformer(Transformers.aliasToBean(clazz));
List<T> items = query.list();
Long rowsCount = (Long) getSingleColumnByHql(getCountStr(queryString.toString()), params);
Pagination<T> pagination = new Pagination((long) pageIndex, (long) pageSize, rowsCount);
pagination.setItems(items);
return pagination;
}
示例3: findByNative
import org.hibernate.transform.Transformers; //導入依賴的package包/類
@Override
public <X> List<X> findByNative(String sql, List<?> params, Pageable pageable, Class<X> clazz) {
Assert.hasText(sql, "native sql can not been null or blank");
Query query = entityManager.createNativeQuery(sql);
if (query != null) {
query.unwrap(SQLQuery.class).setResultTransformer(Transformers.aliasToBean(clazz));
query.setFirstResult(pageable.getOffset());
query.setMaxResults(pageable.getPageSize());
if (CollectionUtils.isNotEmpty(params)) {
for (int i = 0; i < params.size(); i++) {
query.setParameter(i + 1, params.get(i));
}
}
return query.getResultList();
}
return Lists.newArrayList();
}
示例4: exportHistoryLabelsNum
import org.hibernate.transform.Transformers; //導入依賴的package包/類
@Override
public long exportHistoryLabelsNum() {
long pages_num = 0;
Session session = HibernateUtils.getSession();//生成Session實例
Transaction tx=session.beginTransaction();//生成事務實例
try {
Query query = session.createSQLQuery("SELECT export_record.export_id,export_record.export_time,COUNT(*) AS amount FROM "
+ "export_record,export_tag WHERE export_record.export_id = export_tag.export_id GROUP BY export_record.export_id ORDER BY export_record.export_time DESC").setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP) ;
pages_num = query.list().size();
tx.commit();//提交事務
} catch (Exception e) {
e.printStackTrace();
tx.rollback();
}finally {
HibernateUtils.closeSession();//關閉session實例
}
return pages_num;
}
示例5: getAmountContributeOfAllByUser
import org.hibernate.transform.Transformers; //導入依賴的package包/類
@Override
public int getAmountContributeOfAllByUser() {
Session session = HibernateUtils.getSession();
Transaction tx = session.beginTransaction();
String sql = "SELECT id,upload_img_time,upload_img_review_status,username,tel_num FROM user_contribute_img WHERE upload_img_review_status=0 ORDER BY upload_img_time ASC";
List<Contribute_Img > cImgs = new ArrayList<Contribute_Img>();
try {
cImgs = session.createSQLQuery(sql).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
tx.commit();
} catch (Exception e) {
e.printStackTrace();
tx.rollback();
} finally {
HibernateUtils.closeSession(); // 關閉Session實例
}
return cImgs.size();
}
示例6: checkCrossFollow
import org.hibernate.transform.Transformers; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public boolean checkCrossFollow(long userId, long targetUserId) {
String hql = "from mto_follows where user_id = :userId and follow_id = :followId and " +
"user_id in (select follow_id from mto_follows where user_id = :followId)";
Query q = createSQLQuery(hql);
q.setLong("userId", userId);
q.setLong("followId", targetUserId);
q.setResultTransformer(Transformers.aliasToBean(FollowPO.class));
List<FollowPO> list = q.list();
if (list != null && list.size() > 0) {
return true;
}
return false;
}
示例7: listAllowedUsers
import org.hibernate.transform.Transformers; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public List<Actor> listAllowedUsers(Integer taskInstanceId) {
StringBuilder sql = new StringBuilder();
sql.append(" SELECT DISTINCT a.CO_ATOR AS \"cod\",");
sql.append(" a.CO_USUARIO AS \"codUsuario\",");
sql.append(" UPPER(a.NO_ATOR) AS \"nome\",");
sql.append(" a.DS_EMAIL AS \"email\"");
sql.append(" FROM "+ Constants.SCHEMA +" .VW_ATOR a");
sql.append(" ORDER BY UPPER(a.NO_ATOR)");
SQLQuery query = getSession().createSQLQuery(sql.toString());
query.addScalar("cod", StandardBasicTypes.INTEGER);
query.addScalar("codUsuario", StandardBasicTypes.STRING);
query.addScalar("nome", StandardBasicTypes.STRING);
query.addScalar("email", StandardBasicTypes.STRING);
query.setResultTransformer(Transformers.aliasToBean(Actor.class));
return query.list();
}
示例8: calculateClientSurveyScore
import org.hibernate.transform.Transformers; //導入依賴的package包/類
public List<ClientSurveyScore> calculateClientSurveyScore(Integer startIndex,Integer maxItems,String projectGroupCode) {
DetachedCriteria criteria = DetachedCriteria.forClass(SectionScoreEntity.class);
criteria.createAlias("surveyEntity", "surveyEntity");
ProjectionList projectionList = Projections.projectionList();
projectionList.add(Projections.sum("sectionScore"),"surveyScore");
projectionList.add(Projections.property("surveyEntity.id"),"surveyId");
projectionList.add(Projections.property("clientId"),"clientId");
projectionList.add(Projections.property("surveyEntity.projectGroupCode"),"projectGroupCode");
projectionList.add(Projections.property("surveyEntity.createdAt"),"surveyDate");
projectionList.add(Projections.groupProperty("surveyEntity.id"));
projectionList.add(Projections.groupProperty("clientId"));
projectionList.add(Projections.groupProperty("surveyEntity.tagValue"),"surveyTagValue");
criteria.setProjection(projectionList);
criteria.add(Restrictions.eq("surveyEntity.projectGroupCode",projectGroupCode));
criteria.setResultTransformer(Transformers.aliasToBean(ClientSurveyScore.class));
return (List<ClientSurveyScore>) findByCriteria(criteria,startIndex,maxItems);
}
示例9: getFriendships
import org.hibernate.transform.Transformers; //導入依賴的package包/類
/**
* Get a list of all the UUIDs in a player's friends list.
*
* @param left The UUID of the player that owns the friends list we wish to get
* @return A List of UUIDs of players in the friends list, which will be empty if no results were found
*/
public List getFriendships(UUID left) {
Session s = this.plugin.getSession();
Query q;
q = s.createQuery(
"SELECT f.friendUuid FROM Friendship f WHERE f.playerUuid=:uuid"
);
q.setString("uuid", left.toString());
List r = q.list();
if (r.size() < 1) {
return r;
}
List result = s.createCriteria(com.archivesmc.archblock.storage.entities.Player.class)
.add(Restrictions.in("uuid", r))
.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)
.list();
s.close();
return result;
}
示例10: listBySql
import org.hibernate.transform.Transformers; //導入依賴的package包/類
public <N extends Object> List<N> listBySql(String sql, Object[] args, Map<String, Object> alias, Class<?> clz,
boolean hasEntiry) {
sql = initSort(sql);
SQLQuery sq = getSession().createSQLQuery(sql);
setAliasParameter(sq, alias);
setParameter(sq, args);
if (hasEntiry) {
sq.addEntity(clz);
} else {
sq.setResultTransformer(Transformers.aliasToBean(clz));
}
return sq.list();
}
示例11: testJpqlResultTransformer
import org.hibernate.transform.Transformers; //導入依賴的package包/類
@Test
public void testJpqlResultTransformer() {
doInJPA( entityManager -> {
List<PostDTO> postDTOs = entityManager.createQuery(
"select " +
" p.id as id, " +
" p.title as title " +
"from Post p " +
"where p.createdOn > :fromTimestamp")
.setParameter( "fromTimestamp", Timestamp.from(
LocalDateTime.of( 2016, 1, 1, 0, 0, 0 ).toInstant( ZoneOffset.UTC ) ))
.unwrap( org.hibernate.query.Query.class )
.setResultTransformer( Transformers.aliasToBean( PostDTO.class ) )
.getResultList();
assertEquals( 1, postDTOs.size() );
} );
}
開發者ID:vladmihalcea,項目名稱:high-performance-java-persistence,代碼行數:19,代碼來源:HibernateDTOProjectionTest.java
示例12: testNativeQueryResultTransformer
import org.hibernate.transform.Transformers; //導入依賴的package包/類
@Test
public void testNativeQueryResultTransformer() {
doInJPA( entityManager -> {
List postDTOs = entityManager.createNativeQuery(
"select " +
" p.id as \"id\", " +
" p.title as \"title\" " +
"from Post p " +
"where p.created_on > :fromTimestamp")
.setParameter( "fromTimestamp", Timestamp.from(
LocalDateTime.of( 2016, 1, 1, 0, 0, 0 ).toInstant( ZoneOffset.UTC ) ))
.unwrap( org.hibernate.query.NativeQuery.class )
.setResultTransformer( Transformers.aliasToBean( PostDTO.class ) )
.getResultList();
assertEquals( 1, postDTOs.size() );
} );
}
開發者ID:vladmihalcea,項目名稱:high-performance-java-persistence,代碼行數:19,代碼來源:HibernateDTOProjectionTest.java
示例13: getUserProfiles
import org.hibernate.transform.Transformers; //導入依賴的package包/類
/**
* {@inheritDoc}
*/
public List<UserProfile> getUserProfiles(final int start, final int count) {
//get fields directly from the sakaiperson table and use Transformers.aliasToBean to transform into UserProfile pojo
//the idea is we *dont* want a SakaiPerson object
HibernateCallback<List<UserProfile>> hcb = session -> {
Query q = session.getNamedQuery(QUERY_GET_SAKAI_PERSON);
//see scalars in the hbm
q.setFirstResult(start);
q.setMaxResults(count);
q.setResultTransformer(Transformers.aliasToBean(UserProfile.class));
q.setCacheMode(CacheMode.GET);
return q.list();
};
return getHibernateTemplate().execute(hcb);
}
示例14: find
import org.hibernate.transform.Transformers; //導入依賴的package包/類
public PageSupport find(final SqlQuery sqlQuery) {
return (PageSupport) getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
SQLQuery query = session.createSQLQuery(sqlQuery.getQueryString());
if (AppUtils.isNotBlank(sqlQuery.getEntityClass())) {
for (String name : sqlQuery.getEntityClass().keySet()) {
// query.addEntity(name,sqlQuery.getEntityClass().get(name));
query.setResultTransformer(Transformers.aliasToBean(sqlQuery.getEntityClass().get(name)));
}
}
SQLQuery allCountQuery = session.createSQLQuery(sqlQuery.getAllCountString());
createSQLQuery(query, allCountQuery, sqlQuery.getParams(), sqlQuery.getParam(), sqlQuery.getTypes());
// 得到總行數
long allCounts = ((Number) allCountQuery.uniqueResult()).longValue();
int curPageNO = PagerUtil.getCurPageNO(sqlQuery.getCurPage());
int offset = PagerUtil.getOffset(allCounts, curPageNO, sqlQuery.getPageSize());
query.setFirstResult(offset);
query.setMaxResults(sqlQuery.getPageSize());
return new PageSupport(query.list(), sqlQuery.getMyaction(), offset, curPageNO, allCounts, sqlQuery.getPageSize(),
sqlQuery.getPageProvider());
}
});
}
示例15: createNativeQuery
import org.hibernate.transform.Transformers; //導入依賴的package包/類
/**
* CommonDAO 內部方法, NativeQuery
*
* @param entityManager
* entityManager
* @param sql
* sql
* @param values
* values
* @return Query對象
*/
private Query createNativeQuery(EntityManager entityManager, String sql, Class resultClass, boolean mapResult,
Map<String, Object> values) {
Query query = null;
if (resultClass != null) {
query = entityManager.createNativeQuery(sql, resultClass);
} else {
query = entityManager.createNativeQuery(sql);
}
// 封裝為Map結果
if (mapResult) {
query.unwrap(org.hibernate.Query.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
}
if (values != null && values.size() > 0) {
for (Entry<String, Object> e : values.entrySet()) {
query.setParameter(e.getKey(), e.getValue());
}
}
return query;
}