source: main/trunk/greenstone2/perllib/DBDrivers/GDBMTXTGZ.pm@ 30355

Last change on this file since 30355 was 30355, checked in by jmt12, 8 years ago

Initial checkin of OO drivers for new dbutils system

File size: 3.7 KB
Line 
1###############################################################################
2#
3# GDBMTXTGZ.pm -- utility functions for writing to gdbm-txtgz databases
4#
5# A component of the Greenstone digital library software from the New Zealand
6# Digital Library Project at the University of Waikato, New Zealand.
7#
8# Copyright (c) 2015 New Zealand Digital Library Project
9#
10# This program is free software; you can redistribute it and/or modify it under
11# the terms of the GNU General Public License as published by the Free Software
12# Foundation; either version 2 of the License, or (at your option) any later
13# version.
14#
15# This program is distributed in the hope that it will be useful, but WITHOUT
16# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18# more details.
19#
20# You should have received a copy of the GNU General Public License along with
21# this program; if not, write to the Free Software Foundation, Inc., 675 Mass
22# Ave, Cambridge, MA 02139, USA.
23#
24###############################################################################
25
26package DBDrivers::GDBMTXTGZ;
27
28# Pragma
29use strict;
30
31# Libraries
32use util;
33use FileUtils;
34# - OO inheritence
35use parent 'DBDrivers::70HyphenFormat';
36
37
38sub new
39{
40 my $class = shift(@_);
41 my $self = DBDrivers::70HyphenFormat->new(@_);
42 # Default TDB file extension
43 $self->{'default_file_extension'} = 'txt.gz';
44 # note: file separator agnostic
45 $self->{'executable_path'} = $ENV{'GSDLHOME'} . '/bin/' . $ENV{'GSDLOS'};
46 $self->{'read_executable'} = 'gzip --decompress --to-stdout';
47 $self->{'keyread_executable'} = $self->{'read_executable'};
48 $self->{'write_executable'} = 'gzip -';
49 bless ($self, $class);
50 return $self;
51}
52
53# -----------------------------------------------------------------------------
54# GDBM TXT-GZ IMPLEMENTATION
55# -----------------------------------------------------------------------------
56
57# Handled by BaseDBDriver
58# sub get_infodb_file_path(string, string)
59
60# Handled by 70HyphenFormat
61# sub close_infodb_write_handle(filehandle) => void
62# sub read_infodb_file(string, hashmap) => void
63# sub read_infodb_keys(string, hashmap) => void
64# sub write_infodb_entry(filehandle, string, hashmap) => void
65# sub write_infodb_rawentry(filehandle, string, string) => void
66
67
68## @function open_infodb_write_handle(string)
69#
70# Keep infodb in GDBM neutral form => save data as compressed text file, read
71# for txt2db to be run on it later (i.e. by the runtime system, first time the
72# collection is ever accessed). This makes it easier distribute pre-built
73# collections to various architectures.
74#
75# NB: even if two architectures are little endian (e.g. Intel and ARM procesors)
76# GDBM does *not* guarantee that the database generated on one will work on the
77# other
78#
79# Now only responsible for transforming the optional append argument into the
80# correct redirection operand (either > for clobber or >> for append)
81#
82sub open_infodb_write_handle
83{
84 my $self = shift(@_);
85 my $infodb_file_path = shift(@_);
86 my $opt_append = shift(@_);
87 my $infodb_file_handle;
88 # append
89 if (defined $opt_append && $opt_append =~ /^-?append$/) {
90 $infodb_file_handle = $self->SUPER::open_infodb_write_handle($infodb_file_path, '>>');
91 }
92 # create or clobber
93 else {
94 $infodb_file_handle = $self->SUPER::open_infodb_write_handle($infodb_file_path, '>');
95 }
96 return $infodb_file_handle;
97}
98## open_infodb_write_handle(string) => filehandle ##
99
100## @function set_infodb_entry(string, string, hashmap)
101#
102sub set_infodb_entry
103{
104 my $self = shift(@_);
105 print STDERR "***** gdbmtxtgz::set_infodb_entry() not implemented yet!\n";
106}
107## set_infodb_entry(string, string, hashmap) => void ##
108
109
1101;
Note: See TracBrowser for help on using the repository browser.