You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jo...@apache.org on 2010/03/25 05:42:28 UTC
svn commit: r927271 [2/2] - in /ofbiz/trunk: ./
applications/order/script/org/ofbiz/order/customer/
applications/party/webapp/partymgr/WEB-INF/actions/party/
applications/product/script/org/ofbiz/product/test/
framework/common/config/ framework/common/...
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java?rev=927271&r1=927270&r2=927271&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java Thu Mar 25 04:42:26 2010
@@ -39,6 +39,7 @@ import org.ofbiz.entity.GenericDataSourc
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.config.DatasourceInfo;
import org.ofbiz.entity.config.EntityConfigUtil;
+import org.ofbiz.entity.datasource.GenericHelperInfo;
import org.ofbiz.entity.transaction.GenericTransactionException;
import org.ofbiz.entity.transaction.TransactionUtil;
@@ -57,7 +58,7 @@ public class SQLProcessor {
public static boolean ENABLE_TEST = false;
/** The datasource helper (see entityengine.xml <datasource name="..">) */
- private String helperName;
+ private GenericHelperInfo helperInfo;
// / The database resources to be used
private Connection _connection = null;
@@ -87,8 +88,8 @@ public class SQLProcessor {
*
* @param helperName The datasource helper (see entityengine.xml <datasource name="..">)
*/
- public SQLProcessor(String helperName) {
- this.helperName = helperName;
+ public SQLProcessor(GenericHelperInfo helperInfo) {
+ this.helperInfo = helperInfo;
this._manualTX = true;
}
@@ -99,8 +100,8 @@ public class SQLProcessor {
* @param helperName The datasource helper (see entityengine.xml <datasource name="..">)
* @param connection The connection to be used
*/
- public SQLProcessor(String helperName, Connection connection) {
- this.helperName = helperName;
+ public SQLProcessor(GenericHelperInfo helperInfo, Connection connection) {
+ this.helperInfo = helperInfo;
this._connection = connection;
// Do not commit while closing
@@ -245,7 +246,7 @@ public class SQLProcessor {
_manualTX = true;
try {
- _connection = ConnectionFactory.getConnection(helperName);
+ _connection = ConnectionFactory.getConnection(helperInfo);
if (Debug.verboseOn()) Debug.logVerbose("SQLProcessor:connection() : manualTx=" + _manualTX, module);
} catch (SQLException sqle) {
throw new GenericDataSourceException("Unable to esablish a connection with the database.", sqle);
@@ -729,7 +730,7 @@ public class SQLProcessor {
if (field != null) {
_ps.setBlob(_ind, field);
} else {
- DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(this.helperName);
+ DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(this.helperInfo.getHelperBaseName());
if (datasourceInfo.useBinaryTypeForBlob) {
_ps.setNull(_ind, Types.BINARY);
} else {
@@ -780,7 +781,7 @@ public class SQLProcessor {
throw new SQLException(ex.getMessage());
}
} else {
- DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(this.helperName);
+ DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(this.helperInfo.getHelperBaseName());
if (datasourceInfo.useBinaryTypeForBlob) {
_ps.setNull(_ind, Types.BINARY);
} else {
@@ -803,7 +804,7 @@ public class SQLProcessor {
if (bytes != null) {
_ps.setBytes(_ind, bytes);
} else {
- DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(this.helperName);
+ DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(this.helperInfo.getHelperBaseName());
if (datasourceInfo.useBinaryTypeForBlob) {
_ps.setNull(_ind, Types.BINARY);
} else {
@@ -841,7 +842,7 @@ public class SQLProcessor {
// check if the statement was called with a specific fetch size, if not grab the default from the datasource
if (fetchSize < 0) {
- DatasourceInfo ds = EntityConfigUtil.getDatasourceInfo(helperName);
+ DatasourceInfo ds = EntityConfigUtil.getDatasourceInfo(this.helperInfo.getHelperBaseName());
if (ds != null) {
fetchSize = ds.resultFetchSize;
} else {
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelGroupReader.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelGroupReader.java?rev=927271&r1=927270&r2=927271&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelGroupReader.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelGroupReader.java Thu Mar 25 04:42:26 2010
@@ -169,13 +169,17 @@ public class ModelGroupReader implements
* @param entityName The entityName of the Entity Group definition to use.
* @return A group name
*/
- public String getEntityGroupName(String entityName, String delegatorName) {
+ public String getEntityGroupName(String entityName, String delegatorBaseName) {
Map<String, String> gc = getGroupCache();
if (gc != null) {
String groupName = gc.get(entityName);
if (groupName == null) {
- groupName = EntityConfigUtil.getDelegatorInfo(delegatorName).defaultGroupName;
+ DelegatorInfo delegatorInfo = EntityConfigUtil.getDelegatorInfo(delegatorBaseName);
+ if (delegatorInfo == null) {
+ throw new RuntimeException("Could not find DelegatorInfo for delegatorBaseName [" + delegatorBaseName + "]");
+ }
+ groupName = delegatorInfo.defaultGroupName;
}
return groupName;
} else {
@@ -186,11 +190,15 @@ public class ModelGroupReader implements
/** Creates a Set with all of the groupNames defined in the specified XML Entity Group Descriptor file.
* @return A Set of groupNames Strings
*/
- public Set<String> getGroupNames(String delegatorName) {
+ public Set<String> getGroupNames(String delegatorBaseName) {
+ if (delegatorBaseName.indexOf('#') >= 0) {
+ delegatorBaseName = delegatorBaseName.substring(0, delegatorBaseName.indexOf('#'));
+ }
+
getGroupCache();
if (this.groupNames == null) return null;
Set<String> newSet = FastSet.newInstance();
- newSet.add(EntityConfigUtil.getDelegatorInfo(delegatorName).defaultGroupName);
+ newSet.add(EntityConfigUtil.getDelegatorInfo(delegatorBaseName).defaultGroupName);
newSet.addAll(this.groupNames);
return newSet;
}
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/DumbFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/DumbFactory.java?rev=927271&r1=927270&r2=927271&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/DumbFactory.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/DumbFactory.java Thu Mar 25 04:42:26 2010
@@ -36,6 +36,7 @@ import org.ofbiz.base.util.Debug;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.config.DatasourceInfo;
import org.ofbiz.entity.config.EntityConfigUtil;
+import org.ofbiz.entity.datasource.GenericHelperInfo;
import org.ofbiz.entity.jdbc.ConnectionFactory;
/**
@@ -106,14 +107,14 @@ public class DumbFactory implements Tran
return "dumb";
}
- public Connection getConnection(String helperName) throws SQLException, GenericEntityException {
- DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName);
+ public Connection getConnection(GenericHelperInfo helperInfo) throws SQLException, GenericEntityException {
+ DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperInfo.getHelperBaseName());
if (datasourceInfo.inlineJdbcElement != null) {
- Connection otherCon = ConnectionFactory.getManagedConnection(helperName, datasourceInfo.inlineJdbcElement);
- return TransactionFactory.getCursorConnection(helperName, otherCon);
+ Connection otherCon = ConnectionFactory.getManagedConnection(helperInfo, datasourceInfo.inlineJdbcElement);
+ return TransactionFactory.getCursorConnection(helperInfo, otherCon);
} else {
- Debug.logError("Dumb/Empty is the configured transaction manager but no inline-jdbc element was specified in the " + helperName + " datasource. Please check your configuration", module);
+ Debug.logError("Dumb/Empty is the configured transaction manager but no inline-jdbc element was specified in the " + helperInfo.getHelperBaseName() + " datasource. Please check your configuration", module);
return null;
}
}
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/JNDIFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/JNDIFactory.java?rev=927271&r1=927270&r2=927271&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/JNDIFactory.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/JNDIFactory.java Thu Mar 25 04:42:26 2010
@@ -41,6 +41,7 @@ import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.config.DatasourceInfo;
import org.ofbiz.entity.config.EntityConfigUtil;
+import org.ofbiz.entity.datasource.GenericHelperInfo;
import org.ofbiz.entity.jdbc.ConnectionFactory;
import org.w3c.dom.Element;
@@ -134,22 +135,22 @@ public class JNDIFactory implements Tran
return "jndi";
}
- public Connection getConnection(String helperName) throws SQLException, GenericEntityException {
- DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName);
+ public Connection getConnection(GenericHelperInfo helperInfo) throws SQLException, GenericEntityException {
+ DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperInfo.getHelperBaseName());
if (datasourceInfo.jndiJdbcElement != null) {
Element jndiJdbcElement = datasourceInfo.jndiJdbcElement;
String jndiName = jndiJdbcElement.getAttribute("jndi-name");
String jndiServerName = jndiJdbcElement.getAttribute("jndi-server-name");
Connection con = getJndiConnection(jndiName, jndiServerName);
- if (con != null) return TransactionFactory.getCursorConnection(helperName, con);
+ if (con != null) return TransactionFactory.getCursorConnection(helperInfo, con);
} else {
// Debug.logError("JNDI loaded is the configured transaction manager but no jndi-jdbc element was specified in the " + helperName + " datasource. Please check your configuration.", module);
}
if (datasourceInfo.inlineJdbcElement != null) {
- Connection otherCon = ConnectionFactory.getManagedConnection(helperName, datasourceInfo.inlineJdbcElement);
- return TransactionFactory.getCursorConnection(helperName, otherCon);
+ Connection otherCon = ConnectionFactory.getManagedConnection(helperInfo, datasourceInfo.inlineJdbcElement);
+ return TransactionFactory.getCursorConnection(helperInfo, otherCon);
} else {
//no real need to print an error here
return null;
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionFactory.java?rev=927271&r1=927270&r2=927271&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionFactory.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionFactory.java Thu Mar 25 04:42:26 2010
@@ -28,6 +28,7 @@ import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.config.DatasourceInfo;
import org.ofbiz.entity.config.EntityConfigUtil;
+import org.ofbiz.entity.datasource.GenericHelperInfo;
import org.ofbiz.entity.jdbc.CursorConnection;
/**
@@ -92,25 +93,25 @@ public class TransactionFactory {
return getTransactionFactory().getTxMgrName();
}
- public static Connection getConnection(String helperName) throws SQLException, GenericEntityException {
- return getTransactionFactory().getConnection(helperName);
+ public static Connection getConnection(GenericHelperInfo helperInfo) throws SQLException, GenericEntityException {
+ return getTransactionFactory().getConnection(helperInfo);
}
public static void shutdown() {
getTransactionFactory().shutdown();
}
- public static Connection getCursorConnection(String helperName, Connection con) {
- DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName);
+ public static Connection getCursorConnection(GenericHelperInfo helperInfo, Connection con) {
+ DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperInfo.getHelperBaseName());
if (datasourceInfo == null) {
- Debug.logWarning("Could not find configuration for " + helperName + " datasource.", module);
+ Debug.logWarning("Could not find configuration for " + helperInfo.getHelperBaseName() + " datasource.", module);
return con;
} else if (datasourceInfo.useProxyCursor) {
try {
if (datasourceInfo.resultFetchSize > 1)
con = CursorConnection.newCursorConnection(con, datasourceInfo.cursorName, datasourceInfo.resultFetchSize);
} catch (Exception ex) {
- Debug.logWarning(ex, "Error creating the cursor connection proxy " + helperName + " datasource.", module);
+ Debug.logWarning(ex, "Error creating the cursor connection proxy " + helperInfo.getHelperBaseName() + " datasource.", module);
}
}
return con;
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionFactoryInterface.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionFactoryInterface.java?rev=927271&r1=927270&r2=927271&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionFactoryInterface.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionFactoryInterface.java Thu Mar 25 04:42:26 2010
@@ -24,6 +24,7 @@ import javax.transaction.TransactionMana
import javax.transaction.UserTransaction;
import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.datasource.GenericHelperInfo;
/**
* TransactionFactory - central source for JTA objects
@@ -36,7 +37,7 @@ public interface TransactionFactoryInter
public String getTxMgrName();
- public Connection getConnection(String helperName) throws SQLException, GenericEntityException;
+ public Connection getConnection(GenericHelperInfo helperInfo) throws SQLException, GenericEntityException;
public void shutdown();
}
Modified: ofbiz/trunk/framework/entityext/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/entitydef/entitymodel.xml?rev=927271&r1=927270&r2=927271&view=diff
==============================================================================
--- ofbiz/trunk/framework/entityext/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/framework/entityext/entitydef/entitymodel.xml Thu Mar 25 04:42:26 2010
@@ -34,6 +34,7 @@ under the License.
<!-- The modules in this file are as follows: -->
<!-- - org.ofbiz.entity.group -->
<!-- - org.ofbiz.entity.synchronization -->
+ <!-- - org.ofbiz.entity.tenant -->
<!-- ========================================================= -->
@@ -171,4 +172,3 @@ under the License.
<prim-key field="entitySyncRemoveId"/>
</entity>
</entitymodel>
-
Modified: ofbiz/trunk/framework/entityext/ofbiz-component.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/ofbiz-component.xml?rev=927271&r1=927270&r2=927271&view=diff
==============================================================================
--- ofbiz/trunk/framework/entityext/ofbiz-component.xml (original)
+++ ofbiz/trunk/framework/entityext/ofbiz-component.xml Thu Mar 25 04:42:26 2010
@@ -23,10 +23,13 @@ under the License.
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd">
<resource-loader name="main" type="component"/>
<classpath type="jar" location="build/lib/*"/>
+
<entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/>
+
<entity-resource type="data" reader-name="seed" loader="main" location="data/EntityExtTypeData.xml"/>
<entity-resource type="data" reader-name="seed-initial" loader="main" location="data/EntityScheduledServices.xml"/>
<entity-resource type="data" reader-name="seed" loader="main" location="data/EntityExtSecurityData.xml"/>
+
<service-resource type="model" loader="main" location="servicedef/services.xml"/>
<service-resource type="group" loader="main" location="servicedef/groups.xml"/>
</ofbiz-component>
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=927271&r1=927270&r2=927271&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 Thu Mar 25 04:42:26 2010
@@ -37,7 +37,9 @@ import org.ofbiz.base.util.UtilURL;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.DelegatorFactory;
+import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.datasource.GenericHelperInfo;
import org.ofbiz.entity.jdbc.DatabaseUtil;
import org.ofbiz.entity.model.ModelEntity;
import org.ofbiz.entity.util.EntityDataLoader;
@@ -225,19 +227,18 @@ public class EntityDataLoadContainer imp
String delegatorNameToUse = overrideDelegator != null ? overrideDelegator : delegatorName;
String groupNameToUse = overrideGroup != null ? overrideGroup : entityGroupName;
- Delegator delegator = null;
- delegator = DelegatorFactory.getDelegator(delegatorNameToUse);
+ Delegator delegator = DelegatorFactory.getDelegator(delegatorNameToUse);
if (delegator == null) {
throw new ContainerException("Invalid delegator name!");
}
- String helperName = delegator.getGroupHelperName(groupNameToUse);
- if (helperName == null) {
+ GenericHelperInfo helperInfo = delegator.getGroupHelperInfo(groupNameToUse);
+ if (helperInfo == null) {
throw new ContainerException("Unable to locate the datasource helper for the group [" + groupNameToUse + "]");
}
// get the database util object
- DatabaseUtil dbUtil = new DatabaseUtil(helperName);
+ DatabaseUtil dbUtil = new DatabaseUtil(helperInfo);
Map<String, ModelEntity> modelEntities;
try {
modelEntities = delegator.getModelEntityMapByGroup(groupNameToUse);
@@ -324,9 +325,9 @@ public class EntityDataLoadContainer imp
// get the reader name URLs first
List<URL> urlList = null;
if (readerNames != null) {
- urlList = EntityDataLoader.getUrlList(helperName, component, readerNames);
+ urlList = EntityDataLoader.getUrlList(helperInfo.getHelperBaseName(), component, readerNames);
} else if (!"none".equalsIgnoreCase(this.readers)) {
- urlList = EntityDataLoader.getUrlList(helperName, component);
+ urlList = EntityDataLoader.getUrlList(helperInfo.getHelperBaseName(), component);
}
// need a list if it is empty
@@ -379,7 +380,7 @@ public class EntityDataLoadContainer imp
for (URL dataUrl: urlList) {
try {
- int rowsChanged = EntityDataLoader.loadData(dataUrl, helperName, delegator, errorMessages, txTimeout, useDummyFks, maintainTxs, tryInserts);
+ int rowsChanged = EntityDataLoader.loadData(dataUrl, helperInfo.getHelperBaseName(), delegator, errorMessages, txTimeout, useDummyFks, maintainTxs, tryInserts);
totalRowsChanged += rowsChanged;
infoMessages.add(changedFormat.format(rowsChanged) + " of " + changedFormat.format(totalRowsChanged) + " from " + dataUrl.toExternalForm());
} catch (GenericEntityException e) {
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=927271&r1=927270&r2=927271&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 Thu Mar 25 04:42:26 2010
@@ -26,6 +26,7 @@ import org.ofbiz.security.Security;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.datasource.GenericHelperInfo;
import org.ofbiz.entity.jdbc.DatabaseUtil;
import org.ofbiz.entity.model.ModelEntity;
import org.ofbiz.entity.model.ModelField;
@@ -344,8 +345,8 @@ public class EntityDataServices {
if (fixSizes == null) fixSizes = Boolean.FALSE;
List<String> messages = FastList.newInstance();
- String helperName = delegator.getGroupHelperName(groupName);
- DatabaseUtil dbUtil = new DatabaseUtil(helperName);
+ GenericHelperInfo helperInfo = delegator.getGroupHelperInfo(groupName);
+ DatabaseUtil dbUtil = new DatabaseUtil(helperInfo);
Map<String, ModelEntity> modelEntities;
try {
modelEntities = delegator.getModelEntityMapByGroup(groupName);
Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/DelegatorEcaHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/DelegatorEcaHandler.java?rev=927271&r1=927270&r2=927271&view=diff
==============================================================================
--- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/DelegatorEcaHandler.java (original)
+++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/DelegatorEcaHandler.java Thu Mar 25 04:42:26 2010
@@ -51,7 +51,7 @@ public class DelegatorEcaHandler impleme
public void setDelegator(Delegator delegator) {
this.delegator = delegator;
this.delegatorName = delegator.getDelegatorName();
- this.entityEcaReaderName = EntityEcaUtil.getEntityEcaReaderName(delegator.getOriginalDelegatorName());
+ this.entityEcaReaderName = EntityEcaUtil.getEntityEcaReaderName(delegator.getDelegatorBaseName());
this.dctx = EntityServiceFactory.getDispatchContext(delegator);
//preload the cache
Modified: ofbiz/trunk/framework/geronimo/src/org/ofbiz/geronimo/GeronimoTransactionFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/geronimo/src/org/ofbiz/geronimo/GeronimoTransactionFactory.java?rev=927271&r1=927270&r2=927271&view=diff
==============================================================================
--- ofbiz/trunk/framework/geronimo/src/org/ofbiz/geronimo/GeronimoTransactionFactory.java (original)
+++ ofbiz/trunk/framework/geronimo/src/org/ofbiz/geronimo/GeronimoTransactionFactory.java Thu Mar 25 04:42:26 2010
@@ -34,6 +34,7 @@ import org.ofbiz.base.util.Debug;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.config.DatasourceInfo;
import org.ofbiz.entity.config.EntityConfigUtil;
+import org.ofbiz.entity.datasource.GenericHelperInfo;
import org.ofbiz.entity.jdbc.ConnectionFactory;
import org.ofbiz.entity.transaction.TransactionFactoryInterface;
@@ -76,13 +77,13 @@ public class GeronimoTransactionFactory
return "geronimo";
}
- public Connection getConnection(String helperName) throws SQLException, GenericEntityException {
- DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName);
+ public Connection getConnection(GenericHelperInfo helperInfo) throws SQLException, GenericEntityException {
+ DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperInfo.getHelperBaseName());
if (datasourceInfo != null && datasourceInfo.inlineJdbcElement != null) {
- return ConnectionFactory.getManagedConnection(helperName, datasourceInfo.inlineJdbcElement);
+ return ConnectionFactory.getManagedConnection(helperInfo, datasourceInfo.inlineJdbcElement);
} else {
- Debug.logError("Geronimo is the configured transaction manager but no inline-jdbc element was specified in the " + helperName + " datasource. Please check your configuration", module);
+ Debug.logError("Geronimo is the configured transaction manager but no inline-jdbc element was specified in the " + helperInfo.getHelperBaseName() + " datasource. Please check your configuration", module);
return null;
}
}
Modified: ofbiz/trunk/framework/security/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/security/entitydef/entitymodel.xml?rev=927271&r1=927270&r2=927271&view=diff
==============================================================================
--- ofbiz/trunk/framework/security/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/framework/security/entitydef/entitymodel.xml Thu Mar 25 04:42:26 2010
@@ -125,7 +125,7 @@ under the License.
<key-map field-name="userLoginId"/>
</relation>
</entity>
-
+
<!-- ========================================================= -->
<!-- org.ofbiz.security.securitygroup -->
<!-- ========================================================= -->
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/GenericDispatcher.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/GenericDispatcher.java?rev=927271&r1=927270&r2=927271&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/GenericDispatcher.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/GenericDispatcher.java Thu Mar 25 04:42:26 2010
@@ -52,6 +52,11 @@ public class GenericDispatcher extends G
dispatcherName = "default";
Debug.logWarning("Got a getGenericDispatcher call with a null dispatcherName, assuming default for the name.", module);
}
+
+ if (UtilValidate.isNotEmpty(delegator.getDelegatorTenantId())) {
+ dispatcherName += "#" + delegator.getDelegatorTenantId();
+ }
+
LocalDispatcher dispatcher = dispatcherCache.get(dispatcherName);
if (dispatcher == null) {
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java?rev=927271&r1=927270&r2=927271&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java Thu Mar 25 04:42:26 2010
@@ -77,6 +77,8 @@ public class PersistedServiceJob extends
this.storedDate = jobValue.getTimestamp("runTime");
this.runtime = storedDate.getTime();
this.maxRetry = jobValue.get("maxRetry") != null ? jobValue.getLong("maxRetry").longValue() : -1;
+
+ // Debug.logInfo("=============== New PersistedServiceJob, delegator from dctx is [" + dctx.getDelegator().getDelegatorName() + "] and delegator from jobValue is [" + jobValue.getDelegator().getDelegatorName() + "]", module);
}
@Override
@@ -316,7 +318,7 @@ public class PersistedServiceJob extends
GenericValue jobObj = delegator.findOne("JobSandbox", false, "jobId", getJobId());
if (jobObj == null) {
- throw new InvalidJobException("Job [" + getJobId() + "] came back null from datasource");
+ throw new InvalidJobException("Job [" + getJobId() + "] came back null from datasource from delegator " + delegator.getDelegatorName());
}
return jobObj;
} catch (GenericEntityException e) {
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=927271&r1=927270&r2=927271&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 Thu Mar 25 04:42:26 2010
@@ -31,6 +31,7 @@ import java.util.Map;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
@@ -104,13 +105,13 @@ public class ContextFilter implements Fi
// check the serverId
getServerId();
// initialize the delegator
- getDelegator();
+ getDelegator(config.getServletContext());
// initialize authorizer
getAuthz();
// initialize security
getSecurity();
// initialize the services dispatcher
- getDispatcher();
+ getDispatcher(config.getServletContext());
// this will speed up the initial sessionId generation
new java.security.SecureRandom().nextLong();
@@ -273,7 +274,7 @@ public class ContextFilter implements Fi
* @see javax.servlet.Filter#destroy()
*/
public void destroy() {
- getDispatcher().deregister();
+ getDispatcher(config.getServletContext()).deregister();
try {
destroyRmiContainer(); // used in Geronimo/WASCE to allow to deregister
} catch (ServletException e) {
@@ -282,57 +283,65 @@ public class ContextFilter implements Fi
config = null;
}
- protected LocalDispatcher getDispatcher() {
- LocalDispatcher dispatcher = (LocalDispatcher) config.getServletContext().getAttribute("dispatcher");
+ protected static LocalDispatcher getDispatcher(ServletContext servletContext) {
+ LocalDispatcher dispatcher = (LocalDispatcher) servletContext.getAttribute("dispatcher");
if (dispatcher == null) {
- Delegator delegator = getDelegator();
-
- if (delegator == null) {
- Debug.logError("[ContextFilter.init] ERROR: delegator not defined.", module);
- return null;
- }
- Collection<URL> readers = null;
- String readerFiles = config.getServletContext().getInitParameter("serviceReaderUrls");
+ Delegator delegator = getDelegator(servletContext);
+ dispatcher = makeWebappDispatcher(servletContext, delegator);
+ servletContext.setAttribute("dispatcher", dispatcher);
+ }
+ return dispatcher;
+ }
+
+ /** This method only sets up a dispatcher for the current webapp and passed in delegator, it does not save it to the ServletContext or anywhere else, just returns it */
+ public static LocalDispatcher makeWebappDispatcher(ServletContext servletContext, Delegator delegator) {
+ if (delegator == null) {
+ Debug.logError("[ContextFilter.init] ERROR: delegator not defined.", module);
+ return null;
+ }
+ Collection<URL> readers = null;
+ String readerFiles = servletContext.getInitParameter("serviceReaderUrls");
- if (readerFiles != null) {
- readers = FastList.newInstance();
- for (String name: StringUtil.split(readerFiles, ";")) {
- try {
- URL readerURL = config.getServletContext().getResource(name);
- if (readerURL != null) readers.add(readerURL);
- } catch (NullPointerException npe) {
- Debug.logInfo(npe, "[ContextFilter.init] ERROR: Null pointer exception thrown.", module);
- } catch (MalformedURLException e) {
- Debug.logError(e, "[ContextFilter.init] ERROR: cannot get URL from String.", module);
- }
+ if (readerFiles != null) {
+ readers = FastList.newInstance();
+ for (String name: StringUtil.split(readerFiles, ";")) {
+ try {
+ URL readerURL = servletContext.getResource(name);
+ if (readerURL != null) readers.add(readerURL);
+ } catch (NullPointerException npe) {
+ Debug.logInfo(npe, "[ContextFilter.init] ERROR: Null pointer exception thrown.", module);
+ } catch (MalformedURLException e) {
+ Debug.logError(e, "[ContextFilter.init] ERROR: cannot get URL from String.", module);
}
}
- // get the unique name of this dispatcher
- String dispatcherName = config.getServletContext().getInitParameter("localDispatcherName");
+ }
+ // get the unique name of this dispatcher
+ String dispatcherName = servletContext.getInitParameter("localDispatcherName");
- if (dispatcherName == null) {
- Debug.logError("No localDispatcherName specified in the web.xml file", module);
- }
- dispatcher = GenericDispatcher.getLocalDispatcher(dispatcherName, delegator, readers, null);
- config.getServletContext().setAttribute("dispatcher", dispatcher);
- if (dispatcher == null) {
- Debug.logError("[ContextFilter.init] ERROR: dispatcher could not be initialized.", module);
- }
+ if (dispatcherName == null) {
+ Debug.logError("No localDispatcherName specified in the web.xml file", module);
+ dispatcherName = delegator.getDelegatorName();
+ }
+
+ LocalDispatcher dispatcher = GenericDispatcher.getLocalDispatcher(dispatcherName, delegator, readers, null);
+ if (dispatcher == null) {
+ Debug.logError("[ContextFilter.init] ERROR: dispatcher could not be initialized.", module);
}
+
return dispatcher;
}
- protected Delegator getDelegator() {
- Delegator delegator = (Delegator) config.getServletContext().getAttribute("delegator");
+ protected static Delegator getDelegator(ServletContext servletContext) {
+ Delegator delegator = (Delegator) servletContext.getAttribute("delegator");
if (delegator == null) {
- String delegatorName = config.getServletContext().getInitParameter("entityDelegatorName");
+ String delegatorName = servletContext.getInitParameter("entityDelegatorName");
if (delegatorName == null || delegatorName.length() <= 0) {
delegatorName = "default";
}
if (Debug.verboseOn()) Debug.logVerbose("Setup Entity Engine Delegator with name " + delegatorName, module);
delegator = DelegatorFactory.getDelegator(delegatorName);
- config.getServletContext().setAttribute("delegator", delegator);
+ servletContext.setAttribute("delegator", delegator);
if (delegator == null) {
Debug.logError("[ContextFilter.init] ERROR: delegator factory returned null for delegatorName \"" + delegatorName + "\"", module);
}
Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java?rev=927271&r1=927270&r2=927271&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java Thu Mar 25 04:42:26 2010
@@ -45,7 +45,10 @@ import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.transaction.GenericTransactionException;
import org.ofbiz.entity.transaction.TransactionUtil;
import org.ofbiz.security.Security;
+import org.ofbiz.security.SecurityConfigurationException;
+import org.ofbiz.security.SecurityFactory;
import org.ofbiz.security.authz.Authorization;
+import org.ofbiz.security.authz.AuthorizationFactory;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.webapp.stats.ServerHitBin;
import org.ofbiz.webapp.stats.VisitHandler;
@@ -315,7 +318,7 @@ public class ControlServlet extends Http
UtilHttp.setInitialRequestInfo(request);
VisitHandler.getVisitor(request, response);
if (requestHandler.trackStats(request)) {
- ServerHitBin.countRequest(webappName + "." + rname, request, requestStartTime, System.currentTimeMillis() - requestStartTime, userLogin, delegator);
+ ServerHitBin.countRequest(webappName + "." + rname, request, requestStartTime, System.currentTimeMillis() - requestStartTime, userLogin);
}
} catch (Throwable t) {
Debug.logError(t, "Error in ControlServlet saving ServerHit/Bin information; the output was successful, but can't save this tracking information. The error was: " + t.toString(), module);
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=927271&r1=927270&r2=927271&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 Thu Mar 25 04:42:26 2010
@@ -50,6 +50,7 @@ import org.ofbiz.base.util.UtilPropertie
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.StringUtil.StringWrapper;
import org.ofbiz.entity.Delegator;
+import org.ofbiz.entity.DelegatorFactory;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.condition.EntityCondition;
@@ -60,7 +61,10 @@ import org.ofbiz.entity.serialize.XmlSer
import org.ofbiz.entity.transaction.GenericTransactionException;
import org.ofbiz.entity.transaction.TransactionUtil;
import org.ofbiz.security.Security;
+import org.ofbiz.security.SecurityConfigurationException;
+import org.ofbiz.security.SecurityFactory;
import org.ofbiz.security.authz.Authorization;
+import org.ofbiz.security.authz.AuthorizationFactory;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.service.ModelService;
@@ -226,7 +230,7 @@ public class LoginWorker {
if (userLogin != null) {
if (!hasBasePermission(userLogin, request) || isFlaggedLoggedOut(userLogin)) {
Debug.logInfo("User does not have permission or is flagged as logged out", module);
- doBasicLogout(userLogin, request);
+ doBasicLogout(userLogin, request, response);
userLogin = null;
// have to reget this because the old session object will be invalid
@@ -315,20 +319,76 @@ public class LoginWorker {
request.setAttribute("_ERROR_MESSAGE_LIST_", unpwErrMsgList);
return "error";
}
+
+ boolean setupNewDelegatorEtc = false;
+
+ LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
+ Delegator delegator = (Delegator) request.getAttribute("delegator");
- String requirePasswordChange = request.getParameter("requirePasswordChange");
-
- // get the visit id to pass to the userLogin for history
- String visitId = VisitHandler.getVisitId(session);
+ // if a tenantId was passed in, see if the userLoginId is associated with that tenantId (can use any delegator for this, entity is not tenant-specific)
+ String tenantId = request.getParameter("tenantId");
+ if (UtilValidate.isNotEmpty(tenantId)) {
+ // see if we need to activate a tenant delegator, only do if the current delegatorName has a hash symbol in it, and if the passed in tenantId doesn't match the one in the delegatorName
+ String oldDelegatorName = delegator.getDelegatorName();
+ int delegatorNameHashIndex = oldDelegatorName.indexOf('#');
+ String currentDelegatorTenantId = null;
+ if (delegatorNameHashIndex > 0) {
+ currentDelegatorTenantId = oldDelegatorName.substring(delegatorNameHashIndex + 1);
+ }
+
+ if (delegatorNameHashIndex == -1 || (currentDelegatorTenantId != null && !tenantId.equals(currentDelegatorTenantId))) {
+ /* don't require this, allow a user to authenticate inside the tenant as long as the userLoginId and
+ * password match what is in that tenant's database; instead just set things up below
+ try {
+ List<GenericValue> tenantUserLoginList = delegator.findList("TenantUserLogin", EntityCondition.makeCondition(EntityOperator.AND, "tenantId", tenantId, "userLoginId", username), null, null, null, false);
+ if (tenantUserLoginList != null && tenantUserLoginList.size() > 0) {
+ ServletContext servletContext = session.getServletContext();
+
+ // if so make that tenant active, setup a new delegator and a new dispatcher
+ String delegatorName = delegator.getDelegatorName() + "#" + tenantId;
+
+ // after this line the delegator is replaced with the new per-tenant delegator
+ delegator = DelegatorFactory.getDelegator(delegatorName);
+ dispatcher = ContextFilter.makeWebappDispatcher(servletContext, delegator);
+
+ // NOTE: these will be local for now and set in the request and session later, after we've verified that the user
+ setupNewDelegatorEtc = true;
+ } else {
+ // not associated with this tenant, can't login
+ String errMsg = UtilProperties.getMessage(resourceWebapp, "loginevents.unable_to_login_tenant", UtilHttp.getLocale(request));
+ request.setAttribute("_ERROR_MESSAGE_", errMsg);
+ return "error";
+ }
+ } catch (GenericEntityException e) {
+ String errMsg = "Error checking TenantUserLogin: " + e.toString();
+ Debug.logError(e, errMsg, module);
+ request.setAttribute("_ERROR_MESSAGE_", errMsg);
+ return "error";
+ }
+ */
- LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
- Map<String, Object> result = null;
- if (UtilValidate.isNotEmpty(requirePasswordChange) && "Y".equals(requirePasswordChange)) {
+ ServletContext servletContext = session.getServletContext();
+
+ // make that tenant active, setup a new delegator and a new dispatcher
+ String delegatorName = delegator.getDelegatorName() + "#" + tenantId;
+
+ // after this line the delegator is replaced with the new per-tenant delegator
+ delegator = DelegatorFactory.getDelegator(delegatorName);
+ dispatcher = ContextFilter.makeWebappDispatcher(servletContext, delegator);
+
+ // NOTE: these will be local for now and set in the request and session later, after we've verified that the user
+ setupNewDelegatorEtc = true;
+ }
+ }
+
+ String requirePasswordChange = request.getParameter("requirePasswordChange");
+ if ("Y".equals(requirePasswordChange)) {
Map<String, Object> inMap = UtilMisc.<String, Object>toMap("login.username", username, "login.password", password, "locale", UtilHttp.getLocale(request));
inMap.put("userLoginId", username);
inMap.put("currentPassword", password);
inMap.put("newPassword", request.getParameter("newPassword"));
inMap.put("newPasswordVerify", request.getParameter("newPasswordVerify"));
+ Map<String, Object> result = null;
try {
result = dispatcher.runSync("updatePassword", inMap);
} catch (GenericServiceException e) {
@@ -352,7 +412,10 @@ public class LoginWorker {
}
}
+ Map<String, Object> result = null;
try {
+ // get the visit id to pass to the userLogin for history
+ String visitId = VisitHandler.getVisitId(session);
result = dispatcher.runSync("userLogin", UtilMisc.toMap("login.username", username, "login.password", password, "visitId", visitId, "locale", UtilHttp.getLocale(request)));
} catch (GenericServiceException e) {
Debug.logError(e, "Error calling userLogin service", module);
@@ -363,11 +426,19 @@ public class LoginWorker {
}
if (ModelService.RESPOND_SUCCESS.equals(result.get(ModelService.RESPONSE_MESSAGE))) {
+ if (setupNewDelegatorEtc) {
+ // now set the delegator and dispatcher in a bunch of places just in case they were changed
+ setWebContextObjects(request, response, delegator, dispatcher);
+ }
+
+ // check to see if a password change is required for the user
GenericValue userLogin = (GenericValue) result.get("userLogin");
Map<String, Object> userLoginSession = checkMap(result.get("userLoginSession"), String.class, Object.class);
if (userLogin != null && "Y".equals(userLogin.getString("requirePasswordChange"))) {
return "requirePasswordChange";
}
+
+ // check on JavaScriptEnabled
String javaScriptEnabled = "N";
if ("Y".equals(request.getParameter("JavaScriptEnabled"))) {
javaScriptEnabled = "Y";
@@ -377,6 +448,8 @@ public class LoginWorker {
} catch (GenericServiceException e) {
Debug.logError(e, "Error setting user preference", module);
}
+
+ // finally do the main login routine to set everything else up in the session, etc
return doMainLogin(request, response, userLogin, userLoginSession);
} else {
Map<String, String> messageMap = UtilMisc.toMap("errorMessage", (String) result.get(ModelService.ERROR_MESSAGE));
@@ -385,6 +458,42 @@ public class LoginWorker {
return "error";
}
}
+
+ private static void setWebContextObjects(HttpServletRequest request, HttpServletResponse response, Delegator delegator, LocalDispatcher dispatcher) {
+ HttpSession session = request.getSession();
+
+ // NOTE: we do NOT want to set this in the servletContet, only in the request and session
+ session.setAttribute("delegatorName", delegator.getDelegatorName());
+
+ request.setAttribute("delegator", delegator);
+ session.setAttribute("delegator", delegator);
+
+ request.setAttribute("dispatcher", dispatcher);
+ session.setAttribute("dispatcher", dispatcher);
+
+ // we also need to setup the security and authz objects since they are dependent on the delegator
+ try {
+ Security security = SecurityFactory.getInstance(delegator);
+ request.setAttribute("security", security);
+ session.setAttribute("security", security);
+ } catch (SecurityConfigurationException e) {
+ Debug.logError(e, module);
+ }
+
+ try {
+ Authorization authz = AuthorizationFactory.getInstance(delegator);
+ request.setAttribute("authz", authz);
+ session.setAttribute("authz", authz);
+ } catch (SecurityConfigurationException e) {
+ Debug.logError(e, module);
+ }
+
+ // get rid of the visit info since it was pointing to the previous database, and get a new one
+ session.removeAttribute("visitor");
+ session.removeAttribute("visit");
+ VisitHandler.getVisitor(request, response);
+ VisitHandler.getVisit(session);
+ }
public static String doMainLogin(HttpServletRequest request, HttpServletResponse response, GenericValue userLogin, Map<String, Object> userLoginSession) {
HttpSession session = request.getSession();
@@ -458,7 +567,7 @@ public class LoginWorker {
// invalidate the security group list cache
GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
- doBasicLogout(userLogin, request);
+ doBasicLogout(userLogin, request, response);
if (request.getAttribute("_AUTO_LOGIN_LOGOUT_") == null) {
return autoLoginCheck(request, response);
@@ -466,7 +575,7 @@ public class LoginWorker {
return "success";
}
- public static void doBasicLogout(GenericValue userLogin, HttpServletRequest request) {
+ public static void doBasicLogout(GenericValue userLogin, HttpServletRequest request, HttpServletResponse response) {
HttpSession session = request.getSession();
Delegator delegator = (Delegator) request.getAttribute("delegator");
@@ -487,11 +596,32 @@ public class LoginWorker {
// DON'T save the cart, causes too many problems: security issues with things done in cart to easy to miss, especially bad on public systems; was put in here because of the "not me" link for auto-login stuff, but that is a small problem compared to what it causes
//ShoppingCart shoppingCart = (ShoppingCart) session.getAttribute("shoppingCart");
+ // clean up some request attributes to which may no longer be valid now that user has logged out
+ request.removeAttribute("delegator");
+ request.removeAttribute("dispatcher");
+ request.removeAttribute("security");
+ request.removeAttribute("authz");
+
+ // now empty out the session
session.invalidate();
session = request.getSession(true);
+ // setup some things that should always be there
+ UtilHttp.setInitialRequestInfo(request);
+
if (currCatalog != null) session.setAttribute("CURRENT_CATALOG_ID", currCatalog);
- if (delegatorName != null) session.setAttribute("delegatorName", delegatorName);
+ 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);
+ LocalDispatcher dispatcher = ContextFilter.makeWebappDispatcher(session.getServletContext(), delegator);
+ setWebContextObjects(request, response, delegator, dispatcher);
+ }
+
// DON'T save the cart, causes too many problems: if (shoppingCart != null) session.setAttribute("shoppingCart", new WebShoppingCart(shoppingCart, session));
}
Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java?rev=927271&r1=927270&r2=927271&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java Thu Mar 25 04:42:26 2010
@@ -385,7 +385,7 @@ public class RequestHandler {
// save the server hit for the request event
if (this.trackStats(request)) {
ServerHitBin.countEvent(cname + "." + requestMap.event.invoke, request, eventStartTime,
- System.currentTimeMillis() - eventStartTime, userLogin, delegator);
+ System.currentTimeMillis() - eventStartTime, userLogin);
}
// set the default event return
@@ -855,7 +855,7 @@ public class RequestHandler {
if (this.trackStats(req) && vname != null) {
ServerHitBin.countView(cname + "." + vname, req, viewStartTime,
- System.currentTimeMillis() - viewStartTime, userLogin, delegator);
+ System.currentTimeMillis() - viewStartTime, userLogin);
}
}
Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/ServerHitBin.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/ServerHitBin.java?rev=927271&r1=927270&r2=927271&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/ServerHitBin.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/ServerHitBin.java Thu Mar 25 04:42:26 2010
@@ -20,7 +20,6 @@ package org.ofbiz.webapp.stats;
import java.net.InetAddress;
import java.util.Date;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -59,36 +58,30 @@ public class ServerHitBin {
public static final String[] typeNames = {"", "Request", "Event", "View", "Entity", "Service"};
public static final String[] typeIds = {"", "REQUEST", "EVENT", "VIEW", "ENTITY", "SERVICE"};
- public static void countRequest(String id, HttpServletRequest request, long startTime, long runningTime, GenericValue userLogin,
- Delegator delegator) {
- countHit(id, REQUEST, request, startTime, runningTime, userLogin, delegator);
+ public static void countRequest(String id, HttpServletRequest request, long startTime, long runningTime, GenericValue userLogin) {
+ countHit(id, REQUEST, request, startTime, runningTime, userLogin);
}
- public static void countEvent(String id, HttpServletRequest request, long startTime, long runningTime, GenericValue userLogin,
- Delegator delegator) {
- countHit(id, EVENT, request, startTime, runningTime, userLogin, delegator);
+ public static void countEvent(String id, HttpServletRequest request, long startTime, long runningTime, GenericValue userLogin) {
+ countHit(id, EVENT, request, startTime, runningTime, userLogin);
}
- public static void countView(String id, HttpServletRequest request, long startTime, long runningTime, GenericValue userLogin,
- Delegator delegator) {
- countHit(id, VIEW, request, startTime, runningTime, userLogin, delegator);
+ public static void countView(String id, HttpServletRequest request, long startTime, long runningTime, GenericValue userLogin) {
+ countHit(id, VIEW, request, startTime, runningTime, userLogin);
}
- public static void countEntity(String id, HttpServletRequest request, long startTime, long runningTime, GenericValue userLogin,
- Delegator delegator) {
- countHit(id, ENTITY, request, startTime, runningTime, userLogin, delegator);
+ public static void countEntity(String id, HttpServletRequest request, long startTime, long runningTime, GenericValue userLogin) {
+ countHit(id, ENTITY, request, startTime, runningTime, userLogin);
}
- public static void countService(String id, HttpServletRequest request, long startTime, long runningTime, GenericValue userLogin,
- Delegator delegator) {
- countHit(id, SERVICE, request, startTime, runningTime, userLogin, delegator);
+ public static void countService(String id, HttpServletRequest request, long startTime, long runningTime, GenericValue userLogin) {
+ countHit(id, SERVICE, request, startTime, runningTime, userLogin);
}
- public static void countHit(String id, int type, HttpServletRequest request, long startTime, long runningTime, GenericValue userLogin,
- Delegator delegator) {
+ public static void countHit(String id, int type, HttpServletRequest request, long startTime, long runningTime, GenericValue userLogin) {
// only count hits if enabled, if not specified defaults to false
if (!"true".equals(UtilProperties.getPropertyValue("serverstats", "stats.enable." + typeIds[type]))) return;
- countHit(id, type, request, startTime, runningTime, userLogin, delegator, true);
+ countHit(id, type, request, startTime, runningTime, userLogin, true);
}
public static void advanceAllBins(long toTime) {
@@ -108,12 +101,26 @@ public class ServerHitBin {
}
}
}
+
+ private static String makeIdTenantAware(String id, Delegator delegator) {
+ if (UtilValidate.isNotEmpty(delegator.getDelegatorTenantId())) {
+ return id + "#" + delegator.getDelegatorTenantId();
+ } else {
+ return id;
+ }
+ }
- protected static void countHit(String id, int type, HttpServletRequest request, long startTime, long runningTime, GenericValue userLogin,
- Delegator delegator, boolean isOriginal) {
+ protected static void countHit(String baseId, int type, HttpServletRequest request, long startTime, long runningTime, GenericValue userLogin, boolean isOriginal) {
+ String delegatorName = (String) request.getSession().getAttribute("delegatorName");
+ Delegator delegator = null;
+ if (UtilValidate.isNotEmpty(delegatorName)) {
+ delegator = DelegatorFactory.getDelegator(delegatorName);
+ }
if (delegator == null) {
- throw new IllegalArgumentException("The delegator passed to countHit cannot be null");
+ throw new IllegalArgumentException("In countHit could not find a delegator or delegatorName to work from");
}
+
+ String id = makeIdTenantAware(baseId, delegator);
ServerHitBin bin = null;
List<ServerHitBin> binList = null;
@@ -206,29 +213,35 @@ public class ServerHitBin {
}
bin.addHit(startTime, runningTime);
- if (isOriginal && !"GLOBAL".equals(id)) {
- bin.saveHit(request, startTime, runningTime, userLogin);
+ if (isOriginal && !id.startsWith("GLOBAL")) {
+ try {
+ bin.saveHit(request, startTime, runningTime, userLogin);
+ } catch (GenericEntityException e) {
+ Debug.logWarning(e, "Error saving ServerHit: " + e.toString(), module);
+ }
}
// count since start global and per id hits
- if (!"GLOBAL".equals(id))
+ if (!id.startsWith("GLOBAL"))
countHitSinceStart(id, type, startTime, runningTime, isOriginal, delegator);
// also count hits up the hierarchy if the id contains a '.'
if (id.indexOf('.') > 0) {
- countHit(id.substring(0, id.lastIndexOf('.')), type, request, startTime, runningTime, userLogin, delegator, false);
+ countHit(id.substring(0, id.lastIndexOf('.')), type, request, startTime, runningTime, userLogin, false);
}
- if (isOriginal && !"GLOBAL".equals(id))
- countHit("GLOBAL", type, request, startTime, runningTime, userLogin, delegator, true);
+ if (isOriginal && !id.startsWith("GLOBAL"))
+ countHit("GLOBAL", type, request, startTime, runningTime, userLogin, true);
}
- static void countHitSinceStart(String id, int type, long startTime, long runningTime, boolean isOriginal,
+ static void countHitSinceStart(String baseId, int type, long startTime, long runningTime, boolean isOriginal,
Delegator delegator) {
if (delegator == null) {
throw new IllegalArgumentException("The delegator passed to countHitSinceStart cannot be null");
}
+ String id = makeIdTenantAware(baseId, delegator);
+
ServerHitBin bin = null;
// save in global, and try to get bin by id
@@ -584,7 +597,7 @@ public class ServerHitBin {
}
}
- void saveHit(HttpServletRequest request, long startTime, long runningTime, GenericValue userLogin) {
+ void saveHit(HttpServletRequest request, long startTime, long runningTime, GenericValue userLogin) throws GenericEntityException {
// persist record of hit in ServerHit entity if option turned on
if (UtilProperties.propertyValueEqualsIgnoreCase("serverstats", "stats.persist." + ServerHitBin.typeIds[type] + ".hit", "true")) {
// if the hit type is ENTITY and the name contains "ServerHit" don't
@@ -596,24 +609,42 @@ public class ServerHitBin {
// check for type data before running.
GenericValue serverHitType = null;
- try {
- serverHitType = delegator.findByPrimaryKeyCache("ServerHitType", UtilMisc.toMap("hitTypeId", ServerHitBin.typeIds[this.type]));
- } catch (GenericEntityException e) {
- Debug.logError(e, module);
- }
+ serverHitType = delegator.findByPrimaryKeyCache("ServerHitType", UtilMisc.toMap("hitTypeId", ServerHitBin.typeIds[this.type]));
if (serverHitType == null) {
// datamodel data not loaded; not storing hit.
Debug.logWarning("The datamodel data has not been loaded; cannot find hitTypeId '" + ServerHitBin.typeIds[this.type] + " not storing ServerHit.", module);
return;
}
- String visitId = VisitHandler.getVisitId(request.getSession());
-
- if (UtilValidate.isEmpty(visitId)) {
+ GenericValue visit = VisitHandler.getVisit(request.getSession());
+ if (visit == null) {
// no visit info stored, so don't store the ServerHit
Debug.logWarning("Could not find a visitId, so not storing ServerHit. This is probably a configuration error. If you turn of persistance of visits you should also turn off persistence of hits.", module);
return;
}
+ String visitId = visit.getString("visitId");
+
+ Debug.logInfo("Visit delegatorName=" + visit.getDelegator().getDelegatorName() + ", ServerHitBin delegatorName=" + this.delegator.getDelegatorName(), module);
+
+ /* this isn't needed, the problem was better solved elsewhere, and without adding another query; leaving it here because it might be useful for something in the future
+ * else {
+ try {
+ // see if the error was caused by a bad visitId, and if so create a new visit and try again
+ GenericValue freshVisit = delegator.findOne("Visit", false, "visitId", visitId);
+ if (freshVisit == null) {
+ Debug.logInfo("Visit with ID [" + visitId + "] does not exist in the database, removing from session and making a new one", module);
+ // something happened, have a bad visit in the session so remove it and try again
+ request.getSession().removeAttribute("visit");
+ visitId = VisitHandler.getVisitId(request.getSession());
+ Debug.logInfo("After making new Visit the ID is [" + visitId + "]", module);
+ }
+ } catch (GenericEntityException e) {
+ // this is an error on the retry and not part of the main flow, so log it and let it go
+ Debug.logWarning(e, "Error retrying ServerHit: " + e.toString(), module);
+ }
+
+ }
+ */
GenericValue serverHit = delegator.makeValue("ServerHit");
@@ -667,11 +698,7 @@ public class ServerHitBin {
// every server hit even with equal startTimes but that could be
// solved adding a counter to the ServerHit's PK (a counter
// counting multiple hits at the same startTime).
- try {
- serverHit.create();
- } catch (GenericEntityException e) {
- Debug.logError(e, "Could not save ServerHit:", module);
- }
+ serverHit.create();
}
}
}
Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/VisitHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/VisitHandler.java?rev=927271&r1=927270&r2=927271&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/VisitHandler.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/VisitHandler.java Thu Mar 25 04:42:26 2010
@@ -149,7 +149,19 @@ public class VisitHandler {
// get the visitorId
GenericValue visitor = (GenericValue) session.getAttribute("visitor");
if (visitor != null) {
- visit.set("visitorId", visitor.get("visitorId"));
+ String visitorId = visitor.getString("visitorId");
+
+ // sometimes these values get stale, so check it before we use it
+ try {
+ GenericValue checkVisitor = delegator.findOne("Visitor", false, "visitorId", visitorId);
+ if (checkVisitor == null) {
+ GenericValue newVisitor = delegator.create("Visitor", "visitorId", visitorId);
+ session.setAttribute("visitor", visitor);
+ }
+ visit.set("visitorId", visitorId);
+ } catch (GenericEntityException e) {
+ Debug.logWarning("Problem checking the visitorId: " + e.toString(), module);
+ }
}
// get localhost ip address and hostname to store
Modified: ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityMaint.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityMaint.groovy?rev=927271&r1=927270&r2=927271&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityMaint.groovy (original)
+++ ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityMaint.groovy Thu Mar 25 04:42:26 2010
@@ -26,7 +26,7 @@ import org.ofbiz.entity.model.ModelEntit
import org.ofbiz.entity.model.ModelViewEntity;
mgr = delegator.getModelGroupReader();
-entityGroups = mgr.getGroupNames(delegator.getDelegatorName()).iterator();
+entityGroups = mgr.getGroupNames(delegator.getDelegatorBaseName()).iterator();
filterByGroupName = parameters.filterByGroupName;
context.filterByGroupName = filterByGroupName;
Propchange: ofbiz/trunk/specialpurpose/ebaystore/lib/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Mar 25 04:42:26 2010
@@ -1 +1,2 @@
/ofbiz/branches/addbirt/specialpurpose/ebay/lib:831210-885099,885686-886087
+/ofbiz/branches/multitenant20100310/specialpurpose/ebaystore/lib:921280-927264
Propchange: ofbiz/trunk/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/Facilities.groovy
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Mar 25 04:42:26 2010
@@ -0,0 +1,2 @@
+/incubator/ofbiz/trunk/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/Facilities.groovy:418499-490456
+/ofbiz/branches/multitenant20100310/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/Facilities.groovy:921280-927264
Propchange: ofbiz/trunk/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/ProductList.groovy
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Mar 25 04:42:26 2010
@@ -0,0 +1,2 @@
+/incubator/ofbiz/trunk/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/ProductList.groovy:418499-490456
+/ofbiz/branches/multitenant20100310/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/ProductList.groovy:921280-927264
Propchange: ofbiz/trunk/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/ProductStockTake.groovy
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Mar 25 04:42:26 2010
@@ -0,0 +1,2 @@
+/incubator/ofbiz/trunk/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/ProductStockTake.groovy:418499-490456
+/ofbiz/branches/multitenant20100310/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/ProductStockTake.groovy:921280-927264
Modified: ofbiz/trunk/specialpurpose/ldap/src/org/ofbiz/ldap/LdapLoginWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ldap/src/org/ofbiz/ldap/LdapLoginWorker.java?rev=927271&r1=927270&r2=927271&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ldap/src/org/ofbiz/ldap/LdapLoginWorker.java (original)
+++ ofbiz/trunk/specialpurpose/ldap/src/org/ofbiz/ldap/LdapLoginWorker.java Thu Mar 25 04:42:26 2010
@@ -96,7 +96,7 @@ public class LdapLoginWorker extends Log
if (!hasBasePermission(userLogin, request) || isFlaggedLoggedOut(userLogin) || hasLdapLoggedOut) {
Debug.logInfo("User does not have permission or is flagged as logged out", module);
- doBasicLogout(userLogin, request);
+ doBasicLogout(userLogin, request, response);
userLogin = null;
}
}
@@ -179,7 +179,7 @@ public class LdapLoginWorker extends Log
// invalidate the security group list cache
GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
- doBasicLogout(userLogin, request);
+ doBasicLogout(userLogin, request, response);
Element rootElement = getRootElement(request);