@Test void getSqlCreateUpdateTrigger() { EntityType entityType = when(mock(EntityType.class).getId()).thenReturn("entity").getMock(); when(entityType.getId()).thenReturn("entityTypeId"); Attribute attr0 = when(mock(Attribute.class).getName()).thenReturn("attr0").getMock(); when(attr0.getIdentifier()).thenReturn("attr0Id"); Attribute attr1 = when(mock(Attribute.class).getName()).thenReturn("attr1").getMock(); when(attr1.getIdentifier()).thenReturn("attr1Id"); String expectedSql = "CREATE TRIGGER \"update_trigger_entityTypeId#c34894ba\" AFTER UPDATE ON \"entityTypeId#c34894ba\" FOR EACH ROW WHEN (OLD.\"attr0\" IS DISTINCT FROM NEW.\"attr0\" OR OLD.\"attr1\" IS DISTINCT FROM NEW.\"attr1\") EXECUTE PROCEDURE \"validate_update_entityTypeId#c34894ba\"();"; assertEquals( expectedSql, PostgreSqlQueryGenerator.getSqlCreateUpdateTrigger(entityType, asList(attr0, attr1))); }
static String getSqlCreateUpdateTrigger( EntityType entityType, Collection<Attribute> readonlyTableAttrs) { StringBuilder strBuilder = new StringBuilder(512) .append("CREATE TRIGGER ") .append(getUpdateTriggerName(entityType)) .append(" AFTER UPDATE ON ") .append(getTableName(entityType)) .append(" FOR EACH ROW WHEN ("); strBuilder.append( readonlyTableAttrs.stream() .map( attr -> "OLD." + getColumnName(attr) + " IS DISTINCT FROM NEW." + getColumnName(attr)) .collect(joining(" OR "))); strBuilder .append(") EXECUTE PROCEDURE ") .append(getFunctionValidateUpdateName(entityType)) .append("();"); return strBuilder.toString(); }
PostgreSqlQueryGenerator { static String getSqlCreateUpdateTrigger( EntityType entityType, Collection<Attribute> readonlyTableAttrs) { StringBuilder strBuilder = new StringBuilder(512) .append("CREATE TRIGGER ") .append(getUpdateTriggerName(entityType)) .append(" AFTER UPDATE ON ") .append(getTableName(entityType)) .append(" FOR EACH ROW WHEN ("); strBuilder.append( readonlyTableAttrs.stream() .map( attr -> "OLD." + getColumnName(attr) + " IS DISTINCT FROM NEW." + getColumnName(attr)) .collect(joining(" OR "))); strBuilder .append(") EXECUTE PROCEDURE ") .append(getFunctionValidateUpdateName(entityType)) .append("();"); return strBuilder.toString(); } }
PostgreSqlQueryGenerator { static String getSqlCreateUpdateTrigger( EntityType entityType, Collection<Attribute> readonlyTableAttrs) { StringBuilder strBuilder = new StringBuilder(512) .append("CREATE TRIGGER ") .append(getUpdateTriggerName(entityType)) .append(" AFTER UPDATE ON ") .append(getTableName(entityType)) .append(" FOR EACH ROW WHEN ("); strBuilder.append( readonlyTableAttrs.stream() .map( attr -> "OLD." + getColumnName(attr) + " IS DISTINCT FROM NEW." + getColumnName(attr)) .collect(joining(" OR "))); strBuilder .append(") EXECUTE PROCEDURE ") .append(getFunctionValidateUpdateName(entityType)) .append("();"); return strBuilder.toString(); } private  PostgreSqlQueryGenerator(); }
PostgreSqlQueryGenerator { static String getSqlCreateUpdateTrigger( EntityType entityType, Collection<Attribute> readonlyTableAttrs) { StringBuilder strBuilder = new StringBuilder(512) .append("CREATE TRIGGER ") .append(getUpdateTriggerName(entityType)) .append(" AFTER UPDATE ON ") .append(getTableName(entityType)) .append(" FOR EACH ROW WHEN ("); strBuilder.append( readonlyTableAttrs.stream() .map( attr -> "OLD." + getColumnName(attr) + " IS DISTINCT FROM NEW." + getColumnName(attr)) .collect(joining(" OR "))); strBuilder .append(") EXECUTE PROCEDURE ") .append(getFunctionValidateUpdateName(entityType)) .append("();"); return strBuilder.toString(); } private  PostgreSqlQueryGenerator();  }
PostgreSqlQueryGenerator { static String getSqlCreateUpdateTrigger( EntityType entityType, Collection<Attribute> readonlyTableAttrs) { StringBuilder strBuilder = new StringBuilder(512) .append("CREATE TRIGGER ") .append(getUpdateTriggerName(entityType)) .append(" AFTER UPDATE ON ") .append(getTableName(entityType)) .append(" FOR EACH ROW WHEN ("); strBuilder.append( readonlyTableAttrs.stream() .map( attr -> "OLD." + getColumnName(attr) + " IS DISTINCT FROM NEW." + getColumnName(attr)) .collect(joining(" OR "))); strBuilder .append(") EXECUTE PROCEDURE ") .append(getFunctionValidateUpdateName(entityType)) .append("();"); return strBuilder.toString(); } private  PostgreSqlQueryGenerator();   }