Permalink
Browse files

more refactoring

  • Loading branch information...
arcuri82 committed Dec 3, 2018
1 parent 1d7454e commit 7447313f33c4390a1a7028fdd318bb3b6a05bd1f
@@ -4,6 +4,7 @@
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import org.evomaster.client.java.controller.api.dto.database.schema.*;
import org.evomaster.client.java.controller.internal.db.constraint.ConstraintUtils;
import org.evomaster.client.java.controller.internal.db.constraint.H2Constraints;
import java.sql.*;
@@ -133,7 +134,7 @@ We do not do much with it anyway (at least for
To check constraints, we need to do SQL queries on the system tables.
Unfortunately, this is database-dependent
*/
addConstraints(connection, dt, schemaDto);
ConstraintUtils.addConstraints(connection, dt, schemaDto);
return schemaDto;
}
@@ -181,22 +182,6 @@ private static TableDto getTable(DbSchemaDto schema, String tableName) {
return tableDto;
}
/**
* Indicates the first column name that is a foreign key to an autoincrement column
*
* @param schema
* @param tableName
* @return
*/
private static String getColumnNameForeignKeyToAutoIncrementColumn(DbSchemaDto schema, String tableName) {
TableDto tableDto = getTable(schema, tableName);
for (String pkColumnName : tableDto.primaryKeySequence) {
if (isFKToAutoIncrementColumn(schema, tableName, pkColumnName)) {
return pkColumnName;
}
}
return null;
}
/**
* Checks if the given tableName.columnName column is a foreign key to an autoincrement column
@@ -232,33 +217,7 @@ private static boolean isFKToAutoIncrementColumn(DbSchemaDto schema, String tabl
}
/**
* Appends constraints that are database specific.
*
* @param connection
* @param dt
* @param schemaDto
* @throws Exception
*/
private static void addConstraints(Connection connection, DatabaseType dt, DbSchemaDto schemaDto) throws SQLException, JSQLParserException {
switch (dt) {
case H2: {
H2Constraints.addH2Constraints(connection, schemaDto);
break;
}
case DERBY: {
// TODO Derby
break;
}
case OTHER: {
// TODO Other
break;
}
default: {
throw new IllegalArgumentException("Unknown database type " + dt);
}
}
}
@@ -1,8 +1,19 @@
package org.evomaster.client.java.controller.internal.db.constraint;
import net.sf.jsqlparser.JSQLParserException;
import org.evomaster.client.java.controller.api.dto.database.schema.ColumnDto;
import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType;
import org.evomaster.client.java.controller.api.dto.database.schema.DbSchemaDto;
import org.evomaster.client.java.controller.api.dto.database.schema.TableDto;
import java.sql.Connection;
import java.sql.SQLException;
/*
JDBC MetaData is quite limited.
To check constraints, we need to do SQL queries on the system tables.
Unfortunately, this is database-dependent
*/
public class ConstraintUtils {
/**
@@ -21,4 +32,33 @@ public static void addUniqueConstraintToColumn(String tableName, TableDto tableD
columnDto.unique = true;
}
/**
* Appends constraints that are database specific.
*
* @param connection
* @param dt
* @param schemaDto
* @throws Exception
*/
public static void addConstraints(Connection connection, DatabaseType dt, DbSchemaDto schemaDto) throws SQLException, JSQLParserException {
switch (dt) {
case H2: {
H2Constraints.addH2Constraints(connection, schemaDto);
break;
}
case DERBY: {
// TODO Derby
break;
}
case OTHER: {
// TODO Other
break;
}
default: {
throw new IllegalArgumentException("Unknown database type " + dt);
}
}
}
}

0 comments on commit 7447313

Please sign in to comment.