mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-23 10:35:18 +01:00
New delete methods, start auto increment from one for databases
This commit is contained in:
parent
54ef2c0b29
commit
fdf79eeee3
@ -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
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user