Java Code Examples for org.hibernate.Query#iterate()

The following examples show how to use org.hibernate.Query#iterate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WorkletLoader.java    From yawl with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Set<String> getTargettedWorkletKeys() {
    Set<String> keys = new HashSet<String>();
    Query query = Persister.getInstance().createQuery("from RdrConclusion");
    Iterator it = query.iterate();
    while (it.hasNext()) {
        RdrConclusion conclusion = (RdrConclusion) it.next();
         for (RdrPrimitive primitive : conclusion.getPrimitives()) {
            if (primitive.getExletAction().isWorkletAction()) {
                String target = primitive.getTarget();
                if (target.contains(";")) {
                    keys.addAll(extractKeysFromTarget(target));
                }
                else {
                    keys.add(target);
                }
            }
        }
    }
    Persister.getInstance().commit();
    return keys;
}
 
Example 2
Source File: YLogServer.java    From yawl with GNU Lesser General Public License v3.0 6 votes vote down vote up
public String getTaskInstancesForTask(long taskKey) {
    String result;
    if (isEnabled()) {
        Query query = _logDb.createQuery("from YLogTaskInstance as ti where " +
                "ti.taskID=:key")
                .setLong("key", taskKey);
        if (query != null) {
            Iterator itr = query.iterate();
            if (itr.hasNext()) {
                StringBuilder xml = new StringBuilder();
                xml.append(String.format("<taskinstances key=\"%d\">", taskKey));
                while (itr.hasNext()) {
                    YLogTaskInstance instance = (YLogTaskInstance) itr.next();
                    xml.append(instance.toXML());
                }
                xml.append("</taskinstances>");
                result = xml.toString();
            }
            else result = NO_ROWS_ERROR;
        }
        else result = GENERAL_ERROR;
    }
    else result = CONNECTION_ERROR;

    return result;
}
 
Example 3
Source File: YLogServer.java    From yawl with GNU Lesser General Public License v3.0 6 votes vote down vote up
public String getCaseEvents(String caseID) {
    String result;
    if (isEnabled()) {
        Query query = _logDb.createQuery(
                "from YLogNetInstance as n where n.engineInstanceID=:caseID")
                .setString("caseID", caseID);
        if (query != null) {
            Iterator itr = query.iterate();
            if (itr.hasNext()) {
                YLogNetInstance instance = (YLogNetInstance) itr.next();
                result = getCaseEvents(instance.getNetInstanceID());
            }
            else result = NO_ROWS_ERROR;
        }
        else result = GENERAL_ERROR;
    }
    else result = CONNECTION_ERROR;

    return result;
}
 
Example 4
Source File: YLogServer.java    From yawl with GNU Lesser General Public License v3.0 6 votes vote down vote up
public String getTaskInstancesForCase(String caseID) {
    String result;
    if (isEnabled()) {
        Query query = _logDb.createQuery("from YLogTaskInstance as ti where " +
                "ti.engineInstanceID like :key")
                .setString("key", caseID + ".%");
        if (query != null) {
            Iterator itr = query.iterate();
            if (itr.hasNext()) {
                StringBuilder xml = new StringBuilder();
                xml.append(String.format("<taskinstances caseID=\"%s\">", caseID));
                while (itr.hasNext()) {
                    YLogTaskInstance instance = (YLogTaskInstance) itr.next();
                    xml.append(instance.toXML());
                }
                xml.append("</taskinstances>");
                result = xml.toString();
            }
            else result = NO_ROWS_ERROR;
        }
        else result = GENERAL_ERROR;
    }
    else result = CONNECTION_ERROR;

    return result;
}
 
Example 5
Source File: SongDao.java    From Quelea with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public List<Song> getSongs() {
    Query getAllSongQuery = session.createQuery("from Song");
    /*
     * We use an iterator here (rather then just doing getAllSongQuery.list()
     * because the latter will fall over if there are any corrupt songs in 
     * the database. This will force it to go through, and we can remove
     * the corrupt individual songs manually later.
     */
    Iterator<Song> iter = getAllSongQuery.iterate();
    List<Song> ret = new ArrayList<>();
    while (iter.hasNext()) {
        ret.add(iter.next());
    }
    return ret;
}
 
Example 6
Source File: YLogServer.java    From yawl with GNU Lesser General Public License v3.0 6 votes vote down vote up
public String getDataForEvent(long eventKey) {
    String result;
    if (isEnabled()) {
        Query query = _logDb.createQuery("from YLogDataItemInstance as di where " +
                "di.eventID=:key")
                .setLong("key", eventKey);
        if (query != null) {
            Iterator itr = query.iterate();
            if (itr.hasNext()) {
                StringBuilder xml = new StringBuilder();
                xml.append(String.format("<dataitems eventKey=\"%d\">", eventKey));
                while (itr.hasNext()) {
                    YLogDataItemInstance dataItem = (YLogDataItemInstance) itr.next();
                    xml.append(dataItem.toXML());
                }
                xml.append("</dataitems>");
                result = xml.toString();
            }
            else result = NO_ROWS_ERROR;
        }
        else result = GENERAL_ERROR;
    }
    else result = CONNECTION_ERROR;

    return result;
}
 
Example 7
Source File: YLogServer.java    From yawl with GNU Lesser General Public License v3.0 6 votes vote down vote up
public String getDataTypeForDataItem(long dataTypeKey) {
    String result;
    if (isEnabled()) {
        Query query = _logDb.createQuery("from YLogDataType as dt where " +
                "dt.dataTypeID=:key")
                .setLong("key", dataTypeKey);
        if (query != null) {
            Iterator itr = query.iterate();
            if (itr.hasNext()) {
                StringBuilder xml = new StringBuilder();
                YLogDataType dataType = (YLogDataType) itr.next();
                xml.append(dataType.toXML());
                result = xml.toString();
            }
            else result = NO_ROWS_ERROR;
        }
        else result = GENERAL_ERROR;
    }
    else result = CONNECTION_ERROR;

    return result;
}
 
Example 8
Source File: YLogServer.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String getInstanceEvents(long instanceKey) {
    String result;
    if (isEnabled()) {
        Query query = _logDb.createQuery("from YLogEvent as e where " +
                "e.instanceID=:key")
                .setLong("key", instanceKey);
        if (query != null) {
            Iterator itr = query.iterate();
            if (itr.hasNext()) {
                StringBuilder xml = new StringBuilder();
                xml.append(String.format("<events instanceKey=\"%d\">",
                        instanceKey));
                while (itr.hasNext()) {
                    YLogEvent event = (YLogEvent) itr.next();
                    xml.append(event.toXML());
                }
                xml.append("</events>");
                result = xml.toString();
            }
            else result = NO_ROWS_ERROR;
        }
        else result = GENERAL_ERROR;
    }
    else result = CONNECTION_ERROR;

    return result;
}
 
Example 9
Source File: GenericDaoImpl.java    From olat with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <K> Iterator<K> getQueryIterator(String queryName, Map<String, Object> queryParameters) {
    Query query = getNamedQuery(queryName);

    for (String key : queryParameters.keySet()) {
        query.setParameter(key, queryParameters.get(key));
    }
    return query.iterate();
}
 
Example 10
Source File: YEngineRestorer.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
private <T> List<T> restoreObjects(Class<T> clazz, String queryString) throws YPersistenceException {
    List<T> list = new ArrayList<T>();
    Query query = _pmgr.createQuery(queryString);
    for (Iterator it = query.iterate(); it.hasNext(); ) {
        try {
            T item = clazz.cast(it.next());
            if (item != null) list.add(item);
        }
        catch (ClassCastException cce) {
            // ignore this object
            _log.warn("Ignored object while restoring: " + cce.getMessage());
        }
    }
    return list;
}
 
Example 11
Source File: YLogServer.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
private YLogSpecification getSpecification(YSpecificationID specID) {
    if (isEnabled()) {
        String identifier = specID.getIdentifier();
        Query query;
        if (identifier != null) {
            query = _logDb.createQuery(
                    "select distinct s from YLogSpecification s where " +
                    "s.identifier=:id and s.version=:version and s.uri=:uri")
                    .setString("id", identifier)
                    .setString("version", specID.getVersionAsString())
                    .setString("uri", specID.getUri());
        }
        else {
            query = _logDb.createQuery(
                    "select distinct s from YLogSpecification s where " +
                    "s.version=:version and s.uri=:uri")
                    .setString("version", specID.getVersionAsString())
                    .setString("uri", specID.getUri());
        }
        if (query != null) {
            Iterator itr = query.iterate();
            if (itr.hasNext()) {
                return (YLogSpecification) itr.next();
            }
        }
    }
    return null;
}
 
Example 12
Source File: YLogServer.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String getAllCaseEventsByService(String serviceName, String eventType) {
    String result;
    if (isEnabled()) {
        Query query = _logDb.createQuery(
                "select e from YLogEvent as e, YLogService as s where " +
                        "s.serviceID=e.serviceID and " +
                        "s.name=:serviceName and e.descriptor=:event")
                .setString("serviceName", serviceName)
                .setString("event", eventType);
        if (query != null) {
            Iterator itr = query.iterate();
            if (itr.hasNext()) {
                StringBuilder xml = new StringBuilder();
                xml.append(String.format("<caseEvent serviceName=\"%s\">", serviceName));
                while (itr.hasNext()) {
                    YLogEvent event = (YLogEvent) itr.next();
                    xml.append(event.toXML());
                }
                xml.append("</caseEvent>");
                result = xml.toString();
            }
            else result = NO_ROWS_ERROR;
        }
        else result = GENERAL_ERROR;
    }
    else result = CONNECTION_ERROR;

    return result;
}
 
Example 13
Source File: YLogServer.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * ***********************************************************************
 */


public String getCaseEvent(String caseID, String eventType) {
    String result;
    if (isEnabled()) {
        Query query = _logDb.createQuery(
                "select e from YLogEvent as e, YLogNetInstance as ni where " +
                        "ni.engineInstanceID=:caseID and e.instanceID=ni.netInstanceID " +
                        "and e.descriptor=:eventType")
                .setString("caseID", caseID)
                .setString("eventType", eventType);
        if (query != null) {
            Iterator itr = query.iterate();
            if (itr.hasNext()) {
                StringBuilder xml = new StringBuilder();
                xml.append(String.format("<caseEvent caseID=\"%s\">", caseID));
                while (itr.hasNext()) {
                    YLogEvent event = (YLogEvent) itr.next();
                    xml.append(event.toXML());
                }
                xml.append("</caseEvent>");
                result = xml.toString();
            }
            else result = NO_ROWS_ERROR;
        }
        else result = GENERAL_ERROR;
    }
    else result = CONNECTION_ERROR;

    return result;
}
 
Example 14
Source File: YLogServer.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String getTaskInstancesForTask(String caseID, String taskName) {
    String result;
    if (isEnabled()) {
        Query query = _logDb.createQuery(
                "from YLogTaskInstance as ti, YLogTask as t " +
                        "where (ti.engineInstanceID=:caseID " +
                        "or ti.engineInstanceID like :caseIDlike) " +
                        "and ti.taskID=t.taskID " +
                        "and t.name=:taskName")
                .setString("caseID", caseID)
                .setString("caseIDlike", caseID + ".%")
                .setString("taskName", taskName);
        if (query != null) {
            Iterator itr = query.iterate();
            if (itr.hasNext()) {
                StringBuilder xml = new StringBuilder();
                xml.append(String.format("<taskinstances caseID=\"%s\" taskname=\"%s\">",
                        caseID, taskName));
                while (itr.hasNext()) {
                    Object[] next = (Object[]) itr.next();
                    YLogTaskInstance inst = (YLogTaskInstance) next[0];
                    xml.append(getFullyPopulatedTaskInstance(inst));
                }
                xml.append("</taskinstances>");
                result = xml.toString();
            }
            else result = NO_ROWS_ERROR;
        }
        else result = GENERAL_ERROR;
    }
    else result = CONNECTION_ERROR;

    return result;
}
 
Example 15
Source File: YLogServer.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * *************************************************************************
 */

public String getCaseEvents(long rootNetInstanceKey) {
    String result;
    if (isEnabled()) {
        Query query = _logDb.createQuery("from YLogEvent as e where " +
                "e.rootNetInstanceID=:key")
                .setLong("key", rootNetInstanceKey);
        if (query != null) {
            Iterator itr = query.iterate();
            if (itr.hasNext()) {
                StringBuilder xml = new StringBuilder();
                xml.append(String.format("<events rootNetInstanceKey=\"%d\">",
                        rootNetInstanceKey));
                while (itr.hasNext()) {
                    YLogEvent event = (YLogEvent) itr.next();
                    xml.append(event.toXML());
                }
                xml.append("</events>");
                result = xml.toString();
            }
            else result = NO_ROWS_ERROR;
        }
        else result = GENERAL_ERROR;
    }
    else result = CONNECTION_ERROR;

    return result;
}
 
Example 16
Source File: YLogServer.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @param specKey the specification PK to get the case instances for
 * @return the set of all case ids for the specID passed
 */
public String getNetInstancesOfSpecification(long specKey) {
    String result;
    if (isEnabled()) {
        Query query = _logDb.createQuery(
                "select ni from YLogNet as n, YLogNetInstance as ni " +
                        "where ni.netID=n.netID and n.specKey=:specKey")
                .setLong("specKey", specKey);
        if (query != null) {
            Iterator itr = query.iterate();
            if (itr.hasNext()) {
                StringBuilder xml = new StringBuilder();
                xml.append(String.format("<netInstances specID=\"%d\">", specKey));
                while (itr.hasNext()) {
                    YLogNetInstance instance = (YLogNetInstance) itr.next();
                    xml.append(instance.toXML());
                }
                xml.append("</netInstances>");
                result = xml.toString();
            }
            else result = NO_ROWS_ERROR;
        }
        else result = GENERAL_ERROR;
    }
    else result = CONNECTION_ERROR;

    return result;
}
 
Example 17
Source File: WorkletLoader.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Set<WorkletSpecification> loadAllPersistedWorkletSpecifications() {
    Set<WorkletSpecification> worklets = new HashSet<WorkletSpecification>();
    Query query = Persister.getInstance().createQuery("from WorkletSpecification");
    Iterator it = query.iterate();
    while (it.hasNext()) {
        WorkletSpecification spec = (WorkletSpecification) it.next();
        Hibernate.initialize(spec);
        worklets.add(spec);
    }
    Persister.getInstance().commit();
    return worklets;
}
 
Example 18
Source File: RunnerMap.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void restore(String caseID) {
    int selectionType = RuleType.ItemSelection.ordinal();
    String clause = "wr._ruleType" + (caseID == null ? "=" + selectionType :
            "!=" + selectionType + " and wr._parentCaseID='" + caseID + "'");
    Query query = Persister.getInstance().createQuery(
            "from WorkletRunner as wr where " + clause);
    Iterator it = query.iterate();
    if (it.hasNext()) {
        while (it.hasNext()) {
            WorkletRunner runner = (WorkletRunner) it.next();
            _runners.put(runner.getCaseID(), runner);
        }
    }
    Persister.getInstance().commit();
}
 
Example 19
Source File: GenericDaoImpl.java    From olat with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <K> Iterator<K> getQueryIterator(String queryName, Map<String, Object> queryParameters) {
    Query query = getNamedQuery(queryName);

    for (String key : queryParameters.keySet()) {
        query.setParameter(key, queryParameters.get(key));
    }
    return query.iterate();
}
 
Example 20
Source File: ArrivalDeparture.java    From core with GNU General Public License v3.0 4 votes vote down vote up
/**
 * For querying large amount of data. With a Hibernate Iterator not
 * all the data is read in at once. This means that can iterate over
 * a large dataset without running out of memory. But this can be slow
 * because when using iterate() an initial query is done to get all of
 * Id column data and then a separate query is done when iterating 
 * over each row. Doing an individual query per row is of course
 * quite time consuming. Better to use getArrivalsDeparturesFromDb()
 * with a fairly large batch size of ~50000.
 * <p>
 * Note that the session needs to be closed externally once done with
 * the Iterator.
 * 
 * @param session
 * @param beginTime
 * @param endTime
 * @return
 * @throws HibernateException
 */
public static Iterator<ArrivalDeparture> getArrivalsDeparturesDbIterator(
		Session session, Date beginTime, Date endTime) 
		throws HibernateException {
	// Create the query. Table name is case sensitive and needs to be the
	// class name instead of the name of the db table.
	String hql = "FROM ArrivalDeparture " +
			"    WHERE time >= :beginDate " +
			"      AND time < :endDate"; 
	Query query = session.createQuery(hql);
	
	// Set the parameters
	query.setTimestamp("beginDate", beginTime);
	query.setTimestamp("endDate", endTime);

	@SuppressWarnings("unchecked")
	Iterator<ArrivalDeparture> iterator = query.iterate(); 
	return iterator;
}