Changeset 32592

Show
Ignore:
Timestamp:
09.11.2018 19:13:32 (5 weeks ago)
Author:
ak19
Message:

Renamed gssql.pm to gsmysql.pm. Not subclassing the old gssql into gsmysql yet, as there's the complex issue of sighandlers, the static singleton method _get_connection_instance(), the singleton variable _db_instance and its use in the sighandlers and DESTROY, and how all of this can be impacted when making them part of an inheritance chain. Not sure of the best way to structure inheritance around these things. Even if rollback_on_cancel ends up unnecessary, the singleton method _get_connection_instance and singleton object _db_instance still impact decisions around inheritance.

Location:
main/trunk/greenstone2/perllib
Files:
2 modified
1 moved

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/gsmysql.pm

    r32591 r32592  
    11########################################################################### 
    22# 
    3 # gssql.pm -- DBI for SQL related utility functions used by 
     3# gsmysql.pm -- Uses DBI for MySQL related utility functions used by 
    44# GreenstoneSQLPlugout and GreenstoneSQLPlugin too. 
    55# A component of the Greenstone digital library software 
     
    2525########################################################################### 
    2626 
    27 package gssql; 
     27package gsmysql; 
    2828 
    2929use strict; 
     
    4343# TODO Q: If disconnect is automatically called when object destroyed, what does that mean 
    4444# for our file-global handle object, is disconnect only called at end of perl process? 
    45 # Does that mean we don't need to explicitly call disconnect in gssql object's destroy during 
     45# Does that mean we don't need to explicitly call disconnect in gsmysql object's destroy during 
    4646# the GLOBAL destruction phase? 
    4747# https://perldoc.perl.org/perlobj.html#Destructors 
     
    345345} 
    346346 
    347 # Will disconnect if this instance of gssql holds the last reference to the db connection 
     347# Will disconnect if this instance of gsmysql holds the last reference to the db connection 
    348348# If disconnecting and autocommit is off, then this will commit before disconnecting 
    349349sub finished { 
     
    385385    # NO: "When all the data has been fetched from a SELECT statement, the driver will automatically call finish for you. So you should not call it explicitly except when you know that you've not fetched all the data from a statement handle and the handle won't be destroyed soon." 
    386386     
    387     print STDERR "    GSSQL disconnecting from database\n" if $self->{'verbosity'}; 
     387    print STDERR "    GSMySQL disconnecting from database\n" if $self->{'verbosity'}; 
    388388    # Just go through the singleton db handle to disconnect 
    389389    $_dbh_instance->disconnect or warn $_dbh_instance->errstr; 
    390390    $_dbh_instance = undef; 
    391391    } 
    392     # Number of gssql objects that share a live connection is now 0, as the connection's dead 
    393     # either because the last gssql object finished() or because connection was killed (force) 
     392    # Number of gsmysql objects that share a live connection is now 0, as the connection's dead 
     393    # either because the last gsmysql object finished() or because connection was killed (force) 
    394394    $ref_count = 0; 
    395395} 
  • main/trunk/greenstone2/perllib/plugins/GreenstoneSQLPlugin.pm

    r32591 r32592  
    3535use docprint; # for new unescape_text() subroutine 
    3636use GreenstoneXMLPlugin; 
    37 use gssql; 
     37use gsmysql; 
    3838 
    3939 
    4040# TODO: 
    41 # - Run TODOs here, in Plugout and in gssql.pm by Dr Bainbridge. 
     41# - Run TODOs here, in Plugout and in gsmysql.pm by Dr Bainbridge. 
    4242# - Have not yet tested writing out just meta or just fulltxt to sql db and reading just that  
    4343# back in from the sql db while the remainder is to be read back in from the docsql .xml files. 
     
    7171# Test doc with meta and text like macron in Maori text. 
    7272# + TODO Q: During import, the GS SQL Plugin is called before the GS SQL Plugout with undesirable side 
    73 # effect that if the db doesn't exist, gssql::use_db() fails, as it won't create db. 
     73# effect that if the db doesn't exist, gsmysql::use_db() fails, as it won't create db. 
    7474#   This got fixed when GSSQLPlugin stopped connecting on init(). 
    7575# 
     
    8989# Overriding plugins' remove_one() method is all I needed to do for reindex and deletion 
    9090# (incremental and non-incremental) to work. 
    91 # but doing all this needed an overhaul of gssql.pm and its use by the GS SQL plugin and plugout. 
     91# but doing all this needed an overhaul of gsmysql.pm and its use by the GS SQL plugin and plugout. 
    9292# - needed to correct plugin.pm::remove_some() to process all files 
    9393# - and needed to correct GreenstoneSQLPlugin::close_document() to setOID() after all 
     
    145145        'desc' => "{GreenstoneSQLPlug.rollbacl_on_cancel}" } ]; 
    146146 
    147 # TODO: If subclassing gssql for other supporting databases and if they have different required 
     147# TODO: If subclassing gsmysql for other supporting databases and if they have different required 
    148148# connection parameters, we can check how WordPlugin, upon detecting Word is installed, 
    149149# dynamically loads Word specific configuration options. 
     
    229229# as removeold, which should drop the collection tables, happens during the import phase, 
    230230# calling GreenstoneSQLPlugin::and therefore also requires a db connection. 
    231 # + TODO: Eventually can try moving get_gssql_instance into gssql.pm? That way both GS SQL Plugin 
     231# + TODO: Eventually can try moving get_gssql_instance into gsmysql.pm? That way both GS SQL Plugin 
    232232# and Plugout would be using one connection during import.pl phase when both plugs exist. 
    233233 
     
    252252    #################### 
    253253 
    254     # create gssql object. 
     254    # create gsmysql object. 
    255255    # collection name will be used for naming tables (site name will be used for naming database) 
    256     my $gs_sql = new gssql({ 
     256    my $gs_sql = new gsmysql({ 
    257257    'collection_name' => $ENV{'GSDLCOLLECTION'}, 
    258258    'verbosity' => $self->{'verbosity'} || 0 
     
    286286    # This is fatal for the plugout, let's terminate here after disconnecting again 
    287287    # PrintError would already have displayed the warning message on load fail 
    288     # And on die() perl will call gssql destroy which will ensure a disconnect() from db 
     288    # And on die() perl will call gsmysql destroy which will ensure a disconnect() from db 
    289289    #$gs_sql->force_disconnect_from_db(); 
    290290    die("Could not use db $db_name. Can't proceed.\n"); 
     
    310310 
    311311    # Important to call finished(): 
    312     # it will disconnect from db if this is the last gssql instance, 
     312    # it will disconnect from db if this is the last gsmysql instance, 
    313313    # and it will commit to db before disconnecting if rollbback_on_cancel turned on 
    314314    $self->{'gs_sql'}->finished(); 
  • main/trunk/greenstone2/perllib/plugouts/GreenstoneSQLPlugout.pm

    r32591 r32592  
    3434use GreenstoneXMLPlugout; 
    3535use docprint; 
    36 use gssql; 
     36use gsmysql; 
    3737 
    3838use DBI; # the central package for this plugout 
     
    170170    }; 
    171171 
    172     my $gs_sql = new gssql($db_params); 
     172    my $gs_sql = new gsmysql($db_params); 
    173173 
    174174    # if autocommit is set, there's no rollback support 
     
    192192    } 
    193193 
    194     #die("@@@@ TEST. Connected successfully. Testing gssql::destructor.\n"); # WORKS 
     194    #die("@@@@ TEST. Connected successfully. Testing gsmysql::destructor.\n"); # WORKS 
    195195     
    196196    my $db_name = $self->{'site'} || "greenstone2"; # one database per GS3 site, for GS2 the db is called greenstone2 
     
    212212    # This is fatal for the plugout, let's terminate here after disconnecting again 
    213213    # PrintError would already have displayed the warning message on load fail 
    214     # And on die() perl will call gssql destroy which will ensure a disconnect() from db 
     214    # And on die() perl will call gsmysql destroy which will ensure a disconnect() from db 
    215215    #$gs_sql->force_disconnect_from_db(); # disconnect_from_db() will issue a warning on error 
    216216    die("Could not use db $db_name and/or prepare its tables. Can't proceed.\n"); 
     
    237237 
    238238    # Important to call finished(): 
    239     # it will disconnect from db if this is the last gssql instance, 
     239    # it will disconnect from db if this is the last gsmysql instance, 
    240240    # and it will commit to db before disconnecting if rollbback_on_cancel turned on 
    241241    $self->{'gs_sql'}->finished();