Subversion Repositories DevTools

Rev

Rev 5934 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
########################################################################
4466 dpurdie 2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
227 dpurdie 3
#
4466 dpurdie 4
# Module name   : JatsRmApi
227 dpurdie 5
# Module type   : Makefile system
6
# Compiler(s)   : n/a
7
# Environment(s): jats
8
#
4466 dpurdie 9
# Description   : Provides common access function to:
10
#                       The Release Manager
11
#                       The Deployment Manager Databases
12
#                       The ClearQuest Database    
227 dpurdie 13
#
14
#                 Note: The interface provided is constrained
15
#                       by the existing usage.
16
#
17
#                       This is an attempt to provide common accessor
18
#                       functions to open and close a connection
19
#
20
#                Note: This is not a class
21
#                      The connection WILL NOT be released if the
22
#                      containing variables go out of scope, BUT the
23
#                      underlying connection is a class and it WILL release
24
#                      the connection.
25
#
26
#......................................................................#
27
 
255 dpurdie 28
require 5.006_001;
227 dpurdie 29
 
30
use strict;
31
use warnings;
32
 
33
package JatsRmApi;
34
use JatsError;
35
use DBI;
36
 
37
our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION);
38
use Exporter;
39
 
40
$VERSION = 1.00;
41
@ISA = qw(Exporter);
42
 
43
# Symbols to autoexport (:DEFAULT tag)
44
@EXPORT = qw(
45
            connectRM
46
            disconnectRM
47
 
48
            connectDM
49
            disconnectDM
4466 dpurdie 50
 
51
            connectCQ
52
            disconnectCQ
227 dpurdie 53
            );
54
 
55
#
56
#   Globals to contain connection information
57
#
58
our $GBE_RM_LOCATION;
59
our $GBE_RM_USERNAME;
60
our $GBE_RM_PASSWORD;
61
 
62
our $GBE_DM_LOCATION;
63
our $GBE_DM_USERNAME;
64
our $GBE_DM_PASSWORD;
65
 
4466 dpurdie 66
our $GBE_CQ_LOCATION;
67
our $GBE_CQ_USERNAME;
68
our $GBE_CQ_PASSWORD;
227 dpurdie 69
 
70
#-------------------------------------------------------------------------------
71
# Function        : ValidateRef
72
#
73
# Description     : Ensure that the user has passed a valid reference
74
#
75
# Inputs          : $fname      - Function name for error reporting
76
#                   $ref        - Data to test
77
#
78
# Returns         : Will error on error
79
#
80
 
81
sub ValidateRef
82
{
83
    my ($fname, $ref) = @_;
84
 
85
    Error("$fname: No parameter passed") unless ( $ref );
86
 
87
    my $rtype = ref($ref) || 'Simple Type';
88
    Error("$fname: Must pass a scalar REF, not a $rtype") unless ( $rtype =~ m/SCALAR|REF/ );
89
}
90
 
91
#-------------------------------------------------------------------------------
92
# Function        : GetConnData
93
#
94
# Description     : Determine the connection data for either RM or DM
95
#
96
# Inputs          : $fname  - Caller function
97
#                   @rest   - 3 EnvVars to process
98
#
99
# Returns         : An array of 3 variables
4466 dpurdie 100
#                   location, username, password
227 dpurdie 101
#
102
sub GetConnData
103
{
104
    my ($fname, @rest) = @_;
105
    my @result;
106
 
107
    foreach my $var ( @rest )
108
    {
109
        my $val = $ENV{$var};
110
        Error( "Environment Variable '$var' not defined." ) unless ( $val );
111
        push @result, $val;
112
    }
113
 
114
    Verbose ("$fname:",
115
             "Database: $result[0]",
116
             "Username: $result[1]",
117
             "Password: $result[2]");
118
 
119
    return @result;
120
}
121
 
122
#-------------------------------------------------------------------------------
123
# Function        : connectRM
124
# Function        : connectDM
125
#
126
# Description     : Connect to the RM/DM database
127
#
128
# Inputs          : gref        - Reference to a scalar that will hold
129
#                                 the database connection class data
130
#
131
#                                 If 'undef' this function will create
132
#                                 the connection. Otherwise the function
133
#                                 will simply return.
134
#
135
#                   opt_verbose - Verbose connection
136
#
137
# Returns         : 
138
#
139
sub connectRM
140
{
141
    my ($gref, $opt_verbose) = @_;
142
    connectDB('connectRM', $gref, $opt_verbose, 'GBE_RM_LOCATION', 'GBE_RM_USERNAME', 'GBE_RM_PASSWORD');
143
}
144
 
145
sub connectDM
146
{
147
    my ($gref, $opt_verbose) = @_;
148
    connectDB('connectDM', $gref, $opt_verbose, 'GBE_DM_LOCATION', 'GBE_DM_USERNAME', 'GBE_DM_PASSWORD');
149
}
150
 
4466 dpurdie 151
sub connectCQ
152
{
153
    my ($gref, $opt_verbose) = @_;
154
    connectDB('connectCQ', $gref, $opt_verbose, 'GBE_CQ_LOCATION', 'GBE_CQ_USERNAME', 'GBE_CQ_PASSWORD');
155
}
156
 
157
 
227 dpurdie 158
sub connectDB
159
{
160
    my ($fname, $gref, $opt_verbose, @parms) = @_;
161
 
162
    #
163
    #   Sanity Check user parameters
164
    #
165
    ValidateRef( $fname, $gref);
166
    my @condata = GetConnData( $fname , @parms);
167
    my $location = $condata[0];
168
 
169
    unless ( $$gref )
170
    {
171
        $$gref = DBI->connect(@condata, {verbose => $opt_verbose});
172
 
173
        unless ( defined $$gref )
174
        {
175
            Error("$fname: Database [$location]",
176
                  "Reported Error[$DBI::errstr]");
177
        }
178
 
179
        Verbose("$fname: Connected to database [$location]");
180
    }
181
    else
182
    {
183
        Warning ("$fname: Connection Already open");
184
    }
185
}
186
 
187
#-------------------------------------------------------------------------------
188
# Function        : disconnectRM
189
# Function        : disconnectDM
4466 dpurdie 190
# Function        : disconnectCQ
227 dpurdie 191
#
4466 dpurdie 192
# Description     : Disconnect from the DM/RM/CQ database
227 dpurdie 193
#
194
# Inputs          : gref        - Reference to a scalar that will hold
195
#                                 the database connection class data
196
#
197
#                                 If not 'undef' this function will disconnect
198
#                                 the connection. Otherwise the function
199
#                                 will simply return.
200
#
201
 
202
sub disconnectRM
203
{
204
    disconnectDB( 'disconnectRM', @_);
205
}
206
 
207
sub disconnectDM
208
{
209
    disconnectDB( 'disconnectDM', @_);
210
}
211
 
4466 dpurdie 212
sub disconnectCQ
213
{
214
    disconnectDB( 'disconnectCQ', @_);
215
}
216
 
227 dpurdie 217
sub disconnectDB
218
{
219
    my ($fname, $gref) = @_;
220
 
221
    #
222
    #   Sanity Check user parameters
223
    #
224
    ValidateRef( $fname, $gref);
225
 
226
    Verbose("$fname: Disconnect from database");
227
    if ( $$gref )
228
    {
229
        $$gref->disconnect() || Warning ("$fname:Disconnect failed");
230
        $$gref = undef;
231
    }
232
    else
233
    {
234
        Warning("$fname: Connection not open");
235
    }
236
}
237
 
238
1;
239