Search in sources :

Example 61 with ListIterator

use of java.util.ListIterator in project hibernate-orm by hibernate.

the class JoinProcessor method processJoins.

public void processJoins(QueryNode query) {
    final FromClause fromClause = query.getFromClause();
    final List fromElements;
    if (DotNode.useThetaStyleImplicitJoins) {
        // for regression testing against output from the old parser...
        // found it easiest to simply reorder the FromElements here into ascending order
        // in terms of injecting them into the resulting sql ast in orders relative to those
        // expected by the old parser; this is definitely another of those "only needed
        // for regression purposes".  The SyntheticAndFactory, then, simply injects them as it
        // encounters them.
        fromElements = new ArrayList();
        ListIterator liter = fromClause.getFromElements().listIterator(fromClause.getFromElements().size());
        while (liter.hasPrevious()) {
            fromElements.add(liter.previous());
        }
    } else {
        fromElements = new ArrayList(fromClause.getFromElements().size());
        ListIterator<FromElement> liter = fromClause.getFromElements().listIterator();
        while (liter.hasNext()) {
            FromElement fromElement = liter.next();
            // We found an implied from element that is used in the WITH clause of another from element, so it need to become part of it's join sequence
            if (fromElement instanceof ImpliedFromElement && fromElement.getOrigin().getWithClauseFragment() != null && fromElement.getOrigin().getWithClauseFragment().contains(fromElement.getTableAlias())) {
                fromElement.getOrigin().getJoinSequence().addJoin((ImpliedFromElement) fromElement);
                // This from element will be rendered as part of the origins join sequence
                fromElement.setText("");
            } else {
                fromElements.add(fromElement);
            }
        }
    }
    // Iterate through the alias,JoinSequence pairs and generate SQL token nodes.
    Iterator iter = fromElements.iterator();
    while (iter.hasNext()) {
        final FromElement fromElement = (FromElement) iter.next();
        JoinSequence join = fromElement.getJoinSequence();
        join.setSelector(new JoinSequence.Selector() {

            public boolean includeSubclasses(String alias) {
                // The uber-rule here is that we need to include subclass joins if
                // the FromElement is in any way dereferenced by a property from
                // the subclass table; otherwise we end up with column references
                // qualified by a non-existent table reference in the resulting SQL...
                boolean containsTableAlias = fromClause.containsTableAlias(alias);
                if (fromElement.isDereferencedBySubclassProperty()) {
                    // TODO : or should we return 'containsTableAlias'??
                    LOG.tracev("Forcing inclusion of extra joins [alias={0}, containsTableAlias={1}]", alias, containsTableAlias);
                    return true;
                }
                boolean shallowQuery = walker.isShallowQuery();
                boolean includeSubclasses = fromElement.isIncludeSubclasses();
                boolean subQuery = fromClause.isSubQuery();
                return includeSubclasses && containsTableAlias && !subQuery && !shallowQuery;
            }
        });
        addJoinNodes(query, join, fromElement);
    }
}
Also used : FromClause(org.hibernate.hql.internal.ast.tree.FromClause) FromElement(org.hibernate.hql.internal.ast.tree.FromElement) ImpliedFromElement(org.hibernate.hql.internal.ast.tree.ImpliedFromElement) ArrayList(java.util.ArrayList) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ImpliedFromElement(org.hibernate.hql.internal.ast.tree.ImpliedFromElement) ListIterator(java.util.ListIterator) JoinSequence(org.hibernate.engine.internal.JoinSequence)

Example 62 with ListIterator

use of java.util.ListIterator in project hazelcast by hazelcast.

the class ReferenceObjects method isEqual.

public static boolean isEqual(Object a, Object b) {
    if (a == b) {
        return true;
    }
    if (a == null || b == null) {
        return false;
    }
    if (a.getClass().isArray() && b.getClass().isArray()) {
        int length = Array.getLength(a);
        if (length > 0 && !a.getClass().getComponentType().equals(b.getClass().getComponentType())) {
            return false;
        }
        if (Array.getLength(b) != length) {
            return false;
        }
        for (int i = 0; i < length; i++) {
            Object aElement = Array.get(a, i);
            Object bElement = Array.get(b, i);
            if (aElement instanceof StackTraceElement && bElement instanceof StackTraceElement) {
                if (!isEqualStackTrace((StackTraceElement) aElement, (StackTraceElement) bElement)) {
                    return false;
                }
            }
            if (!isEqual(aElement, bElement)) {
                return false;
            }
        }
        return true;
    }
    if (a instanceof List && b instanceof List) {
        ListIterator e1 = ((List) a).listIterator();
        ListIterator e2 = ((List) b).listIterator();
        while (e1.hasNext() && e2.hasNext()) {
            Object o1 = e1.next();
            Object o2 = e2.next();
            if (!isEqual(o1, o2)) {
                return false;
            }
        }
        return !(e1.hasNext() || e2.hasNext());
    }
    return a.equals(b);
}
Also used : List(java.util.List) LinkedList(java.util.LinkedList) ListIterator(java.util.ListIterator)

Example 63 with ListIterator

use of java.util.ListIterator in project hazelcast by hazelcast.

the class ListAbstractTest method testIterator.

// ================== Iterator ====================
@Test
public void testIterator() {
    addItems(10);
    ListIterator iterator = list.listIterator();
    int i = 0;
    while (iterator.hasNext()) {
        Object o = iterator.next();
        assertEquals(o, "item" + i++);
    }
}
Also used : ListIterator(java.util.ListIterator) Test(org.junit.Test)

Example 64 with ListIterator

use of java.util.ListIterator in project hazelcast by hazelcast.

the class ListAbstractTest method testIteratorWithIndex.

@Test
public void testIteratorWithIndex() {
    addItems(10);
    int i = 4;
    ListIterator iterator = list.listIterator(i);
    while (iterator.hasNext()) {
        Object o = iterator.next();
        assertEquals(o, "item" + i++);
    }
}
Also used : ListIterator(java.util.ListIterator) Test(org.junit.Test)

Example 65 with ListIterator

use of java.util.ListIterator in project hazelcast by hazelcast.

the class ListAbstractTest method testIterator_throwsException_whenRemove.

@Test(expected = UnsupportedOperationException.class)
public void testIterator_throwsException_whenRemove() {
    addItems(10);
    ListIterator iterator = list.listIterator();
    iterator.next();
    iterator.remove();
}
Also used : ListIterator(java.util.ListIterator) Test(org.junit.Test)

Aggregations

ListIterator (java.util.ListIterator)121 ArrayList (java.util.ArrayList)42 List (java.util.List)41 LinkedList (java.util.LinkedList)26 Iterator (java.util.Iterator)21 Map (java.util.Map)12 Handler (com.sun.jsftemplating.annotation.Handler)8 AbstractList (java.util.AbstractList)7 HashMap (java.util.HashMap)7 AbstractSequentialList (java.util.AbstractSequentialList)6 IOException (java.io.IOException)5 RandomAccess (java.util.RandomAccess)5 SelectResults (org.apache.geode.cache.query.SelectResults)5 Test (org.junit.Test)5 File (java.io.File)4 HashSet (java.util.HashSet)4 NoSuchElementException (java.util.NoSuchElementException)4 SipURI (javax.sip.address.SipURI)4 ArgumentIntKey (lucee.runtime.type.scope.ArgumentIntKey)4 StructTypeImpl (org.apache.geode.cache.query.internal.types.StructTypeImpl)4