org.midao.jdbc.core.handlers.model
Class QueryParametersLazyList

java.lang.Object
  extended by org.midao.jdbc.core.handlers.model.QueryParametersLazyList
All Implemented Interfaces:
java.lang.Iterable<QueryParameters>, java.util.Collection<QueryParameters>, java.util.List<QueryParameters>

public class QueryParametersLazyList
extends java.lang.Object
implements java.util.List<QueryParameters>

Lazy query output list implementation. Is used to handle ResultSets returned from Query Execution. Currently amount of cache is unlimited. In order to make it more memory friendly - please specify it via Constructor.

It is recommended to use iterator() to iterate through this list in QueryParametersLazyList.Type.READ_ONLY_FORWARD mode (default mode). Also please be aware that first element it returns is not statement params, but actually first value from ResultSet.

By default get(int) returns null if no value was found by that index. In future exception might be thrown instead.

This is reference implementation and is under active development


Nested Class Summary
static class QueryParametersLazyList.Type
          Allowed types of Lazy query output list implementation
 
Constructor Summary
QueryParametersLazyList(java.sql.Statement stmt, TypeHandler typeHandler, boolean readGeneratedKeys)
          Creates new QueryParametersLazyList instance
QueryParametersLazyList(java.sql.Statement stmt, TypeHandler typeHandler, boolean readGeneratedKeys, int maxCacheSize)
          Creates new QueryParametersLazyList instance
QueryParametersLazyList(java.sql.Statement stmt, TypeHandler typeHandler, boolean readGeneratedKeys, QueryParametersLazyList.Type type, int maxCacheSize)
          Creates new QueryParametersLazyList instance
 
Method Summary
 void add(int index, QueryParameters element)
          Currently usage is not allowed.
 boolean add(QueryParameters queryParameters)
          Currently usage is not allowed.
 boolean addAll(java.util.Collection<? extends QueryParameters> c)
          Currently usage is not allowed.
 boolean addAll(int index, java.util.Collection<? extends QueryParameters> c)
          Currently usage is not allowed.
 void clear()
          Currently usage is not allowed.
 void close()
          Performs cleanup of all resources used by this lazy query output list implementation: Statement and ResultSet
 boolean contains(java.lang.Object o)
           
 boolean containsAll(java.util.Collection<?> c)
          Currently usage is not allowed.
 QueryParameters get(int index)
          Returns element at specified position.
 int indexOf(java.lang.Object o)
          Currently usage is not allowed.
 boolean isEmpty()
          Checks if cache list is empty
 java.util.Iterator<QueryParameters> iterator()
          Returns iterator of this lazy query output list implementation.
 int lastIndexOf(java.lang.Object o)
          Currently usage is not allowed.
 java.util.ListIterator<QueryParameters> listIterator()
          Currently usage is not allowed.
 java.util.ListIterator<QueryParameters> listIterator(int index)
          Currently usage is not allowed.
 QueryParameters remove(int index)
          Currently usage is not allowed.
 boolean remove(java.lang.Object o)
          Currently usage is not allowed.
 boolean removeAll(java.util.Collection<?> c)
          Currently usage is not allowed.
 boolean retainAll(java.util.Collection<?> c)
          Currently usage is not allowed.
 QueryParameters set(int index, QueryParameters element)
          Sets value in cache.
 void setMaxCacheSize(int maxCacheSize)
          Sets maximum cache size for this instance.
 int size()
          Function is not allowed to be executed as Lazy query output doesn't know the size of output.
 int sizeCached()
          Returns amount of elements cached (inc.
 java.util.List<QueryParameters> subList(int fromIndex, int toIndex)
          Execution is currently not allowed, as it might result in caching whole query output which would lead to huge memory usage and/or crash.
 java.util.List<QueryParameters> subListCached(int fromIndex, int toIndex)
          Returns sublist of cached elements.
 java.lang.Object[] toArray()
          Function is not allowed to be executed, as it might result in caching whole query output which would lead to huge memory usage and/or crash.
<T> T[]
toArray(T[] a)
          The same as toArray().
 java.lang.Object[] toArrayCached()
          Returns array of cached elements (inc.
<T> T[]
toArrayCached(T[] a)
          The same as toArrayCached().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.List
equals, hashCode
 

Constructor Detail

QueryParametersLazyList

public QueryParametersLazyList(java.sql.Statement stmt,
                               TypeHandler typeHandler,
                               boolean readGeneratedKeys,
                               QueryParametersLazyList.Type type,
                               int maxCacheSize)
                        throws java.sql.SQLException
Creates new QueryParametersLazyList instance

Parameters:
stmt - SQL Statement
typeHandler - Type handler which would be used to process rows after read
readGeneratedKeys - specifies if generated keys should be cached right away
type - lazy list type
Throws:
java.sql.SQLException

QueryParametersLazyList

public QueryParametersLazyList(java.sql.Statement stmt,
                               TypeHandler typeHandler,
                               boolean readGeneratedKeys,
                               int maxCacheSize)
                        throws java.sql.SQLException
Creates new QueryParametersLazyList instance

Parameters:
stmt - SQL Statement
typeHandler - Type handler which would be used to process rows after read
readGeneratedKeys - specifies if generated keys should be cached right away
maxCacheSize - maximum cache size
Throws:
java.sql.SQLException

QueryParametersLazyList

public QueryParametersLazyList(java.sql.Statement stmt,
                               TypeHandler typeHandler,
                               boolean readGeneratedKeys)
                        throws java.sql.SQLException
Creates new QueryParametersLazyList instance

Parameters:
stmt - SQL Statement
typeHandler - Type handler which would be used to process rows after read
readGeneratedKeys - specifies if generated keys should be cached right away
Throws:
java.sql.SQLException
Method Detail

setMaxCacheSize

public void setMaxCacheSize(int maxCacheSize)
Sets maximum cache size for this instance. If new max size limit is already exceeded - trim would be performed only during next cache update.

Parameters:
maxCacheSize - new max cache size

isEmpty

public boolean isEmpty()
Checks if cache list is empty

Specified by:
isEmpty in interface java.util.Collection<QueryParameters>
Specified by:
isEmpty in interface java.util.List<QueryParameters>
Returns:
true - if cache list is empty

size

public int size()
Function is not allowed to be executed as Lazy query output doesn't know the size of output.

Specified by:
size in interface java.util.Collection<QueryParameters>
Specified by:
size in interface java.util.List<QueryParameters>
Returns:
throws Exception

sizeCached

public int sizeCached()
Returns amount of elements cached (inc. header as first element).

Returns:
size of cached elements

toArray

public java.lang.Object[] toArray()
Function is not allowed to be executed, as it might result in caching whole query output which would lead to huge memory usage and/or crash. In future it might be changed and this functionality might be allowed.

Specified by:
toArray in interface java.util.Collection<QueryParameters>
Specified by:
toArray in interface java.util.List<QueryParameters>
Returns:
Exception

toArrayCached

public java.lang.Object[] toArrayCached()
Returns array of cached elements (inc. statement as first element).

Returns:
arrya of cached elements

toArray

public <T> T[] toArray(T[] a)
The same as toArray(). Currently execution is not allowed. Might be changed in future

Specified by:
toArray in interface java.util.Collection<QueryParameters>
Specified by:
toArray in interface java.util.List<QueryParameters>
Parameters:
a - the array into which the elements of this list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
Returns:
Exception

toArrayCached

public <T> T[] toArrayCached(T[] a)
The same as toArrayCached(). Returns array of cached elements(inc. header as first element) as array of Type T.

Parameters:
a - the array into which the elements of this list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
Returns:
array of cached elements as array of Type T.

subList

public java.util.List<QueryParameters> subList(int fromIndex,
                                               int toIndex)
Execution is currently not allowed, as it might result in caching whole query output which would lead to huge memory usage and/or crash.

Specified by:
subList in interface java.util.List<QueryParameters>
See Also:
List#subList(int, int)}

subListCached

public java.util.List<QueryParameters> subListCached(int fromIndex,
                                                     int toIndex)
Returns sublist of cached elements.

Parameters:
fromIndex - low endpoint (inclusive) of the subList
toIndex - high endpoint (exclusive) of the subList
Returns:
a view of the specified range within this list

get

public QueryParameters get(int index)
Returns element at specified position. If no element was found - null is returned (in future exception might be thrown instead).

Specified by:
get in interface java.util.List<QueryParameters>
Parameters:
index - index of the element to return
Returns:
the element at the specified position in this list (null if nothing was found).
See Also:
List#get(int)}

close

public void close()
Performs cleanup of all resources used by this lazy query output list implementation: Statement and ResultSet


iterator

public java.util.Iterator<QueryParameters> iterator()
Returns iterator of this lazy query output list implementation. First element returned - is header. Actual values are returned only starting from second element.

Specified by:
iterator in interface java.lang.Iterable<QueryParameters>
Specified by:
iterator in interface java.util.Collection<QueryParameters>
Specified by:
iterator in interface java.util.List<QueryParameters>
Returns:
new Iterator instance

set

public QueryParameters set(int index,
                           QueryParameters element)
Sets value in cache. Please be aware that currently cache only is updated. No changes to Database are made

Specified by:
set in interface java.util.List<QueryParameters>
Parameters:
index - element number to replace
element - new element value
Returns:
previous element at that position
Throws:
MidaoRuntimeException - if value is not in cache

listIterator

public java.util.ListIterator<QueryParameters> listIterator()
Currently usage is not allowed. Will be implemented along with Updateable/scrollable functionality

Specified by:
listIterator in interface java.util.List<QueryParameters>
Throws:
MidaoRuntimeException

listIterator

public java.util.ListIterator<QueryParameters> listIterator(int index)
Currently usage is not allowed. Will be implemented along with Updateable/scrollable functionality

Specified by:
listIterator in interface java.util.List<QueryParameters>
Throws:
MidaoRuntimeException

add

public boolean add(QueryParameters queryParameters)
Currently usage is not allowed. Will be implemented along with Updateable/scrollable functionality

Specified by:
add in interface java.util.Collection<QueryParameters>
Specified by:
add in interface java.util.List<QueryParameters>
Throws:
MidaoRuntimeException

addAll

public boolean addAll(java.util.Collection<? extends QueryParameters> c)
Currently usage is not allowed. Will be implemented along with Updateable/scrollable functionality

Specified by:
addAll in interface java.util.Collection<QueryParameters>
Specified by:
addAll in interface java.util.List<QueryParameters>
Throws:
MidaoRuntimeException

addAll

public boolean addAll(int index,
                      java.util.Collection<? extends QueryParameters> c)
Currently usage is not allowed. Will be implemented along with Updateable/scrollable functionality

Specified by:
addAll in interface java.util.List<QueryParameters>
Throws:
MidaoRuntimeException

add

public void add(int index,
                QueryParameters element)
Currently usage is not allowed. Will be implemented along with Updateable/scrollable functionality

Specified by:
add in interface java.util.List<QueryParameters>
Throws:
MidaoRuntimeException

remove

public boolean remove(java.lang.Object o)
Currently usage is not allowed. Will be implemented along with Updateable/scrollable functionality

Specified by:
remove in interface java.util.Collection<QueryParameters>
Specified by:
remove in interface java.util.List<QueryParameters>
Throws:
MidaoRuntimeException

remove

public QueryParameters remove(int index)
Currently usage is not allowed. Will be implemented along with Updateable/scrollable functionality

Specified by:
remove in interface java.util.List<QueryParameters>
Throws:
MidaoRuntimeException

removeAll

public boolean removeAll(java.util.Collection<?> c)
Currently usage is not allowed. Will be implemented along with Updateable/scrollable functionality

Specified by:
removeAll in interface java.util.Collection<QueryParameters>
Specified by:
removeAll in interface java.util.List<QueryParameters>
Throws:
MidaoRuntimeException

retainAll

public boolean retainAll(java.util.Collection<?> c)
Currently usage is not allowed. Will be implemented along with Updateable/scrollable functionality

Specified by:
retainAll in interface java.util.Collection<QueryParameters>
Specified by:
retainAll in interface java.util.List<QueryParameters>
Throws:
MidaoRuntimeException

clear

public void clear()
Currently usage is not allowed. Will be implemented along with Updateable/scrollable functionality

Specified by:
clear in interface java.util.Collection<QueryParameters>
Specified by:
clear in interface java.util.List<QueryParameters>
Throws:
MidaoRuntimeException

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection<QueryParameters>
Specified by:
contains in interface java.util.List<QueryParameters>

containsAll

public boolean containsAll(java.util.Collection<?> c)
Currently usage is not allowed. Will be implemented along with Updateable/scrollable functionality

Specified by:
containsAll in interface java.util.Collection<QueryParameters>
Specified by:
containsAll in interface java.util.List<QueryParameters>
Throws:
MidaoRuntimeException

indexOf

public int indexOf(java.lang.Object o)
Currently usage is not allowed. Will be implemented along with Updateable/scrollable functionality

Specified by:
indexOf in interface java.util.List<QueryParameters>
Throws:
MidaoRuntimeException

lastIndexOf

public int lastIndexOf(java.lang.Object o)
Currently usage is not allowed. Will be implemented along with Updateable/scrollable functionality

Specified by:
lastIndexOf in interface java.util.List<QueryParameters>
Throws:
MidaoRuntimeException


Copyright © 2013. All Rights Reserved.