Android Open Source - jepldroid J E P L Result Set D A O Impl






From Project

Back to project page jepldroid.

License

The source code is released under:

Apache License

If you think the Android project jepldroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
   Copyright 2011 Jose Maria Arranz Santamaria
//from w w  w .  j  ava2s.  com
   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 jepl.impl.query;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import jepl.JEPLException;
import jepl.JEPLResultSetDAO;
import jepl.JEPLResultSetDAOListener;
import jepl.impl.JEPLPreparedStatementImpl;

/**
 *
 * @author jmarranz
 */
public class JEPLResultSetDAOImpl<T> extends JEPLResultSetImpl implements JEPLResultSetDAO<T>
{
    protected JEPLResultSetDAOListener<T> listener;
    protected LinkedList<T> internalList = new LinkedList<T>();
    protected boolean constructedObject; // NO INICIAR A FALSE NI A TRUE
    protected boolean detectedDebugMode;  // NO INICIAR A FALSE NI A TRUE

    public JEPLResultSetDAOImpl(JEPLDAOQueryImpl<T> query,JEPLPreparedStatementImpl stmt,ResultSet result,JEPLResultSetDAOListener<T> listener) throws SQLException
    {
        super(query,stmt,result);
        this.listener = listener;
        this.constructedObject = true;
    }

    @SuppressWarnings("unchecked")
    public JEPLDAOQueryImpl<T> getJEPLDAOQueryImpl()
    {
        return (JEPLDAOQueryImpl<T>)query;
    }

    public LinkedList<T> getInternalList()
    {
        return internalList;
    }

    public boolean next()
    {
        if (isClosed()) throw new JEPLException("This result set is already closed, use normal List methods instead");
        boolean res;
        try
        {
            res = result.next();
        }
        catch (SQLException ex) { throw new JEPLException(ex); }

        if (!res)
        {
            close(); // Cerramos automticamente al terminar de iterar para que actue la coleccin interna desde ahora

            query.checkNumOfReturnedRows( count() ); // Por intentar usar la regla del usuario de limitacin de filas SIEMPRE (aunque tenga poco valor la verdad)
        }
        return res;
    }

    public T getObject()
    {
        if (isClosed()) throw new JEPLException("This result set is already closed, use normal List methods instead");

        try
        {
            T obj = listener.createObject(this);
            if (obj != null) // El ser null es como un "continue", til para filtrar objetos            
                listener.fillObject(obj,this);

            // En el caso de obj == null aadimos el null a la List interna pues si utilizramos el List
            // despus esperamos encontrarnos con lo mismo que hemos iterado
            internalList.add(obj);
            return obj;
        }
        catch (JEPLException ex)
        {
            throw ex;
        }
        catch (Exception ex)
        {
            throw new JEPLException(ex);
        }
    }

    public boolean isStopped()
    {
        throw new JEPLException("This call has no sense in this context");
    }

    public void stop()
    {
        throw new JEPLException("This call has no sense in this context");
    }

    public void checkResultSetNotClosed()
    {
        if (!isClosed()) throw new JEPLException("This method cannot be called when ResultSet is still open");
    }


    public void fetchToIndex(int index) // Mtodo interno
    {
        if (isClosed()) return;

        int size = internalList.size();
        int diff = size - 1 - index;
        if (diff >= 0) return;
        else
        {
            for(int i = 0; i < (-diff); i++)
            {
                next();
                getObject();
            }
        }
    }

    public void fetchToTheEndIfNotClosed() // Mtodo interno
    {
//checkResultSetNotClosed();

        if (isClosed()) return; // No hace falta
        while(next())
        {
            getObject();
        }
        // A la salida de este mtodo el ResultSet estar cerrado
    }

    public int count()
    {
        fetchToTheEndIfNotClosed();
        return internalList.size();
    }

    // Desde aqu mtodos implementacin de List
    public int size()
    {
        if (!constructedObject)
        {
            // Se ha llamado a size() antes de que se construta el objeto, esto es cosa del modo
            // debug en NetBeans que en el caso de un List muestra el size() de la coleccin
            // en el campo "Value of Variable"
            // Hay que tener en cuenta que pasamos por aqu antes de pasar por el constructor
            // y de definir los valores iniciales de los atributos (si hubiera que NO deben tener para no sobreescribir detectedDebugMode)
            this.detectedDebugMode = true;
        }

        if (detectedDebugMode && !isClosed())
        {
            JEPLException ex = new JEPLException("size() method cannot be called in debug mode and ResultSet not closed");
            ex.printStackTrace();
            throw ex;
        }

        return count();
    }

    public boolean isEmpty()
    {
        fetchToTheEndIfNotClosed();
        return internalList.isEmpty();
    }

    public boolean contains(Object o)
    {
        fetchToTheEndIfNotClosed();
        return internalList.contains(o);
    }

    public Iterator<T> iterator()
    {
        if (isClosed()) return internalList.iterator();
        else return new JEPLResultSetDAOIteratorImpl<T>(this);
    }

    public Object[] toArray()
    {
        fetchToTheEndIfNotClosed();
        return internalList.toArray();
    }

    public <U> U[] toArray(U[] a)
    {
        fetchToTheEndIfNotClosed();
        return internalList.toArray(a);
    }

    public boolean add(T e)
    {
        fetchToTheEndIfNotClosed();
        return internalList.add(e);
    }

    public boolean remove(Object o)
    {
        fetchToTheEndIfNotClosed();
        return internalList.remove(o);
    }

    public boolean containsAll(Collection<?> c)
    {
        fetchToTheEndIfNotClosed();
        return internalList.containsAll(c);
    }

    public boolean addAll(Collection<? extends T> c)
    {
        fetchToTheEndIfNotClosed();
        return internalList.addAll(c);
    }

    public boolean addAll(int index, Collection<? extends T> c)
    {
        fetchToTheEndIfNotClosed();
        return internalList.addAll(index,c);
    }

    public boolean removeAll(Collection<?> c)
    {
        fetchToTheEndIfNotClosed();
        return internalList.removeAll(c);
    }

    public boolean retainAll(Collection<?> c)
    {
        fetchToTheEndIfNotClosed();
        return internalList.retainAll(c);
    }

    public void clear()
    {
        fetchToTheEndIfNotClosed();
        internalList.clear();
    }

    
    public T get(int index)
    {
        fetchToIndex(index);
        return internalList.get(index);
    }

    public T set(int index, T element)
    {
        fetchToIndex(index);
        return internalList.set(index,element);
    }

    public void add(int index, T element)
    {
        fetchToTheEndIfNotClosed();
        internalList.add(index,element);
    }

    public T remove(int index)
    {
        fetchToTheEndIfNotClosed();
        return internalList.remove(index);
    }

    public int indexOf(Object o)
    {
        fetchToTheEndIfNotClosed();
        return internalList.indexOf(o);
    }

    public int lastIndexOf(Object o)
    {
        fetchToTheEndIfNotClosed();
        return internalList.lastIndexOf(o);
    }

    public ListIterator<T> listIterator()
    {
        if (isClosed()) return internalList.listIterator();
        else return new JEPLResultSetDAOIteratorImpl<T>(this);
    }

    public ListIterator<T> listIterator(int index)
    {
        if (isClosed()) return internalList.listIterator();
        else return new JEPLResultSetDAOIteratorImpl<T>(this,index);
    }

    public List<T> subList(int fromIndex, int toIndex)
    {
        fetchToIndex(fromIndex);
        fetchToIndex(toIndex);
        return internalList.subList(fromIndex,toIndex);
    }
}




Java Source Code List

com.innowhere.jepldroidtest.JEPLDroidTestActivity.java
jepl.JEPLBootNonJTA.java
jepl.JEPLBootRoot.java
jepl.JEPLBoot.java
jepl.JEPLCachedResultSet.java
jepl.JEPLConnectionListener.java
jepl.JEPLConnection.java
jepl.JEPLDALQuery.java
jepl.JEPLDAL.java
jepl.JEPLDAOQuery.java
jepl.JEPLDAO.java
jepl.JEPLDataSource.java
jepl.JEPLException.java
jepl.JEPLListener.java
jepl.JEPLNonJTADataSource.java
jepl.JEPLParameter.java
jepl.JEPLPreparedStatementListener.java
jepl.JEPLPreparedStatement.java
jepl.JEPLResultSetDALListener.java
jepl.JEPLResultSetDAOListenerDefault.java
jepl.JEPLResultSetDAOListener.java
jepl.JEPLResultSetDAO.java
jepl.JEPLResultSet.java
jepl.JEPLRowBeanMapper.java
jepl.JEPLStatement.java
jepl.JEPLTask.java
jepl.JEPLTransactionPropagation.java
jepl.JEPLTransaction.java
jepl.JEPLTransactionalJTA.java
jepl.JEPLTransactionalNonJTA.java
jepl.JEPLUserData.java
jepl.impl.JEPLBootImpl.java
jepl.impl.JEPLBootRootImpl.java
jepl.impl.JEPLConnectionImpl.java
jepl.impl.JEPLCurrentTransactionImpl.java
jepl.impl.JEPLDALDefaultImpl.java
jepl.impl.JEPLDALImpl.java
jepl.impl.JEPLDAOImpl.java
jepl.impl.JEPLDataSourceImpl.java
jepl.impl.JEPLListenerListImpl.java
jepl.impl.JEPLPreparedStatementDefaultImpl.java
jepl.impl.JEPLPreparedStatementImpl.java
jepl.impl.JEPLStatementImpl.java
jepl.impl.JEPLTaskExecContextImpl.java
jepl.impl.JEPLTaskExecContextInConnectionImpl.java
jepl.impl.JEPLTaskOneExecWithConnectionImpl.java
jepl.impl.JEPLTaskOneExecWithConnectionWrapperImpl.java
jepl.impl.JEPLTaskOneExecutionImpl.java
jepl.impl.JEPLTaskOneExecutionWrapperImpl.java
jepl.impl.JEPLUserDataMonoThreadImpl.java
jepl.impl.JEPLUserDataMultiThreadImpl.java
jepl.impl.JEPLUtilImpl.java
jepl.impl.lex.Cursor.java
jepl.impl.lex.Identifier.java
jepl.impl.lex.JDBCParamStandardToken.java
jepl.impl.lex.JDBCParamToken.java
jepl.impl.lex.JDBCParamWithNameToken.java
jepl.impl.lex.JDBCParamWithNumberToken.java
jepl.impl.lex.OtherCharToken.java
jepl.impl.lex.SourceCode.java
jepl.impl.lex.Space.java
jepl.impl.lex.StringDoubleQuote.java
jepl.impl.lex.StringLiteral.java
jepl.impl.lex.StringSimpleQuote.java
jepl.impl.lex.TestSourceCode.java
jepl.impl.lex.TokenFilter.java
jepl.impl.lex.Token.java
jepl.impl.nonjta.JEPLBootNonJTAImpl.java
jepl.impl.nonjta.JEPLCurrentTransactionNonJTAImpl.java
jepl.impl.nonjta.JEPLNonJTAConnectionDefaultImpl.java
jepl.impl.nonjta.JEPLNonJTAConnectionImpl.java
jepl.impl.nonjta.JEPLNonJTADataSourceDefaultImpl.java
jepl.impl.nonjta.JEPLNonJTADataSourceImpl.java
jepl.impl.nonjta.JEPLTaskExecContextInConnectionNonJTAImpl.java
jepl.impl.nonjta.android.JEPLNonJTAConnectionSQLDroidImpl.java
jepl.impl.nonjta.android.JEPLNonJTADataSourceAndroidImpl.java
jepl.impl.nonjta.android.JEPLPreparedStatementSQLDroidImpl.java
jepl.impl.query.JEPLCachedResultSetImpl.java
jepl.impl.query.JEPLDALQueryImpl.java
jepl.impl.query.JEPLDAOQueryImpl.java
jepl.impl.query.JEPLParameterDecImpl.java
jepl.impl.query.JEPLParameterDecWithNameImpl.java
jepl.impl.query.JEPLParameterDecWithNumberImpl.java
jepl.impl.query.JEPLParameterImpl.java
jepl.impl.query.JEPLParameterValueImpl.java
jepl.impl.query.JEPLParameterValueNamedImpl.java
jepl.impl.query.JEPLParameterWithNameImpl.java
jepl.impl.query.JEPLParameterWithNumberImpl.java
jepl.impl.query.JEPLPropertyDescriptorImpl.java
jepl.impl.query.JEPLPropertyDescriptorJavaBeansImpl.java
jepl.impl.query.JEPLQueryParsedCacheImpl.java
jepl.impl.query.JEPLQueryParsedImpl.java
jepl.impl.query.JEPLResultSetBeanInfo.java
jepl.impl.query.JEPLResultSetDAOImpl.java
jepl.impl.query.JEPLResultSetDAOIteratorImpl.java
jepl.impl.query.JEPLResultSetDAOListenerDefaultImpl.java
jepl.impl.query.JEPLResultSetDefaultImpl.java
jepl.impl.query.JEPLResultSetImpl.java