80
80
import org .jooq .Record2 ;
81
81
import org .jooq .Result ;
82
82
import org .jooq .SelectJoinStep ;
83
+ import org .jooq .Table ;
83
84
import org .jooq .impl .DSL ;
84
85
import org .slf4j .Logger ;
85
86
import org .slf4j .LoggerFactory ;
@@ -90,8 +91,9 @@ public class ConfigRepository {
90
91
private static final Logger LOGGER = LoggerFactory .getLogger (ConfigRepository .class );
91
92
private static final String OPERATION_IDS_AGG_FIELD = "operation_ids_agg" ;
92
93
private static final String OPERATION_IDS_AGG_DELIMITER = "," ;
94
+ public static final String PRIMARY_KEY = "id" ;
93
95
94
- // private final ConfigPersistence persistence;
96
+ // private final ConfigPersistence persistence;
95
97
private final ExceptionWrappingDatabase database ;
96
98
private final ActorDefinitionMigrator actorDefinitionMigrator ;
97
99
@@ -337,13 +339,22 @@ public void writeCustomSourceDefinition(final StandardSourceDefinition sourceDef
337
339
}
338
340
339
341
public void deleteStandardSourceDefinition (final UUID sourceDefId ) throws IOException {
340
- try {
341
- persistence .deleteConfig (ConfigSchema .STANDARD_SOURCE_DEFINITION , sourceDefId .toString ());
342
- } catch (final ConfigNotFoundException e ) {
342
+ if (!deleteById (ACTOR_DEFINITION , sourceDefId )) {
343
343
LOGGER .info ("Attempted to delete source definition with id: {}, but it does not exist" , sourceDefId );
344
344
}
345
345
}
346
346
347
+ /**
348
+ * Deletes all records with given id. If it deletes anything, returns true. Otherwise, false.
349
+ * @param table - table from which to delete the record
350
+ * @param id - id of the record to delete
351
+ * @return true if anything was deleted, otherwise false.
352
+ * @throws IOException - you never know when you io
353
+ */
354
+ private boolean deleteById (final Table <?> table , final UUID id ) throws IOException {
355
+ return database .transaction (ctx -> ctx .deleteFrom (table )).where (DSL .field (DSL .name (PRIMARY_KEY )).eq (id )).execute () > 0 ;
356
+ }
357
+
347
358
public void deleteSourceDefinitionAndAssociations (final UUID sourceDefinitionId )
348
359
throws JsonValidationException , ConfigNotFoundException , IOException {
349
360
deleteConnectorDefinitionAndAssociations (
@@ -476,8 +487,7 @@ public void deleteDestinationDefinitionAndAssociations(final UUID destinationDef
476
487
destinationDefinitionId );
477
488
}
478
489
479
- private <T > void deleteConnectorDefinitionAndAssociations (
480
- final ConfigSchema definitionType ,
490
+ private <T > void deleteConnectorDefinitionAndAssociations (final ConfigSchema definitionType ,
481
491
final ConfigSchema connectorType ,
482
492
final Class <T > connectorClass ,
483
493
final Function <T , UUID > connectorIdGetter ,
0 commit comments