New delete methods, start auto increment from one for databases

This commit is contained in:
ceze88 2023-07-25 19:54:05 +02:00
parent 54ef2c0b29
commit fdf79eeee3

View File

@ -233,10 +233,10 @@ public class DataManager {
//recreate upper method using java 8 syntax
try {
Optional<Integer> max = context.select(DSL.max(DSL.field("id"))).from(prefixedTable).fetchOptional().map(record -> record.get(0, Integer.class));
this.autoIncrementCache.put(prefixedTable, new AtomicInteger(max.orElse(1)));
this.autoIncrementCache.put(prefixedTable, new AtomicInteger(max.orElse(0)));
} catch (Exception e) {
//Table is empty
this.autoIncrementCache.put(prefixedTable, new AtomicInteger(1));
this.autoIncrementCache.put(prefixedTable, new AtomicInteger(0));
}
});
}
@ -338,6 +338,20 @@ public class DataManager {
});
}
public void delete(Data data, String idField, Object idValue) {
asyncPool.execute(() -> {
deleteSync(data, idField, idValue);
});
}
public void deleteSync(Data data, String idField, Object idValue) {
databaseConnector.connectDSL(context -> {
context.delete(DSL.table(getTablePrefix() + data.getTableName()))
.where(DSL.field(idField).eq(idValue))
.execute();
});
}
/**
* Deletes the data from the database
*/