You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by oz...@apache.org on 2004/06/02 16:11:57 UTC
cvs commit: jakarta-commons-sandbox/transaction/src/java/org/apache/commons/transaction/memory HashMapFactory.java HashSetFactory.java TransactionalMapWrapper.java
ozeigermann 2004/06/02 07:11:57
Modified: transaction/src/java/org/apache/commons/transaction/memory
TransactionalMapWrapper.java
Added: transaction/src/java/org/apache/commons/transaction/memory
HashMapFactory.java HashSetFactory.java
Log:
Added default factory implementations and let map wrapper use them as default
Revision Changes Path
1.8 +15 -45 jakarta-commons-sandbox/transaction/src/java/org/apache/commons/transaction/memory/TransactionalMapWrapper.java
Index: TransactionalMapWrapper.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/transaction/src/java/org/apache/commons/transaction/memory/TransactionalMapWrapper.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TransactionalMapWrapper.java 2 Jun 2004 12:34:33 -0000 1.7
+++ TransactionalMapWrapper.java 2 Jun 2004 14:11:57 -0000 1.8
@@ -25,8 +25,6 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -52,8 +50,8 @@
protected ThreadLocal activeTx = new ThreadLocal();
- protected MapFactory mapFactory = null;
- protected SetFactory setFactory = null;
+ protected MapFactory mapFactory;
+ protected SetFactory setFactory;
/**
* Creates a new transactional map wrapper. Temporary maps and sets to store transactional
@@ -62,7 +60,7 @@
* @param wrapped map to be wrapped
*/
public TransactionalMapWrapper(Map wrapped) {
- this.wrapped = wrapped;
+ this(wrapped, new HashMapFactory(), new HashSetFactory());
}
/**
@@ -164,8 +162,8 @@
}
// simply forget about tx
- disposeMap(txContext.changes);
- disposeSet(txContext.deletes);
+ mapFactory.disposeMap(txContext.changes);
+ setFactory.disposeSet(txContext.deletes);
setActiveTx(null);
}
@@ -196,8 +194,8 @@
}
// now forget about tx
- disposeMap(txContext.changes);
- disposeSet(txContext.deletes);
+ mapFactory.disposeMap(txContext.changes);
+ setFactory.disposeSet(txContext.deletes);
setActiveTx(null);
}
@@ -310,7 +308,7 @@
if (txContext == null) {
return wrapped.entrySet();
} else {
- Set entrySet = createSet();
+ Set entrySet = setFactory.createSet();
Set keySet = keySet();
// XXX expensive :(
for (Iterator it = keySet.iterator(); it.hasNext();) {
@@ -329,7 +327,7 @@
if (txContext == null) {
return wrapped.keySet();
} else {
- Set keySet = (txContext.cleared ? createSet() : wrapped.keySet());
+ Set keySet = (txContext.cleared ? setFactory.createSet() : wrapped.keySet());
keySet.removeAll(txContext.deletes);
keySet.addAll(txContext.changes.keySet());
return keySet;
@@ -416,34 +414,6 @@
activeTx.set(txContext);
}
- protected Map createMap() {
- if (mapFactory != null) {
- return mapFactory.createMap();
- } else {
- return new HashMap();
- }
- }
-
- protected void disposeMap(Map map) {
- if (mapFactory != null) {
- mapFactory.disposeMap(map);
- }
- }
-
- protected Set createSet() {
- if (setFactory != null) {
- return setFactory.createSet();
- } else {
- return new HashSet();
- }
- }
-
- protected void disposeSet(Set set) {
- if (setFactory != null) {
- setFactory.disposeSet(set);
- }
- }
-
// mostly copied from org.apache.commons.collections.map.AbstractHashedMap
protected static class HashEntry implements Map.Entry {
/** The key */
@@ -500,8 +470,8 @@
protected boolean readOnly;
protected TxContext() {
- deletes = createSet();
- changes = createMap();
+ deletes = setFactory.createSet();
+ changes = mapFactory.createMap();
rollbackOnly = false;
status = Status.STATUS_ACTIVE;
cleared = false;
1.1 jakarta-commons-sandbox/transaction/src/java/org/apache/commons/transaction/memory/HashMapFactory.java
Index: HashMapFactory.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/transaction/src/java/org/apache/commons/transaction/memory/HashMapFactory.java,v 1.1 2004/06/02 14:11:57 ozeigermann Exp $
* $Revision: 1.1 $
* $Date: 2004/06/02 14:11:57 $
*
* ====================================================================
*
* Copyright 1999-2002 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.
* 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.apache.commons.transaction.memory;
import java.util.HashMap;
import java.util.Map;
/**
* Default map factory implementation creating {@link HashMap}s.
*
* @author <a href="mailto:ozeigermann@apache.org">Oliver Zeigermann</a>
* @version $Revision: 1.1 $
*/
public class HashMapFactory implements MapFactory {
public Map createMap() {
return new HashMap();
}
public void disposeMap(Map map) {
}
}
1.1 jakarta-commons-sandbox/transaction/src/java/org/apache/commons/transaction/memory/HashSetFactory.java
Index: HashSetFactory.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/transaction/src/java/org/apache/commons/transaction/memory/HashSetFactory.java,v 1.1 2004/06/02 14:11:57 ozeigermann Exp $
* $Revision: 1.1 $
* $Date: 2004/06/02 14:11:57 $
*
* ====================================================================
*
* Copyright 1999-2002 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.
* 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.apache.commons.transaction.memory;
import java.util.HashSet;
import java.util.Set;
/**
* Default set factory implementation creating {@link HashSet}s.
*
* @author <a href="mailto:ozeigermann@apache.org">Oliver Zeigermann</a>
* @version $Revision: 1.1 $
*/
public class HashSetFactory implements SetFactory {
public Set createSet() {
return new HashSet();
}
public void disposeSet(Set set) {
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org