"Fossies" - the Fresh Open Source Software Archive

Member "metadot/metadot/Metadot/SystemApp/AppObject.pm" (1 Jul 2005, 5143 Bytes) of package /linux/www/old/Metadot6.4.5.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AppObject.pm" see the Fossies "Dox" file reference documentation.

    1 ###########################################################################
    2 # <LICENSEINFO>
    3 # Copyright (C) Daniel Guermeur - 1999-2001
    4 # Copyright (C) Metadot Corporation - 2001-2005
    5 #
    6 # This file is part of Metadot Portal Server software $Name: Release_6_4_5_4 $
    7 #
    8 # Metadot Portal Server software is free software; you can
    9 # redistribute it and/or modify it under the terms of the GNU General Public
   10 # License as published by the Free Software Foundation; either version 2 of
   11 # the License, or (at your option) any later version.
   12 #
   13 # Metadot Portal Server software is distributed in the hope that it
   14 # will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
   15 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
   16 # Public License for more details.
   17 #
   18 # You should have received a copy of the GNU General Public License along with
   19 # Metadot Portal Server; if not, write to the Free Software
   20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21 #
   22 # For more information, please contact info@metadot.com.
   23 #</LICENSEINFO>
   24 ############################################################################
   25 package Metadot::SystemApp::AppObject;
   26 use strict;
   27 
   28 use DBAccess;
   29 
   30 use Metadot::MySQLTableInfo;
   31 use Metadot::DataCollection;
   32 use Metadot::SystemApp::AppObjectClass;
   33 
   34 ############################################################################
   35 ##  class members and methods
   36 ############################################################################
   37 sub get_fields {
   38     my $proto = shift;
   39     my $class = ref($proto) || $proto;
   40 
   41     return Metadot::SystemApp::AppObjectClass->get_fields($class);
   42 }
   43 
   44 sub get_collection {
   45     my $proto = shift;
   46     my $class = ref($proto) || $proto;
   47     my $conditions = shift;
   48     my $order_by = shift;
   49 
   50     my $collection = Metadot::DataCollection->new();
   51     my $sth = $class->get_sth($conditions, $order_by);
   52     while (my $hash_ref = $sth->fetchrow_hashref){
   53         my $instance = $class->new($hash_ref);
   54         $collection->add($instance);
   55     }
   56 
   57     return $collection;
   58 }
   59 
   60 sub restore {
   61     my $proto = shift;
   62     my $class = ref($proto) || $proto;
   63     my $pkey_value = shift;
   64 
   65     my $sth = DBAccess->sqlSelectMany("*", $class->get_table_name(), $class->get_pkey_name()." = '".$pkey_value."'");
   66     return $sth->fetchrow_hashref;
   67 }
   68 
   69 sub get_sth {
   70     my $proto = shift;
   71     my $class = ref($proto) || $proto;
   72     my $conditions = shift;
   73     $conditions = (defined($conditions) && $conditions ne '') ? $conditions : undef;
   74     my $order_by = shift;
   75     $order_by = (defined($order_by) && $order_by ne '') ? "order by $order_by" : undef;
   76 
   77     return DBAccess->sqlSelectMany("*", $class->get_table_name(), $conditions, $order_by);
   78 }
   79 
   80 ############################################################################
   81 ##  static abstract methods, should be overridden
   82 ############################################################################
   83 sub get_table_name {
   84     my $proto = shift;
   85     my $class = ref($proto) || $proto;
   86     die "should be overridden";
   87     return undef;
   88 }
   89 
   90 sub get_pkey_name {
   91     my $proto = shift;
   92     my $class = ref($proto) || $proto;
   93     die "should be overridden";
   94     return undef;
   95 }
   96 
   97 ############################################################################
   98 ##  constructor
   99 ############################################################################
  100 sub new {
  101     my $proto = shift;
  102     my $class = ref($proto) || $proto;
  103     my $params = shift;
  104     # if constructor was called with parameters
  105     if (defined $params) {
  106         # ... and parameters is not a hash reference, than it's instance_id
  107         unless (ref $params) {
  108           my $instance_id = $params;
  109           $params = $class->restore($instance_id);
  110         }
  111     } else {
  112         $params = {};
  113     }
  114 
  115     my $self = $params;
  116 
  117     bless ($self, $class);
  118     $self->load_relations();
  119     return $self;
  120 }
  121 
  122 ############################################################################
  123 #   instance methods
  124 ############################################################################
  125 sub set_value {
  126     my $self = shift;
  127     my $field_name = shift;
  128     my $field_value = shift;
  129 
  130     $self->{$field_name} = $field_value;
  131 }
  132 
  133 sub get_value {
  134     my $self = shift;
  135     my $field_name = shift;
  136     my $field_value = $self->{$field_name};
  137 
  138     return $field_value;
  139 }
  140 
  141 sub set_pkey_value {
  142     my $self = shift;
  143     my $pkey_value = shift;
  144     $self->set_value($self->get_pkey_name(), $pkey_value);
  145 }
  146 
  147 sub get_pkey_value {
  148     my $self = shift;
  149     return $self->get_value($self->get_pkey_name());
  150 }
  151 
  152 sub save {
  153     my $self = shift;
  154     return DBAccess->sqlSaveAppObject($self);
  155 }
  156 
  157 sub delete {
  158     my $self = shift;
  159     return DBAccess->sqlDeleteAppObject($self);
  160 }
  161 
  162 ############################################################################
  163 ##  instance abstract methods, should be overridden
  164 ############################################################################
  165 sub get_name {
  166     my $self = shift;
  167     die "should be overridden";
  168     return "";
  169 }
  170 
  171 sub load_relations {
  172     my $self = shift;
  173     die "should be overridden";
  174     return;
  175 }
  176 
  177 1;