Example usage for org.hibernate Query setLong

List of usage examples for org.hibernate Query setLong

Introduction

In this page you can find the example usage for org.hibernate Query setLong.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setLong(String name, long val) 

Source Link

Document

Bind a named long-valued parameter.

Usage

From source file:de.iew.framework.persistence.hibernate.HbmTreeOperationDaoImpl.java

License:Apache License

public void deleteNodesBetween(long treeId, long leftNestedSetIndex, long rightNestedSetIndex) {
    Session session = getCurrentSession();

    String hql;/*from   ww  w .ja  v a  2  s  . c o m*/
    Query query;
    int update;

    hql = "UPDATE Node SET parent = NULL WHERE tree.id = :treeId AND nestedSetLeft = :leftNestedSetIndex AND nestedSetRight = :rightNestedSetIndex";
    query = session.createQuery(hql);
    query.setLong("treeId", treeId);
    query.setLong("leftNestedSetIndex", leftNestedSetIndex);
    query.setLong("rightNestedSetIndex", rightNestedSetIndex);

    update = query.executeUpdate();
    if (log.isDebugEnabled()) {
        log.debug("Es wurde, fr " + update + " Knoten, die parentId Eigenschaft auf NULL gesetzt.");
    }

    hql = "DELETE FROM Node WHERE tree.id = :treeId AND nestedSetLeft BETWEEN :leftNestedSetIndex AND :rightNestedSetIndex";
    query = session.createQuery(hql);
    query.setLong("treeId", treeId);
    query.setLong("leftNestedSetIndex", leftNestedSetIndex);
    query.setLong("rightNestedSetIndex", rightNestedSetIndex);

    int deleted = query.executeUpdate();
    if (log.isDebugEnabled()) {
        log.debug("Es wurde " + deleted + " Knoten zwischen " + leftNestedSetIndex + " und "
                + rightNestedSetIndex + " gelscht.");
    }

    long delta = Math.round(rightNestedSetIndex - leftNestedSetIndex + 1);
    updateNestedSetIndexImpl(treeId, delta, rightNestedSetIndex);
    /*
            hql = "UPDATE Node SET nestedSetLeft = nestedSetLeft - :delta WHERE tree.id = :treeId AND nestedSetLeft > :rightNestedSetIndex";
            query = session.createQuery(hql);
            query.setLong("delta", delta);
            query.setLong("treeId", treeId);
            query.setLong("rightNestedSetIndex", rightNestedSetIndex);
            
            update = query.executeUpdate();
            if (log.isDebugEnabled()) {
    log.debug("Es wurde, fr " + update + " Knoten, der nestedSetLeft Wert aktualisiert.");
            }
            
            
            hql = "UPDATE Node SET nestedSetRight = nestedSetRight - :delta WHERE tree.id = :treeId AND nestedSetRight > :rightNestedSetIndex";
            query = session.createQuery(hql);
            query.setLong("delta", delta);
            query.setLong("treeId", treeId);
            query.setLong("rightNestedSetIndex", rightNestedSetIndex);
            
            update = query.executeUpdate();
            if (log.isDebugEnabled()) {
    log.debug("Es wurde, fr " + update + " Knoten, der nestedSetRight Wert aktualisiert.");
            }
            */
}

From source file:de.iew.framework.persistence.hibernate.HbmTreeOperationDaoImpl.java

License:Apache License

protected void updateNestedSetIndexImpl(long treeId, long delta, long nestedSetRight) {
    Session session = getCurrentSession();

    String hql;//from  w  w w  .ja v a  2s  . c  om
    Query query;
    int update;

    hql = "UPDATE Node SET nestedSetLeft = nestedSetLeft - :delta WHERE tree.id = :treeId AND nestedSetLeft > :rightNestedSetIndex";
    query = session.createQuery(hql);
    query.setLong("delta", delta);
    query.setLong("treeId", treeId);
    query.setLong("rightNestedSetIndex", nestedSetRight);

    update = query.executeUpdate();
    if (log.isDebugEnabled()) {
        log.debug("Es wurde, fr " + update + " Knoten, der nestedSetLeft Wert aktualisiert.");
    }

    hql = "UPDATE Node SET nestedSetRight = nestedSetRight - :delta WHERE tree.id = :treeId AND nestedSetRight > :rightNestedSetIndex";
    query = session.createQuery(hql);
    query.setLong("delta", delta);
    query.setLong("treeId", treeId);
    query.setLong("rightNestedSetIndex", nestedSetRight);

    update = query.executeUpdate();
    if (log.isDebugEnabled()) {
        log.debug("Es wurde, fr " + update + " Knoten, der nestedSetRight Wert aktualisiert.");
    }
}

From source file:de.innovationgate.webgate.api.jdbc.WGDatabaseImpl.java

License:Open Source License

public List<WGUpdateLog> getUpdateLogs(Comparable fromRevision) throws WGAPIException {

    try {//from w  w  w . ja v a2 s  .  com
        Iterator logEntries;
        if (_ddlVersion >= WGDatabase.CSVERSION_WGA5) {
            Query logEntriesQ = getSession().createQuery(
                    "from de.innovationgate.webgate.api.jdbc.LogEntry as logentry where id > :start order by id asc");
            logEntriesQ.setLong("start", ((Long) fromRevision).longValue());
            logEntries = logEntriesQ.iterate();

        } else {
            Date cutoff = (Date) fromRevision;
            Query logEntriesQ = getSession().createQuery(
                    "from de.innovationgate.webgate.api.jdbc.LogEntry as logentry where logtime >= :start order by logtime asc");
            logEntriesQ.setTimestamp("start", new java.sql.Timestamp(cutoff.getTime()));
            logEntries = logEntriesQ.iterate();
        }

        List wgLogs = new ArrayList();
        LinkedMap wgLogsByTarget = new LinkedMap();
        Map conflictTargets = new HashMap();

        LogEntry entry;

        // First pass: Create update logs
        while (logEntries.hasNext()) {
            entry = (LogEntry) logEntries.next();
            WGUpdateLog newLog = null;
            WGUpdateLog oldLog = null;
            Date currentTime = null;
            if (entry.getTarget() != null && !entry.getTarget().equals("#UNKNOWN#")) {
                newLog = readUpdateLog(entry);
                wgLogs.add(newLog);

                List logsList = (List) wgLogsByTarget.get(entry.getTarget());
                if (logsList == null) {
                    logsList = new ArrayList();
                    wgLogsByTarget.put(entry.getTarget(), logsList);
                }
                logsList.add(newLog);
            }
        }

        // Second pass for CS version < 5 to workaround some weaknesses of the CS3/4 history log
        if (_ddlVersion < WGDatabase.CSVERSION_WGA5) {

            // Determine conflicting log entries, where update and delete is done on the same time and the same document
            Iterator wgLogsByTargetIt = wgLogsByTarget.values().iterator();
            while (wgLogsByTargetIt.hasNext()) {
                List logs = (List) wgLogsByTargetIt.next();
                WGUtils.sortByProperty(logs, "date");
                Iterator logsIt = logs.iterator();
                Date lastTime = null;
                List<WGUpdateLog> logsAtSameTime = new ArrayList();
                while (logsIt.hasNext()) {
                    WGUpdateLog log = (WGUpdateLog) logsIt.next();
                    if (log.getDate().equals(lastTime)) {
                        logsAtSameTime.add(log);
                    } else {
                        resolveLogConflicts(wgLogs, logsAtSameTime);
                        logsAtSameTime.clear();
                    }
                    lastTime = log.getDate();
                }
            }

            // Order logentries that have the same time in an order that assures dependency documents are created before their dependent documents
            Collections.sort(wgLogs, new DocumentDependencyComparator());

        }

        return wgLogs;
    } catch (HibernateException e) {
        throw new WGBackendException("Unable to retrieve updated documents", e);
    }

}

From source file:de.nava.informa.impl.hibernate.ChannelBuilder.java

License:Open Source License

public ItemEnclosureIF createItemEnclosure(ItemIF item, URL location, String type, int length) {
    Query query = session.createQuery("from ItemEnclosure as enc where enc.item.id = ? ");
    query.setLong(0, item.getId());
    ItemEnclosureIF obj = (ItemEnclosureIF) query.uniqueResult();
    if (obj == null) {
        obj = new ItemEnclosure(item, location, type, length);
        session.save(obj);//from   w ww .j a  v  a  2  s . com
    }
    return obj;
}

From source file:de.powerstaff.business.dao.hibernate.NavigatingDAOHibernateImpl.java

License:Open Source License

public T findNext(final T aObject) {

    final String theTypeName = getEntityClass().getName();

    if ((aObject == null) || (aObject.getId() == null)) {
        return findLast();
    }/*  w  ww.  j  a va2  s . c  o m*/

    return (T) getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session aSession) throws SQLException {
            Query theQuery = aSession.createQuery("from " + theTypeName
                    + " i where i.id = (select min(j.id) from " + theTypeName + " j where j.id > :currentID)");
            theQuery.setLong("currentID", aObject.getId());
            Iterator resultIterator = theQuery.list().iterator();
            if (resultIterator.hasNext()) {
                return resultIterator.next();
            }

            return findLast();
        }
    });
}

From source file:de.powerstaff.business.dao.hibernate.NavigatingDAOHibernateImpl.java

License:Open Source License

public T findPrior(final T aObject) {

    final String theTypeName = getEntityClass().getName();

    if ((aObject == null) || (aObject.getId() == null)) {
        return findFirst();
    }//from  w  w  w.j  a v a 2s  .c o m

    return (T) getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session aSession) throws SQLException {
            Query theQuery = aSession.createQuery("from " + theTypeName
                    + " i where i.id = (select max(j.id) from " + theTypeName + " j where j.id < :currentID)");
            theQuery.setLong("currentID", aObject.getId());
            Iterator resultIterator = theQuery.list().iterator();
            if (resultIterator.hasNext()) {
                return resultIterator.next();
            }

            return findFirst();
        }
    });
}

From source file:de.powerstaff.business.dao.hibernate.NavigatingDAOHibernateImpl.java

License:Open Source License

public RecordInfo getRecordInfo(final T aObject) {

    final String theTypeName = getEntityClass().getName();

    return (RecordInfo) getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session aSession) {
            RecordInfo theInfo = new RecordInfo();

            Query theQuery = aSession.createQuery("select count(item.id) from " + theTypeName + " item");
            theInfo.setCount((Long) theQuery.uniqueResult());

            if (aObject.getId() != null) {
                theQuery = aSession.createQuery(
                        "select count(item.id) from " + theTypeName + " item where item.id<= :number");
                theQuery.setLong("number", aObject.getId());
                theInfo.setNumber((Long) theQuery.uniqueResult());
            }//from   w  ww  .  j  a  v a2  s. com

            return theInfo;
        }
    });
}

From source file:de.unisb.cs.st.javalanche.mutation.testsuite.DeleteTest.java

License:Open Source License

private void checkForTestMessageIds(Collection<TestMessage> testMessageIDs) {
    for (TestMessage tm : testMessageIDs) {
        Long id = tm.getId();//  w w  w.j  a v  a2s  .co  m
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        Query q = session.createQuery("FROM TestMessage T WHERE id=:id");
        q.setLong("id", id);
        int resultSize = q.list().size();
        tx.commit();
        session.close();
        Assert.assertEquals("Expecting TestMessage to be deleted", 0, resultSize);

    }

}

From source file:de.unisb.cs.st.javalanche.mutation.testsuite.DeleteTest.java

License:Open Source License

private void checkForResultID(Long resultID) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = session.beginTransaction();
    Query q = session.createQuery("FROM MutationTestResult as mtr where id=:r_id");
    q.setLong("r_id", resultID);
    int resultSize = q.list().size();
    tx.commit();//from  w  w  w.j  a  va  2 s  . c  o  m
    session.close();
    Assert.assertEquals("Expected TestMessage to be deleted", 0, resultSize);

    checkLinkTablesPassing(resultID);
    checkLinkTablesFailing(resultID);
    checkLinkTablesErrors(resultID);

}

From source file:de.unisb.cs.st.javalanche.mutation.testsuite.DeleteTest.java

License:Open Source License

private void checkLinkTablesErrors(Long resultID) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = session.beginTransaction();
    Query q = session
            .createSQLQuery("SELECT * FROM MutationTestResult_Errors S WHERE MutationTestResult_id=:id")
            .addEntity(MutationTestResult.class);
    q.setLong("id", resultID);
    int resultSize = q.list().size();
    tx.commit();//from w  w w.  ja v a2  s .  c o m
    session.close();
    Assert.assertEquals("Expecting result to be deleted", 0, resultSize);
}