use Bugzilla::DB::Schema;
use Bugzilla::Version;
+use Scalar::Util qw(blessed);
use List::Util qw(max);
use Storable qw(dclone);
# Schema Information Methods
#####################################################################
+sub _bz_schema_class {
+ my ($self) = @_;
+ my $class = blessed($self) // $self;
+ my @class_parts = split(/::/, $class);
+ splice(@class_parts, -1, 0, 'Schema');
+
+ return join('::', @class_parts);
+}
+
sub _bz_schema {
my ($self) = @_;
return $self->{private_bz_schema} if exists $self->{private_bz_schema};
- my @module_parts = split('::', ref $self);
- my $module_name = pop @module_parts;
- $self->{private_bz_schema} = Bugzilla::DB::Schema->new($module_name);
+ my $schema_class = $self->_bz_schema_class;
+ eval "require $schema_class";
+ $self->{private_bz_schema} = $schema_class->new();
return $self->{private_bz_schema};
}
=item C<new>
Description: Public constructor method used to instantiate objects of this
- class. However, it also can be used as a factory method to
- instantiate database-specific subclasses when an optional
- driver argument is supplied.
+ class.
Parameters: $driver (optional) - Used to specify the type of database.
This routine C<die>s if no subclass is found for the specified
driver.
my $this = shift;
my $class = ref($this) || $this;
- my $driver = shift;
-
- if ($driver) {
- (my $subclass = $driver) =~ s/^(\S)/\U$1/;
- $class .= '::' . $subclass;
- eval "require $class;";
- die "The $class class could not be found ($subclass " . "not supported?): $@"
- if ($@);
- }
+
die "$class is an abstract base class. Instantiate a subclass instead."
if ($class eq __PACKAGE__);
}
}
- return $class->new(undef, $thawed_hash);
+ return $class->new($thawed_hash);
}
#####################################################################
use lib qw(. t lib);
use Bugzilla;
use Bugzilla::DB::Schema;
+use Bugzilla::DB::Schema::Mysql;
# SQL reserved words
our @tables;
BEGIN {
- $schema = Bugzilla::DB::Schema->new("Mysql");
+ $schema = Bugzilla::DB::Schema::Mysql->new;
@tables = $schema->get_table_list();
}