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 2003/01/11 20:47:48 UTC

cvs commit: jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer ListProxy.java CollectionProxy.java

brj         2003/01/11 11:47:47

  Modified:    src/java/org/apache/ojb/broker/accesslayer
                        CollectionProxy.java
  Added:       src/java/org/apache/ojb/broker/accesslayer ListProxy.java
  Log:
  new ListProxy
  
  Revision  Changes    Path
  1.12      +4 -4      jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/CollectionProxy.java
  
  Index: CollectionProxy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/CollectionProxy.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- CollectionProxy.java	3 Nov 2002 22:13:20 -0000	1.11
  +++ CollectionProxy.java	11 Jan 2003 19:47:47 -0000	1.12
  @@ -123,7 +123,7 @@
   	/**
   	 * loads the data from the database, if count(*) returned > 0
   	 */
  -	protected void loadData() throws PersistenceBrokerException
  +	protected Collection loadData() throws PersistenceBrokerException
   	{
   		try
   		{
  @@ -132,7 +132,7 @@
   			{
   				result = (Collection)getBroker().getCollectionByQuery(getCollectionClass(),getQuery());
   			}
  -			setData(result);
  +			return result;
   		}
   		catch (Exception ex)
   		{
  @@ -338,7 +338,7 @@
   	{
   		if (!isLoaded())
   		{
  -			loadData();
  +			setData(loadData());
   		}	
   
   		return data;
  
  
  
  1.1                  jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/ListProxy.java
  
  Index: ListProxy.java
  ===================================================================
  package org.apache.ojb.broker.accesslayer;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.util.Collection;
  import java.util.List;
  import java.util.ListIterator;
  
  import org.apache.ojb.broker.PBKey;
  import org.apache.ojb.broker.PersistenceBrokerException;
  import org.apache.ojb.broker.query.Query;
  import org.apache.ojb.broker.util.collections.ManageableArrayList;
  
  /**
   * ListProxy. <br> A placeHolder for a whole list to support deferred loading of
   * relationships. The complete relationship is loaded on request.
   * 
   * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
   * @version $Id: ListProxy.java,v 1.1 2003/01/11 19:47:47 brj Exp $
   */
  public class ListProxy extends CollectionProxy implements List
  {
  
  	/**
  	 * Constructor for ListProxy.
  	 * @param aKey
  	 * @param aQuery
  	 */
  	public ListProxy(PBKey aKey, Query aQuery)
  	{
  		this(aKey, ManageableArrayList.class, aQuery);
  	}
  
  	/**
  	 * Constructor for ListProxy.
  	 * @param aKey
  	 * @param aCollClass
  	 * @param aQuery
  	 */
  	public ListProxy(PBKey aKey, Class aCollClass, Query aQuery)
  	{
  		super(aKey, aCollClass, aQuery);
  	}
  
  	/**
  	 * @see java.util.List#addAll(int, java.util.Collection)
  	 */
  	public boolean addAll(int index, Collection c)
  	{
  		return false;
  	}
  
  	/**
  	 * @see java.util.List#get(int)
  	 */
  	public Object get(int index)
  	{
  		return null;
  	}
  
  	/**
  	 * @see java.util.List#set(int, java.lang.Object)
  	 */
  	public Object set(int index, Object element)
  	{
  		return null;
  	}
  
  	/**
  	 * @see java.util.List#add(int, java.lang.Object)
  	 */
  	public void add(int index, Object element)
  	{
          getListData().add(index, element);
  	}
  
  	/**
  	 * @see java.util.List#remove(int)
  	 */
  	public Object remove(int index)
  	{
  		return getListData().remove(index);
  	}
  
  	/**
  	 * @see java.util.List#indexOf(java.lang.Object)
  	 */
  	public int indexOf(Object o)
  	{
  		return getListData().indexOf(o);
  	}
  
  	/**
  	 * @see java.util.List#lastIndexOf(java.lang.Object)
  	 */
  	public int lastIndexOf(Object o)
  	{
  		return getListData().lastIndexOf(o);
  	}
  
  	/**
  	 * @see java.util.List#listIterator()
  	 */
  	public ListIterator listIterator()
  	{
  		return getListData().listIterator();
  	}
  
  	/**
  	 * @see java.util.List#listIterator(int)
  	 */
  	public ListIterator listIterator(int index)
  	{
  		return getListData().listIterator(index);
  	}
  
  	/**
  	 * @see java.util.List#subList(int, int)
  	 */
  	public List subList(int fromIndex, int toIndex)
  	{
  		return getListData().subList(fromIndex, toIndex);
  	}
  
      protected List getListData()
      {
          return (List)super.getData();    
      }
      
  	/**
  	 * @see org.apache.ojb.broker.accesslayer.CollectionProxy#loadData()
  	 */
  	protected Collection loadData() throws PersistenceBrokerException
  	{
          Collection result = super.loadData();
  
          if (result instanceof List)
          {
              return result;
          }    
          else
          {
              throw new PersistenceBrokerException("loaded data is not a java.util.List");
          }
  		
  	}
  
  }