|
|
|
@ -16,6 +16,7 @@ import static java.text.MessageFormat.format; |
|
|
|
|
|
|
|
|
|
|
|
import de.srsoftware.tools.jdbc.Query; |
|
|
|
import de.srsoftware.tools.jdbc.Query; |
|
|
|
import de.srsoftware.umbrella.core.BaseDb; |
|
|
|
import de.srsoftware.umbrella.core.BaseDb; |
|
|
|
|
|
|
|
import de.srsoftware.umbrella.core.api.Owner; |
|
|
|
import de.srsoftware.umbrella.core.model.*; |
|
|
|
import de.srsoftware.umbrella.core.model.*; |
|
|
|
import de.srsoftware.umbrella.core.model.Location; |
|
|
|
import de.srsoftware.umbrella.core.model.Location; |
|
|
|
import java.sql.Connection; |
|
|
|
import java.sql.Connection; |
|
|
|
@ -272,6 +273,18 @@ public class SqliteDb extends BaseDb implements StockDb { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public long nextItemNumberFor(Owner owner) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
var rs = select("max(owner_number)").from(TABLE_ITEMS).where(OWNER,equal(owner.dbCode())).exec(db); |
|
|
|
|
|
|
|
long number = rs.next() ? rs.getLong(1) : 0; |
|
|
|
|
|
|
|
rs.close(); |
|
|
|
|
|
|
|
return number +1L; |
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
throw databaseException("Failed to read last item number for {0}",owner); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void replaceItemsTable() throws SQLException { |
|
|
|
private void replaceItemsTable() throws SQLException { |
|
|
|
db.prepareStatement(format("DROP TABLE {0}",TABLE_ITEMS)).execute(); |
|
|
|
db.prepareStatement(format("DROP TABLE {0}",TABLE_ITEMS)).execute(); |
|
|
|
db.prepareStatement(format("ALTER TABLE {0} RENAME TO {1}","items_temp",TABLE_ITEMS)).execute(); |
|
|
|
db.prepareStatement(format("ALTER TABLE {0} RENAME TO {1}","items_temp",TABLE_ITEMS)).execute(); |
|
|
|
@ -320,8 +333,17 @@ public class SqliteDb extends BaseDb implements StockDb { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Item save(Item item) { |
|
|
|
public Item save(Item item) { |
|
|
|
if (item.id() == 0){ // TODO
|
|
|
|
if (item.id() == 0){ |
|
|
|
LOG.log(ERROR,"StockDb.save(…) not implemented!"); |
|
|
|
try { |
|
|
|
|
|
|
|
var rs = insertInto(TABLE_ITEMS, OWNER, OWNER_NUMBER, CODE, NAME, LOCATION_ID) |
|
|
|
|
|
|
|
.values(item.owner().dbCode(), item.ownerNumber(), item.code(), item.name(), item.location().id()) |
|
|
|
|
|
|
|
.execute(db).getGeneratedKeys(); |
|
|
|
|
|
|
|
if (rs.next()) item.id(rs.getLong(1)); |
|
|
|
|
|
|
|
rs.close(); |
|
|
|
|
|
|
|
return item; |
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
throw databaseException("Failed to save new item to database!"); |
|
|
|
|
|
|
|
} |
|
|
|
} else if (item.isDirty()) { |
|
|
|
} else if (item.isDirty()) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
var location = item.location(); |
|
|
|
var location = item.location(); |
|
|
|
|