diff options
author | Russ Allbery <rra@stanford.edu> | 2007-12-05 01:10:23 +0000 |
---|---|---|
committer | Russ Allbery <rra@stanford.edu> | 2007-12-05 01:10:23 +0000 |
commit | c0c34051887d08a94221f9cbc2b74fbfad34c22c (patch) | |
tree | cf6dbd65beee76296f4a16fef21c86419eaa5ed8 /perl/Wallet/Schema.pm | |
parent | 0e9a5e25ec9c1977c6426f4aea4b61a658fe6855 (diff) |
Determine the class for object and ACL schema implementations from the
database rather than a hard-coded list and provide Wallet::Schema
methods for adding new class mappings.
Add a missing class mapping for the netdb ACL schema verifier.
Diffstat (limited to 'perl/Wallet/Schema.pm')
-rw-r--r-- | perl/Wallet/Schema.pm | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/perl/Wallet/Schema.pm b/perl/Wallet/Schema.pm index 532c61e..2aac445 100644 --- a/perl/Wallet/Schema.pm +++ b/perl/Wallet/Schema.pm @@ -24,7 +24,7 @@ use DBI; $VERSION = '0.02'; ############################################################################## -# Implementation +# Data manipulation ############################################################################## # Create a new Wallet::Schema object, parse the SQL out of the documentation, @@ -63,6 +63,10 @@ sub sql { return @{ $self->{sql} }; } +############################################################################## +# Initialization and cleanup +############################################################################## + # Given a database handle, try to create our database by running the SQL. Do # this in a transaction regardless of the database settings and throw an # exception if this fails. We have to do a bit of fiddling to get syntax that @@ -116,6 +120,44 @@ sub drop { } ############################################################################## +# Administrative actions +############################################################################## + +# Given a database handle, object type, and class name, add a new class +# mapping to that database for the given object type. This is used to +# register new object types. Throws an exception on failure. +sub register_object { + my ($self, $dbh, $type, $class) = @_; + eval { + $dbh->begin_work if $dbh->{AutoCommit}; + my $sql = 'insert into types (ty_name, ty_class) values (?, ?)'; + $dbh->do ($sql, undef, $type, $class); + $dbh->commit; + }; + if ($@) { + $dbh->rollback; + die "$@\n"; + } +} + +# Given a database handle, ACL verifier scheme, and class name, add a new +# class mapping to that database for the given ACL verifier scheme. This is +# used to register new ACL schemes. Throws an exception on failure. +sub register_verifier { + my ($self, $dbh, $scheme, $class) = @_; + eval { + $dbh->begin_work if $dbh->{AutoCommit}; + my $sql = 'insert into acl_schemes (as_name, as_class) values (?, ?)'; + $dbh->do ($sql, undef, $scheme, $class); + $dbh->commit; + }; + if ($@) { + $dbh->rollback; + die "$@\n"; + } +} + +############################################################################## # Schema ############################################################################## @@ -173,6 +215,24 @@ that are part of the current schema or one of the previous known schema and won't remove other tables. On any error, this method will throw a database exception. +=item register_object (DBH, TYPE, CLASS) + +Given a connected database handle, register in that database a mapping from +the object type TYPE to the class CLASS. On any error, including attempting +to add a mapping for a type that already exists, this method will throw a +database exception. + +This method will eventually move to another class. + +=item register_verifier (DBH, SCHEME, CLASS) + +Given a connected database handle, register in that database a mapping from +the ACL scheme SCHEME to the class CLASS. On any error, including +attempting to add a mapping for a scheme that already exists, this method +will throw a database exception. + +This method will eventually move to another class. + =item sql() Returns the schema and the population of the normalization tables as a list |