Bio::Genex::Contact - Methods for processing data from the GeneX DB table: Contact
use Bio::Genex::Contact;
# instantiating an instance my $Contact = Bio::Genex::Contact->new(id=>47);
# retrieve data from the DB for all columns $Contact->fetch();
# creating an instance, without pre-fetching all columns my $Contact = new Bio::Genex::Contact(id=>47);
# creating an instance with pre-fetched data my $Contact = new Bio::Genex::Contact(id=>47, 'fetch_all'=>1);
# retrieving multiple instances via primary keys my @objects = Bio::Genex::Contact->get_objects(23,57,98)
# retrieving all instances from a table my @objects = Bio::Genex::Contact->get_objects('ALL');
# retrieving the primary key for an object, generically my $primary_key = $Contact->id();
# or specifically my $con_pk_val = $Contact->con_pk();
# retreving other DB column attributes my $type_val = $Contact->type(); $Contact->type($value);
my $organization_val = $Contact->organization(); $Contact->organization($value);
my $contact_person_val = $Contact->contact_person(); $Contact->contact_person($value);
my $contact_person_phone_val = $Contact->contact_person_phone(); $Contact->contact_person_phone($value);
my $contact_person_email_val = $Contact->contact_person_email(); $Contact->contact_person_email($value);
my $org_phone_val = $Contact->org_phone(); $Contact->org_phone($value);
my $org_email_val = $Contact->org_email(); $Contact->org_email($value);
my $org_mail_address_val = $Contact->org_mail_address(); $Contact->org_mail_address($value);
my $org_toll_free_phone_val = $Contact->org_toll_free_phone(); $Contact->org_toll_free_phone($value);
my $org_fax_val = $Contact->org_fax(); $Contact->org_fax($value);
my $url_val = $Contact->url(); $Contact->url($value);
my $last_updated_val = $Contact->last_updated(); $Contact->last_updated($value);
Each Genex class has a one to one correspondence with a GeneX DB table of the same name (i.e. the corresponding table for Bio::Genex::Contact is Contact).
Most applications will first create an instance of Bio::Genex::Contact
and then fetch the data for the object from the DB by invoking
fetch()
. However, in cases where you may only be accessing a single
value from an object the built-in delayed fetch
mechanism can be used. All objects are created without pre-fetching
any data from the DB. Whenever an attribute of the object is accessed
via a getter method, the data for that attribute will be fetched from
the DB if it has not already been. Delayed fetching happens
transparently without the user needing to enable or disable any
features.
Since data is not be fetched from the DB until it is accessed by the calling application, it could presumably save a lot of access time for large complicated objects when only a few attribute values are needed.
There are three different types of attributes which instances of Bio::Genex::Contact can access: raw foreign key attributes, Obect-Oriented foreign key attributes, and simple column attributes.
Specifying the 'recursive_fetch
' parameter when calling new()
,
modifies the behavior of this mode. The value given specifies the
number of levels deep that fetch will be invoked on sub-objects
created.
Class Bio::Genex::Contact defines the following utility variables for assisting programmers to access the Contact table.
get_objects()
or any call to a ONE_TO_MANY
or LOOKUP_TABLE
foreign key
accessor method).
new()
. Objects are cached by primary key. The
caching is very simple, and no effort is made to track whether
different invocations of new()
are being made for an object with
the same primary key value, but with different options set. If you
desire to reinstantiate an object with a different set of parameters,
you would need to undefine $USE_CACHE
first.
WARNING: variables other than those listed here are for internal use only and are subject to change without notice. Use them at your own risk.
It is possible to retrieve only the subset of attributes one chooses
by simply creating an object instance and then calling the appropriate
getter function. The object will automatically fetch the value from
the DB when requested. This can potentially save time for large
complicated objects. This triggers a separate DB query for each
attribute that is accessed, whereas calling fetch()
will retrieve
all fields of the object with a single query.
For example:
my $Contact = Bio::Genex::Contact->new(id=>47); my $val = $Contact->con_pk();
The attribute's value is then cached in the object so any further calls to that attribute's getter method do not trigger a DB query.
NOTE: Methods may still return undef
if their value in
the DB is NULL
.
The following methods can all be called without first having an
instance of the class via the Bio::Genex::Contact->methodname()
syntax.
new(%args)
new()
accepts the following arguments:
linking_table()
pkey_name()
table_name()
column2name()
name2column()
%column2name = %{$class->column2name()}; if (exists $column2name{$_}) { push(@column_copy,$column2name{$_}); }
# now that we've translated the names, we sort them @column_copy = sort @column_copy;
# make a header element. push(@rows,th(\@column_copy));
fkeys()
column_names()
# first retrieve the data from the DB $object = $full_module_name->new(id=>$id); $object->fetch();
# now extract the data from the object foreach (@{$class->column_names}) { # we use this to temporarily relax the strict pragma # to use symbolic references no strict 'refs'; $tmp_values{$_} = $object->$_;
# back to our regularily scheduled strictness }
insert_db($dbh)
new()
, set the attributes that you want, and then call
insert_db()
.
my $dbh = Bio::Genex::current_connection(USER=>$SU_USERNAME, PASSWORD=>$SU_PASSWORD); my Contact = Bio::Genex::Contact->new(); Contact->type('some_value'); Contact->insert_db($dbh);
NOTE: You must log into the DB with a user/password that has INSERT priveleges in the DB, otherwise you will get a DBI error.
WARNING: fetch()
will not be called, so if you are using this
method to insert a copy of an existing DB object, then it is up to you
to call fetch()
, otherwise, only the attributes that are currently
set in the object will be inserted.
update_db($dbh)
update_db()
.
my $dbh = Bio::Genex::current_connection(USER=>$SU_USERNAME, PASSWORD=>$SU_PASSWORD); my Contact = Bio::Genex::Contact->new(id=>43); Contact->type('some_value'); Contact->update_db($dbh);
NOTE: You must log into the DB with a user/password that has INSERT priveleges in the DB, otherwise you will get a DBI error.
NOTE: Any modification of the primary key value will be discarded ('con_pk' for module Bio::Genex::Contact).
get_objects(@id_list)
get_objects('ALL')
By passing in an @id_list
, get_objects()
uses each element of the
list as a primary key for the Contact table and returns a single
instance for each entry.
WARNING: Passing incorrect id values to get_objects()
will cause
a warning from Bio::Genex::Contact::initialize()
. Objects will be
created for other correct id values in the list.
By passing the 'ALL' parameter, get_objects()
returns an instance
for every entry in the table.
By passing an anonymous hash reference that contains the 'column' and 'name' keys, the method will return all objects from the DB whose that have the specified value in the specified column.
NOTE: All objects must have the 'id' parameter set before attempting
to use fetch()
or any of the objects getter functions.
The following methods can only be called by first having valid instance of class Bio::Genex::Contact.
fetch()
WARNING: methods other than those listed here are for internal use only and are subject to change without notice. Use them at your own risk.
These are the setter and getter methods for attributes in class Bio::Genex::Contact.
NOTE: To use the getter methods, you may either invoke the
fetch()
method to retrieve all the values for an object, or else
rely on delayed fetching to retrieve the attributes
as needed.
id()
id()
is a special attribute method that is common to all the Genex
classes. This method returns the primary key of the given instance
(and for class Bio::Genex::Contact it is synonomous with the
con_pk()
method). The id()
method can be useful in writing
generic methods because it avoids having to know the name of the
primary key column.
con_pk()
WARNING: methods other than those listed here are for internal use only and are subject to change without notice. Use them at your own risk.
These classes are automatically generated by the
create_genex_classes.pl script. Each class is a subclass of the
ObjectTemplate class (written by Sriram Srinivasan, described in
Advanced Perl Programming, and heavily modified by Jason
Stewart). ObjectTemplate implements automatic class creation in perl
(there exist other options such as Class::Struct
and
Class::MethodMaker
by Damian Conway) via an attributes()
method
call at class creation time.
Please send bug reports to genex@ncgr.org
on Thu Dec 7 18:35:43 2000 by /home/jasons/Genex/scripts/create_genex_class.pl --target=Contact
Jason E. Stewart (jes@ncgr.org)
perl(1).