File: DriverSapDB.java

package info (click to toggle)
libsapdbc-java 5567-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,840 kB
  • ctags: 6,242
  • sloc: java: 49,887; makefile: 83
file content (906 lines) | stat: -rw-r--r-- 30,216 bytes parent folder | download
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
/*


    ========== licence begin GPL
    Copyright (C) 2002-2003 SAP AG

    This program 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 2
    of the License, or (at your option) any later version.

    This program 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 this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    ========== licence end


*/

package com.sap.dbtech.jdbc;

import java.io.*;
import java.sql.*;
import com.sap.dbtech.util.*;
import com.sap.dbtech.rte.comm.*;
import com.sap.dbtech.jdbc.exceptions.*;

/**
 *
 */
public class DriverSapDB
    implements java.sql.Driver
{
    static DriverSapDB driver = new DriverSapDB ();
    static JdbcCommFactory commFactory;
    static public boolean isJDBC20 = detectJDBC20 ();
    static VersionInfo jdbcDriverVersion;
    static final String protocolName_C = "jdbc:sapdb:";
    static final public String nativeCommunication_dllName_C = "sapdbcbin";
    static final String loadbinProperty_C = "com.sap.dbtech.jdbc.loadbin";
    static final String osNameProperty_C = "os.name";
    static final String osLinuxString_C = "Linux";
    static {
        loadDriver ();
    }
    static final String driverName_C = "SAP DB";
    public static final String sapdbEncodingC = "ISO8859_1";

    /*VM version*/
    public static final int JAVA_1_1 = 1001999;
    public static final int JAVA_1_2 = 1002999;
    public static final int JAVA_1_3 = 1003999;
    public static final int currentVMVersion = getVMVersion();

    static int getVMVersion()
    {
        try {
            String vers = System.getProperty("java.version");
            int startpos=vers.indexOf('1');
            if(startpos==-1) {
                return JAVA_1_3;
            }
            int endpos=vers.indexOf('.', startpos);
            if(endpos==-1) {
                return JAVA_1_3;
            }
            int major=Integer.parseInt(vers.substring(startpos, endpos));
            startpos=endpos+1;
            endpos=vers.indexOf('.', startpos);
            if(endpos==-1) {
                return JAVA_1_3;
            }
            int minor=Integer.parseInt(vers.substring(startpos, endpos));
            return major*1000000+minor*1000;
        } catch(NumberFormatException numberFormatEx) {
            return JAVA_1_3;
        } catch(java.security.AccessControlException ex) {
            return JAVA_1_2;
        }
    }

    // Property names
    static final String userName_C = "user";
    static final String passwordName_C = "password";
    static final String urlName_C = "url";
    static final String sqlmodeName_C = "sqlmode";
    static final String cachelimitName_C = "cachelimit";
    static final String timeoutName_C = "timeout";
    static final String isolationName_C = "isolation";
    static final String autocommitName_C = "autocommit";
    static final String traceName_C = "trace";
    static final String traceSize_C = "tracesize";
    static final String transportName_C = "transport";
    static final String cacheName_C = "cache";
    static final String cacheSizeName_C = "cachesize";
    static final String unicodeName_C = "unicode";
    static final String reconnect_C = "reconnect";
    static final String spaceoption_C = "spaceoption";
    static final String application_C = "application";
    static final String appversion_C = "appversion";
    static final String communicationtimeout_C = "communicationtimeout";
    static final String authentication_C = "authentication";
    static final String encrytption_C = "encryption";
    static final String useDefaultValueForUpdatableRS_C = "useDefaultValueForUpdatableRS";
    static final String connecttype_C = "connecttype";

    // internal information about connection
    static final String dburlName_C = "dburl";
    static final String dbName_C = "dbname";
    static final String sqlmodeOracle_C = "oracle";
    static final String niconnect_C  = "niconnect";

    // tracing and checks
    public static final boolean catchAllNotImplemented_C = false;

    /**
     * acceptsURL method comment.
     */
    public boolean acceptsURL(String url) throws java.sql.SQLException {
        boolean result = url.startsWith (protocolName_C);

        return result;
    }
    /**
     *
     * @return java.lang.String
     * @param host java.lang.String
     * @param dbname java.lang.String
     */
    final public static String buildURL (String host, String dbname) {
        return protocolName_C + "//" + host + "/" + dbname;
    }

    /**
     *
     * @return java.sql.Connection
     * @param user java.lang.String
     * @param pwd java.lang.String
     * @param host java.lang.String
     * @param dbname java.lang.String
     * @exception java.sql.SQLException The exception description.
     */
    final public static java.sql.Connection connect (String user, String pwd, String host, String dbname, String properties)
    throws SQLException
    {
        String url = buildURL (host, dbname);
        if ((properties != null) && (properties.length () > 0)) {
            url = url + "?" + properties;
        }
        java.util.Properties info = new java.util.Properties ();
        info.put(userName_C, user);
        info.put(passwordName_C, pwd);

        return singleton ().connect (url, info);
    }
    /**
     * connect method comment.
     */
    public java.sql.Connection connect(
        String url,
        java.util.Properties info)
    throws java.sql.SQLException
    {
        java.sql.Connection result;
        JdbcCommunication session = null;
        boolean wrapSession;

        if (!this.acceptsURL(url)) {
            return null;
        }
        url = this.parseURLProperties (url, info);
        wrapSession = openTrace (url, info);
        Tracer.print ("new Connection '"+ url+"'", info);
        try {
            session = this.openByURL (url, info);
        }
        catch (RTEException rteExc) {
            //rteExc.printStackTrace(System.out);
            if (wrapSession) {
               Tracer.println ("using "+session);
               Tracer.println ("=> FAILED");
            }
            throw new JDBCDriverException (MessageTranslator.translate(
                    MessageKey.ERROR_CONNECTRTEEXCEPTION,
                    url,
                    rteExc.getMessage()),
                this);
        }
        result = new ConnectionSapDB (session, info);
        if (wrapSession) {
           Tracer.println ("using "+session);
           Tracer.println ("=> " + result);
           result = new com.sap.dbtech.jdbc.trace.Connection (result);
        }
        return result;
    }
    /**
     *
     */
    final static public boolean
        openTrace (
        String url,
        java.util.Properties info)
    {
        boolean result = false;
        String trace = info.getProperty(traceName_C);
        if(trace == null){
          try {
            trace = System.getProperty("sapdbctrace");
          }
          catch (java.security.AccessControlException ignore) {}
        }
        long maxTraceSize;
        try {
          maxTraceSize = Long.parseLong(info.getProperty(traceSize_C));
        }
        catch (NumberFormatException ex) {
          maxTraceSize = Long.MAX_VALUE;
        }

//        if (trace == null) {
//            String context = Thread.currentThread().getContextClassLoader().toString();
//            try {
//                java.security.MessageDigest md5 = java.security.MessageDigest.getInstance("MD5");
//                byte [] data = md5.digest(context.getBytes());
//                context = Tracer.Hex2String(data);
//            } catch (Exception e) {
//            }
//            String osName = System.getProperty ("os.name", "<unknown>").toUpperCase();     
//            if ((osName != null) && osName.startsWith("WINDOWS")) {
//                trace="c://temp/MaxDBJDBCTrace_"+context+".prt";
//            } else{
//              trace="/tmp/MaxDBJDBCTrace_"+context+".prt";
//            }  
//        }
        if (trace != null) {
            result = true;
            try {
                Tracer.forceNewLog(trace, true, maxTraceSize);

            }
            catch (IOException ioExc) {
            }
            Tracer.println ("==================================");
            String java_version = "<unknown>";
            try {
              java_version = System.getProperty ("java.version", "<unknown>");
            }
            catch (java.security.AccessControlException ignore) {}
            Tracer.println (getVersionString () + " on Java " + java_version);
        }
        /*
         * extended trace for specific bugs
         */
        trace = info.getProperty ("extendedTrace");
        if (trace != null) {
            TimeoutException.addExtendedTrace(trace);
        }
        return result;
    }
    /**
     *
     * @return boolean
     * @param property java.lang.String
     */
    private static final String [] trueStrings = {
        "true", "yes", "on"
    };
    final public static boolean getBooleanProperty (
        java.util.Properties properties,
        String name,
        boolean defaultValue)
    {
        boolean result = defaultValue;
        String value;

        value = properties.getProperty(name);
        if (value != null) {
                result = false;
            for (int i = 0; i < trueStrings.length; ++i) {
                if (value.equalsIgnoreCase (trueStrings [i])) {
                    result = true;
                    break;
                }
            }
        }
        return result;
    }
    /**
     *
     */
    final public static int
    getIntProperty (
        java.util.Properties properties,
        String name,
        int defaultValue)
    {
        int result = defaultValue;
        String value;

        value = properties.getProperty (name);
        if (value != null) {
            try {
                result = Integer.parseInt (value);
            }
            catch (NumberFormatException exc) {
                // ignore
            }
        }
        return result;
    }
    /**
     * getMajorVersion method comment.
     */
    final public int getMajorVersion() {
        return jdbcDriverVersion.getMajorVersion();
    }
    /**
     * getMinorVersion method comment.
     */
    final public int getMinorVersion() {
        return jdbcDriverVersion.getMinorVersion();
    }
    /**
     *
     * @return java.lang.String
     */
    final String getName () {
        return driverName_C;
    }
    /**
     * getPropertyInfo method comment.
     */
    final public DriverPropertyInfo[] getPropertyInfo(String url, java.util.Properties info) throws SQLException {
        DriverPropertyInfo [] result;
        DriverPropertyInfo userItem = null;
        DriverPropertyInfo passwordItem = null;
        int count = 0;
        int i = 0;

        if (info.getProperty (userName_C) == null) {
            userItem = new DriverPropertyInfo (userName_C, null);
            userItem.required = true;
            ++count;
        }
        if (info.getProperty (passwordName_C) == null) {
            passwordItem = new DriverPropertyInfo (passwordName_C, null);
            passwordItem.required = true;
            ++count;
        }
        result = new DriverPropertyInfo [count];
        if (userItem != null) {
            result [i] = userItem;
            ++i;
        }
        if (passwordItem != null) {
            result [i] = passwordItem;
            ++i;
        }
        return result;
    }
    /**
     *
     * @return java.lang.String
     */
    final public static String getProtocol () {
        return protocolName_C;
    }
    /**
     *
     * @return java.lang.String
     */
    final public static String getVersionString () {
        return getStaticVersion ();
    }
    /**
     *
     */
    static public String
    getStaticVersion ()
    {
        return jdbcDriverVersion.toString();
    }
    /**
     * jdbcCompliant method comment.
     */
    final public boolean jdbcCompliant() {
        return true;
    }
    /**
     *
     */
    public static void load () {
    }
    /**
     *
     * @param args java.lang.String[]
     */
    public static void main(String args[]) {
        if (args.length > 0) {
          if ((args[0].equals ("-V")) || (args[0].equals ("--version"))) {
            System.out.println (getStaticVersion ());
          } else {
            java.util.Properties info = new java.util.Properties ();
            boolean hasUser = false;
            boolean hasDb = false;
            info.put("host","");
            info.put("options","");
            info.put("cmd","Select 'successfully connected' as \"connect test\" from dual");
            for (int i = 0; i < args.length; ++i) {
                String currentArg = args [i];
                if (currentArg.charAt (0) != '-') {
                    break;
                }
                char currentOpt = currentArg.charAt (1);
                switch (currentOpt) {
                case 'u':
                    ++i;
                    currentArg = args [i];
                    int pos = currentArg.indexOf (',');
                    info.put(userName_C, currentArg.substring (0, pos));
                    info.put(passwordName_C, currentArg.substring (pos + 1));
                    hasUser = true;
                    break;
                case 'd':
                    ++i;
                    info.put(dbName_C , args [i]);
                    hasDb = true;
                    break;
                case 'n':
                    ++i;
                    info.put("host" , args [i]);
                    break;
                case 'o':
                    ++i;
                    info.put("options", "?"+args [i]);
                    break;
                case 'c':
                    ++i;
                    info.put("cmd", args [i]);
                    break;
                default:
                    System.err.println ("invalid option " + currentOpt);
                    break;
                }
             }
             if (hasDb && hasUser){
               try {
                 Connection connection = new DriverSapDB().connect (DriverSapDB.buildURL((String)info.get("host"), (String)info.get(dbName_C))+info.get("options") , info);
                 Statement stmt = connection.createStatement ();
                 if (stmt.execute ((String)info.get("cmd"))){
                   ResultSet rs = stmt.getResultSet();
                   if (!rs.next ())
                     System.out.println ("row not found");
                   else{
                    ResultSetMetaData rsmd = rs.getMetaData();
                    StringBuffer res = new StringBuffer(50);
                    res.append("| ");
                    for (int i=1; i<=rsmd.getColumnCount(); i++){
                      String val = rsmd.getColumnName(i);
                      int    len = rsmd.getPrecision(i);
                      if (val.length()>len){
                        res.append(val.substring(0,len));
                      } else {
                        res.append(val);
                        for (int j=0; j < len-val.length();j++) res.append(" ");
                      }
                      res.append(" | ");
                    }
                    System.out.println(res.toString());
                    for (int j=1; j < res.length();j++) System.out.print("-");;
                    System.out.println("");
                    do{
                      res = new StringBuffer(res.capacity());
                      res.append("| ");
                      for (int i=1; i<=rsmd.getColumnCount(); i++){
                      String val = rs.getString(i);
                      int    len = rsmd.getPrecision(i);
                      if (val.length()>len){
                        res.append(val.substring(0,len));
                      } else {
                        res.append(val);
                        for (int j=0; j < len-val.length();j++) res.append(" ");
                      }
                      res.append(" | ");
                    }
                    System.out.println(res.toString());
                    }while(rs.next());
                   }
                 }else{
                   System.out.println (stmt.getUpdateCount() +" row(s) affected");
                 }
               }
               catch (Exception ex) {
                 ex.printStackTrace();
               }
            }
          } //else
        }
    }
    /**
     *
     * @return java.lang.String
     */
    static String mapIsolation (String isolationProperty)
    throws JDBCDriverException
    {
        int isolevel = -1;
        String result;

        try {
            isolevel = Integer.parseInt(isolationProperty);
        }
        catch (NumberFormatException exc1) {
            final String sapdbtechPrefix = "ADABAS";
            final String jdbcPrefix = "TRANSACTION_";
            if (isolationProperty.startsWith (sapdbtechPrefix)) {
                try {
                    isolevel = Integer.parseInt(
                        isolationProperty.substring (sapdbtechPrefix.length()));
                }
                catch (NumberFormatException exc2) {
                    // isolevel kept at invalid
                }
            }
            else if (isolationProperty.startsWith (jdbcPrefix)) {
                String rest = isolationProperty.substring (jdbcPrefix.length());
                if (rest.equals ("READ_UNCOMMITTED")) {
                    isolevel = Connection.TRANSACTION_READ_UNCOMMITTED;
                }
                else if (rest.equals ("READ_COMMITTED")) {
                    isolevel = Connection.TRANSACTION_READ_COMMITTED;
                }
                else if (rest.equals ("REPEATABLE_READ")) {
                    isolevel = Connection.TRANSACTION_REPEATABLE_READ;
                }
                else if (rest.equals ("SERIALIZABLE")) {
                    isolevel = Connection.TRANSACTION_SERIALIZABLE;
                }
            }
        }
        switch (isolevel) {
            case Connection.TRANSACTION_READ_UNCOMMITTED:
                result = "0";
                break;
            case Connection.TRANSACTION_READ_COMMITTED:
                result = "1";
                break;
            case Connection.TRANSACTION_REPEATABLE_READ:
                result = "2";
                break;
            case Connection.TRANSACTION_SERIALIZABLE:
                result = "3";
                break;
            default:
                throw new JDBCDriverException(MessageTranslator.translate(
                    MessageKey.ERROR_INVALIDTRANSACTIONISOLATION,
                    isolationProperty));
        }
        return result;
    }
    /**
     *
     */
    static int
    isolevelString2Jdbc (
        String isolationProperty)
    {
        int isolevel = -1;
        try {
            isolevel = Integer.parseInt(isolationProperty);
        }
        catch (NumberFormatException exc1) {
            final String sapdbtechPrefix = "ADABAS";
            final String jdbcPrefix = "TRANSACTION_";
            if (isolationProperty.startsWith (sapdbtechPrefix)) {
                try {
                    isolevel = Integer.parseInt(
                        isolationProperty.substring (sapdbtechPrefix.length()));
                }
                catch (NumberFormatException exc2) {
                    // isolevel kept at invalid
                }
            }
            else if (isolationProperty.startsWith (jdbcPrefix)) {
                String rest = isolationProperty.substring (jdbcPrefix.length());
                if (rest.equals ("READ_UNCOMMITTED")) {
                    isolevel = Connection.TRANSACTION_READ_UNCOMMITTED;
                }
                else if (rest.equals ("READ_COMMITTED")) {
                    isolevel = Connection.TRANSACTION_READ_COMMITTED;
                }
                else if (rest.equals ("REPEATABLE_READ")) {
                    isolevel = Connection.TRANSACTION_REPEATABLE_READ;
                }
                else if (rest.equals ("SERIALIZABLE")) {
                    isolevel = Connection.TRANSACTION_SERIALIZABLE;
                }
            }
        }
        return isolevel;
    }
    /**
     *
     */
    static String
    isolevelJdbc2native (
        int isolevel)
    throws SQLException
    {
        String result;
        switch (isolevel) {
            case Connection.TRANSACTION_NONE:
            case Connection.TRANSACTION_READ_UNCOMMITTED:
                result = "0";
                break;
            case Connection.TRANSACTION_READ_COMMITTED:
                result = "1";
                break;
            case Connection.TRANSACTION_REPEATABLE_READ:
                result = "2";
                break;
            case Connection.TRANSACTION_SERIALIZABLE:
                result = "3";
                break;
            default:
                throw new JDBCDriverException(MessageTranslator.translate(
                    MessageKey.ERROR_INVALIDTRANSACTIONISOLATION,
                    Integer.toString(isolevel)));
        }
        return result;
    }
    /**
     *
     * @return com.sap.dbtech.rte.comm.JdbcCommunication
     * @param url java.lang.String
     * @exception com.sap.dbtech.rte.comm.RTEException The exception description.
     */
    final private JdbcCommunication openByURL (
        String url,
        java.util.Properties info)
    throws RTEException, SQLException
    {
        int slashPos;
        int closingSlashPos;
        String host;
        String dbname;
        String dburl;
        int urlLength = url.length ();

        slashPos = protocolName_C.length ();
        if ((urlLength >= slashPos + 3)
            && url.substring (slashPos, slashPos + 2).equals ("//")) {
            String strippedUrl = url.substring (slashPos + 2);
            if (strippedUrl.startsWith("sapni:")){
                int endPattern = strippedUrl.indexOf(":inpas", 6);
                if (-1 == endPattern){
                  throw new ConnectionException( new SQLExceptionSapDB (MessageTranslator.translate(MessageKey.ERROR_WRONG_CONNECT_URL, "closing token \":inpas\" not found for SAP routerstring"),"0800",-709));
                }
                host = strippedUrl.substring(6, endPattern);
                dbname = strippedUrl.substring(endPattern + 7, strippedUrl.length());
                info.put(niconnect_C, "true");
                if (commFactory == SocketComm.factory) {
                    commFactory = NiCommunication.factory;
                }
            } else {
	            closingSlashPos = strippedUrl.indexOf ('/');
	            host = strippedUrl.substring (0, closingSlashPos);
	            dbname = strippedUrl.substring(closingSlashPos + 1, strippedUrl.length());
            }
        }
        else {
            host = "";
            dbname = url.substring (slashPos, urlLength).trim();
        }
        dbname = dbname.toUpperCase();
        dburl = buildURL (host, dbname);
        info.put (dburlName_C, dburl);
        info.put (dbName_C, dbname);
        return this.openConnection (host, dbname, info);
    }
    /**
     *
     */
    final private String
    parseURLProperties (
        String url,
        java.util.Properties info)
    {
        int questionPos;

        questionPos = url.indexOf ('?');
        if (questionPos >= 0) {
            this.parsePropertiesString (url.substring (questionPos + 1), info);
            url = url.substring (0, questionPos);
        }
        return url;
    }
    /**
     *
     * @return com.sap.dbtech.rte.comm.JdbcCommunication
     * @param host java.lang.String
     * @param dbname java.lang.String
     * @exception com.sap.dbtech.rte.comm.RTEException The exception description.
     */
    final public JdbcCommunication openConnection (
        String host,
        String dbname,
        java.util.Properties info)
    throws RTEException
    {
        JdbcCommFactory factory;
        JdbcCommunication result;
        String transport;
        if (getBooleanProperty(info, encrytption_C, false)){
          transport = "secure";
        } else {
          transport = info.getProperty (transportName_C, "socket");
        }

        if (transport.equals ("native")) {
            try {
              if (loadNativeCommunication() == nativeCommunication_enabled){
                  factory = NativeComm.factory;
              } else {
                  transport = "socket";                  
              }
            }  catch (Error linkErr) {
                throw new RTEException(MessageTranslator.translate
                    (MessageKey.ERROR_LIBRARYNOTLOADED, nativeCommunication_dllName_C, linkErr.toString()), -10899);
            }
            factory = NativeComm.factory;
        } else if (transport.equals ("socket")) {
            if (getBooleanProperty(info, niconnect_C, false)){
                factory = NiCommunication.factory;
            } else {
                factory = SocketComm.factory;
            }
        }
        else if(transport.equals ("secure")) {
            factory = SecureCommunication.factory;
        }
        else {
            throw new RTEException(MessageTranslator.translate
                (MessageKey.ERROR_INVALIDTRANSPORT, transport),
                                   -10899);
        }
        try {
            result = factory.open (host, dbname, info);
        }  catch (UnsatisfiedLinkError linkErr) {
            throw new RTEException(MessageTranslator.translate
                (MessageKey.ERROR_LIBRARYNOTLOADED, nativeCommunication_dllName_C, linkErr.toString()), -10899);
        }
        return result;
    }

    /**
     *
     * @return boolean
     * @param property java.lang.String
     */
    public static boolean parseBooleanProperty (String property) {
        boolean result = false;

        if (property.equalsIgnoreCase ("true")) {
            result = true;
        }
        return result;
    }
    /**
     *
     * @param urlArgs java.lang.String
     * @param info java.util.Properties
     */
    private void
    parsePropertiesString (
        String urlArgs,
        java.util.Properties info)
    {
        String [] args = StringUtil.split (urlArgs, "&");
        String arg;
        int assignPos;

        for (int i = 0; i < args.length; ++i) {
            arg = args [i];
            assignPos = arg.indexOf ('=');
            if (assignPos > 0) {
                info.put(arg.substring (0, assignPos), arg.substring (assignPos + 1));
            }
        }
    }
    /**
     *
     */
    public static DriverSapDB singleton () {
        return driver;
    }
    /**
     *
     */
    private static void switchTraces (String verbosity, String filename) {
        if (verbosity != null) {
            try {
                Tracer.setVerbosity (Integer.parseInt(verbosity));
            }
            catch (NumberFormatException exc) {
                // ignore
            }
        }
        if (filename != null) {
            try {
                Tracer.openLog (filename);
            }
            catch (IOException exc) {
                System.err.println ("SAP DBTech JDBC: Cannot open log " + filename);
            }
        }
    }
    /**
     *
     */
    private static void switchTracesByProperties (java.util.Properties info) {
        switchTraces (
            info.getProperty ("traceVerbosity"),
            info.getProperty ("traceFile"));
    }
    /**
     *
     */
    private static void
    loadDriver ()
    {
        //getDriverVersion
        jdbcDriverVersion = new com.sap.dbtech.util.VersionInfo(
           "com.sap.dbtech.jdbc", "package com.sap.dbtech.jdbc, SAP DB JDBC Driver, SAP AG, ");
        try {
            DriverManager.registerDriver (driver);
        }
        catch (SQLException sqlExc) {
            // ignore
        }
    }
    
    final static public int nativeCommunication_notInit = 1;
    final static public int nativeCommunication_enabled  = 2;
    final static public int nativeCommunication_disabled = 3;
    
    static private int nativeCommunication = nativeCommunication_notInit;
    
    static public int loadNativeCommunication() {
        if (nativeCommunication != nativeCommunication_notInit){
          return nativeCommunication;  
        }
        try {
            System.loadLibrary(nativeCommunication_dllName_C);
            nativeCommunication = nativeCommunication_enabled;
        } catch (java.security.AccessControlException exc) {
            nativeCommunication = nativeCommunication_disabled;
        } catch (java.lang.UnsatisfiedLinkError err) {
            try {
                System.loadLibrary(nativeCommunication_dllName_C + "32");
                nativeCommunication = nativeCommunication_enabled;
            } catch (java.lang.UnsatisfiedLinkError erro) {
                nativeCommunication = nativeCommunication_disabled;
            } catch (Error e) {
                nativeCommunication = nativeCommunication_disabled;
                throw e;
            }
        } catch (Error e) {
            nativeCommunication = nativeCommunication_disabled;
            throw e;  
        }
        return nativeCommunication;
    }
    /**
     *
     */
    private static boolean
    detectJDBC20 ()
    {
        boolean result;

        try {
            Class.forName ("java.sql.Clob");
            result = true;
        }
        catch (ClassNotFoundException exc) {
            result = false;
        }
        return result;
    }

    /**
     *
     */
    static public JdbcCommFactory
    getCommunicationFactory ()
    {
        return commFactory;
    }
}