IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5185


Ignore:
Timestamp:
Sep 29, 2005, 11:20:25 AM (21 years ago)
Author:
jhoblitt
Message:

add init() subs to all subclasses
add register_children() method
add import()
add init()
move add_new() & find_new() back to PS::IPP::MetaDB

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/PS-IPP-MetaDB/lib/PS/IPP/MetaDB.pm

    r5172 r5185  
    11# Copyright (C) 2005  Joshua Hoblitt
    22#
    3 # $Id: MetaDB.pm,v 1.3 2005-09-28 21:45:08 jhoblitt Exp $
     3# $Id: MetaDB.pm,v 1.4 2005-09-29 21:20:25 jhoblitt Exp $
    44
    55package PS::IPP::MetaDB;
     
    1515use Carp qw( croak );
    1616
    17 __PACKAGE__->set_db('Main', 'dbi:mysql:test', 'test', '');
     17sub import {
     18    my $class = shift;
     19
     20    $class->init( @_ ) if @_;
     21}
     22
     23my @child_inits;
     24
     25sub init {
     26    my $class = shift;
     27    my %p = @_;
     28   
     29    croak "dsn is required" unless exists $p{dsn};
     30
     31    $class->set_db('Main', $p{dsn}, $p{user}, $p{passwd});
     32
     33    foreach my $init (@child_inits) {
     34        &$init;
     35    }
     36}
     37
     38sub register_init {
     39    my $class = shift;
     40    push @child_inits, shift;
     41}
    1842
    1943# lifted from Class::DBI docs (modified)
     
    3660}
    3761
    38 
    39 sub new2newed {
     62sub add_new {
    4063    my $class = shift;
    4164    my %p = @_;
    4265
    43     $class->do_transaction(sub { $class->_new2newed(%p) });
    44 }
    45 
    46 sub _new2newed {
    47     my $class = shift;
    48     my %p = @_;
    49 
    50     "${class}::Image::New"->search(
    51         exp_id      => $p{exp_id},
    52         class_id    => $p{class_id},
    53     )->delete_all;
    54 
    55     "${class}::Image::Newed"->create({
    56         exp_id      => $p{exp_id},
    57         class_id    => $p{class_id},
    58         url         => $p{url},
    59     });
    60 }
    61 
    62 
    63 #package PS::IPP::MetaDB::Image::Prepared;
    64 #package PS::IPP::MetaDB::Image::Reduced;
    65 #package PS::IPP::MetaDB::Image::Analyzed;
    66 #package PS::IPP::MetaDB::Image::Combined;
    67 
    68 =pod
    69 
    70 =head2 Temporal Queues
    71 
    72 These queues all describe work that I<needs> to be performed but hasn't
    73 happened yet.
    74 
    75 =over 4
    76 
    77 =item * new
    78 
    79 This table contains a list of new data waiting to be downloaded from the
    80 summit.  The location of fetched data files is written into the C<newed> table.
    81 
    82 Table description:
    83 
    84 =over 4
    85 
    86 =item * url
    87 
    88 URL to retrieve data from
    89 
    90 =item * exp_id
    91 
    92 exposure ID #
    93 
    94 =item * camera
    95 
    96 Camera that this data was acquired from
    97 
    98 =item * class
    99 
    100 The 'type' of data this is
    101 
    102 =item * class_id
    103 
    104 A unique identifier for data of the same class in the same exposure.
    105 
    106 =back
    107 
    108 =cut
    109 
    110 package PS::IPP::MetaDB::Image::New;
    111 
    112 use base qw( PS::IPP::MetaDB );
    113 
    114 __PACKAGE__->table("new");
    115 __PACKAGE__->create_table(q{
    116     exp_id      BIGINT          NOT NULL PRIMARY KEY,
    117     class_id    BIGINT          NOT NULL,
    118     camera      VARCHAR(255),
    119     class       VARCHAR(255),
    120     url         VARCHAR(255)    NOT NULL
    121 });
    122 __PACKAGE__->set_up_table;
    123 
    124 sub add_new {
    125     my $class = shift;
    126     my %p = @_;
    127 
    128     $class->create({
     66    PS::IPP::MetaDB::Image::New->create({
    12967        exp_id      => $p{exp_id},
    13068        class_id    => $p{class_id},
     
    14078
    14179    if (exists $p{exp_id}) {
    142         $class->search( $p{exp_id}, { order_by => 'class_id' } );
     80        PS::IPP::MetaDB::Image::New->search(
     81            $p{exp_id},
     82            { order_by => 'class_id' },
     83        );
    14384    } else {
    144         $class->retrieve_all;
     85        PS::IPP::MetaDB::Image::New->retrieve_all;
    14586    }
    14687}
    14788
     89sub new2newed {
     90    my $class = shift;
     91    my %p = @_;
     92
     93    $class->do_transaction(sub { $class->_new2newed(%p) });
     94}
     95
     96sub _new2newed {
     97    my $class = shift;
     98    my %p = @_;
     99
     100    $class->search(
     101        exp_id      => $p{exp_id},
     102        class_id    => $p{class_id},
     103    )->delete_all;
     104
     105    $class->create({
     106        exp_id      => $p{exp_id},
     107        class_id    => $p{class_id},
     108        url         => $p{url},
     109    });
     110}
     111
     112
     113#package PS::IPP::MetaDB::Image::Prepared;
     114#package PS::IPP::MetaDB::Image::Reduced;
     115#package PS::IPP::MetaDB::Image::Analyzed;
     116#package PS::IPP::MetaDB::Image::Combined;
     117
     118=pod
     119
     120=head2 Temporal Queues
     121
     122These queues all describe work that I<needs> to be performed but hasn't
     123happened yet.
     124
     125=over 4
     126
     127=item * new
     128
     129This table contains a list of new data waiting to be downloaded from the
     130summit.  The location of fetched data files is written into the C<newed> table.
     131
     132Table description:
     133
     134=over 4
     135
     136=item * url
     137
     138URL to retrieve data from
     139
     140=item * exp_id
     141
     142exposure ID #
     143
     144=item * camera
     145
     146Camera that this data was acquired from
     147
     148=item * class
     149
     150The 'type' of data this is
     151
     152=item * class_id
     153
     154A unique identifier for data of the same class in the same exposure.
     155
     156=back
     157
     158=cut
     159
     160package PS::IPP::MetaDB::Image::New;
     161
     162use base qw( PS::IPP::MetaDB );
     163
     164__PACKAGE__->register_init(\&init);
     165
     166sub init
     167{
     168    __PACKAGE__->table("new");
     169    __PACKAGE__->create_table(q{
     170        exp_id      BIGINT          NOT NULL PRIMARY KEY,
     171        class_id    BIGINT          NOT NULL,
     172        camera      VARCHAR(255),
     173        class       VARCHAR(255),
     174        url         VARCHAR(255)    NOT NULL
     175    });
     176    __PACKAGE__->set_up_table;
     177}
     178
    148179=item * raw
    149180
     
    168199use base qw( PS::IPP::MetaDB );
    169200
    170 __PACKAGE__->table("raw");
    171 __PACKAGE__->create_table(q{
    172     exp_id      BIGINT          NOT NULL PRIMARY KEY,
    173     class_id    BIGINT          NOT NULL
    174 });
    175 __PACKAGE__->set_up_table;
     201__PACKAGE__->register_init(\&init);
     202
     203sub init
     204{
     205    __PACKAGE__->table("raw");
     206    __PACKAGE__->create_table(q{
     207        exp_id      BIGINT          NOT NULL PRIMARY KEY,
     208        class_id    BIGINT          NOT NULL
     209    });
     210    __PACKAGE__->set_up_table;
     211}
    176212
    177213=item * prepare
     
    366402use base qw( PS::IPP::MetaDB );
    367403
    368 __PACKAGE__->table("newed");
    369 __PACKAGE__->create_table(q{
    370     exp_id      BIGINT          NOT NULL PRIMARY KEY,
    371     class_id    BIGINT          NOT NULL,
    372     url         VARCHAR(255)    NOT NULL
    373 });
    374 __PACKAGE__->set_up_table;
     404__PACKAGE__->register_init(\&init);
     405
     406sub init
     407{
     408    __PACKAGE__->table("newed");
     409    __PACKAGE__->create_table(q{
     410        exp_id      BIGINT          NOT NULL PRIMARY KEY,
     411        class_id    BIGINT          NOT NULL,
     412        url         VARCHAR(255)    NOT NULL
     413    });
     414    __PACKAGE__->set_up_table;
     415}
    375416
    376417=item * prepared
Note: See TracChangeset for help on using the changeset viewer.