Dv::Sql::Reference Class Reference

A reference represents a semantic connection between tables. More...

#include <reference.h>

Collaboration diagram for Dv::Sql::Reference:
Collaboration graph
[legend]

List of all members.

Public Types

typedef std::vector< const
Reference * > 
List

Public Member Functions

 Reference (const Table::Ref &from_table, std::vector< const Dv::Sql::Column * > from_columns, const Table::Ref &to_table, std::vector< const Dv::Sql::Column * > to_columns) throw (std::logic_error)
 Constructor.
 ~Reference ()
 Destructor.
size_t to (size_t i) const
 The index of the i'th column in the list of target table columns.
size_t from (size_t i) const
 The index of the i'th column in the list of source table columns.
size_t size () const
 The number of columns in each list.
const SelectExpmatch () const
 Return an SQL "where" condition expressing that corresponding column values should match.
 operator SelectExp () const
SelectExp match_source (const Object &source) const throw (std::logic_error)
 Return an SQL "where" condition expressing that the source column values of the source table should match those of the parameter object.
SelectExp match_target (const Object &target) const throw (std::logic_error)
 Return an SQL "where" condition expressing that the target column values of the target table should match those of the parameter object.

Public Attributes

const Table::Reffrom_table
 The source table of the reference.
const Table::Refto_table
 The target table of the reference.

Private Attributes

std::vector< const
Dv::Sql::Column * > 
from_
 The columns in the source table of the reference.
std::vector< const
Dv::Sql::Column * > 
to_
 The columns in the target table of the reference.
SelectExpselect_exp

Detailed Description

A reference represents a semantic connection between tables.

It consists of two tables, a source and target table and a list of columns in each table. Both lists should have equal length and the corresponding data types of the columns in both lists should agree.

A reference can be followed, e.g. if an object corresponds to a row in the source table, then an object(s) in the target table may be obtained by copying the column values from the source object to a target object and then find all objects in the target table matching the target object. Similarly, a reference can be followed in the "reverse" direction. Note that there is no requirement that a reference is single valued, e.g. there may be many target table rows corresponding to a single source table row.

References are supported by Object and Row as well as by the Object::Set and Row::Set classes.

Example
 const Dv::Sql::Reference acct_cust(
           Database::account, (cols = &Account::customer_id), 
           Database::customer, (cols = &Customer::id)
           );
 Object cust(..); 
 // all accounts of this customer
 Object::Set::Ref accounts =  cust.references(acct_cust);

In addition, reference can be used to generate Dv::Sql::SelectExp objects and queries using the member functions Dv::Sql::Reference::match Dv::Sql::Reference::match_source and Dv::Sql::Reference::match_target .

Example
 const Dv::Sql::Reference acct_cust(
          Database::account, (cols = &Account::customer_id), 
          Database::customer, (cols = &Customer::id)
          );
 const Dv::Sql::Reference trans_acct(
          Database::transaction, (cols = &Transaction::account_code), 
          Database::account, (cols = &Account::code)
          );

 Dv::Sql::SelectExp e = 
    acct_cust.match_target(cust) && acct_cust.match() && trans_acct.match();
 // transs contains all transactions associated with accounts from customer @p cust
 Transaction::Set transs(e);
See also:
Dv::Sql::Object::references
Dv::Sql::Object::Set::Set(const Source&,const Dv::Sql::Reference&)
Dv::Sql::Row::Row(const Dv::Sql::Object&, const Dv::Sql::Reference&)
Dv::Sql::Row::Set::Set(const Source&,const Dv::Sql::Reference&)
Dv::Sql::Reference::match
Dv::Sql::Reference::match_source
Dv::Sql::Reference::match_target
Examples:

example-row.C.

Definition at line 73 of file reference.h.


Member Typedef Documentation

typedef std::vector<const Reference*> Dv::Sql::Reference::List

Definition at line 75 of file reference.h.


Constructor & Destructor Documentation

Dv::Sql::Reference::Reference ( const Table::Ref from_table,
std::vector< const Dv::Sql::Column * >  from_columns,
const Table::Ref to_table,
std::vector< const Dv::Sql::Column * >  to_columns 
) throw (std::logic_error)

Constructor.

Parameters:
from_table source table of the reference
from_columns list of columns in from_table
to_table target table of the reference
to_columns list of columns in the target table
Exceptions:
std::logic_error if from_columns has a different size from to_columns
std::logic_error if from_columns has size 0
Warning:
References should only be used after the parameter Dv::Sql::Table::Ref objects have been properly initialized. E.g. db2cpp generates static Dv::Sql::Table::Ref (and Dv::Sql::Row<Dv::Sql::Table::Ref>::Column) definitions which are only initialized after the database has been opened. A Reference object may use these definitions as constructor arguments, even in static storage. However, the Reference should be used only after all its parameters (which are references or pointers) have been initialized.

In the example below: the constructor will succeed even before Database::account and Account::customer_id have been initialized, but the resulting acct_cust should not be used until they have been initialized.

Example
Dv::Sql::Reference::~Reference (  ) 

Destructor.


Member Function Documentation

size_t Dv::Sql::Reference::to ( size_t  i  )  const [inline]

The index of the i'th column in the list of target table columns.

Parameters:
i the position in the list of target table columns.
Returns:
the index of the i'th column in the list of target table columns.

Definition at line 124 of file reference.h.

References to_.

Referenced by Dv::Sql::Set< Row< database_table > >::Set().

size_t Dv::Sql::Reference::from ( size_t  i  )  const [inline]

The index of the i'th column in the list of source table columns.

Parameters:
i the position in the list of source table columns.
Returns:
the index of the i'th column in the list of source table columns.

Definition at line 130 of file reference.h.

References from_.

Referenced by Dv::Sql::Set< Row< database_table > >::Set().

size_t Dv::Sql::Reference::size (  )  const [inline]

The number of columns in each list.

Returns:
the number of columns in the source and target list.

Definition at line 135 of file reference.h.

References from_.

Referenced by Dv::Sql::Set< Row< database_table > >::Set().

const SelectExp& Dv::Sql::Reference::match (  )  const

Return an SQL "where" condition expressing that corresponding column values should match.

Example
 const Dv::Sql::Reference acct_cust(
          Database::account, (cols = &Account::customer_id), 
          Database::customer, (cols = &Customer::id)
          );
 const Dv::Sql::Reference trans_acct(
          Database::transaction, (cols = &Transaction::account_code), 
          Database::account, (cols = &Account::code)
          );

 Dv::Sql::SelectExp e = 
    acct_cust.match_target(cust) && acct_cust.match() && trans_acct.match();
 // transs contains all transactions associated with accounts from customer @p cust
 Transaction::Set transs(e);
See also:
Dv::Sql::Reference::match_target

Referenced by operator SelectExp().

Dv::Sql::Reference::operator SelectExp (  )  const [inline]

Definition at line 158 of file reference.h.

References match().

SelectExp Dv::Sql::Reference::match_source ( const Object source  )  const throw (std::logic_error)

Return an SQL "where" condition expressing that the source column values of the source table should match those of the parameter object.

Parameters:
source object whose column values will be used to restrict the column values of source table objects. This object should represent a row in the source table.
Returns:
condition expressing the match
See also:
Dv::Sql::Reference::match
Dv::Sql::Reference::match_target
Exceptions:
std::logic_error if the source object's arity does not match the from_table's.
SelectExp Dv::Sql::Reference::match_target ( const Object target  )  const throw (std::logic_error)

Return an SQL "where" condition expressing that the target column values of the target table should match those of the parameter object.

Parameters:
target object whose column values will be used to restrict the column values of target table objects. This object should represent a row in the target table.
Returns:
condition expressing the match
See also:
Dv::Sql::Reference::match
Dv::Sql::Reference::match_source
Exceptions:
std::logic_error iff the target object's arity does not match the to_table's.

Member Data Documentation

The source table of the reference.

Definition at line 115 of file reference.h.

The target table of the reference.

Definition at line 117 of file reference.h.

std::vector<const Dv::Sql::Column*> Dv::Sql::Reference::from_ [private]

The columns in the source table of the reference.

Definition at line 189 of file reference.h.

Referenced by from(), and size().

std::vector<const Dv::Sql::Column*> Dv::Sql::Reference::to_ [private]

The columns in the target table of the reference.

Definition at line 191 of file reference.h.

Referenced by to().

Definition at line 192 of file reference.h.


The documentation for this class was generated from the following file:

dvmysql-1.0.3 [17 November, 2010]