2 # ============================================================================
3 # Zebra perl API header
4 # =============================================================================
7 # ============================================================================
8 package IDZebra::Session;
10 use IDZebra::Logger qw(:flags :calls);
11 use IDZebra::Repository;
12 use IDZebra::Resultset;
15 our @ISA = qw(IDZebra::Logger);
18 # -----------------------------------------------------------------------------
19 # Class constructors, destructor
20 # -----------------------------------------------------------------------------
22 my ($proto,$service) = @_;
23 my $class = ref($proto) || $proto;
25 $self->{service} = $service;
26 $self->{sessionID} = $service->{sessc};
27 bless ($self, $class);
32 my ($proto,$service) = @_;
34 if (ref($proto)) { $self = $proto; } else {
35 $self = $proto->new($service);
37 unless (defined($self->{zh})) {
38 $self->{zh}=IDZebra::open($self->{service}{zs}) if ($self->{service});
40 $self->Repository(); # Make a dummy record group
42 $self->{odr_input} = IDZebra::odr_createmem($IDZebra::ODR_DECODE);
43 $self->{odr_output} = IDZebra::odr_createmem($IDZebra::ODR_ENCODE);
52 IDZebra::close($self->{zh});
56 if ($self->{odr_input}) {
57 IDZebra::odr_reset($self->{odr_input});
58 IDZebra::odr_destroy($self->{odr_input});
59 $self->{odr_input} = undef;
62 if ($self->{odr_output}) {
63 IDZebra::odr_reset($self->{odr_output});
64 IDZebra::odr_destroy($self->{odr_output});
65 $self->{odr_output} = undef;
68 delete($self->{service}{sessions}{$self->{sessionID}});
69 delete($self->{service});
74 print STDERR "Destroy_session\n";
77 # -----------------------------------------------------------------------------
79 # -----------------------------------------------------------------------------
82 return(IDZebra::errCode($self->{zh}));
87 return(IDZebra::errString($self->{zh}));
92 return(IDZebra::errAdd($self->{zh}));
95 # -----------------------------------------------------------------------------
97 # -----------------------------------------------------------------------------
100 unless ($self->{trans_started}) {
101 $self->{trans_started} = 1;
102 IDZebra::begin_trans($self->{zh});
108 if ($self->{trans_started}) {
109 $self->{trans_started} = 0;
110 IDZebra::end_trans($self->{zh});
116 return(IDZebra::begin_read($self->{zh}));
121 IDZebra::end_read($self->{zh});
125 my ($self, $value) = @_;
126 if ($#_ > 0) { IDZebra::set_shadow_enable($self->{zh},$value); }
127 return (IDZebra::get_shadow_enable($self->{zh}));
132 if ($self->shadow_enable) {
133 return(IDZebra::commit($self->{zh}));
137 # -----------------------------------------------------------------------------
138 # We don't really need that...
139 # -----------------------------------------------------------------------------
141 my ($self, $name) = @_;
142 if ($name !~/^(input|output)$/) {
143 croak("Undefined ODR '$name'");
145 IDZebra::odr_reset($self->{"odr_$name"});
148 # -----------------------------------------------------------------------------
150 # -----------------------------------------------------------------------------
153 return(IDZebra::init($self->{zh}));
158 return(IDZebra::compact($self->{zh}));
161 # -----------------------------------------------------------------------------
163 # -----------------------------------------------------------------------------
165 my ($self, %args) = @_;
167 $self->{rep} = IDZebra::Repository->new($self, %args);
169 $self->{rep}->modify(%args);
172 return ($self->{rep});
175 # -----------------------------------------------------------------------------
177 # -----------------------------------------------------------------------------
178 sub select_databases {
179 my ($self, @databases) = @_;
180 return (IDZebra::select_databases($self->{zh},
186 my ($self, $query, $setname) = @_;
187 my $hits = IDZebra::search_PQF($self->{zh},
193 my $rs = IDZebra::Resultset->new($self,
195 recordCount => $hits,
196 errCode => $self->errCode,
197 errString => $self->errString);
201 # -----------------------------------------------------------------------------
204 # Sorting of multiple result sets is not supported by zebra...
205 # -----------------------------------------------------------------------------
208 my ($self, $sortspec, $setname, @sets) = @_;
212 foreach my $rs (@sets) {
213 push (@setnames, $rs->{name});
214 $count += $rs->{recordCount}; # is this really sure ??? It doesn't
218 my $status = IDZebra::sort($self->{zh},
224 my $errCode = $self->errCode;
225 my $errString = $self->errString;
227 if ($status || $errCode) {$count = 0;}
229 my $rs = IDZebra::Resultset->new($self,
231 recordCount => $count,
233 errString => $errString);
255 Peter Popovics, pop@technomat.hu
259 IDZebra, IDZebra::Data1, Zebra documentation