From a0447318e6e907cc7ce88a1ce1824bf3abb7886b Mon Sep 17 00:00:00 2001 From: Franta Pribyl Date: Tue, 20 Jan 2015 10:12:30 +0100 Subject: [PATCH] =?UTF-8?q?Embeded=20m=C4=9Brn=C3=A9=20jednotky=20(new=20M?= =?UTF-8?q?UnitEmb)=20maj=C3=AD=20nyn=C3=AD=20ID=20inicializovan=C3=A9=20n?= =?UTF-8?q?a=200.=20P=C5=99evod=20DB=20nastav=C3=AD=20NULL=20hodnoty=20ID?= =?UTF-8?q?=20na=200,=20tak=C5=BEe=20na=C4=8Dten=C3=AD=20p=C5=99es=20hiber?= =?UTF-8?q?nate=20vytvo=C5=99=C3=AD=20neNULLov=C3=BD=20objekt=20MUnitEmb.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #185 --- .../java/info/bukova/isspst/Constants.java | 2 +- .../info/bukova/isspst/data/MUnitEmb.java | 3 +++ .../services/dbinfo/DbInfoServiceImpl.java | 23 ++++++++++++++++--- .../orders/requirements/RequirementForm.java | 9 +++++++- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/main/java/info/bukova/isspst/Constants.java b/src/main/java/info/bukova/isspst/Constants.java index 024e15f1..316a9b26 100644 --- a/src/main/java/info/bukova/isspst/Constants.java +++ b/src/main/java/info/bukova/isspst/Constants.java @@ -30,7 +30,7 @@ import java.util.Map; public class Constants { - public final static long DB_VERSION = 1; + public final static long DB_VERSION = 2; public final static String DEF_ADMIN = "admin"; public final static String DEF_ADMIN_PASSWD = "admin"; diff --git a/src/main/java/info/bukova/isspst/data/MUnitEmb.java b/src/main/java/info/bukova/isspst/data/MUnitEmb.java index 710ba805..934d54eb 100644 --- a/src/main/java/info/bukova/isspst/data/MUnitEmb.java +++ b/src/main/java/info/bukova/isspst/data/MUnitEmb.java @@ -20,6 +20,9 @@ public class MUnitEmb public MUnitEmb() { + // Embeddable object is loaded by hibernate like NULL, if all properties + // are NULL. So, we set ID. + this.id = 0; } public MUnitEmb(MUnit munit) diff --git a/src/main/java/info/bukova/isspst/services/dbinfo/DbInfoServiceImpl.java b/src/main/java/info/bukova/isspst/services/dbinfo/DbInfoServiceImpl.java index a859a28e..4203419a 100644 --- a/src/main/java/info/bukova/isspst/services/dbinfo/DbInfoServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/dbinfo/DbInfoServiceImpl.java @@ -64,9 +64,13 @@ public class DbInfoServiceImpl extends AbstractService implements DbInfo if (Constants.DB_VERSION > dbVersion) { + SQLQuery sq = null; + String sql = ""; + if (dbVersion < 1) { List tables = new ArrayList(); + tables.add(new Str2Str("address", "DESCRIPTION")); tables.add(new Str2Str("building", "DESCRIPTION")); tables.add(new Str2Str("material", "DESCRIPTION")); @@ -90,9 +94,6 @@ public class DbInfoServiceImpl extends AbstractService implements DbInfo tables.add(new Str2Str("triprequirement", "VEHICLE_DESCRIPTION")); tables.add(new Str2Str("trip_bill_items", "BACK_VEHICLE_DESCRIPTION")); tables.add(new Str2Str("trip_bill_items", "VEHICLE_DESCRIPTION")); - - SQLQuery sq = null; - String sql = ""; for (Str2Str item : tables) { @@ -102,6 +103,22 @@ public class DbInfoServiceImpl extends AbstractService implements DbInfo } } + if (dbVersion < 2) + { + List tables = new ArrayList(); + + tables.add("material"); + tables.add("order_item"); + tables.add("requirement_items"); + + for (String item : tables) + { + sql = "UPDATE " + item + " SET MUNIT_ID = 0 WHERE (MUNIT_ID Is NULL) "; + sq = this.dao.getSession().createSQLQuery(sql); + sq.executeUpdate(); + } + } + this.updateDatabaseVersion(); } } diff --git a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java index cfb6409e..c3e96ec9 100644 --- a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java +++ b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java @@ -183,7 +183,14 @@ public class RequirementForm extends FormViewModel if (isMaterial) { Material materialItem = (Material) selected; - item.setMunit(materialItem.getMunit()); + MUnitEmb unit = materialItem.getMunit(); + + // if (unit == null) + // { + // unit = new MUnitEmb(); + // } + + item.setMunit(unit); } this.setSelectedItem(item);