protected void createDatabase() { if (databasePlatform == null) { ResettableBasicDataSource ds = new ResettableBasicDataSource(); ds.setDriverClassName(Driver.class.getName()); ds.setMaxActive(1); ds.setInitialSize(1); ds.setMinIdle(1); ds.setMaxIdle(1); databaseName = UUID.randomUUID().toString(); if (inMemoryCompare) { ds.setUrl("jdbc:h2:mem:" + databaseName); } else { ds.setUrl("jdbc:h2:file:./" + databaseName); } databasePlatform = JdbcDatabasePlatformFactory.createNewPlatformInstance( ds, new SqlTemplateSettings(), true, false); Model inputModel = context.getFlowStep().getComponent().getInputModel(); List<ModelEntity> entities = inputModel.getModelEntities(); for (ModelEntity entity : entities) { Table table = new Table(); table.setName(entity.getName() + "_1"); List<ModelAttribute> attributes = entity.getModelAttributes(); for (ModelAttribute attribute : attributes) { DataType dataType = attribute.getDataType(); Column column = new Column(attribute.getName()); if (dataType.isNumeric()) { column.setTypeCode(Types.DECIMAL); } else if (dataType.isBoolean()) { column.setTypeCode(Types.BOOLEAN); } else if (dataType.isTimestamp()) { column.setTypeCode(Types.TIMESTAMP); } else if (dataType.isBinary()) { column.setTypeCode(Types.BLOB); } else { column.setTypeCode(Types.LONGVARCHAR); } column.setPrimaryKey(attribute.isPk()); table.addColumn(column); } alterCaseToMatchLogicalCase(table); databasePlatform.createTables(false, false, table); table.setName(entity.getName().toUpperCase() + "_2"); databasePlatform.createTables(false, false, table); } log(LogLevel.INFO, "Creating databasePlatform with the following url: %s", ds.getUrl()); } }
@Override protected void start() { error = null; TypedProperties properties = getTypedProperties(); this.sourceStep1Id = properties.get(SOURCE_1); if (isBlank(sourceStep1Id)) { throw new MisconfiguredException("Please choose a step where the original data comes from"); } this.sourceStep2Id = properties.get(SOURCE_2); if (isBlank(sourceStep2Id)) { throw new MisconfiguredException("Please choose a step where the data to compare comes from"); } this.inMemoryCompare = properties.is(IN_MEMORY_COMPARE); this.rowsPerMessage = properties.getInt(ROWS_PER_MESSAGE); Component comp = context.getFlowStep().getComponent(); comp.setOutputModel(comp.getInputModel()); Model inputModel = context.getFlowStep().getComponent().getInputModel(); if (inputModel == null) { throw new MisconfiguredException("The input model is not set and it is required"); } entities = new ArrayList<>(inputModel.getModelEntities()); Collections.sort( entities, new Comparator<ModelEntity>() { @Override public int compare(ModelEntity o1, ModelEntity o2) { ComponentEntitySetting order1 = context .getFlowStep() .getComponent() .getSingleEntitySetting(o1.getId(), DataDiff.ENTITY_ORDER); int orderValue1 = order1 != null ? Integer.parseInt(order1.getValue()) : 0; ComponentEntitySetting order2 = context .getFlowStep() .getComponent() .getSingleEntitySetting(o2.getId(), DataDiff.ENTITY_ORDER); int orderValue2 = order2 != null ? Integer.parseInt(order2.getValue()) : 0; return new Integer(orderValue1).compareTo(new Integer(orderValue2)); } }); }