|
|
|
|
@ -276,6 +276,26 @@ public class SqliteDb extends BaseDb implements StockDb {
@@ -276,6 +276,26 @@ public class SqliteDb extends BaseDb implements StockDb {
|
|
|
|
|
db.prepareStatement(format("ALTER TABLE {0} RENAME TO {1}","locations_temp",TABLE_LOCATIONS)).execute(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Location save(DbLocation location) { |
|
|
|
|
if (location.id() == 0) { // new location
|
|
|
|
|
try { |
|
|
|
|
var rs = insertInto(TABLE_LOCATIONS,OWNER,PARENT_LOCATION_ID,NAME,DESCRIPTION) |
|
|
|
|
.values(location.owner().dbCode(),location.parent(),location.name(),null) |
|
|
|
|
.execute(db).getGeneratedKeys(); |
|
|
|
|
long id = 0; |
|
|
|
|
if (rs.next()) id = rs.getLong(1); |
|
|
|
|
rs.close(); |
|
|
|
|
if (id == 0) throw databaseException("Failed to save new location ({0})",location.name()); |
|
|
|
|
return location.id(id); |
|
|
|
|
} catch (SQLException e){ |
|
|
|
|
throw databaseException("Failed to save new location ({0})",location.name()); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
throw databaseException("Updating locations not implemented"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Item save(Item item) { |
|
|
|
|
if (item.id() == 0){ // TODO
|
|
|
|
|
|