|
From: <han...@us...> - 2010-10-11 13:11:29
|
Revision: 849
http://posper.svn.sourceforge.net/posper/?rev=849&view=rev
Author: hans_artmann
Date: 2010-10-11 13:11:22 +0000 (Mon, 11 Oct 2010)
Log Message:
-----------
- check required database schema in basic.properties against posper.schema entry on posper_property for the
db version check. We assume db backward compatibility and do no db upgrades in posper.
Existing databases can be upgraded using the migrations in POSper Backoffice.
Modified Paths:
--------------
1.00/CHANGELOG
1.00/buildNumber.properties
1.00/src/main/java/org/posper/gui/panels/JFrmTPV.java
1.00/src/main/java/org/posper/hibernate/setup/DatabaseValidator.java
1.00/src/main/java/org/posper/hibernate/setup/DbSetup.java
1.00/src/main/resources/basic.properties
1.00/src/main/resources/net/adrianromero/tpv/i18n/messages.properties
1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_ca.properties
1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_da.properties
1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_de.properties
1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_es.properties
1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_fr.properties
1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_gl.properties
1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_it.properties
1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_nl.properties
1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_pt.properties
1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_ro.properties
Modified: 1.00/CHANGELOG
===================================================================
--- 1.00/CHANGELOG 2010-10-11 10:12:54 UTC (rev 848)
+++ 1.00/CHANGELOG 2010-10-11 13:11:22 UTC (rev 849)
@@ -70,3 +70,6 @@
- add customergroup modifier (not yet evaluated)
- add Modifiers#getCustomerMask and Modifiers#getCustomerGroupMask (not used until customers can be assigned)
- fix category selection bug SF #3037463
+- check required database schema in basic.properties against posper.schema entry on posper_property for the
+ db version check. We assume db backward compatibility and do no db upgrades in posper.
+ Existing databases can be upgraded using the migrations in POSper Backoffice.
Modified: 1.00/buildNumber.properties
===================================================================
--- 1.00/buildNumber.properties 2010-10-11 10:12:54 UTC (rev 848)
+++ 1.00/buildNumber.properties 2010-10-11 13:11:22 UTC (rev 849)
@@ -1,3 +1,3 @@
#maven.buildNumber.plugin properties file
-#Mon Oct 11 10:39:05 CEST 2010
-buildNumber0=48
+#Mon Oct 11 15:03:06 CEST 2010
+buildNumber0=71
Modified: 1.00/src/main/java/org/posper/gui/panels/JFrmTPV.java
===================================================================
--- 1.00/src/main/java/org/posper/gui/panels/JFrmTPV.java 2010-10-11 10:12:54 UTC (rev 848)
+++ 1.00/src/main/java/org/posper/gui/panels/JFrmTPV.java 2010-10-11 13:11:22 UTC (rev 849)
@@ -411,77 +411,92 @@
}
}
- // TODO write build information by host (key: posper.build.<host>)
DatabaseValidator.updateBuild();
+
+ if (DatabaseValidator.compareDatabase() > 0) {
+ // DB version < required scheam version
+ // The database needs to be upgraded
+ JOptionPane.showMessageDialog(this,
+ appLocal.getIntString("message.olddatabase"),
+ appLocal.getIntString("message.title"),
+ JOptionPane.WARNING_MESSAGE);
+ System.exit(0);
+ }
- while (DatabaseValidator.compareDatabase() > 0) {
- // DB version < program version
- DatabaseValidator.doTrivialUpgrade();
+ // No (trivial) upgrades need to be performed because we
+ // check schema version assuming backward comüatiility
+// while (DatabaseValidator.compareDatabase() > 0) {
+//
+// // DB version < program version
+//
+/// DatabaseValidator.doTrivialUpgrade();
+//
+// if (DatabaseValidator.compareDatabase() == 0) {
+// break; // was a trivial upgrade, early exit
+// }
+// if (DatabaseValidator.upgradePossible()) {
+// if (JOptionPane.showConfirmDialog(this,
+// appLocal.getIntString("message.updatedatabase"),
+// appLocal.getIntString("message.title"),
+// JOptionPane.YES_NO_OPTION,
+// JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
+// DatabaseValidator.upgradeDatabase();
+// HibernateUtil.getInstance().reInitialize();
+// } else {
+// return false;
+// }
+// } else {
+// if (JOptionPane.showOptionDialog(this,
+// appLocal.getIntString("message.upgradeunavailable"),
+// appLocal.getIntString("message.title"),
+// JOptionPane.YES_NO_OPTION,
+// JOptionPane.QUESTION_MESSAGE, null, new String[]{
+// appLocal.getIntString("message.yes"),
+// appLocal.getIntString("message.no")
+// }, appLocal.getIntString("message.no")) == JOptionPane.YES_OPTION) {
+// HibernateUtil.getInstance().setHbm2ddlType("upgrade");
+// HibernateUtil.getInstance().reInitialize();
+// DbSetup.setDbVersionCurrent();
+// return false;
+// } else {
+// return false;
+// }
+// }
+// }
+//
+// // TODO handle thos properly
+// // for now we assume that database upgrades are always downward compatible
+// if (DatabaseValidator.compareDatabase() < 0 && JOptionPane.showOptionDialog(
+// this, appLocal.getIntString("message.dbversionnewer"),
+// appLocal.getIntString("message.title"),
+// // DB version > program version
+// JOptionPane.YES_NO_OPTION,
+// JOptionPane.QUESTION_MESSAGE, null, new String[]{
+// appLocal.getIntString("message.yes"),
+// appLocal.getIntString("message.no")
+// }, appLocal.getIntString("message.no")) == JOptionPane.YES_OPTION) {
+// HibernateUtil.getInstance().setHbm2ddlType("upgrade");
+// HibernateUtil.getInstance().reInitialize();
+// }
- if (DatabaseValidator.compareDatabase() == 0) {
- break; // was a trivial upgrade, early exit
- }
- if (DatabaseValidator.upgradePossible()) {
- if (JOptionPane.showConfirmDialog(this,
- appLocal.getIntString("message.updatedatabase"),
- appLocal.getIntString("message.title"),
- JOptionPane.YES_NO_OPTION,
- JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
- DatabaseValidator.upgradeDatabase();
- HibernateUtil.getInstance().reInitialize();
- } else {
- return false;
- }
- } else {
- if (JOptionPane.showOptionDialog(this,
- appLocal.getIntString("message.upgradeunavailable"),
- appLocal.getIntString("message.title"),
- JOptionPane.YES_NO_OPTION,
- JOptionPane.QUESTION_MESSAGE, null, new String[]{
- appLocal.getIntString("message.yes"),
- appLocal.getIntString("message.no")
- }, appLocal.getIntString("message.no")) == JOptionPane.YES_OPTION) {
- HibernateUtil.getInstance().setHbm2ddlType("upgrade");
- HibernateUtil.getInstance().reInitialize();
- DbSetup.setDbVersionCurrent();
- return false;
- } else {
- return false;
- }
- }
- }
-
- if (DatabaseValidator.compareDatabase() < 0 && JOptionPane.showOptionDialog(
- this, appLocal.getIntString("message.dbversionnewer"),
- appLocal.getIntString("message.title"),
- // DB version > program version
- JOptionPane.YES_NO_OPTION,
- JOptionPane.QUESTION_MESSAGE, null, new String[]{
- appLocal.getIntString("message.yes"),
- appLocal.getIntString("message.no")
- }, appLocal.getIntString("message.no")) == JOptionPane.YES_OPTION) {
- HibernateUtil.getInstance().setHbm2ddlType("upgrade");
- HibernateUtil.getInstance().reInitialize();
- }
-
} catch (HibernateException e) {
JMessageDialog.showMessage(this, new MessageInf(
MessageInf.SGN_DANGER, appLocal.getIntString(
"Database.ScriptError"), e));
return false;
- } catch (IOException e) {
- JMessageDialog.showMessage(this, new MessageInf(
- MessageInf.SGN_DANGER, appLocal.getIntString(
- "Database.ScriptError"), e));
+// } catch (IOException e) {
+// JMessageDialog.showMessage(this, new MessageInf(
+// MessageInf.SGN_DANGER, appLocal.getIntString(
+// "Database.ScriptError"), e));
} catch (BasicException e) {
JMessageDialog.showMessage(this, new MessageInf(
MessageInf.SGN_DANGER, appLocal.getIntString(
"Database.ScriptError"), e));
- } catch (SQLException e) {
- JMessageDialog.showMessage(this, new MessageInf(
- MessageInf.SGN_DANGER, appLocal.getIntString(
- "Database.ScriptError"), e));
+// } catch (SQLException e) {
+// JMessageDialog.showMessage(this, new MessageInf(
+// MessageInf.SGN_DANGER, appLocal.getIntString(
+// "Database.ScriptError"), e));
}
//don't try to update the splashscreen if it was already killed
@@ -1281,7 +1296,8 @@
this.getProperty("posper.customer");
String aVersion = "Release: " +
BasicProperties.getProperty("posper.version") + "-" +
- BasicProperties.getProperty("posper.build");
+ BasicProperties.getProperty("posper.build") +
+ " Schema: " + DatabaseValidator.getDbSchema();
// Here we have all examples for 'properties' in posper:
// a) database
Modified: 1.00/src/main/java/org/posper/hibernate/setup/DatabaseValidator.java
===================================================================
--- 1.00/src/main/java/org/posper/hibernate/setup/DatabaseValidator.java 2010-10-11 10:12:54 UTC (rev 848)
+++ 1.00/src/main/java/org/posper/hibernate/setup/DatabaseValidator.java 2010-10-11 13:11:22 UTC (rev 849)
@@ -58,6 +58,7 @@
private static Logger logger = Logger.getLogger("org.posper");
private static final String POSPER_VERSION = "posper.version";
private static final String POSPER_BUILD = "posper.build";
+ private static final String POSPER_SCHEMA = "posper.schema";
private static final String TINAPOSPLUS = "tpp";
private static final String TINAPOS = "tp";
private static Boolean isTPP = false;
@@ -83,15 +84,33 @@
* older
*/
public static int compareDatabase() {
- String version = getDbVersion();
- logger.debug("DB versions compared: "
- + BasicProperties.getProperty(POSPER_VERSION) + "," + version);
-
- //don't bother comparing database versions if there is no database.
- if ((BasicProperties.getProperty(POSPER_VERSION) != null) && (version != null)) {
- return BasicProperties.getProperty(POSPER_VERSION).compareTo(version);
- } else {
+ int dbSchema = getDbSchema();
+ int posperSchema; // min. required schema
+ try {
+ posperSchema = Integer.parseInt(BasicProperties.getProperty(POSPER_SCHEMA));
+ } catch (NumberFormatException numberFormatException) {
+ logger.error("POSper schema entry is not a number");
+ posperSchema = 0;
+ }
+ logger.info("DB versions compared (basic.properties, db: "
+ + posperSchema + "," + dbSchema);
+
+ return posperSchema - dbSchema;
+ }
+
+ public static int getDbSchema() {
+ try {
+ String schema = HibDAOFactory.getPropertyDAO().get(POSPER_SCHEMA).getValue();
+ return Integer.parseInt(schema);
+ } catch (HibernateException hibe) {
+ // db not created, no worries
return 0;
+ } catch (NullPointerException npe) {
+ // db not created, no worries
+ return 0;
+ } catch (NumberFormatException numberFormatException) {
+ logger.error("Database schema entry is not a number");
+ return 0;
}
}
@@ -472,6 +491,18 @@
logger.info("Current build: " + versionProperty.getValue());
}
+ public static void setSchema() {
+ String key = POSPER_SCHEMA ;
+ Property schemaProperty = new Property(key);
+ schemaProperty.setValue(BasicProperties.getProperty(POSPER_SCHEMA));
+ try {
+ schemaProperty.save();
+ } catch (BasicException e) {
+ logger.error("Cannot set schema info", e);
+ }
+ logger.info("Set schema info to: " + schemaProperty.getValue());
+ }
+
/**
* This method will update the version in the database to the highest
* version possible that doesn't require an upgrade script. For instance if
@@ -481,37 +512,34 @@
*/
public static void doTrivialUpgrade() {
- //
+ // This function should currently not be used in this branch
+ // There are no update procedures defined in posper.
- String version = getDbVersion();
try {
boolean noTrivial = false;
-// The following is commented out because for this branch we'll not have SQL
-// scripts to do any upgrade.
-// DB upgrades are supposed to be performed from the backoffice application.
-//
+
// TODO implement upgrade warning depending of the db scheme number
-// String version = getDbVersion();
-// List<URL> allScripts = listResources("org/posper/dbscripts");
-// for (Iterator<URL> iter = allScripts.iterator(); iter.hasNext();) {
-// URL url = iter.next();
-// String[] pieces;
-// if (url.getProtocol().equals("file"))
-//
-// // we have a very unexpected exception here don't know why???
-// pieces = url.getFile().split(File.separator);
-// else
-// pieces = url.getFile().split("/");
-// String lastPart = pieces[pieces.length - 1];
-// String[] sections = lastPart.split("_");
-// if (sections.length != 3)
-// continue;
-// if (sections[1].compareTo(version) > 0)
-// // we don't have trivial upgrade to current
-// noTrivial = true;
-// }
+ String version = getDbVersion();
+ List<URL> allScripts = listResources("org/posper/dbscripts");
+ for (Iterator<URL> iter = allScripts.iterator(); iter.hasNext();) {
+ URL url = iter.next();
+ String[] pieces;
+ if (url.getProtocol().equals("file"))
+ // we have a very unexpected exception here don't know why???
+ pieces = url.getFile().split(File.separator);
+ else
+ pieces = url.getFile().split("/");
+ String lastPart = pieces[pieces.length - 1];
+ String[] sections = lastPart.split("_");
+ if (sections.length != 3)
+ continue;
+ if (sections[1].compareTo(version) > 0)
+ // we don't have trivial upgrade to current
+ noTrivial = true;
+ }
+
if (!noTrivial) // our version is greater than any script so we have
// a trivial upgrade to current
{
@@ -525,6 +553,8 @@
// logger.error("Cannot load database scripts", e);
// } catch (IOException e) {
// logger.error("Cannot load database scripts", e);
+ } catch (IOException ex) {
+ java.util.logging.Logger.getLogger(DatabaseValidator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (BasicException e) {
logger.error("Cannot load database scripts", e);
}
Modified: 1.00/src/main/java/org/posper/hibernate/setup/DbSetup.java
===================================================================
--- 1.00/src/main/java/org/posper/hibernate/setup/DbSetup.java 2010-10-11 10:12:54 UTC (rev 848)
+++ 1.00/src/main/java/org/posper/hibernate/setup/DbSetup.java 2010-10-11 13:11:22 UTC (rev 849)
@@ -523,7 +523,9 @@
}
versionProperty.setValue(BasicProperties.getProperty(POSPER_BUILD));
versionProperty.save();
-
+
+ // set schema info entry
+ DatabaseValidator.setSchema();
}
}
Modified: 1.00/src/main/resources/basic.properties
===================================================================
--- 1.00/src/main/resources/basic.properties 2010-10-11 10:12:54 UTC (rev 848)
+++ 1.00/src/main/resources/basic.properties 2010-10-11 13:11:22 UTC (rev 849)
@@ -1,3 +1,3 @@
-posper.version=${project.version}-${version}
+posper.version=${project.version}
posper.schema=847
posper.build=${buildNumber}
Modified: 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages.properties
===================================================================
--- 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages.properties 2010-10-11 10:12:54 UTC (rev 848)
+++ 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages.properties 2010-10-11 13:11:22 UTC (rev 849)
@@ -677,4 +677,5 @@
paygate.cannot_find_transaction=The transaction could not be found.
paygate.not_matching_amount=The given amount does not match the amount of the original topup.
paygate.balance_not_sufficient=Cancelling the topup would lead to a balance below the customers limit.
-paygate.cannot_save_record=The account record could not be saved.
\ No newline at end of file
+paygate.cannot_save_record=The account record could not be saved.
+message.olddatabase=A database from a previous version has been detected. The database must first be upgraded manually or using POSPer Backoffice.
Modified: 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_ca.properties
===================================================================
--- 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_ca.properties 2010-10-11 10:12:54 UTC (rev 848)
+++ 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_ca.properties 2010-10-11 13:11:22 UTC (rev 849)
@@ -413,3 +413,4 @@
label.ticketid.edit=Receipt
ProductsEditor.label.category=Category Name
ProductsEditor.label.associated=Associated
+message.olddatabase=A database from a previous version has been detected. The database must first be upgraded manually or using POSPer Backoffice.
Modified: 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_da.properties
===================================================================
--- 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_da.properties 2010-10-11 10:12:54 UTC (rev 848)
+++ 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_da.properties 2010-10-11 13:11:22 UTC (rev 849)
@@ -403,3 +403,4 @@
label.ticketid.edit=Receipt
ProductsEditor.label.category=Category Name
ProductsEditor.label.associated=Associated
+message.olddatabase=A database from a previous version has been detected. The database must first be upgraded manually or using POSPer Backoffice.
Modified: 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_de.properties
===================================================================
--- 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_de.properties 2010-10-11 10:12:54 UTC (rev 848)
+++ 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_de.properties 2010-10-11 13:11:22 UTC (rev 849)
@@ -621,3 +621,4 @@
paygate.not_matching_amount=Der Stornobetrag entspricht nicht dem Betrag der urspr\u00fcnglichen Aufladung.
paygate.balance_not_sufficient=Das Storno der Aufladung w\u00fcrde das Kreditlimit unterschreiten und wird nicht ausgef\u00fchrt.
paygate.cannot_save_record=Der Kontodatensatz konnte nicht gespeichert werden.
+message.olddatabase=Die Datenbankversion ist veraltet. F\u00fchren Sie erst einen Update der Datenbank durch, entweder manuell oder mit Hilfe von POSper Backoffice.
Modified: 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_es.properties
===================================================================
--- 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_es.properties 2010-10-11 10:12:54 UTC (rev 848)
+++ 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_es.properties 2010-10-11 13:11:22 UTC (rev 849)
@@ -412,3 +412,4 @@
label.ticketid.edit=Receipt
ProductsEditor.label.category=Category Name
ProductsEditor.label.associated=Associated
+message.olddatabase=A database from a previous version has been detected. The database must first be upgraded manually or using POSPer Backoffice.
Modified: 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_fr.properties
===================================================================
--- 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_fr.properties 2010-10-11 10:12:54 UTC (rev 848)
+++ 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_fr.properties 2010-10-11 13:11:22 UTC (rev 849)
@@ -587,3 +587,4 @@
label.ticketid.edit=Receipt
ProductsEditor.label.category=Category Name
ProductsEditor.label.associated=Associated
+message.olddatabase=A database from a previous version has been detected. The database must first be upgraded manually or using POSPer Backoffice.
Modified: 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_gl.properties
===================================================================
--- 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_gl.properties 2010-10-11 10:12:54 UTC (rev 848)
+++ 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_gl.properties 2010-10-11 13:11:22 UTC (rev 849)
@@ -422,3 +422,4 @@
label.ticketid.edit=Receipt
ProductsEditor.label.category=Category Name
ProductsEditor.label.associated=Associated
+message.olddatabase=A database from a previous version has been detected. The database must first be upgraded manually or using POSPer Backoffice.
Modified: 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_it.properties
===================================================================
--- 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_it.properties 2010-10-11 10:12:54 UTC (rev 848)
+++ 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_it.properties 2010-10-11 13:11:22 UTC (rev 849)
@@ -407,3 +407,4 @@
label.ticketid.edit=Receipt
ProductsEditor.label.category=Category Name
ProductsEditor.label.associated=Associated
+message.olddatabase=A database from a previous version has been detected. The database must first be upgraded manually or using POSPer Backoffice.
Modified: 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_nl.properties
===================================================================
--- 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_nl.properties 2010-10-11 10:12:54 UTC (rev 848)
+++ 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_nl.properties 2010-10-11 13:11:22 UTC (rev 849)
@@ -379,3 +379,4 @@
label.ticketid.edit=Receipt
ProductsEditor.label.category=Category Name
ProductsEditor.label.associated=Associated
+message.olddatabase=A database from a previous version has been detected. The database must first be upgraded manually or using POSPer Backoffice.
Modified: 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_pt.properties
===================================================================
--- 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_pt.properties 2010-10-11 10:12:54 UTC (rev 848)
+++ 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_pt.properties 2010-10-11 13:11:22 UTC (rev 849)
@@ -407,3 +407,4 @@
label.ticketid.edit=Receipt
ProductsEditor.label.category=Category Name
ProductsEditor.label.associated=Associated
+message.olddatabase=A database from a previous version has been detected. The database must first be upgraded manually or using POSPer Backoffice.
Modified: 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_ro.properties
===================================================================
--- 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_ro.properties 2010-10-11 10:12:54 UTC (rev 848)
+++ 1.00/src/main/resources/net/adrianromero/tpv/i18n/messages_ro.properties 2010-10-11 13:11:22 UTC (rev 849)
@@ -397,3 +397,4 @@
label.ticketid.edit=Receipt
ProductsEditor.label.category=Category Name
ProductsEditor.label.associated=Associated
+message.olddatabase=A database from a previous version has been detected. The database must first be upgraded manually or using POSPer Backoffice.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|