You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by mk...@apache.org on 2006/09/18 13:56:13 UTC
svn commit: r447380 -
/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/proxy/AbstractIndirectionHandler.java
Author: mkalen
Date: Mon Sep 18 04:56:13 2006
New Revision: 447380
URL: http://svn.apache.org/viewvc?view=rev&rev=447380
Log:
Allow dynamic proxies to work with multiple per-thread profiles. See http://mail-archives.apache.org/mod_mbox/db-ojb-dev/200410.mbox/%3c41615921.4000508@curalia.se%3e
Modified:
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/proxy/AbstractIndirectionHandler.java
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/proxy/AbstractIndirectionHandler.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/proxy/AbstractIndirectionHandler.java?view=diff&rev=447380&r1=447379&r2=447380
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/proxy/AbstractIndirectionHandler.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/proxy/AbstractIndirectionHandler.java Mon Sep 18 04:56:13 2006
@@ -1,6 +1,6 @@
package org.apache.ojb.broker.core.proxy;
-/* Copyright 2002-2005 The Apache Software Foundation
+/* Copyright 2002-2006 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +26,8 @@
import org.apache.ojb.broker.PersistenceBrokerFactory;
import org.apache.ojb.broker.PersistenceBrokerInternal;
import org.apache.ojb.broker.core.PersistenceBrokerThreadMapping;
+import org.apache.ojb.broker.metadata.MetadataException;
+import org.apache.ojb.broker.metadata.MetadataManager;
import org.apache.ojb.broker.util.logging.LoggerFactory;
/**
@@ -35,10 +37,15 @@
*/
public abstract class AbstractIndirectionHandler implements IndirectionHandler
{
- static final long serialVersionUID = -1993879565033755826L;
+
+ private static final long serialVersionUID = 2L;
/** The key for acquiring the above broker */
private PBKey _brokerKey;
+ /** Flag set when per-thread metadata profiles are in use. */
+ private boolean _perThreadDescriptorsEnabled;
+ /** Profile key used when lazy-loading with per-thread metadata profiles. */
+ private Object _profileKey;
/** The real subject which this is hidden by the proxy */
private Object _realSubject = null;
/** Represents the identity of the real subject. When the real subject is not
@@ -61,6 +68,25 @@
setIdentity(id);
}
+ /**
+ * Reactivates metadata profile used when creating proxy, if needed.
+ * Calls to this method should be guarded by checking
+ * {@link #_perThreadDescriptorsEnabled} since the profile never
+ * needs to be reloaded if not using pre-thread metadata changes.
+ */
+ protected void loadProfileIfNeeded()
+ {
+ final Object key = getProfileKey();
+ if (key != null)
+ {
+ final MetadataManager mm = MetadataManager.getInstance();
+ if (!key.equals(mm.getCurrentProfileKey()))
+ {
+ mm.loadProfile(key);
+ }
+ }
+ }
+
/**
* Returns the identity of the subject.
*
@@ -146,6 +172,9 @@
{
MaterializationListener listener;
+ if (_perThreadDescriptorsEnabled) {
+ loadProfileIfNeeded();
+ }
for (int idx = _listeners.size() - 1; idx >= 0; idx--)
{
listener = (MaterializationListener) _listeners.get(idx);
@@ -164,11 +193,13 @@
{
MaterializationListener listener;
+ if (_perThreadDescriptorsEnabled) {
+ loadProfileIfNeeded();
+ }
// listeners may remove themselves during the afterMaterialization
// callback.
// thus we must iterate through the listeners vector from back to
- // front
- // to avoid index problems.
+ // front to avoid index problems.
for (int idx = _listeners.size() - 1; idx >= 0; idx--)
{
listener = (MaterializationListener) _listeners.get(idx);
@@ -188,6 +219,11 @@
PersistenceBrokerInternal broker;
boolean needsClose = false;
+ if (_perThreadDescriptorsEnabled)
+ {
+ loadProfileIfNeeded();
+ }
+
if (getBrokerKey() == null)
{
/*
@@ -437,6 +473,26 @@
{
return new OJBSerializableProxy(getIdentity().getObjectsRealClass(), this);
}
+
+ /**
+ * Returns the metadata profile key used when creating this proxy.
+ *
+ * @return brokerKey The key of the broker
+ */
+ protected Object getProfileKey()
+ {
+ return _profileKey;
+ }
+
+ /**
+ * Sets the metadata profile key used when creating this proxy.
+ *
+ * @param profileKey the metadata profile key
+ */
+ public void setProfileKey(Object profileKey)
+ {
+ _profileKey = profileKey;
+ }
//===================================================================
// inner class
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org