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 br...@apache.org on 2004/11/14 12:56:31 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/util/collections RemovalAwareVector.java AbstractListWrapper.java AbstractCollectionWrapper.java
brj 2004/11/14 03:56:31
Modified: src/java/org/apache/ojb/broker/util/collections
AbstractListWrapper.java
AbstractCollectionWrapper.java
Added: src/java/org/apache/ojb/broker/util/collections
RemovalAwareVector.java
Log:
protected default constructors
new RemovalAwareVector
Revision Changes Path
1.2 +4 -5 db-ojb/src/java/org/apache/ojb/broker/util/collections/AbstractListWrapper.java
Index: AbstractListWrapper.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/collections/AbstractListWrapper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractListWrapper.java 13 Nov 2004 10:08:16 -0000 1.1
+++ AbstractListWrapper.java 14 Nov 2004 11:56:31 -0000 1.2
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.ListIterator;
@@ -30,11 +29,11 @@
public abstract class AbstractListWrapper extends AbstractCollectionWrapper implements List
{
/**
- * Default Constructor. Wraps an ArrayList.
+ * Default Constructor.
*/
- public AbstractListWrapper()
+ protected AbstractListWrapper()
{
- this(new ArrayList());
+ super();
}
/**
1.2 +9 -2 db-ojb/src/java/org/apache/ojb/broker/util/collections/AbstractCollectionWrapper.java
Index: AbstractCollectionWrapper.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/collections/AbstractCollectionWrapper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractCollectionWrapper.java 13 Nov 2004 10:08:16 -0000 1.1
+++ AbstractCollectionWrapper.java 14 Nov 2004 11:56:31 -0000 1.2
@@ -30,11 +30,18 @@
private Collection m_collection;
/**
+ * Default Constructor.
+ */
+ protected AbstractCollectionWrapper()
+ {
+ super();
+ }
+
+ /**
* @param collection the wrapped Collection
*/
public AbstractCollectionWrapper(Collection collection)
{
- super();
if (collection == null)
{
throw new IllegalArgumentException("Collection must not be null");
1.1 db-ojb/src/java/org/apache/ojb/broker/util/collections/RemovalAwareVector.java
Index: RemovalAwareVector.java
===================================================================
package org.apache.ojb.broker.util.collections;
/* Copyright 2003-2004 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.
*/
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.PersistenceBrokerException;
import org.apache.ojb.broker.metadata.CollectionDescriptor;
import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
/**
* This is a collection that tracks removal and addition of elements.
* This tracking allow the PersistenceBroker to delete elements from
* the database that have been removed from the collection before a
* PB.store() orperation occurs.
* This will allow to use the PB api in way pretty close to ODMG persistent
* collections!
* @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
* @version $Id: RemovalAwareVector.java,v 1.1 2004/11/14 11:56:31 brj Exp $
*/
public class RemovalAwareVector extends ManageableVector implements IRemovalAwareCollection
{
private Collection allObjectsToBeRemoved = new ArrayList();
/**
* @see org.apache.ojb.broker.util.collections.IRemovalAwareCollection#afterStore(org.apache.ojb.broker.PersistenceBroker, org.apache.ojb.broker.metadata.CollectionDescriptor)
*/
public void afterStore(PersistenceBroker broker, CollectionDescriptor cod) throws PersistenceBrokerException
{
if (cod.getCascadingStore() != ObjectReferenceDescriptor.CASCADE_OBJECT)
{
return;
}
// make sure allObjectsToBeRemoved does not contain
// any instances that got re-added to the list
allObjectsToBeRemoved.removeAll(this);
Iterator iter = allObjectsToBeRemoved.iterator();
while (iter.hasNext())
{
// @todo: once a PB instance is available as a callback parameter we should use it!
broker.delete(iter.next());
}
allObjectsToBeRemoved.clear();
}
/**
* @see java.util.List#remove(int)
*/
public Object remove(int index)
{
Object toBeRemoved = super.remove(index);
registerForDeletion(toBeRemoved);
return toBeRemoved;
}
protected void registerForDeletion(Object toBeRemoved)
{
//only add objects once to avoid double deletions
if (!allObjectsToBeRemoved.contains(toBeRemoved))
{
this.allObjectsToBeRemoved.add(toBeRemoved);
}
}
/**
* @see java.util.Collection#remove(Object)
*/
public boolean remove(Object o)
{
boolean result = super.remove(o);
registerForDeletion(o);
return result;
}
/**
* @see java.util.Vector#removeAllElements()
*/
public synchronized void removeAllElements()
{
for (int i = 0; i < this.size(); i++)
{
registerForDeletion(this.get(i));
}
super.removeAllElements();
}
/**
* @see java.util.Vector#removeElementAt(int)
*/
public synchronized void removeElementAt(int index)
{
Object toBeDeleted = this.get(index);
registerForDeletion(toBeDeleted);
super.removeElementAt(index);
}
/**
* @see java.util.AbstractList#removeRange(int, int)
*/
protected void removeRange(int fromIndex, int toIndex)
{
for (int i = fromIndex; i < toIndex; i++)
{
registerForDeletion(this.get(i));
}
super.removeRange(fromIndex, toIndex);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org