summaryrefslogtreecommitdiffstats
path: root/java/rasj/RasImplementation.java
blob: d30a7f3f768b19158042a92f6814af58362f9c43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
package rasj;

import rasj.odmg.*;
import rasj.global.*;		// RASJ_VERSION
import rasj.rnp.*;
import org.odmg.*;
import rasj.clientcommhttp.*;

import java.io.*;
import java.net.*;
import java.lang.*;
import java.util.*;

/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
*/
/** ***********************************************************
 * <pre>
 *
 * PURPOSE:
 * ODMG Implementation Bootstrap Object
 * This class implements an ODMG Bootstrap Object. This is the only vendor-dependent
 * object a user needs for performing database operations.
 * @version $Revision: 1.16 $
 *
 *
 * COMMENTS:
 *
 * </pre>
 *********************************************************** */


public class RasImplementation implements Implementation
    {
    /**
     * This is the "real" Implementation object that is used. Because it contains a lot of
     * internal methods that have to be used by the rasj.odmg package, it has been put
     * into that package in order to avoid making this internal methods publicly visible and
     * available.
     **/
    private RasImplementationInterface imp = null;
    
    private static boolean isRNP           = true; // use RNP by default

    /**
     * C/s protocol indicators.
     */
    public static final String PROTOCOL_RNP  = "RNP" ;	// RNP protocol indicator
    public static final String PROTOCOL_RPC  = "RPC" ;	// RPC protocol indicator
    public static final String PROTOCOL_HTTP = "HTTP" ;	// HTTP protocol indicator
    public static final String PROTOCOL_COMP = "COMPAT" ;	// "compatiblity", means: using RNP (legacy)

    /**
     * Standard constructor.
     * @param server - Complete URL of the RasDaMan httpserver (including port number)
     */
    public RasImplementation(String server)
    {   
        Debug.talkCritical( RasGlobalDefs.RASJ_VERSION );
        Debug.talkCritical( " Using server " + server );

        String envVar = System.getProperty("RMANPROTOCOL");	// uses "-D" option  
       
        boolean useRNP = isRNP;
       
        if(envVar != null)
          {
            Debug.talkWarning( "environment variable RMANPROTOCOL enforces protocol " + envVar );
	    if ( envVar.equalsIgnoreCase( PROTOCOL_RNP ) )
                useRNP = true;
	    else if ( envVar.equalsIgnoreCase( PROTOCOL_RPC ) )
            {
	        Debug.talkCritical( "Error: protocol " + PROTOCOL_RPC + " not supported by rasj: using " + PROTOCOL_RNP + " instead." ); 
                useRNP = true;
            }
            else if ( envVar.equalsIgnoreCase( PROTOCOL_HTTP ) )
                useRNP = false;
            else if ( envVar.equalsIgnoreCase( PROTOCOL_COMP ) )
            {
	        Debug.talkCritical( "Compatibility mode specified, using " + PROTOCOL_RNP + "." ); 
                useRNP = true;
            }
            else
            {
                Debug.talkCritical( "Error: unknown protocol: " + envVar + "; using protocol " + PROTOCOL_RNP + "." );
                useRNP = true;
            }
	  }  

        if(useRNP) 
          {	  
	    Debug.talkVerbose( "RasImplementation.constructor: using protocol " + PROTOCOL_RNP + "." ); 
	    imp = new RasRNPImplementation(server);
	  }
        else
          {
	    Debug.talkVerbose( "RasImplementation.constructor: using protocol " + PROTOCOL_HTTP + "." ); 
            imp = new RasODMGImplementation(server);	
	  }	    
       } // RasImplementation()

    /**
     * Extended constructor, allowing to set protocol (does not query env var).
     * If the protocol is illegal, RNP is assumed as default.
     * @param server - Complete URL of the RasDaMan httpserver (including port number)
     * @param protocol - c/s communication protocol selector, one of: "RNP", "HTTP"
     */
    public RasImplementation(String server, String protocol)
    {
        Debug.talkCritical( RasGlobalDefs.RASJ_VERSION );
        Debug.talkCritical( " Using server " + server );

        if( protocol.equalsIgnoreCase( PROTOCOL_RNP ) )
          {
            Debug.talkVerbose( "Using protocol " + PROTOCOL_RNP + "." );
            imp = new RasRNPImplementation(server);
          }
        else if( protocol.equalsIgnoreCase( PROTOCOL_HTTP ) )
          {
            Debug.talkVerbose( "Using protocol " + PROTOCOL_HTTP + "." );
            imp = new RasODMGImplementation(server);
          }
        else
          {
            Debug.talkCritical( "Error: unknown protocol: " + protocol + "; using " + PROTOCOL_RNP + " instead." );
            imp = new RasRNPImplementation(server);
          }

       } // RasImplementation()

     public static void setRNP()
       {
	 isRNP = true;
       }

     public static void setHTTP()
       {
	 isRNP = false;
       }

     public boolean isDefaultRNP()
       {
	 Debug.talkVerbose( "RasImplementation.isDefaultRNP: RNP=" + isRNP + "." ); 
         return isRNP;
       }

    /**
     *  returns 1 if an openDB command is executed (closeDB sets it back to 0).
     */
    public int dbIsOpen()
       {
         return imp.dbIsOpen();
       }

    /*
     * Create a new transaction object and associate it with the current thread.
     */
    public Transaction newTransaction()
      {
         return imp.newTransaction();
      }

    /**
     * Get current transaction for thread, or NULL if none.
     */
    public Transaction currentTransaction()
      {
	 return imp.currentTransaction();
      }

    /**
     * Create a new database object.
     */
    public Database newDatabase()
      {
	 return imp.newDatabase();
      }

    /**
     * Create a new query object.
     */
    public OQLQuery newOQLQuery()
        {
	return imp.newOQLQuery();
        }

    /**
     * Create a new DList object.
     */
    public DList newDList()
        {
	return imp.newDList();
        }

    /**
     * Create a new DBag object.
     */
    public DBag newDBag()
        {
	return imp.newDBag();
        }

    /**
     * Create a new DSet object.
     */
    public DSet newDSet()
        {
        return imp.newDSet();
        }

    /**
     * Not implemented yet.
     */
    public DArray newDArray()
        {
	throw new NotImplementedException();
        }

    /**
     * Not implemented yet.
     */
    public DMap newDMap()
        {
	throw new NotImplementedException();
        }

    /**
     * Get a String representation of the object's identifier.
     */
    public String getObjectId(Object obj)
        {
	return imp.getObjectId(obj);
        }

    /**
     * Not implemented yet.
     */
    public Database getDatabase(Object obj)
        {
	throw new NotImplementedException();
        }

   /**
    * Open database
    */
    public void openDB(String name, int accessMode) throws ODMGException
        {
	imp.openDB(name,accessMode);
        }

    /**
     * Closes an open database. At the moment, only one database can be open at
     * a given time and thus no parameter "database" is necessary here.
     */
    public  void closeDB() throws ODMGException
        {
	imp.closeDB();
        }

    /**
     * Begin a transaction.
     */
    public void beginTA()throws ODMGException
        {
	imp.beginTA();
        }

    /**
     * Returns TRUE if a transaction is currently open.
     */
    public boolean isOpenTA()throws ODMGException
        {
        Debug.talkCritical( "RasImplementation::isOpenTA: calling imp.isOpenTA()" );
	return imp.isOpenTA();
        }

    /**
     * Commit a transaction.
     */
    public void commitTA()throws ODMGException
        {
	imp.commitTA();
        }

    /**
     * Abort a transaction.
     */
    public void abortTA()throws ODMGException
        {
	imp.abortTA();
        }

    /**
     * Set the maximum retry parameter
     */
    public void setMaxRetry(int newRetry)
       {
       imp.setMaxRetry(newRetry);
       }

    /**
     * Get the maximum retry parameter
     */
    public int getMaxRetry()
       {
       return imp.getMaxRetry();
       }

   /**
    * Set user identification : name/plain password
    * (default is rasguest/rasguest)
    */
   public void setUserIdentification(String userName, String plainPass)
     {
     imp.setUserIdentification(userName,plainPass);
     }

    /**
     * Set trace output threshold
     * (0 = minimal, 4 = verbose; 1 = default)
     */
    public void setTraceThreshold( int level )
       {
	Debug.talkCritical( "setting trace level to " + level );
       rasj.global.Debug.setDebugThreshold( level );
       }

}