diff --git a/jOOQ/src/main/java/org/jooq/DSLContext.java b/jOOQ/src/main/java/org/jooq/DSLContext.java
index a22eb23ab1..9dbfedc9a5 100644
--- a/jOOQ/src/main/java/org/jooq/DSLContext.java
+++ b/jOOQ/src/main/java/org/jooq/DSLContext.java
@@ -248,6 +248,11 @@ public interface DSLContext extends Scope , AutoCloseable {
*/
DataSource diagnosticsDataSource();
+ /**
+ * Initialise a {@link Version}.
+ */
+ Version version(String id);
+
/**
* Access the database meta data.
*
diff --git a/jOOQ/src/main/java/org/jooq/Meta.java b/jOOQ/src/main/java/org/jooq/Meta.java
index 60f80f50ce..928d657fe3 100644
--- a/jOOQ/src/main/java/org/jooq/Meta.java
+++ b/jOOQ/src/main/java/org/jooq/Meta.java
@@ -221,42 +221,38 @@ public interface Meta extends Scope {
*/
Queries ddl(DDLExportConfiguration configuration) throws DataAccessException;
+ /**
+ * Apply a diff to this meta to produce a new {@link Meta}.
+ *
+ * @see Parser#parse(String)
+ * @throws DataAccessException If something went wrong fetching the meta
+ * objects
+ */
+ Meta apply(String diff) throws DataAccessException;
+ /**
+ * Apply a diff to this meta to produce a new {@link Meta}.
+ *
+ * @throws DataAccessException If something went wrong fetching the meta
+ * objects
+ */
+ Meta apply(Query... diff) throws DataAccessException;
+ /**
+ * Apply a diff to this meta to produce a new {@link Meta}.
+ *
+ * @throws DataAccessException If something went wrong fetching the meta
+ * objects
+ */
+ Meta apply(Collection extends Query> diff) throws DataAccessException;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ /**
+ * Apply a diff to this meta to produce a new {@link Meta}.
+ *
+ * @throws DataAccessException If something went wrong fetching the meta
+ * objects
+ */
+ Meta apply(Queries diff) throws DataAccessException;
diff --git a/jOOQ/src/main/java/org/jooq/Version.java b/jOOQ/src/main/java/org/jooq/Version.java
new file mode 100644
index 0000000000..47f10edbd7
--- /dev/null
+++ b/jOOQ/src/main/java/org/jooq/Version.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Other licenses:
+ * -----------------------------------------------------------------------------
+ * Commercial licenses for this work are available. These replace the above
+ * ASL 2.0 and offer limited warranties, support, maintenance, and commercial
+ * database integrations.
+ *
+ * For more information, please visit: http://www.jooq.org/licenses
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ */
+package org.jooq;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * A version ID attached to a {@link Meta} description of a database.
+ *
+ * @author Lukas Eder
+ */
+public interface Version {
+
+ /**
+ * The version ID, which is unique in the version graph.
+ */
+ String id();
+
+ /**
+ * The version's {@link Meta} representation of the database.
+ */
+ Meta meta();
+
+ /**
+ * The parents of this version.
+ */
+ List parents();
+
+ /**
+ * Produce a migration from a previous version.
+ */
+ Queries migrateFrom(Version version);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /**
+ * Apply a change set to produce a new version.
+ */
+ Version apply(String id, Queries diff);
+
+ /**
+ * Apply a change set to produce a new version.
+ *
+ * @see #apply(String, Queries)
+ */
+ Version apply(String id, Query... diff);
+
+ /**
+ * Apply a change set to produce a new version.
+ *
+ * @see #apply(String, Queries)
+ */
+ Version apply(String id, Collection extends Query> diff);
+
+ /**
+ * Apply a change set to produce a new version.
+ *
+ * @see #apply(String, Queries)
+ */
+ Version apply(String id, String diff);
+}
diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractMeta.java b/jOOQ/src/main/java/org/jooq/impl/AbstractMeta.java
index 74aeda6b76..2d1098c4d8 100644
--- a/jOOQ/src/main/java/org/jooq/impl/AbstractMeta.java
+++ b/jOOQ/src/main/java/org/jooq/impl/AbstractMeta.java
@@ -297,29 +297,25 @@ abstract class AbstractMeta extends AbstractScope implements Meta, Serializable
return new DDL(dsl(), exportConfiguration).queries(this);
}
+ @Override
+ public final Meta apply(String diff) {
+ return apply(dsl().parser().parse(diff));
+ }
+ @Override
+ public final Meta apply(Query... diff) {
+ return apply(dsl().queries(diff));
+ }
+ @Override
+ public final Meta apply(Collection extends Query> diff) {
+ return apply(dsl().queries(diff));
+ }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ @Override
+ public final Meta apply(Queries diff) {
+ return dsl().meta(ddl().concat(diff).queries());
+ }
diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java
index 6b5f3ab69d..9ad6b52702 100644
--- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java
+++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java
@@ -253,6 +253,7 @@ import org.jooq.UDTRecord;
import org.jooq.UpdatableRecord;
import org.jooq.UpdateQuery;
import org.jooq.UpdateSetFirstStep;
+import org.jooq.Version;
import org.jooq.WithAsStep;
import org.jooq.WithAsStep1;
import org.jooq.WithAsStep10;
@@ -409,6 +410,11 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
return new DiagnosticsDataSource(configuration());
}
+ @Override
+ public Version version(String id) {
+ return new VersionImpl(this, id, null);
+ }
+
@Override
public Meta meta() {
return configuration().metaProvider().provide();
diff --git a/jOOQ/src/main/java/org/jooq/impl/VersionImpl.java b/jOOQ/src/main/java/org/jooq/impl/VersionImpl.java
new file mode 100644
index 0000000000..5bebff03fd
--- /dev/null
+++ b/jOOQ/src/main/java/org/jooq/impl/VersionImpl.java
@@ -0,0 +1,221 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Other licenses:
+ * -----------------------------------------------------------------------------
+ * Commercial licenses for this work are available. These replace the above
+ * ASL 2.0 and offer limited warranties, support, maintenance, and commercial
+ * database integrations.
+ *
+ * For more information, please visit: http://www.jooq.org/licenses
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ */
+package org.jooq.impl;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.jooq.DSLContext;
+import org.jooq.Internal;
+import org.jooq.Meta;
+import org.jooq.Queries;
+import org.jooq.Query;
+import org.jooq.Source;
+import org.jooq.Version;
+
+/**
+ * @author Lukas Eder
+ */
+@Internal
+final class VersionImpl implements Version {
+
+ private final DSLContext ctx;
+ private final String id;
+ private final Meta meta;
+ private final List parents;
+
+ VersionImpl(DSLContext ctx, String id, Meta meta, Version... parents) {
+ this.ctx = ctx;
+ this.id = id;
+ this.meta = meta != null ? meta : ctx.meta("");
+ this.parents = Arrays.asList(parents);
+ }
+
+ @Override
+ public final String id() {
+ return id;
+ }
+
+ @Override
+ public final Meta meta() {
+ return meta;
+ }
+
+ @Override
+ public final List parents() {
+ return Collections.unmodifiableList(parents);
+ }
+
+ @Override
+ public final Version apply(String newId, Query... diff) {
+ return apply(newId, ctx.queries(diff));
+ }
+
+ @Override
+ public final Version apply(String newId, Collection extends Query> diff) {
+ return apply(newId, ctx.queries(diff));
+ }
+
+ @Override
+ public final Version apply(String newId, String diff) {
+ return apply(newId, ctx.parser().parse(diff));
+ }
+
+ @Override
+ public final Version apply(String newId, Queries diff) {
+ return new VersionImpl(ctx, newId, meta().apply(diff), new Version[] { this });
+ }
+
+ @Override
+ public final Queries migrateFrom(Version version) {
+ Queries result = null;
+
+
+
+
+
+ // TODO: Provide OSS edition solution here
+ return result;
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ VersionImpl other = (VersionImpl) obj;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ }
+ else if (!id.equals(other.id))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "-- Version: " + id() + "\n" + meta();
+ }
+}