|
Revision 1406, 1.3 kB
(checked in by bchoate, 21 months ago)
|
|
Updated with prioritization support from TheSchwartz 1.07
|
-
Property svn:keywords set to
Id Revision
|
| Line | |
|---|
| 1 | # $Id$ |
|---|
| 2 | |
|---|
| 3 | package TheSchwartz::FuncMap; |
|---|
| 4 | use strict; |
|---|
| 5 | use base qw( Data::ObjectDriver::BaseObject ); |
|---|
| 6 | |
|---|
| 7 | use Carp qw( croak ); |
|---|
| 8 | |
|---|
| 9 | __PACKAGE__->install_properties({ |
|---|
| 10 | columns => [ qw( funcid funcname ) ], |
|---|
| 11 | datasource => 'funcmap', |
|---|
| 12 | primary_key => 'funcid', |
|---|
| 13 | }); |
|---|
| 14 | |
|---|
| 15 | sub create_or_find { |
|---|
| 16 | my $class = shift; |
|---|
| 17 | my($driver, $funcname) = @_; |
|---|
| 18 | |
|---|
| 19 | ## Attempt to select funcmap record by name. If successful, return |
|---|
| 20 | ## object, otherwise proceed with insertion and return. |
|---|
| 21 | my ($map) = $driver->search('TheSchwartz::FuncMap' => |
|---|
| 22 | { funcname => $funcname } |
|---|
| 23 | ); |
|---|
| 24 | return $map if $map; |
|---|
| 25 | |
|---|
| 26 | ## Attempt to insert a new funcmap row. Since the funcname column is |
|---|
| 27 | ## UNIQUE, if the row already exists, an exception will be thrown. |
|---|
| 28 | $map = $class->new; |
|---|
| 29 | $map->funcname($funcname); |
|---|
| 30 | eval { $driver->insert($map) }; |
|---|
| 31 | |
|---|
| 32 | ## If we got an exception, try to load the record with this funcname; |
|---|
| 33 | ## in all likelihood, the exception was that the record was added by |
|---|
| 34 | ## another process. |
|---|
| 35 | if (my $err = $@) { |
|---|
| 36 | ($map) = $driver->search('TheSchwartz::FuncMap' => |
|---|
| 37 | { funcname => $funcname } |
|---|
| 38 | ) or croak "Can't find or create funcname $funcname: $err"; |
|---|
| 39 | } |
|---|
| 40 | return $map; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | 1; |
|---|