committed by
Michael Minella
parent
4877a92adb
commit
6d87cc47f0
@@ -101,10 +101,13 @@ public enum DatabaseType {
|
||||
* @return DatabaseType for given product name.
|
||||
* @throws IllegalArgumentException if none is found.
|
||||
*/
|
||||
public static DatabaseType fromProductName(String productName){
|
||||
if(!dbNameMap.containsKey(productName)){
|
||||
throw new IllegalArgumentException("DatabaseType not found for product name: [" +
|
||||
productName + "]");
|
||||
public static DatabaseType fromProductName(String productName) {
|
||||
if (productName.equals("MariaDB")) {
|
||||
productName = "MySQL";
|
||||
}
|
||||
if (!dbNameMap.containsKey(productName)) {
|
||||
throw new IllegalArgumentException(
|
||||
"DatabaseType not found for product name: [" + productName + "]");
|
||||
}
|
||||
else{
|
||||
return dbNameMap.get(productName);
|
||||
|
||||
@@ -101,7 +101,7 @@ public class TaskExecutionDaoFactoryBean implements FactoryBean<TaskExecutionDao
|
||||
this.dao = new JdbcTaskExecutionDao(dataSource, this.tablePrefix);
|
||||
String databaseType;
|
||||
try {
|
||||
databaseType = org.springframework.batch.support.DatabaseType.fromMetaData(dataSource).name();
|
||||
databaseType = DatabaseType.fromMetaData(dataSource).name();
|
||||
}
|
||||
catch (MetaDataAccessException e) {
|
||||
throw new IllegalStateException(e);
|
||||
|
||||
@@ -15,6 +15,12 @@
|
||||
*/
|
||||
package org.springframework.cloud.task.repository.support;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cloud.task.util.TestDBUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.cloud.task.repository.support.DatabaseType.HSQL;
|
||||
import static org.springframework.cloud.task.repository.support.DatabaseType.MYSQL;
|
||||
@@ -22,11 +28,6 @@ import static org.springframework.cloud.task.repository.support.DatabaseType.ORA
|
||||
import static org.springframework.cloud.task.repository.support.DatabaseType.POSTGRES;
|
||||
import static org.springframework.cloud.task.repository.support.DatabaseType.fromProductName;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.task.util.TestDBUtils;
|
||||
|
||||
/**
|
||||
* Tests that the correct database names are selected from datasource metadata.
|
||||
*
|
||||
@@ -43,6 +44,7 @@ public class DatabaseTypeTests {
|
||||
assertEquals(ORACLE, fromProductName("Oracle"));
|
||||
assertEquals(POSTGRES, fromProductName("PostgreSQL"));
|
||||
assertEquals(MYSQL, fromProductName("MySQL"));
|
||||
assertEquals(MYSQL, fromProductName("MariaDB"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -74,4 +76,10 @@ public class DatabaseTypeTests {
|
||||
assertEquals(MYSQL, DatabaseType.fromMetaData(ds));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromMetaDataForMariaDB() throws Exception {
|
||||
DataSource ds = TestDBUtils.getMockDataSource("MariaDB");
|
||||
assertEquals(MYSQL, DatabaseType.fromMetaData(ds));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user