added SqlPlatform class with getters to platform specific implementations
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package jef.model;
|
||||
|
||||
import jef.Database;
|
||||
import jef.DbSet;
|
||||
import jef.model.annotations.Clazz;
|
||||
import jef.model.constraints.ForeignKeyConstraint;
|
||||
import jef.platform.base.Database;
|
||||
import jef.serializable.SerializableObject;
|
||||
import lombok.Getter;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package jef.model;
|
||||
|
||||
import jef.DatabaseOptions;
|
||||
import jef.platform.base.DatabaseOptions;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
14
core/src/main/java/jef/platform/SqlPlatform.java
Normal file
14
core/src/main/java/jef/platform/SqlPlatform.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package jef.platform;
|
||||
|
||||
import jef.platform.base.SqlTypeMapper;
|
||||
import jef.platform.base.DatabaseOptions;
|
||||
import jef.platform.base.migration.MigrationApplier;
|
||||
import jef.platform.base.MigrationOperationTranslator;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
public interface SqlPlatform {
|
||||
MigrationOperationTranslator getTranslator();
|
||||
SqlTypeMapper getTypeMapper();
|
||||
MigrationApplier getMigrationApplier(Connection connection, DatabaseOptions options);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package jef;
|
||||
package jef.platform.base;
|
||||
|
||||
import jef.MigrationException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package jef;
|
||||
package jef.platform.base;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package jef.platform.base;
|
||||
|
||||
import jef.model.migration.operation.MigrationOperation;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public interface MigrationOperationTranslator {
|
||||
PreparedStatement translate(Connection connection, MigrationOperation op) throws SQLException;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package jef.model;
|
||||
package jef.platform.base;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package jef.mysql.migration;
|
||||
package jef.platform.base.migration;
|
||||
|
||||
import jef.DatabaseOptions;
|
||||
import jef.MigrationException;
|
||||
import jef.model.migration.Migration;
|
||||
import jef.model.migration.MigrationBuilder;
|
||||
import jef.model.migration.operation.MigrationOperation;
|
||||
import jef.platform.SqlPlatform;
|
||||
import jef.platform.base.DatabaseOptions;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -21,6 +22,7 @@ import java.util.stream.Collectors;
|
||||
public abstract class MigrationApplier {
|
||||
protected final Connection connection;
|
||||
protected final DatabaseOptions options;
|
||||
protected final SqlPlatform sqlPlatform;
|
||||
|
||||
public void migrate() throws MigrationException {
|
||||
var migrations = findMigrations(options.getMigrationsPackage()); //TODO find all migrations, support multiple db contexts
|
||||
@@ -47,7 +49,7 @@ public abstract class MigrationApplier {
|
||||
connection.setAutoCommit(false);
|
||||
try {
|
||||
for (MigrationOperation op : operations) {
|
||||
var stmt = MysqlMigrationOperationTranslator.translate(connection, op);
|
||||
var stmt = sqlPlatform.getTranslator().translate(connection, op);
|
||||
try {
|
||||
stmt.execute();
|
||||
} catch (SQLException e) {
|
||||
14
core/src/main/java/jef/platform/nul/NullDatabase.java
Normal file
14
core/src/main/java/jef/platform/nul/NullDatabase.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package jef.platform.nul;
|
||||
|
||||
import jef.MigrationException;
|
||||
import jef.platform.base.Database;
|
||||
|
||||
public class NullDatabase extends Database {
|
||||
public NullDatabase() {
|
||||
super(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void migrate() throws MigrationException {
|
||||
}
|
||||
}
|
||||
26
core/src/main/java/jef/platform/nul/NullPlatform.java
Normal file
26
core/src/main/java/jef/platform/nul/NullPlatform.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package jef.platform.nul;
|
||||
|
||||
import jef.platform.SqlPlatform;
|
||||
import jef.platform.base.DatabaseOptions;
|
||||
import jef.platform.base.MigrationOperationTranslator;
|
||||
import jef.platform.base.SqlTypeMapper;
|
||||
import jef.platform.base.migration.MigrationApplier;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
public class NullPlatform implements SqlPlatform {
|
||||
@Override
|
||||
public MigrationOperationTranslator getTranslator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlTypeMapper getTypeMapper() {
|
||||
return new NullTypeMapper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MigrationApplier getMigrationApplier(Connection connection, DatabaseOptions options) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
12
core/src/main/java/jef/platform/nul/NullTypeMapper.java
Normal file
12
core/src/main/java/jef/platform/nul/NullTypeMapper.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package jef.platform.nul;
|
||||
|
||||
import jef.platform.base.SqlTypeMapper;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class NullTypeMapper extends SqlTypeMapper {
|
||||
@Override
|
||||
public Optional<String> map(String typeName) {
|
||||
return Optional.ofNullable(typeName);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user