mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-10-22 20:30:41 +02: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
|
//recreate upper method using java 8 syntax
|
||||||
try {
|
try {
|
||||||
Optional<Integer> max = context.select(DSL.max(DSL.field("id"))).from(prefixedTable).fetchOptional().map(record -> record.get(0, Integer.class));
|
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) {
|
} catch (Exception e) {
|
||||||
//Table is empty
|
//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
|
* Deletes the data from the database
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user