Search in sources :

Example 1 with SingletonIterator

use of org.hibernate.internal.util.collections.SingletonIterator in project hibernate-orm by hibernate.

the class PersistentClass method getSubclassClosureIterator.

public Iterator getSubclassClosureIterator() {
    ArrayList iters = new ArrayList();
    iters.add(new SingletonIterator(this));
    Iterator iter = getSubclassIterator();
    while (iter.hasNext()) {
        PersistentClass clazz = (PersistentClass) iter.next();
        iters.add(clazz.getSubclassClosureIterator());
    }
    return new JoinedIterator(iters);
}
Also used : SingletonIterator(org.hibernate.internal.util.collections.SingletonIterator) ArrayList(java.util.ArrayList) JoinedIterator(org.hibernate.internal.util.collections.JoinedIterator) Iterator(java.util.Iterator) SingletonIterator(org.hibernate.internal.util.collections.SingletonIterator) EmptyIterator(org.hibernate.internal.util.collections.EmptyIterator) JoinedIterator(org.hibernate.internal.util.collections.JoinedIterator)

Example 2 with SingletonIterator

use of org.hibernate.internal.util.collections.SingletonIterator in project hibernate-orm by hibernate.

the class UnionSubclassEntityPersister method generateSubquery.

protected String generateSubquery(PersistentClass model, Mapping mapping) {
    Dialect dialect = getFactory().getDialect();
    Settings settings = getFactory().getSettings();
    if (!model.hasSubclasses()) {
        return model.getTable().getQualifiedName(dialect, settings.getDefaultCatalogName(), settings.getDefaultSchemaName());
    }
    HashSet columns = new LinkedHashSet();
    Iterator titer = model.getSubclassTableClosureIterator();
    while (titer.hasNext()) {
        Table table = (Table) titer.next();
        if (!table.isAbstractUnionTable()) {
            Iterator citer = table.getColumnIterator();
            while (citer.hasNext()) {
                columns.add(citer.next());
            }
        }
    }
    StringBuilder buf = new StringBuilder().append("( ");
    Iterator siter = new JoinedIterator(new SingletonIterator(model), model.getSubclassIterator());
    while (siter.hasNext()) {
        PersistentClass clazz = (PersistentClass) siter.next();
        Table table = clazz.getTable();
        if (!table.isAbstractUnionTable()) {
            //TODO: move to .sql package!!
            buf.append("select ");
            Iterator citer = columns.iterator();
            while (citer.hasNext()) {
                Column col = (Column) citer.next();
                if (!table.containsColumn(col)) {
                    int sqlType = col.getSqlTypeCode(mapping);
                    buf.append(dialect.getSelectClauseNullString(sqlType)).append(" as ");
                }
                buf.append(col.getQuotedName(dialect));
                buf.append(", ");
            }
            buf.append(clazz.getSubclassId()).append(" as clazz_");
            buf.append(" from ").append(table.getQualifiedName(dialect, settings.getDefaultCatalogName(), settings.getDefaultSchemaName()));
            buf.append(" union ");
            if (dialect.supportsUnionAll()) {
                buf.append("all ");
            }
        }
    }
    if (buf.length() > 2) {
        //chop the last union (all)
        buf.setLength(buf.length() - (dialect.supportsUnionAll() ? 11 : 7));
    }
    return buf.append(" )").toString();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Table(org.hibernate.mapping.Table) Column(org.hibernate.mapping.Column) SingletonIterator(org.hibernate.internal.util.collections.SingletonIterator) Dialect(org.hibernate.dialect.Dialect) JoinedIterator(org.hibernate.internal.util.collections.JoinedIterator) Iterator(java.util.Iterator) SingletonIterator(org.hibernate.internal.util.collections.SingletonIterator) Settings(org.hibernate.cfg.Settings) JoinedIterator(org.hibernate.internal.util.collections.JoinedIterator) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) PersistentClass(org.hibernate.mapping.PersistentClass)

Aggregations

Iterator (java.util.Iterator)2 JoinedIterator (org.hibernate.internal.util.collections.JoinedIterator)2 SingletonIterator (org.hibernate.internal.util.collections.SingletonIterator)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Settings (org.hibernate.cfg.Settings)1 Dialect (org.hibernate.dialect.Dialect)1 EmptyIterator (org.hibernate.internal.util.collections.EmptyIterator)1 Column (org.hibernate.mapping.Column)1 PersistentClass (org.hibernate.mapping.PersistentClass)1 Table (org.hibernate.mapping.Table)1