How to use handleTableEntry method of org.evomaster.client.java.controller.internal.db.SchemaExtractor class

Best EvoMaster code snippet using org.evomaster.client.java.controller.internal.db.SchemaExtractor.handleTableEntry

Source:SchemaExtractor.java Github

copy

Full Screen

...135 schemaDto.name = schemaDto.name.toLowerCase();136 tables = md.getTables(null, schemaDto.name, null, new String[]{"TABLE"});137 if (tables.next()) {138 do {139 handleTableEntry(schemaDto, md, tables, tableNames);140 } while (tables.next());141 }142 } else {143 do {144 handleTableEntry(schemaDto, md, tables, tableNames);145 } while (tables.next());146 }147 tables.close();148 /*149 Mark those columns that are using auto generated values150 */151 addForeignKeyToAutoIncrement(schemaDto);152 /*153 JDBC MetaData is quite limited.154 To check constraints, we need to do SQL queries on the system tables.155 Unfortunately, this is database-dependent156 */157 addConstraints(connection, dt, schemaDto);158 assert validate(schemaDto);159 return schemaDto;160 }161 /**162 * Adds a unique constraint to the corresponding ColumnDTO for the selected table.column pair.163 * Requires the ColumnDTO to be contained in the TableDTO.164 * If the column DTO is not contained, a IllegalArgumentException is thrown.165 *166 * @param tableDto the DTO of the table167 * @param columnName the name of the column to add the unique constraint on168 **/169 public static void addUniqueConstraintToColumn(TableDto tableDto, String columnName) {170 ColumnDto columnDto = tableDto.columns.stream()171 .filter(c -> c.name.equals(columnName)).findAny().orElse(null);172 if (columnDto == null) {173 throw new IllegalArgumentException("Missing column DTO for column:" + tableDto.name + "." + columnName);174 }175 columnDto.unique = true;176 }177 /**178 * Appends constraints that are database specific.179 */180 private static void addConstraints(Connection connection, DatabaseType dt, DbSchemaDto schemaDto) throws SQLException {181 TableConstraintExtractor constraintExtractor = TableConstraintExtractorFactory.buildConstraintExtractor(dt);182 if (constraintExtractor != null) {183 final List<DbTableConstraint> dbTableConstraints = constraintExtractor.extract(connection, schemaDto);184 addConstraints(schemaDto, dbTableConstraints);185 } else {186 SimpleLogger.uniqueWarn("WARNING: EvoMaster cannot extract constraints from database " + dt);187 }188 }189 private static void addConstraints(DbSchemaDto schemaDto, List<DbTableConstraint> constraintList) {190 for (DbTableConstraint constraint : constraintList) {191 String tableName = constraint.getTableName();192 TableDto tableDto = schemaDto.tables.stream().filter(t -> t.name.equalsIgnoreCase(tableName)).findFirst().orElse(null);193 if (constraint instanceof DbTableCheckExpression) {194 TableCheckExpressionDto constraintDto = new TableCheckExpressionDto();195 final DbTableCheckExpression tableCheckExpression = (DbTableCheckExpression) constraint;196 constraintDto.sqlCheckExpression = tableCheckExpression.getSqlCheckExpression();197 tableDto.tableCheckExpressions.add(constraintDto);198 } else if (constraint instanceof DbTableUniqueConstraint) {199 DbTableUniqueConstraint tableUniqueConstraint = (DbTableUniqueConstraint) constraint;200 for (String columnName : tableUniqueConstraint.getUniqueColumnNames()) {201 addUniqueConstraintToColumn(tableDto, columnName);202 }203 } else {204 throw new RuntimeException("Unknown constraint type " + constraint.getClass().getName());205 }206 }207 }208 private static void handleTableEntry(DbSchemaDto schemaDto, DatabaseMetaData md, ResultSet tables, Set<String> tableNames) throws SQLException {209 TableDto tableDto = new TableDto();210 schemaDto.tables.add(tableDto);211 tableDto.name = tables.getString("TABLE_NAME");212 if (tableNames.contains(tableDto.name)) {213 /*214 * Perhaps we should throw a more specific exception than IllegalArgumentException215 */216 throw new IllegalArgumentException("Cannot handle repeated table " + tableDto.name + " in schema");217 } else {218 tableNames.add(tableDto.name);219 }220 Set<String> pks = new HashSet<>();221 SortedMap<Integer, String> primaryKeySequence = new TreeMap<>();222 ResultSet rsPK = md.getPrimaryKeys(null, null, tableDto.name);...

Full Screen

Full Screen

handleTableEntry

Using AI Code Generation

copy

Full Screen

1 import org.evomaster.client.java.controller.internal.db.SqlScriptRunner;2 import org.evomaster.client.java.controller.internal.db.SqlScriptRunnerImpl;3 import org.evomaster.client.java.controller.internal.db.SqlScriptRunnerImpl;4 import org.evomaster.client.java.controller.internal.db.h2.H2SchemaExtractor;5 import org.evomaster.client.java.controller.internal.db.h2.H2Table;6 import org.evomaster.client.java.controller.internal.db.h2.H2TableColumn;7 import org.evomaster.client.java.controller.internal.db.schema.Table;8 import org.evomaster.client.java.controller.internal.db.schema.TableColumn;9 import org.evomaster.client.java.controller.internal.db.schema.TableIndex;10 import org.evomaster.client.java.controller.internal.db.schema.TableIndexColumn;11 import org.evomaster.client.java.controller.internal.db.h2.H2SchemaExtractor;12 import org.evomaster.client.java.controller.internal.db.h2.H2Table;13 import org.evomaster.client.java.controller.internal.db.h2.H2TableColumn;14 import org.evomaster.client.java.controller.internal.db.h2.H2TableIndex;15 import org.evomaster.client.java.controller.internal.db.h2.H2TableIndexColumn;16 import org.evomaster.client.java.controller.internal.db.h2.H2TableUniqueIndex;17 import org.evomaster.client.java.controller.internal.db.h2.H2TableUniqueIndexColumn;18 import org.evomaster.client.java.controller.internal.db.h2.H2TableForeignKey;19 import org.evomaster.client.java.controller.internal.db.h2.H2TableForeignKeyColumn;20 import org.evomaster.client.java.controller.internal.db.h2.H2Trigger;21 import org.evomaster.client.java.controller.internal.db.h2.H2TriggerColumn;22 import org.evomaster.client.java.controller.internal.db.schema.Table;23 import org.evomaster.client.java.controller.internal.db.schema.TableColumn;24 import org.evomaster.client.java.controller.internal.db.schema.TableIndex;25 import org.evomaster.client.java.controller.internal.db.schema.TableIndexColumn;26 import org.evomaster.client.java

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful