]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg.pm
41ade711cbd9fbe7c640e51d31796563b91e1ac7
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Storage / Driver / Pg.pm
1 #-------------------------------------------------------------------------------
2 use Class::DBI;
3 package Class::DBI;
4
5 sub search_fti {
6         my $self = shift;
7         my @args = @_;
8         if (ref($args[-1]) eq 'HASH') {
9                 $args[-1]->{_placeholder} = "to_tsquery('default',?)";
10         } else {
11                 push @args, {_placeholder => "to_tsquery('default',?)"};
12         }
13         $self->_do_search("@@"  => @args);
14 }
15
16 #-------------------------------------------------------------------------------
17 package OpenILS::Application::Storage::FTS;
18 use OpenSRF::Utils::Logger qw/:level/;
19 my $log = 'OpenSRF::Utils::Logger';
20
21 sub compile {
22         my $self = shift;
23         my $term = shift;
24
25         $self = ref($self) || $self;
26         $self = bless {} => $self;
27
28         $self->decompose($term);
29
30         my $newterm = join('&', $self->words);
31
32         if ($self->nots) {
33                 $newterm = '('.$newterm.')&('. join('|', $self->nots) . ')';
34         }
35
36         $newterm = OpenILS::Application::Storage->driver->quote($newterm);
37
38         $self->{fts_query} = ["to_tsquery('default',$newterm)"];
39         $self->{fts_query_nots} = [];
40         $self->{fts_op} = '@@';
41
42         return $self;
43 }
44
45
46 #-------------------------------------------------------------------------------
47 package OpenILS::Application::Storage::Driver::Pg;
48 use base qw/Class::DBI DBD::Pg OpenILS::Application::Storage/;
49 use DBI;
50 use DBD::Pg;
51 use OpenSRF::Utils::Logger qw/:level/;
52
53 __PACKAGE__->set_sql( retrieve_limited => 'SELECT * FROM __TABLE__ ORDER BY id LIMIT ?' );
54
55 my $_dbh;
56
57 sub db_Main {   
58         return $_dbh if (defined $_dbh and $_dbh->ping);
59
60         my $self = shift;
61
62         my %args = (%OpenILS::Application::Storage::_db_params,@_);
63
64         my %attrs = (   %{$self->_default_attributes},
65                         RootClass => 'DBIx::ContextualFetch',
66                         ShowErrorStatement => 1,
67                         RaiseError => 1,
68                         AutoCommit => 1,
69                         PrintError => 1,
70                         Taint => 1,
71                         pg_enable_utf8 => 1,
72                         FetchHashKeyName => 'NAME_lc',
73                         ChopBlanks => 1,
74         );
75
76         $log->debug(" Default attributes for this DB connection are:\n\t".join("\n\t",map { "$_\t==> $attrs{$_}" } keys %attrs), INTERNAL);
77
78         $_dbh = DBI->connect( "dbi:Pg:host=$args{host};dbname=$args{database}",$args{user},$args{pw}, \%attrs );
79         $_dbh->do("SET CLIENT_ENCODING TO 'SQL_ASCII';");
80
81         return $_dbh;
82 }
83
84 #-------------------------------------------------------------------------------
85 package asset::call_number;
86 use base qw/OpenILS::App::Storage::CDBI/;
87
88 __PACKAGE__->table( 'asset.call_number' );
89 __PACKAGE__->sequence( 'asset.call_number_id_seq' );
90 __PACKAGE__->columns( Primary => qw/id/ );
91 __PACKAGE__->columns( Essential => qw/record/ );
92
93 __PACKAGE__->has_a( record => 'biblio::record_entry' );
94 __PACKAGE__->has_many( copies => 'asset::copy' );
95
96
97
98 #-------------------------------------------------------------------------------
99 package asset::copy;
100 use base qw/OpenILS::App::Storage::CDBI/;
101
102 __PACKAGE__->table( 'asset.copy' );
103 __PACKAGE__->sequence( 'asset.copy_id_seq' );
104 __PACKAGE__->columns( Primary => qw/id/ );
105 __PACKAGE__->columns( Essential => qw/call_number barcode/ );
106
107 #__PACKAGE__->has_a( call_number => 'asset::call_number' );
108
109
110
111 #-------------------------------------------------------------------------------
112 package biblio::record_entry;
113 use base qw/OpenILS::App::Storage::CDBI/;
114
115 __PACKAGE__->table( 'biblio.record_entry' );
116 __PACKAGE__->sequence( 'biblio.record_entry_id_seq' );
117 __PACKAGE__->columns( Primary => qw/id/ );
118
119 #__PACKAGE__->columns( Essential => qw/tcn_source tcn_value metarecord creator editor create_date edit_date source active deleted/ );
120 __PACKAGE__->columns( Others => qw/tcn_source tcn_value metarecord creator editor create_date edit_date source active deleted/ );
121
122 __PACKAGE__->has_a( note => 'biblio::record_note' );
123 __PACKAGE__->has_many( nodes => 'biblio::record_data' );
124
125 #__PACKAGE__->has_a( metarecord => 'metabib::metarecord' );
126 #__PACKAGE__->has_many( field_entries => 'metabib::field_entry' );
127 #__PACKAGE__->has_many( call_numbers => 'asset::call_number' );
128
129 #-------------------------------------------------------------------------------
130 package biblio::record_node::subnode;
131 sub _load { 
132         my $intra_doc_id = shift;
133         my $owner_doc = shift()->owner_doc;
134         return (biblio::record_node->search( owner_doc => $owner_doc, intra_doc_id => $intra_doc_id ))[0];
135 }
136
137 package biblio::record_node;
138 use base qw/OpenILS::App::Storage::CDBI/;
139
140 __PACKAGE__->table( 'biblio.record_data' );
141 __PACKAGE__->sequence( 'biblio.record_data_id_seq' );
142 __PACKAGE__->columns( Primary => qw/id/ );
143 __PACKAGE__->columns( Essential => qw/owner_doc intra_doc_id parent_node node_type namespace_uri name value/ );
144
145 __PACKAGE__->has_a( owner_doc => 'biblio::record_entry' );
146 __PACKAGE__->has_a(
147         parent_node     => 'biblio::record_node::subnode',
148         inflate         => sub { return biblio::record_node::subnode::_load(@_) },
149 );
150
151
152 #-------------------------------------------------------------------------------
153 package biblio::record_note;
154 use base qw/OpenILS::App::Storage::CDBI/;
155
156 __PACKAGE__->table( 'biblio.record_note' );
157 __PACKAGE__->sequence( 'biblio.record_note_id_seq' );
158 __PACKAGE__->columns( Primary => qw/id/ );
159 __PACKAGE__->columns( Stringify => qw/value/ );
160 __PACKAGE__->columns( Essential => qw/record value creator editor create_date edit_date/ );
161
162 __PACKAGE__->has_a( record_entry => 'biblio::record_entry' );
163
164 #-------------------------------------------------------------------------------
165 #-------------------------------------------------------------------------------
166
167 1;
168