source: gs2-extensions/tdb/trunk/perllib/DBDrivers/JDBM.pm@ 30347

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

Continuing to refactor driver code to move shared code up to parent classes. Have all the basic drivers done...

  • Property svn:executable set to *
File size: 3.6 KB
RevLine 
[30318]1###############################################################################
2#
3# DBDrivers/JDBM.pm -- utility functions for writing to jdbm 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) 1999-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::JDBM;
27
28# Pragma
29use strict;
30
31# Libraries
32use util;
33use FileUtils;
[30338]34# - OO inheritence
[30347]35use parent 'DBDrivers::70HyphenFormat';
[30318]36
37sub BEGIN
38{
[30338]39 if (!defined $ENV{'GSDLHOME'} || !defined $ENV{'GSDLOS'}) {
40 die("Error! Environment must be prepared by sourcing setup.bash\n");
41 }
[30318]42}
43
[30338]44
45## @function constructor
46#
[30318]47sub new
48{
49 my $class = shift(@_);
[30347]50 my $self = DBDrivers::70HyphenFormat->new(@_);
[30338]51 $self->{'default_file_extension'} = 'jdb';
[30347]52
53 # Executables need a little extra work since we are using Java
54 # - we need to build up the classpath continue the Jar libraries to use
55 my $jdbmwrap_jar = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, 'bin', 'java', 'JDBMWrapper.jar');
56 my $jdbm_jar = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, 'lib', 'java', 'jdbm.jar');
57 my $classpath = &util::pathname_cat($jdbmwrap_jar,$jdbm_jar);
58 # Massage paths for Cygwin. Away to run a java program, using a binary that
59 # is native to Windows, so need Windows directory and path separators
60 if ($^O eq "cygwin") {
61 $classpath = `cygpath -wp "$classpath"`;
62 chomp($classpath);
63 $classpath =~ s%\\%\\\\%g;
64 }
65 $self->{'executable_path'} = '';
66 $self->{'read_executable'} = 'java -cp "' . $classpath . '" Jdb2Txt';
67 $self->{'keyread_executable'} = 'java -cp "' . $classpath . '" JdbKeys';
68 $self->{'write_executable'} = 'java -cp "' . $classpath . '" Txt2Jdb';
69 # Support
70 $self->{'supports_set'} = 1;
71
[30338]72 bless($self, $class);
73 return $self;
[30318]74}
[30338]75## constructor() ##
[30318]76
[30338]77
[30318]78# -----------------------------------------------------------------------------
79# JDBM IMPLEMENTATION
80# -----------------------------------------------------------------------------
81
82# When DBUtil::* is properly structured with inheritence, then
83# much of this code (along with GDBM and GDBM-TXT-GZ) can be grouped into
84# a shared base class. Really it is only the the command that needs to
85# be constructed that changes between much of the code that is used
86
[30338]87# Handled by BaseDBDriver
88# sub get_infodb_file_path {}
89
[30347]90# Handles by 70HyphenFormat
91# sub open_infodb_write_handle(string, string?) => filehandle
92# sub close_infodb_write_handle(filehandle) => void
93# sub read_infodb_file(string, hashmap) => void
94# sub read_infodb_keys(string, hashmap) => void
95# sub write_infodb_entry(filehandle, string, hashmap) => void
96# sub write_infodb_rawentry(filehandle, string, string) => void
97# sub set_infodb_entry(filehandle, string, string) => void
98# sub delete_infodb_entry(filehandle, string) => void
[30338]99
[30318]1001;
Note: See TracBrowser for help on using the repository browser.