use of org.hibernate.SQLQuery in project hibernate-orm by hibernate.
the class NativeSqlAndQuotedIdentifiersTest method testPartialScalarDiscovery.
@Test
public void testPartialScalarDiscovery() {
Session session = openSession();
session.beginTransaction();
SQLQuery query = (SQLQuery) session.getNamedQuery("query-person");
query.setResultSetMapping("person-scalar");
query.list();
session.getTransaction().commit();
session.close();
}
use of org.hibernate.SQLQuery in project JessMA by ldcsaa.
the class HibernateFacade method sqlQuery4.
/**
*
* 根据起始记录和最大记录数执行SQL查询,并根据Entities和Joins返回查询结果
*
* @param firstResult : 起始记录索引
* @param maxResults : 最大记录数
* @param sql : SQL 查询语句
* @param entities : 要绑定的查询实体集合
* @param joins : 要绑定的连接实体集合
* @param params : 查询参数
* @return : 查询结果
*
*/
protected <T> List<T> sqlQuery4(int firstResult, int maxResults, String sql, KV<String, Object>[] entities, KV<String, String>[] joins, Object... params) {
SQLQuery sqlQuery = getSession().createSQLQuery(sql);
for (int i = 0; i < params.length; i++) sqlQuery.setParameter(i, params[i]);
if (entities != null) {
for (int i = 0; i < entities.length; i++) {
KV<String, Object> entity = entities[i];
String key = entity.getKey();
Object value = entity.getValue();
Class<?> v1 = (value instanceof Class) ? (Class<?>) value : null;
String v2 = v1 == null ? (String) value : null;
if (key == null || key.length() == 0) {
if (v1 != null)
sqlQuery.addEntity(v1);
else
sqlQuery.addEntity(v2);
} else {
if (v1 != null)
sqlQuery.addEntity(key, v1);
else
sqlQuery.addEntity(key, v2);
}
}
}
if (joins != null) {
for (KV<String, String> join : joins) sqlQuery.addJoin(join.getKey(), (String) join.getValue());
}
if (firstResult > 0)
sqlQuery.setFirstResult(firstResult);
if (maxResults > 0)
sqlQuery.setMaxResults(maxResults);
return sqlQuery.list();
}
use of org.hibernate.SQLQuery in project midpoint by Evolveum.
the class DeleteTest method delete0003.
@Test
public void delete0003() throws Exception {
PrismObject<ShadowType> shadow = prismContext.parseObject(new File(FOLDER_BASE, "delete/shadow.xml"));
OperationResult result = new OperationResult("add shadow");
final String oid = repositoryService.addObject(shadow, null, result);
PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, oid, null, result);
shadow = prismContext.parseObject(new File(FOLDER_BASE, "delete/shadow.xml"));
AssertJUnit.assertEquals(shadow, repoShadow);
repositoryService.deleteObject(ShadowType.class, oid, result);
result.recomputeStatus();
AssertJUnit.assertTrue(result.isSuccess());
Session session = getFactory().openSession();
try {
SQLQuery query = session.createSQLQuery("select count(*) from m_trigger where owner_oid = ?");
query.setString(0, oid);
Number count = (Number) query.uniqueResult();
AssertJUnit.assertEquals(count.longValue(), 0L);
} finally {
session.close();
}
}
use of org.hibernate.SQLQuery in project dhis2-core by dhis2.
the class HibernateGenericStore method getSqlQuery.
/**
* Creates a SqlQuery.
*
* @param sql the sql query.
* @return a SqlQuery instance.
*/
protected final SQLQuery getSqlQuery(String sql) {
SQLQuery query = getSession().createSQLQuery(sql);
query.setCacheable(cacheable);
return query;
}
Aggregations