TSK-1472: Replaced the DB check with productName by productId (#1353)
* TSK-1472: Moved initialization of the schema from the taskanaEngineConfiguration to taskanaEngineImpl. * TSK-1472: Changed the check of current DB type from productName to productId to enable places where we don't want to open a connection to the DB not to do so. * TSK-1472: Improvements after review
This commit is contained in:
parent
9af19203a1
commit
0dc26f5fe1
|
@ -21,6 +21,8 @@ import org.apache.ibatis.jdbc.ScriptRunner;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import pro.taskana.common.internal.configuration.DB;
|
||||
|
||||
/** This class generates sample data for manual testing purposes. */
|
||||
public class SampleDataGenerator {
|
||||
|
||||
|
@ -90,9 +92,10 @@ public class SampleDataGenerator {
|
|||
|
||||
private List<String> parseScripts(Stream<String> scripts) {
|
||||
try (Connection connection = dataSource.getConnection()) {
|
||||
String dbProductName = connection.getMetaData().getDatabaseProductName();
|
||||
String dbProductId =
|
||||
DB.getDatabaseProductId(connection.getMetaData().getDatabaseProductName());
|
||||
return scripts
|
||||
.map(script -> SqlReplacer.getScriptAsSql(dbProductName, now, script))
|
||||
.map(script -> SqlReplacer.getScriptAsSql(dbProductId, now, script))
|
||||
.collect(Collectors.toList());
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeSqlException("Connection to database failed.", e);
|
||||
|
|
|
@ -23,8 +23,8 @@ final class SqlReplacer {
|
|||
// to prevent initialization
|
||||
private SqlReplacer() {}
|
||||
|
||||
static String getScriptAsSql(String dbProductName, ZonedDateTime now, String scriptPath) {
|
||||
return parseAndReplace(getScriptBufferedStream(scriptPath), now, dbProductName);
|
||||
static String getScriptAsSql(String dbProductId, ZonedDateTime now, String scriptPath) {
|
||||
return parseAndReplace(getScriptBufferedStream(scriptPath), now, dbProductId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,10 +65,9 @@ final class SqlReplacer {
|
|||
}
|
||||
|
||||
private static String parseAndReplace(
|
||||
BufferedReader bufferedReader, ZonedDateTime now, String dbProductname) {
|
||||
boolean isDb2 = DB.isDb2(dbProductname);
|
||||
BufferedReader bufferedReader, ZonedDateTime now, String dbProductId) {
|
||||
String sql = bufferedReader.lines().collect(Collectors.joining(System.lineSeparator()));
|
||||
if (isDb2) {
|
||||
if (DB.isDb2(dbProductId)) {
|
||||
sql = replaceBooleanWithInteger(sql);
|
||||
}
|
||||
return replaceDatePlaceholder(now, sql);
|
||||
|
|
|
@ -1,43 +1,58 @@
|
|||
package pro.taskana.common.internal.configuration;
|
||||
|
||||
import pro.taskana.common.api.exceptions.SystemException;
|
||||
import pro.taskana.common.api.exceptions.UnsupportedDatabaseException;
|
||||
|
||||
/** Supported versions of databases. */
|
||||
public enum DB {
|
||||
H2("H2", "h2"),
|
||||
DB2("DB2", "db2"),
|
||||
POSTGRESS("PostgreSQL", "postgres");
|
||||
POSTGRES("PostgreSQL", "postgres");
|
||||
|
||||
public final String dbProductname;
|
||||
public final String dbProductName;
|
||||
public final String dbProductId;
|
||||
|
||||
DB(String dbProductname, String dbProductId) {
|
||||
this.dbProductname = dbProductname;
|
||||
DB(String dbProductName, String dbProductId) {
|
||||
this.dbProductName = dbProductName;
|
||||
this.dbProductId = dbProductId;
|
||||
}
|
||||
|
||||
public static boolean isDb2(String dbProductName) {
|
||||
return dbProductName != null && dbProductName.contains(DB2.dbProductname);
|
||||
public static boolean isH2(String dbProductId) {
|
||||
return H2.dbProductId.equals(dbProductId);
|
||||
}
|
||||
|
||||
public static boolean isH2(String dbProductName) {
|
||||
return dbProductName != null && dbProductName.contains(H2.dbProductname);
|
||||
public static boolean isDb2(String dbProductId) {
|
||||
return DB2.dbProductId.equals(dbProductId);
|
||||
}
|
||||
|
||||
public static boolean isPostgreSql(String dbProductName) {
|
||||
return POSTGRESS.dbProductname.equals(dbProductName);
|
||||
public static boolean isPostgres(String dbProductId) {
|
||||
return POSTGRES.dbProductId.equals(dbProductId);
|
||||
}
|
||||
|
||||
public static DB getDbForId(String databaseId) {
|
||||
if (isH2(databaseId)) {
|
||||
return H2;
|
||||
} else if (isDb2(databaseId)) {
|
||||
return DB2;
|
||||
} else if (isPostgres(databaseId)) {
|
||||
return POSTGRES;
|
||||
}
|
||||
throw new SystemException("Unknown database id: " + databaseId);
|
||||
}
|
||||
|
||||
public static String getDatabaseProductId(String dbProductName) {
|
||||
|
||||
if (isDb2(dbProductName)) {
|
||||
return DB2.dbProductId;
|
||||
} else if (isH2(dbProductName)) {
|
||||
if (dbProductName.contains(H2.dbProductName)) {
|
||||
return H2.dbProductId;
|
||||
} else if (isPostgreSql(dbProductName)) {
|
||||
return POSTGRESS.dbProductId;
|
||||
} else if (dbProductName.contains(DB2.dbProductName)) {
|
||||
return DB2.dbProductId;
|
||||
} else if (POSTGRES.dbProductName.equals(dbProductName)) {
|
||||
return POSTGRES.dbProductId;
|
||||
} else {
|
||||
throw new UnsupportedDatabaseException(dbProductName);
|
||||
}
|
||||
}
|
||||
|
||||
public String getProductId() {
|
||||
return this.dbProductId;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,10 +61,11 @@ public class DbSchemaCreator {
|
|||
connection.getMetaData().getDatabaseProductName(),
|
||||
connection.getMetaData().getURL());
|
||||
ScriptRunner runner = getScriptRunnerInstance(connection);
|
||||
String dbProductId =
|
||||
DB.getDatabaseProductId(connection.getMetaData().getDatabaseProductName());
|
||||
|
||||
if (!isSchemaPreexisting(connection)) {
|
||||
String scriptPath =
|
||||
selectDbScriptFileName(connection.getMetaData().getDatabaseProductName());
|
||||
if (!isSchemaPreexisting(connection, dbProductId)) {
|
||||
String scriptPath = selectDbScriptFileName(dbProductId);
|
||||
InputStream resourceAsStream = DbSchemaCreator.class.getResourceAsStream(scriptPath);
|
||||
BufferedReader reader =
|
||||
new BufferedReader(new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8));
|
||||
|
@ -120,18 +121,28 @@ public class DbSchemaCreator {
|
|||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
private static String selectDbScriptFileName(String dbProductName) {
|
||||
return DB.isPostgreSql(dbProductName)
|
||||
? DB_SCHEMA_POSTGRES
|
||||
: DB.isH2(dbProductName) ? DB_SCHEMA_H2 : DB_SCHEMA_DB2;
|
||||
private static String selectDbScriptFileName(String dbProductId) {
|
||||
|
||||
switch (DB.getDbForId(dbProductId)) {
|
||||
case DB2:
|
||||
return DB_SCHEMA_DB2;
|
||||
case POSTGRES:
|
||||
return DB_SCHEMA_POSTGRES;
|
||||
default:
|
||||
return DB_SCHEMA_H2;
|
||||
}
|
||||
}
|
||||
|
||||
private static String selectDbSchemaDetectionScript(String dbProductName) {
|
||||
private static String selectDbSchemaDetectionScript(String dbProductId) {
|
||||
|
||||
if (DB.isPostgreSql(dbProductName)) {
|
||||
switch (DB.getDbForId(dbProductId)) {
|
||||
case DB2:
|
||||
return DB_SCHEMA_DETECTION_DB2;
|
||||
case POSTGRES:
|
||||
return DB_SCHEMA_DETECTION_POSTGRES;
|
||||
default:
|
||||
return DB_SCHEMA_DETECTION_H2;
|
||||
}
|
||||
return DB.isH2(dbProductName) ? DB_SCHEMA_DETECTION_H2 : DB_SCHEMA_DETECTION_DB2;
|
||||
}
|
||||
|
||||
private ScriptRunner getScriptRunnerInstance(Connection connection) {
|
||||
|
@ -142,18 +153,17 @@ public class DbSchemaCreator {
|
|||
return runner;
|
||||
}
|
||||
|
||||
private boolean isSchemaPreexisting(Connection connection) {
|
||||
private boolean isSchemaPreexisting(Connection connection, String dbProductId) {
|
||||
ScriptRunner runner = getScriptRunnerInstance(connection);
|
||||
StringWriter errorWriter = new StringWriter();
|
||||
runner.setErrorLogWriter(new PrintWriter(errorWriter));
|
||||
try {
|
||||
String scriptPath =
|
||||
selectDbSchemaDetectionScript(connection.getMetaData().getDatabaseProductName());
|
||||
InputStream resourceAsStream = DbSchemaCreator.class.getResourceAsStream(scriptPath);
|
||||
BufferedReader reader =
|
||||
new BufferedReader(new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8));
|
||||
|
||||
String scriptPath = selectDbSchemaDetectionScript(dbProductId);
|
||||
try (InputStream resource = DbSchemaCreator.class.getResourceAsStream(scriptPath);
|
||||
InputStreamReader inputReader = new InputStreamReader(resource, StandardCharsets.UTF_8);
|
||||
BufferedReader reader = new BufferedReader(inputReader)) {
|
||||
runner.runScript(getSqlSchemaNameParsed(reader));
|
||||
} catch (RuntimeSqlException | SQLException e) {
|
||||
} catch (RuntimeSqlException | IOException e) {
|
||||
LOGGER.debug("Schema does not exist.");
|
||||
if (!errorWriter.toString().trim().isEmpty()) {
|
||||
LOGGER.debug(errorWriter.toString());
|
||||
|
|
|
@ -8,6 +8,7 @@ import static org.mockito.Mockito.verify;
|
|||
import static org.mockito.Mockito.when;
|
||||
|
||||
import acceptance.AbstractAccTest;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
|
@ -54,7 +55,7 @@ class SimpleHistoryServiceImplTest {
|
|||
@Mock private SqlSession sqlSessionMock;
|
||||
|
||||
@Test
|
||||
void testInitializeSimpleHistoryService() {
|
||||
void testInitializeSimpleHistoryService() throws SQLException {
|
||||
when(sqlSessionManagerMock.getMapper(TaskHistoryEventMapper.class))
|
||||
.thenReturn(taskHistoryEventMapperMock);
|
||||
when(sqlSessionManagerMock.getMapper(WorkbasketHistoryEventMapper.class))
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package pro.taskana.simplehistory.rest;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
|
@ -90,7 +91,8 @@ public class TaskHistoryEventController extends AbstractPagingController {
|
|||
public TaskHistoryEventController(
|
||||
TaskanaEngineConfiguration taskanaEngineConfiguration,
|
||||
SimpleHistoryServiceImpl simpleHistoryServiceImpl,
|
||||
TaskHistoryEventRepresentationModelAssembler taskHistoryEventRepresentationModelAssembler) {
|
||||
TaskHistoryEventRepresentationModelAssembler taskHistoryEventRepresentationModelAssembler)
|
||||
throws SQLException {
|
||||
|
||||
this.simpleHistoryService = simpleHistoryServiceImpl;
|
||||
this.simpleHistoryService.initialize(taskanaEngineConfiguration.buildTaskanaEngine());
|
||||
|
|
|
@ -60,7 +60,7 @@ public class TaskanaProducers {
|
|||
|
||||
@ApplicationScoped
|
||||
@Produces
|
||||
public TaskanaEngine generateTaskEngine() {
|
||||
public TaskanaEngine generateTaskEngine() throws SQLException {
|
||||
return taskanaEngineConfiguration.buildTaskanaEngine();
|
||||
}
|
||||
|
||||
|
|
|
@ -39,8 +39,6 @@ import pro.taskana.common.api.exceptions.SystemException;
|
|||
import pro.taskana.common.api.exceptions.WrongCustomHolidayFormatException;
|
||||
import pro.taskana.common.internal.TaskanaEngineImpl;
|
||||
import pro.taskana.common.internal.configuration.DB;
|
||||
import pro.taskana.common.internal.configuration.DbSchemaCreator;
|
||||
import pro.taskana.common.internal.configuration.SecurityVerifier;
|
||||
import pro.taskana.common.internal.util.CheckedFunction;
|
||||
import pro.taskana.common.internal.util.Pair;
|
||||
|
||||
|
@ -53,8 +51,6 @@ public class TaskanaEngineConfiguration {
|
|||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TaskanaEngineConfiguration.class);
|
||||
|
||||
// must match the VERSION value in table
|
||||
private static final String TASKANA_SCHEMA_VERSION = "4.0.0";
|
||||
private static final String TASKANA_PROPERTIES = "/taskana.properties";
|
||||
private static final String TASKANA_PROPERTY_SEPARATOR = "|";
|
||||
private static final String TASKANA_JOB_BATCH_SIZE = "taskana.jobs.batchSize";
|
||||
|
@ -84,7 +80,6 @@ public class TaskanaEngineConfiguration {
|
|||
protected String propertiesFileName = TASKANA_PROPERTIES;
|
||||
// Taskana datasource configuration
|
||||
protected DataSource dataSource;
|
||||
protected DbSchemaCreator dbSchemaCreator;
|
||||
protected String schemaName;
|
||||
// Taskana role configuration
|
||||
protected String propertiesSeparator = TASKANA_PROPERTY_SEPARATOR;
|
||||
|
@ -92,7 +87,6 @@ public class TaskanaEngineConfiguration {
|
|||
// global switch to enable JAAS based authentication and Taskana
|
||||
// authorizations
|
||||
protected boolean securityEnabled;
|
||||
protected SecurityVerifier securityVerifier;
|
||||
protected boolean useManagedTransactions;
|
||||
// List of configured domain names
|
||||
protected List<String> domains = new ArrayList<>();
|
||||
|
@ -113,8 +107,7 @@ public class TaskanaEngineConfiguration {
|
|||
private boolean taskCleanupJobAllCompletedSameParentBusiness = true;
|
||||
|
||||
public TaskanaEngineConfiguration(
|
||||
DataSource dataSource, boolean useManagedTransactions, String schemaName)
|
||||
throws SQLException {
|
||||
DataSource dataSource, boolean useManagedTransactions, String schemaName) {
|
||||
this(dataSource, useManagedTransactions, true, schemaName);
|
||||
}
|
||||
|
||||
|
@ -122,8 +115,7 @@ public class TaskanaEngineConfiguration {
|
|||
DataSource dataSource,
|
||||
boolean useManagedTransactions,
|
||||
boolean securityEnabled,
|
||||
String schemaName)
|
||||
throws SQLException {
|
||||
String schemaName) {
|
||||
this(dataSource, useManagedTransactions, securityEnabled, null, null, schemaName);
|
||||
}
|
||||
|
||||
|
@ -133,8 +125,7 @@ public class TaskanaEngineConfiguration {
|
|||
boolean securityEnabled,
|
||||
String propertiesFileName,
|
||||
String propertySeparator,
|
||||
String schemaName)
|
||||
throws SQLException {
|
||||
String schemaName) {
|
||||
this.useManagedTransactions = useManagedTransactions;
|
||||
this.securityEnabled = securityEnabled;
|
||||
|
||||
|
@ -155,18 +146,6 @@ public class TaskanaEngineConfiguration {
|
|||
|
||||
initSchemaName(schemaName);
|
||||
initTaskanaProperties(this.propertiesFileName, this.propertiesSeparator);
|
||||
|
||||
dbSchemaCreator = new DbSchemaCreator(this.dataSource, this.getSchemaName());
|
||||
dbSchemaCreator.run();
|
||||
|
||||
if (!dbSchemaCreator.isValidSchemaVersion(TASKANA_SCHEMA_VERSION)) {
|
||||
throw new SystemException(
|
||||
"The Database Schema Version doesn't match the expected minimal version "
|
||||
+ TASKANA_SCHEMA_VERSION);
|
||||
}
|
||||
|
||||
securityVerifier = new SecurityVerifier(this.dataSource, this.getSchemaName());
|
||||
securityVerifier.checkSecureAccess(securityEnabled);
|
||||
}
|
||||
|
||||
public void initTaskanaProperties(String propertiesFile, String separator) {
|
||||
|
@ -210,8 +189,9 @@ public class TaskanaEngineConfiguration {
|
|||
* This method creates the TaskanaEngine without an sqlSessionFactory.
|
||||
*
|
||||
* @return the TaskanaEngine
|
||||
* @throws SQLException if a database access error occurs
|
||||
*/
|
||||
public TaskanaEngine buildTaskanaEngine() {
|
||||
public TaskanaEngine buildTaskanaEngine() throws SQLException {
|
||||
return TaskanaEngineImpl.createTaskanaEngine(this);
|
||||
}
|
||||
|
||||
|
@ -491,8 +471,9 @@ public class TaskanaEngineConfiguration {
|
|||
}
|
||||
|
||||
try (Connection connection = dataSource.getConnection()) {
|
||||
String databaseProductName = connection.getMetaData().getDatabaseProductName();
|
||||
if (DB.isPostgreSql(databaseProductName)) {
|
||||
String databaseProductId =
|
||||
DB.getDatabaseProductId(connection.getMetaData().getDatabaseProductName());
|
||||
if (DB.isPostgres(databaseProductId)) {
|
||||
this.schemaName = this.schemaName.toLowerCase();
|
||||
} else {
|
||||
this.schemaName = this.schemaName.toUpperCase();
|
||||
|
|
|
@ -44,6 +44,8 @@ import pro.taskana.common.api.exceptions.TaskanaRuntimeException;
|
|||
import pro.taskana.common.api.security.CurrentUserContext;
|
||||
import pro.taskana.common.api.security.GroupPrincipal;
|
||||
import pro.taskana.common.internal.configuration.DB;
|
||||
import pro.taskana.common.internal.configuration.DbSchemaCreator;
|
||||
import pro.taskana.common.internal.configuration.SecurityVerifier;
|
||||
import pro.taskana.common.internal.persistence.InstantTypeHandler;
|
||||
import pro.taskana.common.internal.persistence.MapTypeHandler;
|
||||
import pro.taskana.common.internal.security.CurrentUserContextImpl;
|
||||
|
@ -70,7 +72,8 @@ import pro.taskana.workbasket.internal.WorkbasketServiceImpl;
|
|||
/** This is the implementation of TaskanaEngine. */
|
||||
public class TaskanaEngineImpl implements TaskanaEngine {
|
||||
|
||||
private static final String DEFAULT = "default";
|
||||
// must match the VERSION value in table
|
||||
private static final String TASKANA_SCHEMA_VERSION = "4.0.0";
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TaskanaEngineImpl.class);
|
||||
private static final SessionStack SESSION_STACK = new SessionStack();
|
||||
private final TaskRoutingManager taskRoutingManager;
|
||||
|
@ -85,10 +88,13 @@ public class TaskanaEngineImpl implements TaskanaEngine {
|
|||
protected ConnectionManagementMode mode = ConnectionManagementMode.PARTICIPATE;
|
||||
protected Connection connection = null;
|
||||
|
||||
protected TaskanaEngineImpl(TaskanaEngineConfiguration taskanaEngineConfiguration) {
|
||||
protected TaskanaEngineImpl(TaskanaEngineConfiguration taskanaEngineConfiguration)
|
||||
throws SQLException {
|
||||
this.taskanaEngineConfiguration = taskanaEngineConfiguration;
|
||||
createTransactionFactory(taskanaEngineConfiguration.getUseManagedTransactions());
|
||||
this.sessionManager = createSqlSessionManager();
|
||||
initializeDbSchema(taskanaEngineConfiguration);
|
||||
|
||||
historyEventManager = HistoryEventManager.getInstance(this);
|
||||
taskRoutingManager = TaskRoutingManager.getInstance(this);
|
||||
createTaskPreprocessorManager = CreateTaskPreprocessorManager.getInstance();
|
||||
|
@ -103,7 +109,7 @@ public class TaskanaEngineImpl implements TaskanaEngine {
|
|||
}
|
||||
|
||||
public static TaskanaEngine createTaskanaEngine(
|
||||
TaskanaEngineConfiguration taskanaEngineConfiguration) {
|
||||
TaskanaEngineConfiguration taskanaEngineConfiguration) throws SQLException {
|
||||
return new TaskanaEngineImpl(taskanaEngineConfiguration);
|
||||
}
|
||||
|
||||
|
@ -253,13 +259,12 @@ public class TaskanaEngineImpl implements TaskanaEngine {
|
|||
protected SqlSessionManager createSqlSessionManager() {
|
||||
Environment environment =
|
||||
new Environment(
|
||||
DEFAULT, this.transactionFactory, taskanaEngineConfiguration.getDatasource());
|
||||
"default", this.transactionFactory, taskanaEngineConfiguration.getDatasource());
|
||||
Configuration configuration = new Configuration(environment);
|
||||
|
||||
// set databaseId
|
||||
String databaseProductName;
|
||||
try (Connection con = taskanaEngineConfiguration.getDatasource().getConnection()) {
|
||||
databaseProductName = con.getMetaData().getDatabaseProductName();
|
||||
String databaseProductName = con.getMetaData().getDatabaseProductName();
|
||||
String databaseProductId = DB.getDatabaseProductId(databaseProductName);
|
||||
configuration.setDatabaseId(databaseProductId);
|
||||
|
||||
|
@ -292,6 +297,23 @@ public class TaskanaEngineImpl implements TaskanaEngine {
|
|||
return SqlSessionManager.newInstance(localSessionFactory);
|
||||
}
|
||||
|
||||
private void initializeDbSchema(TaskanaEngineConfiguration taskanaEngineConfiguration)
|
||||
throws SQLException {
|
||||
DbSchemaCreator dbSchemaCreator =
|
||||
new DbSchemaCreator(
|
||||
taskanaEngineConfiguration.getDatasource(), taskanaEngineConfiguration.getSchemaName());
|
||||
dbSchemaCreator.run();
|
||||
|
||||
if (!dbSchemaCreator.isValidSchemaVersion(TASKANA_SCHEMA_VERSION)) {
|
||||
throw new SystemException(
|
||||
"The Database Schema Version doesn't match the expected minimal version "
|
||||
+ TASKANA_SCHEMA_VERSION);
|
||||
}
|
||||
new SecurityVerifier(
|
||||
taskanaEngineConfiguration.getDatasource(), taskanaEngineConfiguration.getSchemaName())
|
||||
.checkSecureAccess(taskanaEngineConfiguration.isSecurityEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* creates the MyBatis transaction factory.
|
||||
*
|
||||
|
|
|
@ -710,7 +710,7 @@ public class TaskQueryImpl implements TaskQuery {
|
|||
|
||||
@Override
|
||||
public TaskQuery orderByClassificationKey(SortDirection sortDirection) {
|
||||
return DB.DB2.dbProductId.equals(getDatabaseId())
|
||||
return DB.isDb2(getDatabaseId())
|
||||
? addOrderCriteria("TCLASSIFICATION_KEY", sortDirection)
|
||||
: addOrderCriteria("t.CLASSIFICATION_KEY", sortDirection);
|
||||
}
|
||||
|
@ -719,7 +719,7 @@ public class TaskQueryImpl implements TaskQuery {
|
|||
public TaskQuery orderByClassificationName(SortDirection sortDirection) {
|
||||
joinWithClassifications = true;
|
||||
addClassificationNameToSelectClauseForOrdering = true;
|
||||
return DB.DB2.dbProductId.equals(getDatabaseId())
|
||||
return DB.isDb2(getDatabaseId())
|
||||
? addOrderCriteria("CNAME", sortDirection)
|
||||
: addOrderCriteria("c.NAME", sortDirection);
|
||||
}
|
||||
|
@ -866,7 +866,7 @@ public class TaskQueryImpl implements TaskQuery {
|
|||
public TaskQuery orderByAttachmentClassificationKey(SortDirection sortDirection) {
|
||||
joinWithAttachments = true;
|
||||
addAttachmentColumnsToSelectClauseForOrdering = true;
|
||||
return DB.DB2.dbProductId.equals(getDatabaseId())
|
||||
return DB.isDb2(getDatabaseId())
|
||||
? addOrderCriteria("ACLASSIFICATION_KEY", sortDirection)
|
||||
: addOrderCriteria("a.CLASSIFICATION_KEY", sortDirection);
|
||||
}
|
||||
|
@ -875,7 +875,7 @@ public class TaskQueryImpl implements TaskQuery {
|
|||
public TaskQuery orderByAttachmentClassificationName(SortDirection sortDirection) {
|
||||
joinWithAttachments = true;
|
||||
addAttachmentClassificationNameToSelectClauseForOrdering = true;
|
||||
return DB.DB2.dbProductId.equals(getDatabaseId())
|
||||
return DB.isDb2(getDatabaseId())
|
||||
? addOrderCriteria("ACNAME", sortDirection)
|
||||
: addOrderCriteria("ac.NAME", sortDirection);
|
||||
}
|
||||
|
@ -884,7 +884,7 @@ public class TaskQueryImpl implements TaskQuery {
|
|||
public TaskQuery orderByAttachmentClassificationId(SortDirection sortDirection) {
|
||||
joinWithAttachments = true;
|
||||
addAttachmentColumnsToSelectClauseForOrdering = true;
|
||||
return DB.DB2.dbProductId.equals(getDatabaseId())
|
||||
return DB.isDb2(getDatabaseId())
|
||||
? addOrderCriteria("ACLASSIFICATION_ID", sortDirection)
|
||||
: addOrderCriteria("a.CLASSIFICATION_ID", sortDirection);
|
||||
}
|
||||
|
@ -1059,7 +1059,7 @@ public class TaskQueryImpl implements TaskQuery {
|
|||
// optimized query for db2 can't be used for now in case of selectAndClaim because of temporary
|
||||
// tables and the "for update" clause clashing in db2
|
||||
public String getLinkToMapperScript() {
|
||||
if (DB.DB2.dbProductId.equals(getDatabaseId()) && !selectAndClaim) {
|
||||
if (DB.isDb2(getDatabaseId()) && !selectAndClaim) {
|
||||
return LINK_TO_MAPPER_DB2;
|
||||
} else {
|
||||
return LINK_TO_MAPPER;
|
||||
|
@ -1067,7 +1067,7 @@ public class TaskQueryImpl implements TaskQuery {
|
|||
}
|
||||
|
||||
public String getLinkToCounterTaskScript() {
|
||||
return DB.DB2.dbProductId.equals(getDatabaseId()) ? LINK_TO_COUNTER_DB2 : LINK_TO_COUNTER;
|
||||
return DB.isDb2(getDatabaseId()) ? LINK_TO_COUNTER_DB2 : LINK_TO_COUNTER;
|
||||
}
|
||||
|
||||
public boolean isUseDistinctKeyword() {
|
||||
|
|
|
@ -6,9 +6,9 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import javax.sql.DataSource;
|
||||
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -25,10 +25,10 @@ class TaskanaSecurityConfigAccTest {
|
|||
DataSource dataSource = TaskanaEngineTestConfiguration.getDataSource();
|
||||
String schemaName = TaskanaEngineTestConfiguration.getSchemaName();
|
||||
|
||||
SampleDataGenerator sampleDataGenerator = new SampleDataGenerator(dataSource, schemaName);
|
||||
sampleDataGenerator.dropDb();
|
||||
DbSchemaCreator dbSchemaCreator = new DbSchemaCreator(dataSource, schemaName);
|
||||
dbSchemaCreator.run();
|
||||
SampleDataGenerator sampleDataGenerator = new SampleDataGenerator(dataSource, schemaName);
|
||||
sampleDataGenerator.clearDb();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -37,17 +37,7 @@ class TaskanaSecurityConfigAccTest {
|
|||
|
||||
setSecurityFlag(true);
|
||||
|
||||
ThrowingCallable createUnsecuredTaskanaEngineConfiguration =
|
||||
() -> {
|
||||
TaskanaEngineConfiguration taskanaEngineConfiguration =
|
||||
new TaskanaEngineConfiguration(
|
||||
TaskanaEngineTestConfiguration.getDataSource(),
|
||||
false,
|
||||
false,
|
||||
TaskanaEngineTestConfiguration.getSchemaName());
|
||||
};
|
||||
|
||||
assertThatThrownBy(createUnsecuredTaskanaEngineConfiguration)
|
||||
assertThatThrownBy(() -> createTaskanaEngine(false))
|
||||
.isInstanceOf(SystemException.class)
|
||||
.hasMessageContaining("Secured TASKANA mode is enforced, can't start in unsecured mode");
|
||||
}
|
||||
|
@ -58,17 +48,8 @@ class TaskanaSecurityConfigAccTest {
|
|||
|
||||
setSecurityFlag(false);
|
||||
|
||||
ThrowingCallable createUnsecuredTaskanaEngineConfiguration =
|
||||
() -> {
|
||||
TaskanaEngineConfiguration taskanaEngineConfiguration =
|
||||
new TaskanaEngineConfiguration(
|
||||
TaskanaEngineTestConfiguration.getDataSource(),
|
||||
false,
|
||||
false,
|
||||
TaskanaEngineTestConfiguration.getSchemaName());
|
||||
};
|
||||
|
||||
assertThatCode(createUnsecuredTaskanaEngineConfiguration).doesNotThrowAnyException();
|
||||
assertThatCode(() -> createTaskanaEngine(false)).doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -77,17 +58,7 @@ class TaskanaSecurityConfigAccTest {
|
|||
|
||||
assertThat(retrieveSecurityFlag()).isNull();
|
||||
|
||||
ThrowingCallable createUnsecuredTaskanaEngineConfiguration =
|
||||
() -> {
|
||||
TaskanaEngineConfiguration taskanaEngineConfiguration =
|
||||
new TaskanaEngineConfiguration(
|
||||
TaskanaEngineTestConfiguration.getDataSource(),
|
||||
false,
|
||||
false,
|
||||
TaskanaEngineTestConfiguration.getSchemaName());
|
||||
};
|
||||
|
||||
assertThatCode(createUnsecuredTaskanaEngineConfiguration).doesNotThrowAnyException();
|
||||
assertThatCode(() -> createTaskanaEngine(false)).doesNotThrowAnyException();
|
||||
|
||||
assertThat(retrieveSecurityFlag()).isFalse();
|
||||
}
|
||||
|
@ -98,19 +69,18 @@ class TaskanaSecurityConfigAccTest {
|
|||
|
||||
assertThat(retrieveSecurityFlag()).isNull();
|
||||
|
||||
ThrowingCallable createSecuredTaskanaEngineConfiguration =
|
||||
() -> {
|
||||
TaskanaEngineConfiguration taskanaEngineConfiguration =
|
||||
assertThatCode(() -> createTaskanaEngine(true)).doesNotThrowAnyException();
|
||||
|
||||
assertThat(retrieveSecurityFlag()).isTrue();
|
||||
}
|
||||
|
||||
private void createTaskanaEngine(boolean securityEnabled) throws SQLException {
|
||||
new TaskanaEngineConfiguration(
|
||||
TaskanaEngineTestConfiguration.getDataSource(),
|
||||
false,
|
||||
true,
|
||||
TaskanaEngineTestConfiguration.getSchemaName());
|
||||
};
|
||||
|
||||
assertThatCode(createSecuredTaskanaEngineConfiguration).doesNotThrowAnyException();
|
||||
|
||||
assertThat(retrieveSecurityFlag()).isTrue();
|
||||
securityEnabled,
|
||||
TaskanaEngineTestConfiguration.getSchemaName())
|
||||
.buildTaskanaEngine();
|
||||
}
|
||||
|
||||
private Boolean retrieveSecurityFlag() throws Exception {
|
||||
|
|
|
@ -32,7 +32,7 @@ class ClassificationServiceImplIntAutoCommitTest {
|
|||
private ClassificationService classificationService;
|
||||
|
||||
@BeforeAll
|
||||
static void beforeAll() throws Exception {
|
||||
static void beforeAll() {
|
||||
DataSource dataSource = TaskanaEngineTestConfiguration.getDataSource();
|
||||
String schemaName = TaskanaEngineTestConfiguration.getSchemaName();
|
||||
sampleDataGenerator = new SampleDataGenerator(dataSource, schemaName);
|
||||
|
@ -41,7 +41,7 @@ class ClassificationServiceImplIntAutoCommitTest {
|
|||
}
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
void setup() throws Exception {
|
||||
TaskanaEngine taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||
classificationService = taskanaEngine.getClassificationService();
|
||||
TaskanaEngineImpl taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||
|
|
|
@ -17,7 +17,7 @@ public final class TaskanaEngineTestConfiguration {
|
|||
private static final Logger LOGGER =
|
||||
LoggerFactory.getLogger(TaskanaEngineTestConfiguration.class);
|
||||
private static final int POOL_TIME_TO_WAIT = 50;
|
||||
private static DataSource dataSource;
|
||||
private static final DataSource DATA_SOURCE;
|
||||
private static String schemaName = null;
|
||||
|
||||
static {
|
||||
|
@ -25,9 +25,9 @@ public final class TaskanaEngineTestConfiguration {
|
|||
String propertiesFileName = userHomeDirectroy + "/taskanaUnitTest.properties";
|
||||
File f = new File(propertiesFileName);
|
||||
if (f.exists() && !f.isDirectory()) {
|
||||
dataSource = createDataSourceFromProperties(propertiesFileName);
|
||||
DATA_SOURCE = createDataSourceFromProperties(propertiesFileName);
|
||||
} else {
|
||||
dataSource = createDefaultDataSource();
|
||||
DATA_SOURCE = createDefaultDataSource();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ public final class TaskanaEngineTestConfiguration {
|
|||
* @return dataSource for unit test
|
||||
*/
|
||||
public static DataSource getDataSource() {
|
||||
return dataSource;
|
||||
return DATA_SOURCE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -54,7 +54,7 @@ class TaskServiceImplIntAutocommitTest {
|
|||
private WorkbasketService workbasketService;
|
||||
|
||||
@BeforeAll
|
||||
static void beforeAll() throws Exception {
|
||||
static void beforeAll() {
|
||||
DataSource dataSource = TaskanaEngineTestConfiguration.getDataSource();
|
||||
String schemaName = TaskanaEngineTestConfiguration.getSchemaName();
|
||||
sampleDataGenerator = new SampleDataGenerator(dataSource, schemaName);
|
||||
|
@ -63,7 +63,7 @@ class TaskServiceImplIntAutocommitTest {
|
|||
}
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
void setup() throws Exception {
|
||||
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||
taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||
taskanaEngineImpl.setConnectionManagementMode(ConnectionManagementMode.AUTOCOMMIT);
|
||||
|
|
|
@ -47,13 +47,13 @@ public class TaskanaConfig {
|
|||
}
|
||||
|
||||
@Bean
|
||||
public SpringTaskanaEngineConfiguration taskanaEngineConfiguration(DataSource dataSource)
|
||||
throws SQLException {
|
||||
public SpringTaskanaEngineConfiguration taskanaEngineConfiguration(DataSource dataSource) {
|
||||
return new SpringTaskanaEngineConfiguration(dataSource, true, false, schemaName);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskanaEngine taskanaEngine(SpringTaskanaEngineConfiguration taskanaEngineConfiguration) {
|
||||
public TaskanaEngine taskanaEngine(SpringTaskanaEngineConfiguration taskanaEngineConfiguration)
|
||||
throws SQLException {
|
||||
return taskanaEngineConfiguration.buildTaskanaEngine();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,7 @@ public class SpringTaskanaEngineConfiguration extends TaskanaEngineConfiguration
|
|||
DataSource dataSource,
|
||||
boolean useManagedTransactions,
|
||||
boolean securityEnabled,
|
||||
String schemaName)
|
||||
throws SQLException {
|
||||
String schemaName) {
|
||||
super(dataSource, useManagedTransactions, securityEnabled, schemaName);
|
||||
}
|
||||
|
||||
|
@ -24,8 +23,7 @@ public class SpringTaskanaEngineConfiguration extends TaskanaEngineConfiguration
|
|||
boolean securityEnabled,
|
||||
String propertiesFileName,
|
||||
String propertiesSeparator,
|
||||
String schemaName)
|
||||
throws SQLException {
|
||||
String schemaName) {
|
||||
super(
|
||||
dataSource,
|
||||
useManagedTransactions,
|
||||
|
@ -41,7 +39,7 @@ public class SpringTaskanaEngineConfiguration extends TaskanaEngineConfiguration
|
|||
* @return the TaskanaEngine
|
||||
*/
|
||||
@Override
|
||||
public TaskanaEngine buildTaskanaEngine() {
|
||||
public TaskanaEngine buildTaskanaEngine() throws SQLException {
|
||||
this.useManagedTransactions = true;
|
||||
return new SpringTaskanaEngineImpl(this);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package pro.taskana.common.internal;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import javax.annotation.PostConstruct;
|
||||
import org.mybatis.spring.transaction.SpringManagedTransactionFactory;
|
||||
|
||||
|
@ -8,7 +9,8 @@ import pro.taskana.SpringTaskanaEngineConfiguration;
|
|||
/** This class configures the TaskanaEngine for spring. */
|
||||
public class SpringTaskanaEngineImpl extends TaskanaEngineImpl {
|
||||
|
||||
public SpringTaskanaEngineImpl(SpringTaskanaEngineConfiguration taskanaEngineConfiguration) {
|
||||
public SpringTaskanaEngineImpl(SpringTaskanaEngineConfiguration taskanaEngineConfiguration)
|
||||
throws SQLException {
|
||||
super(taskanaEngineConfiguration);
|
||||
}
|
||||
|
||||
|
|
|
@ -53,14 +53,14 @@ public class RestConfiguration {
|
|||
}
|
||||
|
||||
@Bean
|
||||
public TaskanaEngine getTaskanaEngine(TaskanaEngineConfiguration taskanaEngineConfiguration) {
|
||||
public TaskanaEngine getTaskanaEngine(TaskanaEngineConfiguration taskanaEngineConfiguration)
|
||||
throws SQLException {
|
||||
return taskanaEngineConfiguration.buildTaskanaEngine();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(TaskanaEngineConfiguration.class)
|
||||
public TaskanaEngineConfiguration taskanaEngineConfiguration(DataSource dataSource)
|
||||
throws SQLException {
|
||||
public TaskanaEngineConfiguration taskanaEngineConfiguration(DataSource dataSource) {
|
||||
return new SpringTaskanaEngineConfiguration(dataSource, true, true, schemaName);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,10 +29,10 @@ class TestSchemaNameCustomizable {
|
|||
void resetDb() throws SQLException {
|
||||
SampleDataGenerator sampleDataGenerator;
|
||||
try (Connection connection = dataSource.getConnection()) {
|
||||
String databaseProductName = connection.getMetaData().getDatabaseProductName();
|
||||
isPostgres = DB.POSTGRESS.dbProductname.equals(databaseProductName);
|
||||
String databaseProductId =
|
||||
DB.getDatabaseProductId(connection.getMetaData().getDatabaseProductName());
|
||||
|
||||
if (isPostgres) {
|
||||
if (DB.isPostgres(databaseProductId)) {
|
||||
schemaName = schemaName.toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue