details: /erp/devel/pi/rev/06986d086563
changeset: 10954:06986d086563
user: Martin Taal <martin.taal <at> openbravo.com>
date: Tue Mar 01 21:52:53 2011 +0100
summary: Solve escape character problem on Oracle
details: /erp/devel/pi/rev/3e4e4993fee9
changeset: 10955:3e4e4993fee9
user: Martin Taal <martin.taal <at> openbravo.com>
date: Tue Mar 01 21:54:21 2011 +0100
summary: Added active filter in hibernate mapping
diffstat:
modules/org.openbravo.service.json/src/org/openbravo/service/json/QueryBuilder.java
| 3 +-
src-test/org/openbravo/test/AllAntTaskTests.java
| 2 +
src-test/org/openbravo/test/AllQuickAntTaskTests.java
| 2 +
src-test/org/openbravo/test/AllTests.java
| 2 +
src-test/org/openbravo/test/dal/DalFilterTest.java
| 73 ++++++++++
src/org/openbravo/dal/core/DalMappingGenerator.java
| 14 +-
src/org/openbravo/dal/core/template_main.hbm.xml
| 30 ++-
src/org/openbravo/dal/service/OBDal.java
| 23 +++
8 files changed, 137 insertions(+), 12 deletions(-)
diffs (271 lines):
diff -r 718e718db21c -r 3e4e4993fee9
modules/org.openbravo.service.json/src/org/openbravo/service/json/QueryBuilder.java
---
a/modules/org.openbravo.service.json/src/org/openbravo/service/json/QueryBuilder.java
Tue Mar 01 18:53:44 2011 +0100
+++
b/modules/org.openbravo.service.json/src/org/openbravo/service/json/QueryBuilder.java
Tue Mar 01 21:54:21 2011 +0100
@@ -50,7 +50,7 @@
private static final String PARAM_DELIMITER = "@";
private static final String ALIAS_PREFIX = "alias_";
- private static final char ESCAPE_CHAR = '!';
+ private static final char ESCAPE_CHAR = '|';
public static enum TextMatching {
startsWith, exact, substring
@@ -734,7 +734,6 @@
return value;
}
String localValue = value.replace(ESCAPE_CHAR + "", ESCAPE_CHAR +
ESCAPE_CHAR + "");
- localValue = localValue.replace("\\", ESCAPE_CHAR + "\\");
localValue = localValue.replace("_", ESCAPE_CHAR + "_");
localValue = localValue.replace("%", ESCAPE_CHAR + "%");
return localValue;
diff -r 718e718db21c -r 3e4e4993fee9
src-test/org/openbravo/test/AllAntTaskTests.java
--- a/src-test/org/openbravo/test/AllAntTaskTests.java Tue Mar 01 18:53:44
2011 +0100
+++ b/src-test/org/openbravo/test/AllAntTaskTests.java Tue Mar 01 21:54:21
2011 +0100
@@ -27,6 +27,7 @@
import org.openbravo.test.dal.DalComplexQueryRequisitionTest;
import org.openbravo.test.dal.DalComplexQueryTestOrderLine;
import org.openbravo.test.dal.DalConnectionProviderTest;
+import org.openbravo.test.dal.DalFilterTest;
import org.openbravo.test.dal.DalPerformanceInventoryLineTest;
import org.openbravo.test.dal.DalPerformanceProductTest;
import org.openbravo.test.dal.DalQueryTest;
@@ -86,6 +87,7 @@
suite.addTestSuite(DalPerformanceInventoryLineTest.class);
suite.addTestSuite(DalPerformanceProductTest.class);
suite.addTestSuite(DalQueryTest.class);
+ suite.addTestSuite(DalFilterTest.class);
suite.addTestSuite(DalTest.class);
suite.addTestSuite(DalUtilTest.class);
suite.addTestSuite(IssuesTest.class);
diff -r 718e718db21c -r 3e4e4993fee9
src-test/org/openbravo/test/AllQuickAntTaskTests.java
--- a/src-test/org/openbravo/test/AllQuickAntTaskTests.java Tue Mar 01
18:53:44 2011 +0100
+++ b/src-test/org/openbravo/test/AllQuickAntTaskTests.java Tue Mar 01
21:54:21 2011 +0100
@@ -25,6 +25,7 @@
import org.openbravo.erpCommon.info.ClassicSelectorTest;
import org.openbravo.test.dal.AdminContextTest;
import org.openbravo.test.dal.DalConnectionProviderTest;
+import org.openbravo.test.dal.DalFilterTest;
import org.openbravo.test.dal.DalStoredProcedureTest;
import org.openbravo.test.dal.DalTest;
import org.openbravo.test.dal.DalUtilTest;
@@ -72,6 +73,7 @@
// suite.addTestSuite(DalPerformanceProductTest.class);
// suite.addTestSuite(DalQueryTest.class);
suite.addTestSuite(DalTest.class);
+ suite.addTestSuite(DalFilterTest.class);
suite.addTestSuite(DalUtilTest.class);
suite.addTestSuite(DalConnectionProviderTest.class);
// suite.addTestSuite(DynamicEntityTest.class);
diff -r 718e718db21c -r 3e4e4993fee9 src-test/org/openbravo/test/AllTests.java
--- a/src-test/org/openbravo/test/AllTests.java Tue Mar 01 18:53:44 2011 +0100
+++ b/src-test/org/openbravo/test/AllTests.java Tue Mar 01 21:54:21 2011 +0100
@@ -25,6 +25,7 @@
import org.openbravo.erpCommon.info.ClassicSelectorTest;
import org.openbravo.test.dal.DalConnectionProviderTest;
import org.openbravo.test.dal.DalCopyTest;
+import org.openbravo.test.dal.DalFilterTest;
import org.openbravo.test.dal.DalQueryTest;
import org.openbravo.test.dal.DalStoredProcedureTest;
import org.openbravo.test.dal.DalTest;
@@ -70,6 +71,7 @@
suite.addTestSuite(ValidationTest.class);
suite.addTestSuite(DynamicEntityTest.class);
suite.addTestSuite(DalTest.class);
+ suite.addTestSuite(DalFilterTest.class);
suite.addTestSuite(DalUtilTest.class);
suite.addTestSuite(IssuesTest.class);
suite.addTestSuite(DalQueryTest.class);
diff -r 718e718db21c -r 3e4e4993fee9
src-test/org/openbravo/test/dal/DalFilterTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/dal/DalFilterTest.java Tue Mar 01
21:54:21 2011 +0100
@@ -0,0 +1,73 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo Public License
+ * Version 1.1 (the "License"), being the Mozilla Public License
+ * Version 1.1 with a permitted attribution clause; you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2011 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):
+ * Martin Taal <[email protected]>,
+ ************************************************************************
+ */
+
+package org.openbravo.test.dal;
+
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.dal.service.OBQuery;
+import org.openbravo.model.ad.datamodel.Column;
+import org.openbravo.model.ad.datamodel.Table;
+import org.openbravo.test.base.BaseTest;
+
+/**
+ * Test the filters added to the hibernate mapping.
+ *
+ * @author mtaal
+ */
+
+public class DalFilterTest extends BaseTest {
+ public void testActiveFilterDisabled() {
+ doTest(true);
+ }
+
+ public void testActiveFilterEnabled() {
+ OBDal.getInstance().commitAndClose();
+ OBDal.getInstance().enableActiveFilter();
+ doTest(false);
+ }
+
+ public void testActiveFilterEnDisabled() {
+ OBDal.getInstance().commitAndClose();
+ OBDal.getInstance().enableActiveFilter();
+ OBDal.getInstance().disableActiveFilter();
+ doTest(true);
+ }
+
+ /**
+ * test active filter both querying as well as collection
+ */
+ private void doTest(boolean present) {
+ setSystemAdministratorContext();
+ final Table table = OBDal.getInstance().get(Table.class, "111");
+ boolean inActiveColPresent = false;
+ for (Column col : table.getADColumnList()) {
+ if (!col.isActive()) {
+ inActiveColPresent = true;
+ break;
+ }
+ }
+ assertTrue(inActiveColPresent == present);
+ final OBQuery<Column> columns =
OBDal.getInstance().createQuery(Column.class, " table =:table");
+ columns.setNamedParameter("table", table);
+ columns.setFilterOnActive(false);
+ assertEquals(table.getADColumnList().size(), columns.list().size());
+ }
+
+}
diff -r 718e718db21c -r 3e4e4993fee9
src/org/openbravo/dal/core/DalMappingGenerator.java
--- a/src/org/openbravo/dal/core/DalMappingGenerator.java Tue Mar 01
18:53:44 2011 +0100
+++ b/src/org/openbravo/dal/core/DalMappingGenerator.java Tue Mar 01
21:54:21 2011 +0100
@@ -11,7 +11,7 @@
* under the License.
* The Original Code is Openbravo ERP.
* The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2008-2010 Openbravo SLU
+ * All portions are Copyright (C) 2008-2011 Openbravo SLU
* All Rights Reserved.
* Contributor(s): ______________________________________.
************************************************************************
@@ -160,10 +160,18 @@
}
}
+ if (entity.isActiveEnabled()) {
+ content.append(getActiveFilter());
+ }
+
hbm = hbm.replace("content", content.toString());
return hbm;
}
+ private String getActiveFilter() {
+ return "<filter name=\"activeFilter\" condition=\":activeParam =
isActive\"/>\n";
+ }
+
private String generatePrimitiveMapping(Property p) {
if (p.getHibernateType() == Object.class) {
return "";
@@ -285,6 +293,10 @@
sb.append(TAB3 + "<key column=\"" +
p.getReferencedProperty().getColumnName() + "\""
+ (p.getReferencedProperty().isMandatory() ? " not-null=\"true\"" :
"") + "/>" + NL);
sb.append(TAB3 + "<one-to-many entity-name=\"" +
p.getTargetEntity().getName() + "\"/>" + NL);
+
+ if (p.getTargetEntity().isActiveEnabled()) {
+ sb.append(getActiveFilter());
+ }
sb.append(TAB2 + "</bag>" + NL);
}
diff -r 718e718db21c -r 3e4e4993fee9
src/org/openbravo/dal/core/template_main.hbm.xml
--- a/src/org/openbravo/dal/core/template_main.hbm.xml Tue Mar 01 18:53:44
2011 +0100
+++ b/src/org/openbravo/dal/core/template_main.hbm.xml Tue Mar 01 21:54:21
2011 +0100
@@ -1,16 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- *
***********************************************************************************
- * Copyright (C) 2001-2009 Openbravo S.L.U. Licensed under the Apache Software
- * License version 2.0 You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
- *
***********************************************************************************
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo Public License
+ * Version 1.1 (the "License"), being the Mozilla Public License
+ * Version 1.1 with a permitted attribution clause; you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2008-2011 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s): ______________________________________.
+ ************************************************************************
+ */
-->
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD
3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
content
+ <filter-def name="activeFilter">
+ <filter-param name="activeParam" type="string"/>
+ </filter-def>
</hibernate-mapping>
\ No newline at end of file
diff -r 718e718db21c -r 3e4e4993fee9 src/org/openbravo/dal/service/OBDal.java
--- a/src/org/openbravo/dal/service/OBDal.java Tue Mar 01 18:53:44 2011 +0100
+++ b/src/org/openbravo/dal/service/OBDal.java Tue Mar 01 21:54:21 2011 +0100
@@ -73,6 +73,29 @@
}
/**
+ * After calling this method all collections and queries will only return
objects which are
+ * active. Note that this overrides the active filtering setting on
+ * {@link OBQuery#setFilterOnActive(boolean)} and {@link
OBCriteria#setFilterOnActive(boolean)}.
+ *
+ * @see #disableActiveFilter()
+ */
+ public void enableActiveFilter() {
+
SessionHandler.getInstance().getSession().enableFilter("activeFilter").setParameter(
+ "activeParam", "Y");
+ }
+
+ /**
+ * After calling this method the active filter is disabled. Note that then
the settings in
+ * {@link OBQuery#setFilterOnActive(boolean)} and {@link
OBCriteria#setFilterOnActive(boolean)}
+ * will apply.
+ *
+ * @see #enableActiveFilter()
+ */
+ public void disableActiveFilter() {
+ SessionHandler.getInstance().getSession().disableFilter("activeFilter");
+ }
+
+ /**
* Returns the connection used by the hibernate session.
*
* Note: flushes the hibernate session before returning the connection.
------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in
Real-Time with Splunk. Collect, index and harness all the fast moving IT data
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business
insights. http://p.sf.net/sfu/splunk-dev2dev
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits