本文整理匯總了Java中com.haulmont.cuba.core.Query.getResultList方法的典型用法代碼示例。如果您正苦於以下問題:Java Query.getResultList方法的具體用法?Java Query.getResultList怎麽用?Java Query.getResultList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.haulmont.cuba.core.Query
的用法示例。
在下文中一共展示了Query.getResultList方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loadUser
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
@Nullable
@Override
public User loadUser(String login) throws LoginException {
// first check if login is a valid user's email, and find the corresponding login name
// to pass to the super impl
if (login == null)
throw new IllegalArgumentException("Login is null");
EntityManager em = persistence.getEntityManager();
String queryStr = "select u.loginLowerCase from sec$User u where lower(u.email) = ?1 and (u.active = true or u.active is null)";
Query q = em.createQuery(queryStr);
q.setParameter(1, login.toLowerCase());
List results = q.getResultList();
if (!results.isEmpty())
return super.loadUser((String) results.get(0));
return super.loadUser(login);
}
示例2: loadUser
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
@Nullable
protected User loadUser(String login) throws LoginException {
if (login == null) {
throw new IllegalArgumentException("Login is null");
}
EntityManager em = persistence.getEntityManager();
String queryStr = "select u from sec$User u where u.loginLowerCase = ?1 and (u.active = true or u.active is null)";
Query q = em.createQuery(queryStr);
q.setParameter(1, login.toLowerCase());
List list = q.getResultList();
if (list.isEmpty()) {
log.debug("Unable to find user: {}", login);
return null;
} else {
//noinspection UnnecessaryLocalVariable
User user = (User) list.get(0);
return user;
}
}
示例3: getAvailableUsers
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
@Override
public List<String> getAvailableUsers() {
List<String> result = new ArrayList<>();
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
Query query = em.createQuery("select u from sec$User u");
List<User> userList = query.getResultList();
for (User user : userList) {
result.add(user.getLogin());
}
tx.commit();
} finally {
tx.end();
}
return result;
}
示例4: isLastExecutionFinished
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
@Override
public boolean isLastExecutionFinished(ScheduledTask task, long now) {
EntityManager em = persistence.getEntityManager();
Query query = em.createQuery(
"select e.finishTime from sys$ScheduledExecution e where e.task.id = ?1 and e.startTime = ?2");
query.setParameter(1, task.getId());
query.setParameter(2, task.getLastStartTime());
List list = query.getResultList();
if (list.isEmpty() || list.get(0) == null) {
// Execution finish was not registered by some reason, so using timeout value or just return false
boolean result = task.getTimeout() != null && task.getLastStart() + task.getTimeout() <= now;
if (result)
log.trace(task + ": considered finished because of timeout");
else
log.trace(task + ": not finished and not timed out");
return result;
}
Date date = (Date) list.get(0);
log.trace(task + ": finished at " + date.getTime());
return true;
}
示例5: checkSequenceExists
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
protected void checkSequenceExists(String entityName, long startValue, long increment) {
String seqName = getSequenceName(entityName);
if (existingSequences.contains(seqName))
return;
// Create sequence in separate transaction because it's name is cached and we want to be sure it is created
// regardless of possible errors in the invoking code
Transaction tx = persistence.createTransaction(getDataStore(entityName));
try {
EntityManager em = persistence.getEntityManager(getDataStore(entityName));
SequenceSupport sequenceSupport = getSequenceSupport(entityName);
Query query = em.createNativeQuery(sequenceSupport.sequenceExistsSql(seqName));
List list = query.getResultList();
if (list.isEmpty()) {
query = em.createNativeQuery(sequenceSupport.createSequenceSql(seqName, startValue, increment));
query.executeUpdate();
}
existingSequences.add(seqName);
tx.commit();
} finally {
tx.end();
}
}
示例6: isCollectionEmpty
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
protected boolean isCollectionEmpty(MetaProperty property) {
MetaProperty inverseProperty = property.getInverse();
if (inverseProperty == null) {
log.warn("Inverse property not found for property " + property);
Collection<Entity> value = entity.getValue(property.getName());
return value == null || value.isEmpty();
}
String invPropName = inverseProperty.getName();
String collectionPkName = metadata.getTools().getPrimaryKeyName(property.getRange().asClass());
String qlStr = "select e." + collectionPkName + " from " + property.getRange().asClass().getName() +
" e where e." + invPropName + "." + primaryKeyName + " = ?1";
Query query = entityManager.createQuery(qlStr);
query.setParameter(1, entity.getId());
query.setMaxResults(1);
List<Entity> list = query.getResultList();
return list.isEmpty();
}
示例7: testQuery
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
@Test
public void testQuery() {
System.out.println("===================== BEGIN testQuery =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Query query = em.createQuery("select r from sec$Role r where r.name = ?1");
query.setParameter(1, "roleToBeDeleted");
List<Role> list = query.getResultList();
assertTrue(list.isEmpty());
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testQuery =====================");
}
示例8: testQuery_CleanupMode
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
@Test
public void testQuery_CleanupMode() {
System.out.println("===================== BEGIN testQuery_CleanupMode =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
em.setSoftDeletion(false);
Query query = em.createQuery("select r from sec$Role r where r.name = ?1");
query.setParameter(1, "roleToBeDeleted");
List<Role> list = query.getResultList();
assertTrue(!list.isEmpty());
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testQuery_CleanupMode =====================");
}
示例9: testQueryWithoutConditions
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
@Test
public void testQueryWithoutConditions() {
System.out.println("===================== BEGIN testQueryWithoutConditions =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Query query = em.createQuery("select r from sec$Role r");
List<Role> list = query.getResultList();
for (Role role : list) {
if (role.getId().equals(role2Id)) {
fail();
}
}
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testQueryWithoutConditions =====================");
}
示例10: getTasks
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
protected synchronized List<ScheduledTask> getTasks() {
log.trace("Read all active tasks from DB and lock them");
EntityManager em = persistence.getEntityManager();
Query query = em.createQuery("select t from sys$ScheduledTask t where t.active = true");
query.setLockMode(LockModeType.PESSIMISTIC_WRITE);
return query.getResultList();
}
示例11: checkSequenceExists
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
protected void checkSequenceExists(String domain) {
String seqName = getSequenceName(domain);
if (containsSequence(seqName))
return;
// Create sequence in separate transaction because it's name is cached and we want to be sure it is created
// regardless of possible errors in the invoking code
Transaction tx = persistence.createTransaction(getDataStore(domain));
try {
lock.readLock().unlock();
lock.writeLock().lock();
EntityManager em = persistence.getEntityManager(getDataStore(domain));
Query query = em.createNativeQuery(getSequenceSupport(domain).sequenceExistsSql(seqName));
List list = query.getResultList();
if (list.isEmpty()) {
query = em.createNativeQuery(getSequenceSupport(domain).createSequenceSql(seqName, 1, 1));
query.executeUpdate();
}
tx.commit();
existingSequences.add(seqName);
} finally {
lock.readLock().lock();
lock.writeLock().unlock();
tx.end();
}
}
示例12: executeSelectSql
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
@Override
@Transactional(timeout = 2)
public String executeSelectSql(String sql) {
checkTestMode();
log.info("started: " + sql);
EntityManager em = persistence.getEntityManager();
Query query = em.createNativeQuery(sql);
query.getResultList();
log.info("finished: " + sql);
return "Done";
}
示例13: getCollection
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
protected Collection<Entity> getCollection(MetaProperty property) {
MetaProperty inverseProperty = property.getInverse();
if (inverseProperty == null) {
log.warn("Inverse property not found for property " + property);
Collection<Entity> value = entity.getValue(property.getName());
return value == null ? Collections.EMPTY_LIST : value;
}
String invPropName = inverseProperty.getName();
String qlStr = "select e from " + property.getRange().asClass().getName() + " e where e." + invPropName + "." +
primaryKeyName + " = ?1";
Query query = entityManager.createQuery(qlStr);
query.setParameter(1, entity.getId());
List<Entity> list = query.getResultList();
// If the property is not loaded, it means it was not modified and further check is not needed
if (!PersistenceHelper.isLoaded(entity, property.getName())) {
return list;
}
// Check whether the collection items still belong to the master entity, because they could be changed in the
// current transaction that did not affect the database yet
List<Entity> result = new ArrayList<>(list.size());
for (Entity item : list) {
Entity master = item.getValue(invPropName);
if (entity.equals(master))
result.add(item);
}
return result;
}
示例14: cascade
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
protected void cascade(String entityName, MetaProperty property) {
String template = property.getRange().getCardinality().isMany() ?
"select e from %s e join e.%s c where c." + primaryKeyName + " = ?1" :
"select e from %s e where e.%s." + primaryKeyName + " = ?1";
String qstr = String.format(template, entityName, property.getName());
Query query = entityManager.createQuery(qstr);
query.setParameter(1, entity.getId());
List<Entity> list = query.getResultList();
for (Entity e : list) {
entityManager.remove(e);
}
}
示例15: unlink
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
protected void unlink(String entityName, MetaProperty property) {
if (metadata.getTools().isOwningSide(property)) {
String template = property.getRange().getCardinality().isMany() ?
"select e from %s e join e.%s c where c." + primaryKeyName + " = ?1" :
"select e from %s e where e.%s." + primaryKeyName + " = ?1";
String qstr = String.format(template, entityName, property.getName());
Query query = entityManager.createQuery(qstr);
query.setParameter(1, entity.getId());
List<Entity> list = query.getResultList();
for (Entity e : list) {
if (property.getRange().getCardinality().isMany()) {
Collection collection = e.getValue(property.getName());
if (collection != null) {
for (Iterator it = collection.iterator(); it.hasNext(); ) {
if (entity.equals(it.next())) {
it.remove();
}
}
}
} else {
setReferenceNull(e, property);
}
}
} else {
MetaProperty inverseProp = property.getInverse();
if (inverseProp != null && inverseProp.getDomain().equals(metaClass)) {
setReferenceNull(entity, inverseProp);
}
}
}