Author: hansbak
Date: Wed Feb 1 07:22:12 2012 New Revision: 1238954 URL: http://svn.apache.org/viewvc?rev=1238954&view=rev Log: make <property-to-field/> in minilanguage first look in the newly created SystemProperty entity to be able to override the system properties defined in the properties files Added: ofbiz/trunk/framework/common/data/CommonSystemPropertyData.xml (with props) ofbiz/trunk/framework/entity/script/ ofbiz/trunk/framework/entity/script/org/ ofbiz/trunk/framework/entity/script/org/ofbiz/ ofbiz/trunk/framework/entity/script/org/ofbiz/entity/ ofbiz/trunk/framework/entity/script/org/ofbiz/entity/test/ ofbiz/trunk/framework/entity/script/org/ofbiz/entity/test/EntityUtilPropertiesTests.xml (with props) ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtilProperties.java (with props) Modified: ofbiz/trunk/framework/common/entitydef/entitymodel.xml ofbiz/trunk/framework/common/ofbiz-component.xml ofbiz/trunk/framework/entity/entitydef/entitygroup.xml ofbiz/trunk/framework/entity/entitydef/entitymodel.xml ofbiz/trunk/framework/entity/src/org/ofbiz/entity/DelegatorFactory.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java ofbiz/trunk/framework/entity/testdef/entitytests.xml ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataServices.java ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/otherops/PropertyToField.java ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java Added: ofbiz/trunk/framework/common/data/CommonSystemPropertyData.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/data/CommonSystemPropertyData.xml?rev=1238954&view=auto ============================================================================== --- ofbiz/trunk/framework/common/data/CommonSystemPropertyData.xml (added) +++ ofbiz/trunk/framework/common/data/CommonSystemPropertyData.xml Wed Feb 1 07:22:12 2012 @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. 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. +--> +<entity-engine-xml> + <SystemProperty systemPropertyId="currency.uom.id.default" systemPropertyValue="THB" description="the default currency to use for prices, etc"/> + <SystemProperty systemPropertyId="defaultFromEmailAddress" systemPropertyValue="[hidden email]" description="general default 'fromEmailAddress' can be overridden in: EmailTemplateSetting"/> +</entity-engine-xml> Propchange: ofbiz/trunk/framework/common/data/CommonSystemPropertyData.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/framework/common/data/CommonSystemPropertyData.xml ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/framework/common/data/CommonSystemPropertyData.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Modified: ofbiz/trunk/framework/common/entitydef/entitymodel.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/entitydef/entitymodel.xml?rev=1238954&r1=1238953&r2=1238954&view=diff ============================================================================== --- ofbiz/trunk/framework/common/entitydef/entitymodel.xml (original) +++ ofbiz/trunk/framework/common/entitydef/entitymodel.xml Wed Feb 1 07:22:12 2012 @@ -839,4 +839,15 @@ under the License. <key-map field-name="portalPageId"/> </view-link> </view-entity> + + <!-- ============================ --> + <!-- org.ofbiz.common.property --> + <!-- ============================ --> + + <entity entity-name="SystemProperty" package-name="org.ofbiz.common.property" title="Defines a System Property"> + <field name="systemPropertyId" type="id-long-ne"></field> + <field name="systemPropertyValue" type="value"></field> + <field name="description" type="description"></field> + <prim-key field="systemPropertyId"/> + </entity> </entitymodel> Modified: ofbiz/trunk/framework/common/ofbiz-component.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/ofbiz-component.xml?rev=1238954&r1=1238953&r2=1238954&view=diff ============================================================================== --- ofbiz/trunk/framework/common/ofbiz-component.xml (original) +++ ofbiz/trunk/framework/common/ofbiz-component.xml Wed Feb 1 07:22:12 2012 @@ -28,6 +28,7 @@ under the License. <entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel_olap.xml"/> <entity-resource type="group" reader-name="main" loader="main" location="entitydef/entitygroup_olap.xml"/> <entity-resource type="data" reader-name="seed" loader="main" location="data/CommonSecurityData.xml"/> + <entity-resource type="data" reader-name="seed" loader="main" location="data/CommonSystemPropertyData.xml"/> <entity-resource type="data" reader-name="seed" loader="main" location="data/CommonTypeData.xml"/> <entity-resource type="data" reader-name="seed" loader="main" location="data/CountryCodeData.xml"/> <entity-resource type="data" reader-name="seed" loader="main" location="data/CurrencyData.xml"/> Modified: ofbiz/trunk/framework/entity/entitydef/entitygroup.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/entitydef/entitygroup.xml?rev=1238954&r1=1238953&r2=1238954&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/entitydef/entitygroup.xml (original) +++ ofbiz/trunk/framework/entity/entitydef/entitygroup.xml Wed Feb 1 07:22:12 2012 @@ -29,4 +29,5 @@ under the License. <!-- <entity-group group="org.ofbiz.tenant" entity="TenantUserLogin"/> --> <entity-group group="org.ofbiz.tenant" entity="Component"/> <entity-group group="org.ofbiz.tenant" entity="TenantComponent"/> + <entity-group group="org.ofbiz.tenant" entity="TenantDomainName"/> </entitygroup> Modified: ofbiz/trunk/framework/entity/entitydef/entitymodel.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/entitydef/entitymodel.xml?rev=1238954&r1=1238953&r2=1238954&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/entitydef/entitymodel.xml (original) +++ ofbiz/trunk/framework/entity/entitydef/entitymodel.xml Wed Feb 1 07:22:12 2012 @@ -66,8 +66,6 @@ under the License. <entity entity-name="Tenant" package-name="org.ofbiz.entity.tenant"> <field name="tenantId" type="id-ne"/> <field name="tenantName" type="name"/> - <field name="domainName" type="long-varchar"/> - <field name="initialPath" type="value"/> <field name="disabled" type="indicator"><description>Disabled if 'Y', defaults to 'N' (not disabled).</description></field> <prim-key field="tenantId"/> </entity> @@ -141,4 +139,14 @@ under the License. <key-map field-name="componentName"/> </relation> </entity> + <entity entity-name="TenantDomainName" package-name="org.ofbiz.entity.tenant"> + <field name="tenantId" type="id-ne"/> + <field name="domainName" type="long-varchar"/> + <field name="initialPath" type="value"/> + <prim-key field="tenantId"/> + <prim-key field="domainName"/> + <relation type="one" fk-name="TNTDMN_TNT" rel-entity-name="Tenant"> + <key-map field-name="tenantId"/> + </relation> + </entity> </entitymodel> Added: ofbiz/trunk/framework/entity/script/org/ofbiz/entity/test/EntityUtilPropertiesTests.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/script/org/ofbiz/entity/test/EntityUtilPropertiesTests.xml?rev=1238954&view=auto ============================================================================== --- ofbiz/trunk/framework/entity/script/org/ofbiz/entity/test/EntityUtilPropertiesTests.xml (added) +++ ofbiz/trunk/framework/entity/script/org/ofbiz/entity/test/EntityUtilPropertiesTests.xml Wed Feb 1 07:22:12 2012 @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. 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. +--> + +<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/simple-methods.xsd"> + + <simple-method method-name="testGetGeneralProperties" short-description="test getting general properties" login-required="false"> + <call-class-method ret-field="currencyUomIdDefault" method-name="getPropertyValue" class-name="org.ofbiz.entity.util.EntityUtilProperties"> + <string value="general"/> + <string value="currency.uom.id.default"/> + <field field="delegator" type="org.ofbiz.entity.Delegator"/> + </call-class-method> + <assert><if-compare field="currencyUomIdDefault" operator="equals" value="THB"></if-compare></assert> + + <call-class-method ret-field="defaultFromEmailAddress" method-name="getPropertyValue" class-name="org.ofbiz.entity.util.EntityUtilProperties"> + <string value="general"/> + <string value="defaultFromEmailAddress"/> + <field field="delegator" type="org.ofbiz.entity.Delegator"/> + </call-class-method> + <assert><if-compare field="defaultFromEmailAddress" operator="equals" value="[hidden email]"></if-compare></assert> + + <property-to-field resource="general" property="currency.uom.id.default" field="currencyUomIdDefault"/> + <assert><if-compare field="currencyUomIdDefault" operator="equals" value="THB"></if-compare></assert> + + <property-to-field resource="general" property="defaultFromEmailAddress" field="defaultFromEmailAddress"/> + <assert><if-compare field="defaultFromEmailAddress" operator="equals" value="[hidden email]"></if-compare></assert> + </simple-method> +</simple-methods> Propchange: ofbiz/trunk/framework/entity/script/org/ofbiz/entity/test/EntityUtilPropertiesTests.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/framework/entity/script/org/ofbiz/entity/test/EntityUtilPropertiesTests.xml ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/framework/entity/script/org/ofbiz/entity/test/EntityUtilPropertiesTests.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/DelegatorFactory.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/DelegatorFactory.java?rev=1238954&r1=1238953&r2=1238954&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/DelegatorFactory.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/DelegatorFactory.java Wed Feb 1 07:22:12 2012 @@ -56,4 +56,8 @@ public abstract class DelegatorFactory i delegatorCache.putIfAbsent(delegatorName, delegator); } while (true); } + + public static void removeDelegator(String delegatorName) { + delegatorCache.remove(delegatorName); + } } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java?rev=1238954&r1=1238953&r2=1238954&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java Wed Feb 1 07:22:12 2012 @@ -18,6 +18,16 @@ *******************************************************************************/ package org.ofbiz.entity.connection; +import java.sql.Connection; +import java.sql.Driver; +import java.sql.SQLException; +import java.util.Map; +import java.util.Properties; + +import javax.transaction.TransactionManager; + +import javolution.util.FastMap; + import org.apache.commons.dbcp.ConnectionFactory; import org.apache.commons.dbcp.DriverConnectionFactory; import org.apache.commons.dbcp.PoolableConnectionFactory; @@ -32,15 +42,6 @@ import org.ofbiz.entity.datasource.Gener import org.ofbiz.entity.transaction.TransactionFactory; import org.w3c.dom.Element; -import javax.transaction.TransactionManager; -import java.sql.Connection; -import java.sql.Driver; -import java.sql.SQLException; -import java.util.Map; -import java.util.Properties; - -import javolution.util.FastMap; - /** * DBCPConnectionFactory */ @@ -48,6 +49,8 @@ public class DBCPConnectionFactory imple public static final String module = DBCPConnectionFactory.class.getName(); protected static Map<String, ManagedDataSource> dsCache = FastMap.newInstance(); + protected static Map<String, XAConnectionFactory> xacfCache = FastMap.newInstance(); + protected static Map<String, GenericObjectPool> gopCache = FastMap.newInstance(); public Connection getConnection(GenericHelperInfo helperInfo, Element jdbcElement) throws SQLException, GenericEntityException { ManagedDataSource mds = dsCache.get(helperInfo.getHelperFullName()); @@ -171,13 +174,27 @@ public class DBCPConnectionFactory imple // cache the pool dsCache.put(helperInfo.getHelperFullName(), mds); + xacfCache.put(helperInfo.getHelperFullName(), xacf); + gopCache.put(helperInfo.getHelperFullName(), pool); return TransactionFactory.getCursorConnection(helperInfo, mds.getConnection()); } } + + public void removeConnection(GenericHelperInfo helperInfo) { + dsCache.remove(helperInfo.getHelperFullName()); + } public void closeAll() { // no methods on the pool to shutdown; so just clearing for GC dsCache.clear(); } + + public XAConnectionFactory getXAConnectionFactory(GenericHelperInfo helperInfo) { + return xacfCache.get(helperInfo.getHelperFullName()); + } + + public GenericObjectPool getGenericObjectPool(GenericHelperInfo helperInfo) { + return gopCache.get(helperInfo.getHelperFullName()); + } } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java?rev=1238954&r1=1238953&r2=1238954&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java Wed Feb 1 07:22:12 2012 @@ -1212,11 +1212,14 @@ public class GenericDAO { public void checkDb(Map<String, ModelEntity> modelEntities, List<String> messages, boolean addMissing) { DatabaseUtil dbUtil = new DatabaseUtil(this.helperInfo, this.executor); dbUtil.checkDb(modelEntities, messages, addMissing); + dbUtil.close(); } /** Creates a list of ModelEntity objects based on meta data from the database */ public List<ModelEntity> induceModelFromDb(Collection<String> messages) { DatabaseUtil dbUtil = new DatabaseUtil(this.helperInfo, this.executor); - return dbUtil.induceModelFromDb(messages); + List<ModelEntity> modelEntities = dbUtil.induceModelFromDb(messages); + dbUtil.close(); + return modelEntities; } } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java?rev=1238954&r1=1238953&r2=1238954&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java Wed Feb 1 07:22:12 2012 @@ -83,6 +83,7 @@ public class DatabaseUtil { boolean isLegacy = false; protected ExecutorService executor; + protected List<Connection> connections = FastList.newInstance(); // OFBiz DatabaseUtil public DatabaseUtil(GenericHelperInfo helperInfo) { @@ -145,6 +146,9 @@ public class DatabaseUtil { throw new GenericEntityException("No connection avaialble for URL [" + connectionUrl + "]"); } } + + connections.add(connection); + if (!TransactionUtil.isTransactionInPlace()) { connection.setAutoCommit(true); } @@ -3203,6 +3207,18 @@ public class DatabaseUtil { } } } + + public void close() { + for (Connection connection : connections) { + try { + if (!connection.isClosed()) { + connection.close(); + } + } catch (SQLException e) { + Debug.logWarning("Could not close connection: " + connection, module); + } + } + } /* ====================================================================== */ /* ====================================================================== */ Added: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtilProperties.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtilProperties.java?rev=1238954&view=auto ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtilProperties.java (added) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtilProperties.java Wed Feb 1 07:22:12 2012 @@ -0,0 +1,242 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. 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. + *******************************************************************************/ +package org.ofbiz.entity.util; + +import java.io.IOException; +import java.io.InputStream; +import java.io.Serializable; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.net.URL; +import java.util.InvalidPropertiesFormatException; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Properties; +import java.util.ResourceBundle; +import java.util.Set; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilProperties; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.collections.ResourceBundleMapWrapper; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.GenericValue; + +@SuppressWarnings("serial") +public class EntityUtilProperties implements Serializable { + + public final static String module = EntityUtilProperties.class.getName(); + + protected static String getSystemPropertyValue(String name, Delegator delegator) { + if (name == null || name.length() <= 0) return ""; + + // find system property + try { + List<GenericValue> systemProperties = delegator.findByAnd("SystemProperty", UtilMisc.toMap("systemPropertyId", name)); + if (UtilValidate.isNotEmpty(systemProperties)) { + GenericValue systemProperty = EntityUtil.getFirst(systemProperties); + String systemPropertyValue = systemProperty.getString("systemPropertyValue"); + return systemPropertyValue; + } + } catch (Exception e) { + Debug.logWarning("Could not get a sytem property for " + name + " : " + e.getMessage(), module); + } + return null; + } + + public static boolean propertyValueEquals(String resource, String name, String compareString) { + return UtilProperties.propertyValueEquals(resource, name, compareString); + } + + public static boolean propertyValueEqualsIgnoreCase(String resource, String name, String compareString) { + return UtilProperties.propertyValueEqualsIgnoreCase(resource, name, compareString); + } + + public static String getPropertyValue(String resource, String name, String defaultValue) { + return UtilProperties.getPropertyValue(resource, name, defaultValue); + } + + public static double getPropertyNumber(String resource, String name, double defaultValue) { + return UtilProperties.getPropertyNumber(resource, name, defaultValue); + } + + public static double getPropertyNumber(String resource, String name) { + return UtilProperties.getPropertyNumber(resource, name); + } + + public static Boolean getPropertyAsBoolean(String resource, String name, boolean defaultValue) { + return UtilProperties.getPropertyAsBoolean(resource, name, defaultValue); + } + + public static Integer getPropertyAsInteger(String resource, String name, int defaultNumber) { + return UtilProperties.getPropertyAsInteger(resource, name, defaultNumber); + } + + public static Long getPropertyAsLong(String resource, String name, long defaultNumber) { + return UtilProperties.getPropertyAsLong(resource, name, defaultNumber); + } + + public static Float getPropertyAsFloat(String resource, String name, float defaultNumber) { + return UtilProperties.getPropertyAsFloat(resource, name, defaultNumber); + } + + public static Double getPropertyAsDouble(String resource, String name, double defaultNumber) { + return UtilProperties.getPropertyAsDouble(resource, name, defaultNumber); + } + + public static BigInteger getPropertyAsBigInteger(String resource, String name, BigInteger defaultNumber) { + return UtilProperties.getPropertyAsBigInteger(resource, name, defaultNumber); + } + + public static BigDecimal getPropertyAsBigDecimal(String resource, String name, BigDecimal defaultNumber) { + return UtilProperties.getPropertyAsBigDecimal(resource, name, defaultNumber); + } + + public static String getPropertyValue(String resource, String name, Delegator delegator) { + String value = getSystemPropertyValue(name, delegator); + if (UtilValidate.isEmpty(value)) { + value = UtilProperties.getPropertyValue(resource, name); + } + return value; + } + + public static Properties getProperties(String resource) { + return UtilProperties.getProperties(resource); + } + + public static Properties getProperties(URL url) { + return UtilProperties.getProperties(url); + } + + public static boolean propertyValueEquals(URL url, String name, String compareString) { + return UtilProperties.propertyValueEquals(url, name, compareString); + } + + public static boolean propertyValueEqualsIgnoreCase(URL url, String name, String compareString) { + return UtilProperties.propertyValueEqualsIgnoreCase(url, name, compareString); + } + + public static String getPropertyValue(URL url, String name, String defaultValue) { + return UtilProperties.getPropertyValue(url, name, defaultValue); + } + + public static double getPropertyNumber(URL url, String name, double defaultValue) { + return UtilProperties.getPropertyNumber(url, name, defaultValue); + } + + public static double getPropertyNumber(URL url, String name) { + return UtilProperties.getPropertyNumber(url, name); + } + + public static String getPropertyValue(URL url, String name) { + return UtilProperties.getPropertyValue(url, name); + } + + public static String getSplitPropertyValue(URL url, String name) { + return UtilProperties.getSplitPropertyValue(url, name); + } + + public static void setPropertyValue(String resource, String name, String value) { + UtilProperties.setPropertyValue(resource, name, value); + } + + public static void setPropertyValueInMemory(String resource, String name, String value) { + UtilProperties.setPropertyValueInMemory(resource, name, value); + } + + public static String getMessage(String resource, String name, Locale locale, Delegator delegator) { + String value = getSystemPropertyValue(name, delegator); + if (UtilValidate.isEmpty(value)) { + value = UtilProperties.getMessage(resource, name, locale); + } + return value; + } + + public static String getMessage(String resource, String name, Object[] arguments, Locale locale) { + return UtilProperties.getMessage(resource, name, arguments, locale); + } + + public static <E> String getMessage(String resource, String name, List<E> arguments, Locale locale) { + return UtilProperties.getMessage(resource, name, arguments, locale); + } + + public static String getMessageList(String resource, String name, Locale locale, Object... arguments) { + return UtilProperties.getMessageList(resource, name, locale, arguments); + } + + public static String getMessage(String resource, String name, Map<String, ? extends Object> context, Locale locale) { + return UtilProperties.getMessage(resource, name, context, locale); + } + + public static String getMessageMap(String resource, String name, Locale locale, Object... context) { + return UtilProperties.getMessageMap(resource, name, locale, context); + } + + public static ResourceBundle getResourceBundle(String resource, Locale locale) { + return UtilProperties.getResourceBundle(resource, locale); + } + + public static ResourceBundleMapWrapper getResourceBundleMap(String resource, Locale locale) { + return UtilProperties.getResourceBundleMap(resource, locale); + } + + public static ResourceBundleMapWrapper getResourceBundleMap(String resource, Locale locale, Map<String, Object> context) { + return UtilProperties.getResourceBundleMap(resource, locale, context); + } + + public static Properties getProperties(String resource, Locale locale) { + return UtilProperties.getProperties(resource, locale); + } + + @Deprecated + public static Locale getFallbackLocale() { + return UtilProperties.getFallbackLocale(); + } + + public static List<Locale> localeToCandidateList(Locale locale) { + return UtilProperties.localeToCandidateList(locale); + } + + public static Set<Locale> getDefaultCandidateLocales() { + return UtilProperties.getDefaultCandidateLocales(); + } + + @Deprecated + public static List<Locale> getCandidateLocales(Locale locale) { + return UtilProperties.getCandidateLocales(locale); + } + + public static String createResourceName(String resource, Locale locale, boolean removeExtension) { + return UtilProperties.createResourceName(resource, locale, removeExtension); + } + + public static boolean isPropertiesResourceNotFound(String resource, Locale locale, boolean removeExtension) { + return UtilProperties.isPropertiesResourceNotFound(resource, locale, removeExtension); + } + + public static URL resolvePropertiesUrl(String resource, Locale locale) { + return UtilProperties.resolvePropertiesUrl(resource, locale); + } + + public static Properties xmlToProperties(InputStream in, Locale locale, Properties properties) throws IOException, InvalidPropertiesFormatException { + return UtilProperties.xmlToProperties(in, locale, properties); + } +} Propchange: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtilProperties.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtilProperties.java ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtilProperties.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: ofbiz/trunk/framework/entity/testdef/entitytests.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/testdef/entitytests.xml?rev=1238954&r1=1238953&r2=1238954&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/testdef/entitytests.xml (original) +++ ofbiz/trunk/framework/entity/testdef/entitytests.xml Wed Feb 1 07:22:12 2012 @@ -22,4 +22,7 @@ under the License. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/test-suite.xsd"> <test-case case-name="entity-tests"><junit-test-suite class-name="org.ofbiz.entity.test.EntityTestSuite"/></test-case> + <test-case case-name="entity-util-properties-tests"> + <simple-method-test location="component://entity/script/org/ofbiz/entity/test/EntityUtilPropertiesTests.xml"/> + </test-case> </test-suite> Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java?rev=1238954&r1=1238953&r2=1238954&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java Wed Feb 1 07:22:12 2012 @@ -564,6 +564,8 @@ public class EntityDataLoadContainer imp } } } + + dbUtil.close(); } /** * @see org.ofbiz.base.container.Container#stop() Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataServices.java?rev=1238954&r1=1238953&r2=1238954&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataServices.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataServices.java Wed Feb 1 07:22:12 2012 @@ -407,6 +407,8 @@ public class EntityDataServices { // step 8 - checkdb Debug.logImportant("Running DB check with add missing enabled", module); dbUtil.checkDb(modelEntities, messages, true); + + dbUtil.close(); Map<String, Object> result = ServiceUtil.returnSuccess(); result.put("messages", messages); Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/otherops/PropertyToField.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/otherops/PropertyToField.java?rev=1238954&r1=1238953&r2=1238954&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/otherops/PropertyToField.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/otherops/PropertyToField.java Wed Feb 1 07:22:12 2012 @@ -24,6 +24,7 @@ import java.util.*; import org.w3c.dom.*; import javolution.util.FastMap; import org.ofbiz.base.util.*; +import org.ofbiz.entity.util.EntityUtilProperties; import org.ofbiz.minilang.*; import org.ofbiz.minilang.method.*; @@ -71,9 +72,9 @@ public class PropertyToField extends Met String value = null; if (noLocale) { - value = UtilProperties.getPropertyValue(resource, property); + value = EntityUtilProperties.getPropertyValue(resource, property, methodContext.getDelegator()); } else { - value = UtilProperties.getMessage(resource, property, methodContext.getLocale()); + value = EntityUtilProperties.getMessage(resource, property, methodContext.getLocale(), methodContext.getDelegator()); } if (UtilValidate.isEmpty(value)) { value = defaultVal; Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java?rev=1238954&r1=1238953&r2=1238954&view=diff ============================================================================== --- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java (original) +++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java Wed Feb 1 07:22:12 2012 @@ -280,16 +280,28 @@ public class ContextFilter implements Fi // get tenant delegator by domain name String serverName = httpRequest.getServerName(); try { + // first set the delegator to default + String delegatorName = config.getServletContext().getInitParameter("entityDelegatorName"); + + if (delegatorName == null || delegatorName.length() <= 0) { + delegatorName = "default"; + } + if (Debug.verboseOn()) Debug.logVerbose("Setup Entity Engine Delegator with name " + delegatorName, module); + Delegator delegator = DelegatorFactory.getDelegator(delegatorName); + config.getServletContext().setAttribute("delegator", delegator); + if (delegator == null) { + Debug.logError("[ContextFilter.init] ERROR: delegator factory returned null for delegatorName \"" + delegatorName + "\"", module); + } + // if tenant was specified, replace delegator with the new per-tenant delegator and set tenantId to session attribute - Delegator delegator = getDelegator(config.getServletContext()); - List<GenericValue> tenants = delegator.findList("Tenant", EntityCondition.makeCondition("domainName", serverName), null, UtilMisc.toList("-createdStamp"), null, false); - if (UtilValidate.isNotEmpty(tenants)) { - GenericValue tenant = EntityUtil.getFirst(tenants); - String tenantId = tenant.getString("tenantId"); + List<GenericValue> tenantDomainNames = delegator.findList("TenantDomainName", EntityCondition.makeCondition("domainName", serverName), null, UtilMisc.toList("-createdStamp"), null, false); + if (UtilValidate.isNotEmpty(tenantDomainNames)) { + GenericValue tenantDomainName = EntityUtil.getFirst(tenantDomainNames); + String tenantId = tenantDomainName.getString("tenantId"); // if the request path is a root mount then redirect to the initial path if (UtilValidate.isNotEmpty(requestPath) && requestPath.equals(contextUri)) { - String initialPath = tenant.getString("initialPath"); + String initialPath = tenantDomainName.getString("initialPath"); if (UtilValidate.isNotEmpty(initialPath) && !"/".equals(initialPath)) { ((HttpServletResponse)response).sendRedirect(initialPath); return; @@ -297,32 +309,33 @@ public class ContextFilter implements Fi } // make that tenant active, setup a new delegator and a new dispatcher - String tenantDelegatorName = delegator.getDelegatorBaseName() + "#" + tenantId; - httpRequest.getSession().setAttribute("delegatorName", tenantDelegatorName); + delegatorName = delegator.getDelegatorBaseName() + "#" + tenantId; + httpRequest.getSession().setAttribute("delegatorName", delegatorName); // after this line the delegator is replaced with the new per-tenant delegator - delegator = DelegatorFactory.getDelegator(tenantDelegatorName); - config.getServletContext().setAttribute("delegator", delegator); - - // clear web context objects - config.getServletContext().setAttribute("authorization", null); - config.getServletContext().setAttribute("security", null); - config.getServletContext().setAttribute("dispatcher", null); - - // initialize authorizer - getAuthz(); - // initialize security - Security security = getSecurity(); - // initialize the services dispatcher - LocalDispatcher dispatcher = getDispatcher(config.getServletContext()); - - // set web context objects - httpRequest.getSession().setAttribute("dispatcher", dispatcher); - httpRequest.getSession().setAttribute("security", security); + delegator = DelegatorFactory.getDelegator(delegatorName); httpRequest.setAttribute("tenantId", tenantId); } + config.getServletContext().setAttribute("delegator", delegator); + + // clear web context objects + config.getServletContext().setAttribute("authorization", null); + config.getServletContext().setAttribute("security", null); + config.getServletContext().setAttribute("dispatcher", null); + + // initialize authorizer + getAuthz(); + // initialize security + Security security = getSecurity(); + // initialize the services dispatcher + LocalDispatcher dispatcher = getDispatcher(config.getServletContext()); + + // set web context objects + httpRequest.getSession().setAttribute("dispatcher", dispatcher); + httpRequest.getSession().setAttribute("security", security); + // NOTE DEJ20101130: do NOT always put the delegator name in the user's session because the user may // have logged in and specified a tenant, and even if no Tenant record with a matching domainName field // is found this will change the user's delegator back to the base one instead of the one for the Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java?rev=1238954&r1=1238953&r2=1238954&view=diff ============================================================================== --- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java (original) +++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java Wed Feb 1 07:22:12 2012 @@ -645,9 +645,11 @@ public class LoginWorker { if (currCatalog != null) session.setAttribute("CURRENT_CATALOG_ID", currCatalog); if (delegatorName != null) { // if there is a tenantId in the delegatorName remove it now so that tenant selection doesn't last beyond logout + /* if (delegatorName.indexOf('#') > 0) { delegatorName = delegatorName.substring(0, delegatorName.indexOf('#')); } + */ session.setAttribute("delegatorName", delegatorName); delegator = DelegatorFactory.getDelegator(delegatorName); |
Free forum by Nabble | Edit this page |