details: /erp/devel/main/rev/eb86e4c97fe5 changeset: 7570:eb86e4c97fe5 user: Martin Taal <martin.taal <at> openbravo.com> date: Mon Jun 07 20:12:45 2010 +0200 summary: fixes issue 13509: In a OBCriteria you can't use list() after a count() call
details: /erp/devel/main/rev/c65b9bc04055 changeset: 7571:c65b9bc04055 user: Martin Taal <martin.taal <at> openbravo.com> date: Mon Jun 07 20:29:21 2010 +0200 summary: fixes issue 13571: Small changes to log messages and logging in various locations details: /erp/devel/main/rev/d425ef421479 changeset: 7572:d425ef421479 user: Martin Taal <martin.taal <at> openbravo.com> date: Mon Jun 07 20:50:55 2010 +0200 summary: Fixes issue 13572: Maintain and print stacktraces when calls to setAdminMode and restoreAdminMode are unbalanced details: /erp/devel/main/rev/6ee32655824a changeset: 7573:6ee32655824a user: RM packaging bot <staff.rm <at> openbravo.com> date: Tue Jun 08 02:22:14 2010 +0000 summary: CI: promote changesets from pi to main details: /erp/devel/main/rev/6875c9c0ac89 changeset: 7574:6875c9c0ac89 user: RM packaging bot <staff.rm <at> openbravo.com> date: Tue Jun 08 02:22:15 2010 +0000 summary: CI: update AD_MODULE - Core version and label diffstat: src-db/database/sourcedata/AD_MODULE.xml | 4 +- src-test/org/openbravo/test/dal/IssuesTest.java | 17 ++++ src-test/org/openbravo/test/dal/OBContextTest.java | 16 ++++ src/org/openbravo/base/model/ModelProvider.java | 12 +- src/org/openbravo/base/session/OBPropertiesProvider.java | 4 +- src/org/openbravo/dal/core/OBContext.java | 61 +++++++++++++-- src/org/openbravo/dal/service/OBCriteria.java | 4 +- 7 files changed, 100 insertions(+), 18 deletions(-) diffs (265 lines): diff -r b282c7c51f4d -r 6875c9c0ac89 src-db/database/sourcedata/AD_MODULE.xml --- a/src-db/database/sourcedata/AD_MODULE.xml Mon Jun 07 15:33:42 2010 +0200 +++ b/src-db/database/sourcedata/AD_MODULE.xml Tue Jun 08 02:22:15 2010 +0000 @@ -6,7 +6,7 @@ <!--0--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID> <!--0--> <ISACTIVE><![CDATA[Y]]></ISACTIVE> <!--0--> <NAME><![CDATA[core]]></NAME> -<!--0--> <VERSION><![CDATA[2.50.17411]]></VERSION> +<!--0--> <VERSION><![CDATA[2.50.17573]]></VERSION> <!--0--> <DESCRIPTION><![CDATA[Core module is the base one]]></DESCRIPTION> <!--0--> <HELP><![CDATA[Core module is the base one, all developments in core are included as part of the standard Openbravo ERP.]]></HELP> <!--0--> <URL><![CDATA[www.openbravo.com]]></URL> @@ -21,7 +21,7 @@ <!--0--> <HASCHARTOFACCOUNTS><![CDATA[N]]></HASCHARTOFACCOUNTS> <!--0--> <ISTRANSLATIONMODULE><![CDATA[N]]></ISTRANSLATIONMODULE> <!--0--> <HASREFERENCEDATA><![CDATA[Y]]></HASREFERENCEDATA> -<!--0--> <VERSION_LABEL><![CDATA[dev]]></VERSION_LABEL> +<!--0--> <VERSION_LABEL><![CDATA[CI]]></VERSION_LABEL> <!--0--> <ISCOMMERCIAL><![CDATA[N]]></ISCOMMERCIAL> <!--0--></AD_MODULE> diff -r b282c7c51f4d -r 6875c9c0ac89 src-test/org/openbravo/test/dal/IssuesTest.java --- a/src-test/org/openbravo/test/dal/IssuesTest.java Mon Jun 07 15:33:42 2010 +0200 +++ b/src-test/org/openbravo/test/dal/IssuesTest.java Tue Jun 08 02:22:15 2010 +0000 @@ -101,6 +101,9 @@ * https://issues.openbravo.com/view.php?id=13283: [REST] use organization of the object to * retrieved referenced objects * + * https://issues.openbravo.com/view.php?id=13509: In a OBCriteria you can't use list() after a + * count() call + * * @author mtaal * @author iperdomo */ @@ -433,4 +436,18 @@ final Order order = (Order) result.get(0); assertTrue(order.getOrganization().getId().equals("1000000")); } + + /** + * https://issues.openbravo.com/view.php?id=13509: In a OBCriteria you can't use list() after a + * count() call + */ + public void test13509() throws Exception { + setBigBazaarAdminContext(); + final OBCriteria<Organization> orgs = OBDal.getInstance().createCriteria(Organization.class); + final int cnt = orgs.count(); + assertTrue(cnt > 0); + final Organization org = orgs.list().get(0); + assertTrue(null != org); + assertTrue(cnt == orgs.list().size()); + } } \ No newline at end of file diff -r b282c7c51f4d -r 6875c9c0ac89 src-test/org/openbravo/test/dal/OBContextTest.java --- a/src-test/org/openbravo/test/dal/OBContextTest.java Mon Jun 07 15:33:42 2010 +0200 +++ b/src-test/org/openbravo/test/dal/OBContextTest.java Tue Jun 08 02:22:15 2010 +0000 @@ -151,6 +151,22 @@ } } + /** + * See issue: https://issues.openbravo.com/view.php?id=13572 Maintain and print stacktraces when + * calls to setAdminMode and restoreAdminMode are unbalanced + * + * To test this issue set the OBContext.ADMIN_TRACE_SIZE to a higher value than 0 + */ + public void testUnbalancedCallsToAdminMode() { + OBContext.setAdminMode(); + OBContext.setAdminMode(); + OBContext.setAdminMode(); + OBContext.restorePreviousMode(); + OBContext.restorePreviousMode(); + OBContext.restorePreviousMode(); + OBContext.restorePreviousMode(); + } + // the scenario: // thread1 T1 // thread2 T2 diff -r b282c7c51f4d -r 6875c9c0ac89 src/org/openbravo/base/model/ModelProvider.java --- a/src/org/openbravo/base/model/ModelProvider.java Mon Jun 07 15:33:42 2010 +0200 +++ b/src/org/openbravo/base/model/ModelProvider.java Tue Jun 08 02:22:15 2010 +0000 @@ -385,10 +385,9 @@ log.debug("Setting targetEntity and reference Property for " + thisProp); final Column thatColumn = c.getReferenceType(); if (thatColumn == null) { - log - .error("Property " - + thisProp - + " is mapped incorrectly, there is no reference column for it, removing from the mapping"); + log.error("Property " + + thisProp + + " is mapped incorrectly, there is no reference column for it, removing from the mapping"); thisProp.getEntity().getProperties().remove(thisProp); if (thisProp.getEntity().getIdProperties().remove(thisProp)) { Check.fail("Incorrect mapping for property " + thisProp @@ -430,7 +429,10 @@ // } if (t.getPrimaryKeyColumns().size() == 0) { - log.debug("Ignoring table " + t.getName() + " because it has no primary key columns"); + if (!t.isView()) { + // don't log the views, these are ignored anyway + log.warn("Ignoring table " + t.getName() + " because it has no primary key columns"); + } toRemove.add(t); continue; } diff -r b282c7c51f4d -r 6875c9c0ac89 src/org/openbravo/base/session/OBPropertiesProvider.java --- a/src/org/openbravo/base/session/OBPropertiesProvider.java Mon Jun 07 15:33:42 2010 +0200 +++ b/src/org/openbravo/base/session/OBPropertiesProvider.java Tue Jun 08 02:22:15 2010 +0000 @@ -87,7 +87,9 @@ } public void setProperties(InputStream is) { - Check.isNull(obProperties, "Openbravo properties have already been set"); + if (obProperties != null) { + log.warn("Openbravo properties have already been set, setting them again"); + } log.debug("Setting openbravo.properties through input stream"); obProperties = new Properties(); try { diff -r b282c7c51f4d -r 6875c9c0ac89 src/org/openbravo/dal/core/OBContext.java --- a/src/org/openbravo/dal/core/OBContext.java Mon Jun 07 15:33:42 2010 +0200 +++ b/src/org/openbravo/dal/core/OBContext.java Tue Jun 08 02:22:15 2010 +0000 @@ -21,6 +21,9 @@ import java.io.IOException; import java.io.ObjectOutputStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; @@ -79,11 +82,15 @@ private static final String CLIENT = "#AD_Client_ID"; private static final String ORG = "#AD_Org_ID"; + // set this to a higher value to enable admin mode tracing + private static final int ADMIN_TRACE_SIZE = 0; + private static ThreadLocal<OBContext> instance = new ThreadLocal<OBContext>(); private static ThreadLocal<OBContext> adminModeSet = new ThreadLocal<OBContext>(); private static ThreadLocal<Stack<Boolean>> adminModeStack = new ThreadLocal<Stack<Boolean>>(); + private static ThreadLocal<List<String>> adminModeTrace = new ThreadLocal<List<String>>(); public static final String CONTEXT_PARAM = "#OBContext"; @@ -133,6 +140,9 @@ } else if (OBContext.getOBContext() == adminContext) { return; } + if (OBContext.getOBContext() != null) { + addStackTrace("setAdminMode"); + } } private static Stack<Boolean> getAdminModeStack() { @@ -162,18 +172,51 @@ if (stack.size() > 0) { stack.pop(); } else { - log.warn("Unbalanced calls to enableAsAdminContext and resetAsAdminContext", - new IllegalStateException()); + final List<String> adminModeTraceList = adminModeTrace.get(); + final StringBuilder sb = new StringBuilder(); + if (adminModeTrace != null) { + for (String adminModeTraceValue : adminModeTraceList) { + sb.append("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); + sb.append(adminModeTraceValue); + } + } + if (ADMIN_TRACE_SIZE == 0) { + log.warn( + "Unbalanced calls to setAdminMode and restorePreviousMode. " + + "Consider setting the constant OBContext.ADMIN_TRACE_SIZE to a value higher than 0 to debug this situation", + new IllegalStateException()); + } else { + log.warn("Unbalanced calls to setAdminMode and restorePreviousMode" + sb.toString(), + new IllegalStateException()); + } } if (OBContext.getOBContext() == null) { return; } + addStackTrace("restorePreviousMode"); if (stack.isEmpty() && OBContext.getOBContext() == adminContext) { OBContext.setOBContext((OBContext) null); } } + private static void addStackTrace(String prefix) { + final StringWriter sw = new StringWriter(); + final PrintWriter pw = new PrintWriter(sw); + sw.write(prefix + "\n"); + new Exception().printStackTrace(pw); + if (adminModeTrace.get() == null) { + adminModeTrace.set(new ArrayList<String>()); + } + final List<String> list = adminModeTrace.get(); + if (list.size() > 0 && list.size() >= ADMIN_TRACE_SIZE) { + list.remove(0); + } + if (ADMIN_TRACE_SIZE > 0) { + list.add(sw.toString()); + } + } + /** * Clears the admin context stack. */ @@ -187,6 +230,7 @@ log.warn("Unbalanced calls to enableAsAdminContext and resetAsAdminContext"); adminModeSet.set(null); } + adminModeTrace.set(null); } /** @@ -234,10 +278,9 @@ return; } if (context != null && context == adminContext) { - log - .warn("Trying to set the admin context in the session, " - + "this means that the context has not been reset correctly in a finally block." - + " When using the admin context it should always be removed in a finally block by the application"); + log.warn("Trying to set the admin context in the session, " + + "this means that the context has not been reset correctly in a finally block." + + " When using the admin context it should always be removed in a finally block by the application"); return; } session.setAttribute(CONTEXT_PARAM, context); @@ -666,9 +709,9 @@ Check.isNotNull(getRole(), "Role may not be null"); if (orgId != null) { - final Organization o = getOne(Organization.class, "select r from " - + Organization.class.getName() + " r where " + " r." + Organization.PROPERTY_ID + "='" - + orgId + "'"); + final Organization o = getOne(Organization.class, + "select r from " + Organization.class.getName() + " r where " + " r." + + Organization.PROPERTY_ID + "='" + orgId + "'"); setCurrentOrganization(o); } else if (getUser().getDefaultOrganization() != null && getUser().getDefaultOrganization().isActive()) { diff -r b282c7c51f4d -r 6875c9c0ac89 src/org/openbravo/dal/service/OBCriteria.java --- a/src/org/openbravo/dal/service/OBCriteria.java Mon Jun 07 15:33:42 2010 +0200 +++ b/src/org/openbravo/dal/service/OBCriteria.java Tue Jun 08 02:22:15 2010 +0000 @@ -99,7 +99,9 @@ initialize(); setProjection(Projections.rowCount()); log.debug("Counting using criteria " + toString()); - return ((Number) uniqueResult()).intValue(); + final int result = ((Number) uniqueResult()).intValue(); + setProjection(null); + return result; } /** ------------------------------------------------------------------------------ ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo _______________________________________________ Openbravo-commits mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openbravo-commits
