[jOOQ/jOOQ#9506] Added org.jooq.Versions as a result type for VersionProvider
This commit is contained in:
parent
350f995030
commit
ade3869e8f
@ -37,8 +37,6 @@
|
||||
*/
|
||||
package org.jooq;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* An SPI that allows for providing a graph of versions.
|
||||
*
|
||||
@ -55,6 +53,5 @@ public interface VersionProvider {
|
||||
* {@link Version#migrateTo(Version)} and other operations are undefined
|
||||
* if two versions do not have a common ancestor.
|
||||
*/
|
||||
@Internal // TODO Produce a better type than Set<Version>. Possibly, #current() can be obtained from the new result type.
|
||||
Set<Version> provide();
|
||||
Versions provide();
|
||||
}
|
||||
|
||||
57
jOOQ/src/main/java/org/jooq/Versions.java
Normal file
57
jOOQ/src/main/java/org/jooq/Versions.java
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* A directed, acyclic graph of {@link Version} objects
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public interface Versions {
|
||||
|
||||
/**
|
||||
* The root version of this graph.
|
||||
*/
|
||||
Version root();
|
||||
|
||||
/**
|
||||
* Find a version by its id, or <code>null</code>, if no such version was
|
||||
* found.
|
||||
*/
|
||||
Version get(String id);
|
||||
}
|
||||
@ -37,15 +37,13 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.Parser;
|
||||
import org.jooq.Source;
|
||||
import org.jooq.Version;
|
||||
import org.jooq.VersionProvider;
|
||||
import org.jooq.Versions;
|
||||
|
||||
/**
|
||||
* A default implementation of the {@link VersionProvider} SPI, which provides
|
||||
@ -67,10 +65,9 @@ public class DefaultVersionProvider implements VersionProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Version> provide() {
|
||||
Set<Version> result = new LinkedHashSet<>();
|
||||
public Versions provide() {
|
||||
Version parent;
|
||||
result.add(parent = ctx.version("initial"));
|
||||
VersionsImpl result = new VersionsImpl(parent = ctx.version("initial"));
|
||||
|
||||
Parser parser = ctx.parser();
|
||||
for (int i = 0; i < sources.length; i++)
|
||||
|
||||
@ -54,10 +54,8 @@ import static org.jooq.impl.MigrationImpl.Status.SUCCESS;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jooq.Configuration;
|
||||
@ -77,6 +75,7 @@ import org.jooq.Table;
|
||||
import org.jooq.TableField;
|
||||
import org.jooq.UniqueKey;
|
||||
import org.jooq.Version;
|
||||
import org.jooq.Versions;
|
||||
import org.jooq.conf.InterpreterSearchSchema;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
import org.jooq.exception.DataMigrationException;
|
||||
@ -96,7 +95,7 @@ final class MigrationImpl extends AbstractScope implements Migration {
|
||||
private final Version to;
|
||||
private Version from;
|
||||
private Queries queries;
|
||||
private Map<String, Version> versions;
|
||||
private Versions versions;
|
||||
|
||||
MigrationImpl(Configuration configuration, Version to) {
|
||||
super(configuration.derive(new ThreadLocalTransactionProvider(configuration.systemConnectionProvider())));
|
||||
@ -127,13 +126,9 @@ final class MigrationImpl extends AbstractScope implements Migration {
|
||||
return queries;
|
||||
}
|
||||
|
||||
private final Map<String, Version> versions() {
|
||||
if (versions == null) {
|
||||
versions = new HashMap<>();
|
||||
|
||||
for (Version version : configuration().versionProvider().provide())
|
||||
versions.put(version.id(), version);
|
||||
}
|
||||
private final Versions versions() {
|
||||
if (versions == null)
|
||||
versions = configuration().versionProvider().provide();
|
||||
|
||||
return versions;
|
||||
}
|
||||
@ -159,7 +154,7 @@ final class MigrationImpl extends AbstractScope implements Migration {
|
||||
}
|
||||
|
||||
private final void validateVersionProvider(Version version) {
|
||||
if (!versions().containsKey(version.id()))
|
||||
if (versions().get(version.id()) == null)
|
||||
throw new DataMigrationValidationException("Version is not available from VersionProvider: " + version.id());
|
||||
}
|
||||
|
||||
|
||||
84
jOOQ/src/main/java/org/jooq/impl/VersionsImpl.java
Normal file
84
jOOQ/src/main/java/org/jooq/impl/VersionsImpl.java
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jooq.Version;
|
||||
import org.jooq.Versions;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
final class VersionsImpl implements Versions {
|
||||
|
||||
final Version root;
|
||||
final Map<String, Version> versions;
|
||||
|
||||
VersionsImpl(Version root) {
|
||||
this.root = root;
|
||||
this.versions = new HashMap<>();
|
||||
|
||||
add(root);
|
||||
}
|
||||
|
||||
void add(Version version) {
|
||||
versions.put(version.id(), version);
|
||||
}
|
||||
|
||||
void addAll(Collection<? extends Version> v) {
|
||||
for (Version version : v)
|
||||
add(version);
|
||||
}
|
||||
|
||||
void remove(Version version) {
|
||||
versions.remove(version.id());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Version root() {
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Version get(String id) {
|
||||
return versions.get(id);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user