org.imemex.dataservices.relation
Class AbstractDBMSRelation<E>

java.lang.Object
  extended by org.imemex.dataservices.relation.AbstractDBMSRelation<E>
All Implemented Interfaces:
java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>, Relation<E>, TupleToObjectTranslator<E>
Direct Known Subclasses:
DBMSDataSourceMetadataSet, DBMSDataSourcePluginMetadataSet, DBMSResourceViewMetadataSet, DefaultDBMSRelation

public abstract class AbstractDBMSRelation<E>
extends java.lang.Object
implements Relation<E>, TupleToObjectTranslator<E>

This class contains generic implementations of the relation interface using a DBMS table. We use the Template Method design pattern to concentrate data access code in this class that would otherwise have to be replicated among subclasses.

Author:
marcos type type of meta data

Constructor Summary
AbstractDBMSRelation()
          Instantiates a new AbstractDBMSRelation.
AbstractDBMSRelation(DBMSRelationSchema schema)
          Instantiates a new AbstractDBMSRelation with the given schema.
 
Method Summary
 boolean add(E o)
           
 boolean addAll(java.util.Collection<? extends E> c)
           
 void clear()
           
 void close()
          Release resources allocated by this instance, such as its database connection.
 boolean contains(java.lang.Object o)
           
 boolean containsAll(java.util.Collection<?> c)
           
 void finalize()
          On destruction, releases all resources allocated by this instance.
 E get(java.lang.String whereCondition, java.lang.Object[] bindings)
          Performs a query supposed to return only one element as a result.
 E getObjectFromTuple(java.sql.ResultSet rs, java.lang.String[] columnNames)
          Obtains an object representation of the tuple currently pointed by the result set.
 boolean hasUpdated()
          Indicates whether an update happened during the last addAll operation.
 boolean isEmpty()
           
 java.util.Iterator<E> iterator()
           
 void optimize()
          Performs optimization actions in the underlying implementation of the relation.
 PullOperator<E> query(java.lang.String whereCondition, java.lang.Object[] bindings)
          Obtains all elements that conform to the given condition.
 PullOperator<E> query(java.lang.String whereCondition, java.lang.Object[] bindings, java.lang.String orderByColumns)
          Obtains all elements that conform to the given condition in the order specified in .
 boolean remove(java.lang.Object o)
           
 boolean remove(java.lang.String whereCondition, java.lang.Object[] bindings)
          Removes all elements specified by the given condition.
 boolean removeAll(java.util.Collection<?> c)
           
 boolean retainAll(java.util.Collection c)
           
 int size()
           
 java.lang.Object[] toArray()
           
 java.lang.Object[] toArray(java.lang.Object[] a)
           
 boolean update(E metadata)
          Updates the given element in the set.
 boolean update(java.lang.String setAssignments, java.lang.Object[] setBindings, java.lang.String whereCondition, java.lang.Object[] whereBindings)
          Updates the given relation by touching all elements specified by the given condition and changing them in the way specified in the given assigments.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Set
equals, hashCode
 

Constructor Detail

AbstractDBMSRelation

public AbstractDBMSRelation()
Instantiates a new AbstractDBMSRelation.


AbstractDBMSRelation

public AbstractDBMSRelation(DBMSRelationSchema schema)
Instantiates a new AbstractDBMSRelation with the given schema.

Parameters:
schema -
Method Detail

update

public boolean update(E metadata)
Description copied from interface: Relation
Updates the given element in the set. The update method is necessary for a relation and is not present originally in the Set interface. This is the only method in this interface that does not have a SQL flavor, but rather complements the simple object-relational offered by a relational implementation of the Set interface.

Specified by:
update in interface Relation<E>
Parameters:
metadata - - the element to be updated.
Returns:
true, if update was successful; false, otherwise.

update

public boolean update(java.lang.String setAssignments,
                      java.lang.Object[] setBindings,
                      java.lang.String whereCondition,
                      java.lang.Object[] whereBindings)
Description copied from interface: Relation
Updates the given relation by touching all elements specified by the given condition and changing them in the way specified in the given assigments. The condition and assigments must be specified with the attribute names used in the underlying implementation of the relation.

Specified by:
update in interface Relation<E>
Parameters:
setAssignments - - the assigments to be placed in a SQL-set clause. As in JDBC-style, all bind variables in the conditions should be represented by "?" and their bound values should be given positionally in the list .
setBindings - - the values to be bound to the .
whereCondition - - a condition to be used in a SQL-where clause. As in JDBC-style, all bind variables in the conditions should be represented by "?" and their bound values should be given positionally in the list .
whereBindings - - the values to be bound to the .
Returns:
true, if any elements where successfully updated; false, otherwise.

size

public int size()
Specified by:
size in interface java.util.Collection<E>
Specified by:
size in interface java.util.Set<E>

clear

public void clear()
Specified by:
clear in interface java.util.Collection<E>
Specified by:
clear in interface java.util.Set<E>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection<E>
Specified by:
isEmpty in interface java.util.Set<E>

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection<E>
Specified by:
toArray in interface java.util.Set<E>

add

public boolean add(E o)
Specified by:
add in interface java.util.Collection<E>
Specified by:
add in interface java.util.Set<E>

contains

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

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection<E>
Specified by:
remove in interface java.util.Set<E>

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Specified by:
toArray in interface java.util.Collection<E>
Specified by:
toArray in interface java.util.Set<E>

addAll

public boolean addAll(java.util.Collection<? extends E> c)
Specified by:
addAll in interface java.util.Collection<E>
Specified by:
addAll in interface java.util.Set<E>

hasUpdated

public boolean hasUpdated()
Indicates whether an update happened during the last addAll operation.

Returns:
true, if an update happened; false, otherwise.

containsAll

public boolean containsAll(java.util.Collection<?> c)
Specified by:
containsAll in interface java.util.Collection<E>
Specified by:
containsAll in interface java.util.Set<E>

removeAll

public boolean removeAll(java.util.Collection<?> c)
Specified by:
removeAll in interface java.util.Collection<E>
Specified by:
removeAll in interface java.util.Set<E>

remove

public boolean remove(java.lang.String whereCondition,
                      java.lang.Object[] bindings)
Description copied from interface: Relation
Removes all elements specified by the given condition. The condition must be specified with the attribute names used in the underlying implementation of the relation.

Specified by:
remove in interface Relation<E>
Parameters:
whereCondition - - a condition to be used in a SQL-where clause that qualifies elements of the relation to be deleted. As in JDBC-style, all bind variables in the conditions should be represented by "?" and their bound values should be given positionally in the list .
bindings - - the values to be bound to the .
Returns:
true, if any elements were successfully removed; false, otherwise.

retainAll

public boolean retainAll(java.util.Collection c)
Specified by:
retainAll in interface java.util.Collection<E>
Specified by:
retainAll in interface java.util.Set<E>

iterator

public java.util.Iterator<E> iterator()
Specified by:
iterator in interface java.lang.Iterable<E>
Specified by:
iterator in interface java.util.Collection<E>
Specified by:
iterator in interface java.util.Set<E>

query

public PullOperator<E> query(java.lang.String whereCondition,
                             java.lang.Object[] bindings)
Description copied from interface: Relation
Obtains all elements that conform to the given condition.

Specified by:
query in interface Relation<E>
Parameters:
whereCondition - - a condition to be used in a SQL-where clause that qualifies elements of the relation to be returned. As in JDBC-style, all bind variables in the conditions should be represented by "?" and their bound values should be given positionally in the list .
bindings - - the values to be bound to the .
Returns:
an Iterator on all elements that qualify.

query

public PullOperator<E> query(java.lang.String whereCondition,
                             java.lang.Object[] bindings,
                             java.lang.String orderByColumns)
Description copied from interface: Relation
Obtains all elements that conform to the given condition in the order specified in .

Specified by:
query in interface Relation<E>
Parameters:
whereCondition - - a condition to be used in a SQL-where clause that qualifies elements of the relation to be returned. As in JDBC-style, all bind variables in the conditions should be represented by "?" and their bound values should be given positionally in the list .
bindings - - the values to be bound to the .
orderByColumns - - the column list to be used in a SQL-order by clause that defines the order in which elements in the resulting pull operator are returned.
Returns:
an Iterator on all elements that qualify.

get

public E get(java.lang.String whereCondition,
             java.lang.Object[] bindings)
Description copied from interface: Relation
Performs a query supposed to return only one element as a result.

Specified by:
get in interface Relation<E>
Parameters:
whereCondition - - a condition to be used in a SQL-where clause that qualifies the specific element of the relation to be returned. As in JDBC-style, all bind variables in the conditions should be represented by "?" and their bound values should be given positionally in the list .
bindings - - the values to be bound to the .
Returns:
the first element selected or null if no such element exists.

optimize

public void optimize()
Description copied from interface: Relation
Performs optimization actions in the underlying implementation of the relation. Such actions may be, for example, collecting DBMS statistics or re-creating indexes.

Specified by:
optimize in interface Relation<E>

getObjectFromTuple

public E getObjectFromTuple(java.sql.ResultSet rs,
                            java.lang.String[] columnNames)
Description copied from interface: TupleToObjectTranslator
Obtains an object representation of the tuple currently pointed by the result set.

Specified by:
getObjectFromTuple in interface TupleToObjectTranslator<E>
Parameters:
rs - - the result set.
columnNames - - the column names part of the schema respected by the result set.
Returns:
an object representation of the current tuple.

close

public void close()
Description copied from interface: Relation
Release resources allocated by this instance, such as its database connection.

Specified by:
close in interface Relation<E>

finalize

public void finalize()
On destruction, releases all resources allocated by this instance.

Overrides:
finalize in class java.lang.Object