use of org.hibernate.internal.util.collections.JoinedIterator 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();
}
use of org.hibernate.internal.util.collections.JoinedIterator in project hibernate-orm by hibernate.
the class FooBarTest method testTransientOrphanDelete.
@Test
public void testTransientOrphanDelete() throws Exception {
Session s = openSession();
Transaction t = s.beginTransaction();
Baz baz = new Baz();
Set bars = new HashSet();
baz.setCascadingBars(bars);
bars.add(new Bar());
bars.add(new Bar());
bars.add(new Bar());
List foos = new ArrayList();
foos.add(new Foo());
foos.add(new Foo());
baz.setFooBag(foos);
s.save(baz);
Iterator i = new JoinedIterator(new Iterator[] { foos.iterator(), bars.iterator() });
while (i.hasNext()) {
FooComponent cmp = ((Foo) i.next()).getComponent();
s.delete(cmp.getGlarch());
cmp.setGlarch(null);
}
t.commit();
s.close();
bars.remove(bars.iterator().next());
foos.remove(1);
s = openSession();
t = s.beginTransaction();
s.update(baz);
assertEquals(2, s.createQuery("From Bar bar").list().size());
assertEquals(3, s.createQuery("From Foo foo").list().size());
t.commit();
s.close();
foos.remove(0);
s = openSession();
t = s.beginTransaction();
s.update(baz);
bars.remove(bars.iterator().next());
assertEquals(1, s.createQuery("From Foo foo").list().size());
s.delete(baz);
//s.flush();
assertEquals(0, s.createQuery("From Foo foo").list().size());
t.commit();
s.close();
}
use of org.hibernate.internal.util.collections.JoinedIterator in project hibernate-orm by hibernate.
the class HQLQueryPlan method performIterate.
/**
* Coordinates the efforts to perform an iterate across all the included query translators.
*
* @param queryParameters The query parameters
* @param session The session
*
* @return The query result iterator
*
* @throws HibernateException Indicates a problem performing the query
*/
@SuppressWarnings("unchecked")
public Iterator performIterate(QueryParameters queryParameters, EventSource session) throws HibernateException {
if (traceEnabled) {
LOG.tracev("Iterate: {0}", getSourceQuery());
queryParameters.traceParameters(session.getFactory());
}
if (translators.length == 0) {
return EmptyIterator.INSTANCE;
}
final boolean many = translators.length > 1;
Iterator[] results = null;
if (many) {
results = new Iterator[translators.length];
}
Iterator result = null;
for (int i = 0; i < translators.length; i++) {
result = translators[i].iterate(queryParameters, session);
if (many) {
results[i] = result;
}
}
return many ? new JoinedIterator(results) : result;
}
use of org.hibernate.internal.util.collections.JoinedIterator in project hibernate-orm by hibernate.
the class DenormalizedTable method getIndexIterator.
@Override
public Iterator getIndexIterator() {
List indexes = new ArrayList();
Iterator iter = includedTable.getIndexIterator();
while (iter.hasNext()) {
Index parentIndex = (Index) iter.next();
Index index = new Index();
index.setName(getName() + parentIndex.getName());
index.setTable(this);
index.addColumns(parentIndex.getColumnIterator());
indexes.add(index);
}
return new JoinedIterator(indexes.iterator(), super.getIndexIterator());
}
use of org.hibernate.internal.util.collections.JoinedIterator in project hibernate-orm by hibernate.
the class PersistentClass method getSubclassIterator.
/**
* Iterate over subclasses in a special 'order', most derived subclasses
* first.
*/
public Iterator getSubclassIterator() {
Iterator[] iters = new Iterator[subclasses.size() + 1];
Iterator iter = subclasses.iterator();
int i = 0;
while (iter.hasNext()) {
iters[i++] = ((Subclass) iter.next()).getSubclassIterator();
}
iters[i] = subclasses.iterator();
return new JoinedIterator(iters);
}
Aggregations