@Override public DeployExecution valueOf(Map<String, Object> result) { long id = platform.getLongValue(result.get(idColName)).longValue(); DeployExecutionStatus status = DeployExecutionStatus.IN_PROGRESS.valueOfStatusCode(((String) result.get(statusColName)).charAt(0)); Timestamp deployTime = platform.getTimestampValue(result.get(deployTimeColName)); String executorId = (String) result.get(executorIdColName); String toolVersion = (String) result.get(toolVersionColName); boolean init = platform.getIntegerValue(result.get(initCommandColName)).intValue() == 1; boolean rollback = platform.getIntegerValue(result.get(rollbackCommandColName)).intValue() == 1; String requesterId = (String) result.get(requesterIdColName); String reason = (String) result.get(reasonColName); String productVersion = (String) result.get(productVersionColName); ImmutableSet<DeployExecutionAttribute> deployExecutionAttributes = attrsById.get(id).toSet().toImmutable(); DeployExecutionImpl deployExecution = new DeployExecutionImpl(requesterId, executorId, schema, toolVersion, deployTime, init, rollback, productVersion, reason, deployExecutionAttributes); deployExecution.setId(id); deployExecution.setStatus(status); return deployExecution; } }).toImmutable();
@Override public DeployExecution valueOf(Map<String, Object> result) { long id = platform.getLongValue(result.get(idColName)).longValue(); DeployExecutionStatus status = DeployExecutionStatus.IN_PROGRESS.valueOfStatusCode(((String) result.get(statusColName)).charAt(0)); Timestamp deployTime = platform.getTimestampValue(result.get(deployTimeColName)); String executorId = (String) result.get(executorIdColName); String toolVersion = (String) result.get(toolVersionColName); boolean init = platform.getIntegerValue(result.get(initCommandColName)).intValue() == 1; boolean rollback = platform.getIntegerValue(result.get(rollbackCommandColName)).intValue() == 1; String requesterId = (String) result.get(requesterIdColName); String reason = (String) result.get(reasonColName); String productVersion = (String) result.get(productVersionColName); ImmutableSet<DeployExecutionAttribute> deployExecutionAttributes = attrsById.get(id).toSet().toImmutable(); DeployExecutionImpl deployExecution = new DeployExecutionImpl(requesterId, executorId, schema, toolVersion, deployTime, init, rollback, productVersion, reason, deployExecutionAttributes); deployExecution.setId(id); deployExecution.setStatus(status); return deployExecution; } }).toImmutable();
@Override public void persistNew(DeployExecution deployExecution, PhysicalSchema physicalSchema) { MongoDatabase database = mongoClient.getDatabase(physicalSchema.getPhysicalName()); MongoCollection<Document> auditCollection = database.getCollection(deployExecutionTableName); MutableInt mutableInt = nextIdBySchema.get(physicalSchema); mutableInt.increment(); ((DeployExecutionImpl) deployExecution).setId(mutableInt.longValue()); Document doc = getDocumentFromDeployExecution(deployExecution, false); auditCollection.insertOne(doc); }
@Override public void persistNew(DeployExecution deployExecution, PhysicalSchema physicalSchema) { MongoDatabase database = mongoClient.getDatabase(physicalSchema.getPhysicalName()); MongoCollection<Document> auditCollection = database.getCollection(deployExecutionTableName); MutableInt mutableInt = nextIdBySchema.get(physicalSchema); mutableInt.increment(); ((DeployExecutionImpl) deployExecution).setId(mutableInt.longValue()); Document doc = getDocumentFromDeployExecution(deployExecution, false); auditCollection.insertOne(doc); }
@Test public void test() { ChangeType changeType = mock(ChangeType.class); when(changeType.getName()).thenReturn("type"); Platform platform = mock(Platform.class); when(platform.getChangeType(Mockito.anyString())).thenReturn(changeType); MongoDbEnvironment env = mock(MongoDbEnvironment.class); when(env.getPhysicalSchema("mydb")).thenReturn(new PhysicalSchema("mydb")); when(env.getPhysicalSchemas()).thenReturn(Sets.immutable.of(new PhysicalSchema("mydb"))); MongoDbChangeAuditDao changeAuditDao = new MongoDbChangeAuditDao(mongoClient, env, platform, "test"); DeployExecutionImpl exec = new DeployExecutionImpl("requester", "executor", "schema", "1.0.0", new Timestamp(new Date().getTime()), false, false, "1.0.0", "reason", Sets.immutable.<DeployExecutionAttribute>empty()); exec.setId(1L); Change change = new ChangeIncremental(changeType, "mydb", "obj1", "c1", 0, "hash", "content"); changeAuditDao.insertNewChange(change, exec); assertEquals(1, changeAuditDao.getDeployedChanges().size()); } }
@Test public void test() { ChangeType changeType = mock(ChangeType.class); when(changeType.getName()).thenReturn("type"); Platform platform = mock(Platform.class); when(platform.getChangeType(Mockito.anyString())).thenReturn(changeType); MongoDbEnvironment env = mock(MongoDbEnvironment.class); when(env.getPhysicalSchema("mydb")).thenReturn(new PhysicalSchema("mydb")); when(env.getPhysicalSchemas()).thenReturn(Sets.immutable.of(new PhysicalSchema("mydb"))); MongoDbChangeAuditDao changeAuditDao = new MongoDbChangeAuditDao(mongoClient, env, platform, "test"); DeployExecutionImpl exec = new DeployExecutionImpl("requester", "executor", "schema", "1.0.0", new Timestamp(new Date().getTime()), false, false, "1.0.0", "reason", Sets.immutable.<DeployExecutionAttribute>empty()); exec.setId(1L); Change change = new ChangeIncremental(changeType, "mydb", "obj1", "c1", 0, "hash", "content"); changeAuditDao.insertNewChange(change, exec); assertEquals(1, changeAuditDao.getDeployedChanges().size()); } }
@Override public DeployExecution valueOf(Document doc) { MutableList<Document> attrsList = ListAdapter.adapt(doc.get("attrs", List.class)); MutableList<DeployExecutionAttribute> attrs = attrsList.collect(new Function<Document, DeployExecutionAttribute>() { @Override public DeployExecutionAttribute valueOf(Document object) { return new DeployExecutionAttributeImpl( object.getString(attrNameColName), object.getString(attrValueColName) ); } }); DeployExecutionImpl exec = new DeployExecutionImpl( doc.getString(requesterIdColName), doc.getString(deployExecutionIdColName), doc.getString(dbSchemaColName), doc.getString(toolVersionColName), new Timestamp(doc.getDate(deployTimeColName).getTime()), doc.getBoolean(initCommandColName), doc.getBoolean(rollbackCommandColName), doc.getString(productVersionColName), doc.getString(reasonColName), attrs.toSet().toImmutable() ); exec.setId(doc.getLong(idColName)); return exec; } }).toImmutable();
@Override public DeployExecution valueOf(Document doc) { MutableList<Document> attrsList = ListAdapter.adapt(doc.get("attrs", List.class)); MutableList<DeployExecutionAttribute> attrs = attrsList.collect(new Function<Document, DeployExecutionAttribute>() { @Override public DeployExecutionAttribute valueOf(Document object) { return new DeployExecutionAttributeImpl( object.getString(attrNameColName), object.getString(attrValueColName) ); } }); DeployExecutionImpl exec = new DeployExecutionImpl( doc.getString(requesterIdColName), doc.getString(deployExecutionIdColName), doc.getString(dbSchemaColName), doc.getString(toolVersionColName), new Timestamp(doc.getDate(deployTimeColName).getTime()), doc.getBoolean(initCommandColName), doc.getBoolean(rollbackCommandColName), doc.getString(productVersionColName), doc.getString(reasonColName), attrs.toSet().toImmutable() ); exec.setId(doc.getLong(idColName)); return exec; } }).toImmutable();
final String attrInsertValueString = Interval.oneTo(allAttrColumns.size()).collect(Functions.getFixedValue("?")).makeString("(", ", ", ")"); ((DeployExecutionImpl) entry).setId(nextIdBySchema.get(physicalSchema).longValue()); jdbc.update(conn, "INSERT INTO " + platform.getSchemaPrefix(physicalSchema) + deployExecutionTableName + " " + insertColumnString + " " +
final String attrInsertValueString = Interval.oneTo(allAttrColumns.size()).collect(Functions.getFixedValue("?")).makeString("(", ", ", ")"); ((DeployExecutionImpl) entry).setId(nextIdBySchema.get(physicalSchema).longValue()); jdbc.update(conn, "INSERT INTO " + platform.getSchemaPrefix(physicalSchema) + deployExecutionTableName + " " + insertColumnString + " " +