cvsuser 02/01/16 10:32:32
Modified: P5EEx/Blue/P5EEx/Blue Repository.pm
P5EEx/Blue/P5EEx/Blue/Repository DBI.pm
Log:
major update
Revision Changes Path
1.5 +63 -74 p5ee/P5EEx/Blue/P5EEx/Blue/Repository.pm
Index: Repository.pm
===================================================================
RCS file: /cvs/public/p5ee/P5EEx/Blue/P5EEx/Blue/Repository.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -r1.4 -r1.5
--- Repository.pm 6 Jan 2002 20:57:07 -0000 1.4
+++ Repository.pm 16 Jan 2002 18:32:31 -0000 1.5
@@ -1,6 +1,6 @@
#############################################################################
-## $Id: Repository.pm,v 1.4 2002/01/06 20:57:07 spadkins Exp $
+## $Id: Repository.pm,v 1.5 2002/01/16 18:32:31 spadkins Exp $
#############################################################################
package P5EEx::Blue::Repository;
@@ -84,14 +84,17 @@
# HIGH-LEVEL (CACHED)
+ $key = $rep->get_key ($table, \@cols, \@values);
+ $key = $rep->get_key ($table, \@cols, \@values, \@keycolidx);
@keys = $rep->get_keys($table, \%paramvalues);
@keys = $rep->get_related_keys($table, $key, $related_table, $relation);
@values = $rep->get_values($table, $key, \@cols);
$value = $rep->get_value ($table, $key, "first_name");
- $key = $rep->set_values($table, $key, \@cols, \@values);
- $key = $rep->set_value ($table, $key, "first_name", $value);
+ $rep->set_values($table, $key, \@cols, \@values);
+ $rep->set_value ($table, $key, $column, $value);
+ $rep->set_rows ($table, \@cols, \@rows);
$rows = $rep->get_rows($table, undef, \%paramvalues);
$rows = $rep->get_rows($table, \@cols, \%paramvalues);
@@ -260,68 +263,28 @@
# $self->{table}{$table}{column}{$column}{notnull}
# $self->{table}{$table}{column}{$column}{quoted}
-#############################################################################
-# CONSTRUCTOR
-#############################################################################
-
-# $rep = Repository::Base->new();
-
-#sub new {
-# my $this = shift;
-# my ($class, $self);
-# $self = {};
-#
-# # contructing a new object from scratch from the class
-# # i.e. $rep = Repository::Base->new(...);
-# if (ref($this) eq "") {
-# $class = $this; # must be a scalar, presumably a class name
-## bless $self, $class;
-# $self->init_service(@_);
-# }
-# # contructing a new object from another object
-# # $rep = $rep1->new();
-# else {
-# $class = ref($this);
-# bless $self, $class;
-# $self->init_service($this->{name},$this->{config});
-# }
-#
-# return $self;
-#}
-
#####################################################################
-# init_service()
+# init()
# initialize the {config} structure and the {name} attribute
#####################################################################
-sub init_service {
+
+sub init {
my ($self, $args) = @_;
my ($dbidriver, $dbname, $dbuser, $dbpass, $dbioptions, $dbschema);
- my ($name, $config, $repconfig);
-
- $name = $args->{name};
-
- $self->{name} = $name;
- $self->{config} = $config;
+ my ($name, $config);
$self->{numrows} = 0;
$self->{error} = "";
- $repconfig = $self->{config};
- if (!$repconfig || ref($repconfig) ne "HASH") {
- print STDERR "Error: config does not have an entry for the [$name]
repository (\$conf->{repository}{$name})\n";
- return(undef);
- }
- $self->{repconfig} = $repconfig;
-
- $self->init($args);
+ $self->init2($args);
- if (!$self->connect()) {
- my ($repconfig);
- $repconfig = $self->{repconfig};
+ if (!$self->{config}{deferConnection} && !$self->connect()) {
+ my ($config);
+ $config = $self->{config};
print STDERR "Error on connect():";
- foreach (keys %$repconfig) {
- print STDERR " $_=[", $repconfig->{$_}, "]";
+ foreach (keys %$config) {
+ print STDERR " $_=[", $config->{$_}, "]";
}
print STDERR "\n";
return(undef);
@@ -330,30 +293,22 @@
$self->load_rep_metadata();
}
-sub init { } # OVERRIDE IN SUBCLASS
-
-sub DESTROY {
+sub init2 { # OVERRIDE IN SUBCLASS TO GET NON-DEFAULT CAPABILITIES
my $self = shift;
- $self->disconnect();
-}
-
-#############################################################################
-# CONFIG METHODS
-#############################################################################
-sub make_config { # OVERRIDE IN SUBCLASS
- my $conf = {
- 'repository' => {
- 'db' => {
- },
- },
- };
- $conf;
+ my ($config, $var);
+ $config = $self->{config};
+ if (defined $config) {
+ foreach $var (keys %$config) {
+ $self->{$var} = $config->{$var};
+ }
+ }
}
-sub read_config {
- my ($self, $file) = @_;
- return Repository->read_config($file);
+
+sub DESTROY {
+ my $self = shift;
+ $self->disconnect();
}
#############################################################################
@@ -825,6 +780,20 @@
$row;
}
+# $key = $rep->get_key ($table, \@cols, \@values);
+# $key = $rep->get_key ($table, \@cols, \@values, \@keycolidx);
+sub get_key {
+ my ($self, $table, $colsref, $valueref, $keycolidxref) = @_;
+ #my (@keys);
+ #$self->get_rows($table, undef, $paramvalueshashref, \@keys);
+ #if (wantarray) {
+ # return (@keys)
+ #}
+ #else {
+ # return ($#keys > -1) ? $keys[0] : undef;
+ #}
+}
+
# @keys = $rep->get_keys($table, \%paramvalues);
sub get_keys {
my ($self, $table, $paramvalueshashref) = @_;
@@ -867,6 +836,27 @@
$row->[$colidx];
}
+# $rep->set_rows ($table, \@cols, \@rows);
+sub set_rows {
+ my ($self, $table, $colsref, $rows) = @_;
+ my (@colidx, $row, $i, $cacherowidx);
+ $self->add_columns_fetched($table, $colsref, \@colidx);
+
+ # xyz
+ #$cacherowidx = $self->{table}{$table}{cache}{rowidx}{$key};
+ #if (defined $cacherowidx) {
+ # $row = $self->{table}{$table}{cache}{rows}[$cacherowidx];
+ #}
+ #else {
+ # $row = $self->get_row($table, $key);
+ # $cacherowidx = $self->{table}{$table}{cache}{rowidx}{$key};
+ #}
+ #for ($i = 0; $i <= $#$colsref; $i++) {
+ # $row->[$colidx[$i]] = $valuesref->[$i];
+ #}
+ #$self->{table}{$table}{cache}{rowchange}[$cacherowidx] = "U";
+}
+
# $key = $rep->set_values($table, $key, \@cols, \@values);
sub set_values {
my ($self, $table, $key, $colsref, $valuesref) = @_;
@@ -905,7 +895,6 @@
}
$row->[$colidx] = $value;
$self->{table}{$table}{cache}{rowchange}[$cacherowidx] = "U";
- $key;
}
# @idx = $rep->get_column_idx($table, \@cols);
1.3 +29 -69 p5ee/P5EEx/Blue/P5EEx/Blue/Repository/DBI.pm
Index: DBI.pm
===================================================================
RCS file: /cvs/public/p5ee/P5EEx/Blue/P5EEx/Blue/Repository/DBI.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -r1.2 -r1.3
--- DBI.pm 6 Jan 2002 20:57:07 -0000 1.2
+++ DBI.pm 16 Jan 2002 18:32:32 -0000 1.3
@@ -1,13 +1,13 @@
######################################################################
-## File: $Id: DBI.pm,v 1.2 2002/01/06 20:57:07 spadkins Exp $
+## File: $Id: DBI.pm,v 1.3 2002/01/16 18:32:32 spadkins Exp $
######################################################################
use P5EEx::Blue::P5EE;
use P5EEx::Blue::Repository;
package P5EEx::Blue::Repository::DBI;
-$VERSION = do { my @r=(q$Revision: 1.2 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
+$VERSION = do { my @r=(q$Revision: 1.3 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
use P5EEx::Blue::Repository;
@ISA = ( "P5EEx::Blue::Repository" );
@@ -136,60 +136,29 @@
# INITIALIZATION
######################################################################
-sub init {
+sub init2 {
my $self = shift;
- my ($name, $repconf);
- $repconfig = P5EEx::Blue::P5EE->config();
+ my ($name, $config);
$name = $self->{name};
- $repconf = $self->{repconfig};
- if (defined $repconf->{dbh}) {
- $self->{dbh} = $repconf->{dbh};
+ $config = $self->{config};
+ if (defined $config->{dbh}) {
+ $self->{dbh} = $config->{dbh};
$self->{preconnected} = 1;
}
+ else {
+ my ($var, $capsvar);
+ foreach $var qw(dbidriver dbname dbuser dbpass dbioptions dbschema) {
+ if (defined $config->{$var}) {
+ $self->{$var} = $config->{$var};
+ }
+ else {
+ $capsvar = uc($var);
+ if ($ENV{$capsvar}) {
+ $self->{$var} = $ENV{$capsvar};
}
-
-######################################################################
-# CONFIG METHODS
-######################################################################
-
-# take positional args and turn them into a %config structure
-sub make_config {
- my ($self, $dbidriver, $dbname, $dbuser, $dbpass, $dbioptions, $dbschema) = @_;
- my ($conf, $repconf);
-
- $repconf = {};
- $repconf->{dbidriver} = $dbidriver;
- $repconf->{dbname} = $dbname;
- $repconf->{dbuser} = $dbuser;
- $repconf->{dbpass} = $dbpass;
- $repconf->{dbioptions} = $dbioptions;
- $repconf->{dbschema} = $dbschema;
-
- $conf = {
- 'repository' => {
- 'db' => $repconf,
- },
- };
-
- $conf;
}
-
-sub read_config {
- my $self = shift;
-
- if ($ENV{DBIDRIVER} && $ENV{DBNAME}) {
- return $self->make_config(
- $ENV{DBIDRIVER},
- $ENV{DBNAME},
- $ENV{DBUSER},
- $ENV{DBPASS},
- $ENV{DBIOPTIONS},
- $ENV{DBSCHEMA}
- );
}
- else {
- return ($self->SUPER::read_config());
}
}
@@ -200,42 +169,33 @@
sub connect {
my $self = shift;
- my ($repname, $repconf);
- $repname = $self->{name};
- $repconf = $self->{config}{repository}{$repname};
+ my $config = $self->{config};
if (!defined $self->{dbh}) {
if (!defined $self->{dsn}) {
my ($dbidriver, $dbname, $dbuser, $dbpass, $dbioptions, $dbschema);
- $dbidriver = $repconf->{dbidriver};
- $dbname = $repconf->{dbname};
- $dbuser = $repconf->{dbuser};
- $dbpass = $repconf->{dbpass};
- $dbioptions = $repconf->{dbioptions};
- $dbschema = $repconf->{dbschema};
+ $dbidriver = $self->{dbidriver};
+ $dbname = $self->{dbname};
+ $dbuser = $self->{dbuser};
+ $dbpass = $self->{dbpass};
+ $dbioptions = $self->{dbioptions};
+ $dbschema = $self->{dbschema};
- print STDERR "ERROR: missing DBI driver and/or db name
[$dbidriver,$dbname] in configuration.\n"
+ die "ERROR: missing DBI driver and/or db name [$dbidriver,$dbname] in
configuration.\n"
if (!$dbidriver || !$dbname);
- $self->{dbidriver} = $dbidriver;
- $self->{dbname} = $dbname;
- $self->{dbuser} = $dbuser;
- $self->{dbpass} = $dbpass;
- $self->{dbioptions} = $dbioptions;
- $self->{dbschema} = $dbschema;
-
$self->{dsn} = "dbi:${dbidriver}:database=${dbname}";
# enforce driver-specific rules here
if ($dbidriver eq "mysql") {
# force an update of a row to report that is was found (even if the
values didn't change)
$self->{dsn} .= ";mysql_client_found_rows=true";
- $self->{attr} = { "PrintError" => 0, "AutoCommit" => 1 };
+ $self->{attr} = { "PrintError" => 0, "AutoCommit" => 1,
"RaiseError" => 1 };
}
else {
- $self->{attr} = { "PrintError" => 0, "AutoCommit" => 0 };
+ $self->{attr} = { "PrintError" => 0, "AutoCommit" => 0,
"RaiseError" => 1 };
}
}