Search in sources :

Example 6 with DataDefinitionException

use of org.jooq.exception.DataDefinitionException in project jOOQ by jOOQ.

the class AbstractNode method commonAncestor.

@SuppressWarnings("unchecked")
final N commonAncestor(N other) {
    if (this.id().equals(other.id()))
        return (N) this;
    // TODO: Find a better solution than the brute force one
    // See e.g. https://en.wikipedia.org/wiki/Lowest_common_ancestor
    Map<N, Integer> a1 = ancestors((N) this, new HashMap<>(), 1);
    Map<N, Integer> a2 = ancestors(other, new HashMap<>(), 1);
    N node = null;
    Integer distance = null;
    for (Entry<N, Integer> entry : a1.entrySet()) {
        if (a2.containsKey(entry.getKey())) {
            // TODO: What if there are several conflicting paths?
            if (distance == null || distance > entry.getValue()) {
                node = entry.getKey();
                distance = entry.getValue();
            }
        }
    }
    if (node == null)
        throw new DataDefinitionException("Versions " + this.id() + " and " + other.id() + " do not have a common ancestor");
    return node;
}
Also used : DataDefinitionException(org.jooq.exception.DataDefinitionException)

Aggregations

DataDefinitionException (org.jooq.exception.DataDefinitionException)6 ArrayList (java.util.ArrayList)2 Field (org.jooq.Field)2 Query (org.jooq.Query)2 TableField (org.jooq.TableField)2 ParserException (org.jooq.impl.ParserException)2 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Check (org.jooq.Check)1 CommonTableExpression (org.jooq.CommonTableExpression)1 Configuration (org.jooq.Configuration)1 Constraint (org.jooq.Constraint)1 DSLContext (org.jooq.DSLContext)1 DataType (org.jooq.DataType)1 FieldOrConstraint (org.jooq.FieldOrConstraint)1 ForeignKey (org.jooq.ForeignKey)1 Meta (org.jooq.Meta)1