File: ConnectionSapDB.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 (1529 lines) | stat: -rw-r--r-- 57,592 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
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
/*


    Copyright (C) 2003 SAP AG

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; 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.sql.*;
import com.sap.dbtech.rte.comm.*;
import com.sap.dbtech.util.*;
import com.sap.dbtech.util.security.Authentication;
import com.sap.dbtech.jdbc.exceptions.*;
import com.sap.dbtech.jdbc.packet.*;
import com.sap.dbtech.jdbc.translators.ConversionExceptionSapDB;
import com.sap.dbtech.vsp001.*;

import java.util.Map;
import java.util.Properties;
import java.lang.ref.WeakReference;
/**
 *
 */
public class ConnectionSapDB implements java.sql.Connection {

        /**
         * Control flag for garbage collection on execute. If this is
         * set, old cursors/parse ids are sent <i>together with</i> the current
         * statement for being dropped.
         */
        public static final int GC_ALLOWED = 1;

        /**
         * Control flag for garbage collection on execute. If this is
         * set, old cursors/parse ids are sent <i>after</i> the current
         * statement for being dropped.
         */
        public static final int GC_DELAYED = 2;

        /**
         * Control flag for garbage collection on execute. If this is
         * set, nothing is done to drop cursors or parse ids.
         */
        public static final int GC_NONE    = 3;

    JdbcCommunication session;
    boolean autocommit = true;
    private boolean inTransaction = false;
    java.util.Stack packetPool = new java.util.Stack ();
    java.util.Stack packetPoolUnicode = new java.util.Stack ();
//    private boolean isUnicode = false;
    private SQLWarning warningList;
    private java.util.Properties connectProperties;
    private UniqueID UniqueID = new UniqueID() ;
    private Map typeMap;
    private Object executingObject = null;
    private boolean inReconnect = false;
    private com.sap.dbtech.util.GarbageParseid garbageParseids = null;
    private com.sap.dbtech.util.GarbageCursor  garbageCursors  = null;
    java.util.ArrayList statementContainer = null;
    private boolean keepGarbage = false;
    private int isolationLevel = Connection.TRANSACTION_READ_COMMITTED;
    private int resultSetHoldability = StatementSapDB.defaultHoldability_C;
    ParseinfoCache parseCache = null;
    DbsCache dbsCache = null;
    int sessionID = -1;
    boolean isSQLModeOracle = false;
    boolean isSpaceoptionSet = false;
    private DatabaseMetaData DatabaseMetaData = null;
    private String cursorPrefix = "JDBC_CURSOR_";
    private static final String syncObj = "";
    private int nonRecyclingExecutions=0;
    private String applID = null;
    private int    kernelversion; // Version without patch level, e.g. 70402 or 70600.
    final private static byte defaultFeatureSet[] = {1,0,2,0,3,0,4,0,5,0,6,0};
    private byte kernelFeatures[] = new byte[defaultFeatureSet.length];

	private boolean releaseSavePointSupported;
    /**
     *
     * @param info java.util.Properties
     * @exception java.sql.SQLException The exception description.
     */
    public ConnectionSapDB(
        JdbcCommunication session,
        java.util.Properties info)
    throws SQLException
    {
        this.session = session;
        this.connectProperties = (java.util.Properties) info.clone ();
        this.isSQLModeOracle = (this.getConnectProperty(DriverSapDB.sqlmodeName_C).equalsIgnoreCase(DriverSapDB.sqlmodeOracle_C))
                               ?true:false;
//        this.isUnicode = DriverSapDB.getBooleanProperty(this.connectProperties,DriverSapDB.unicodeName_C, false);
        this.isSpaceoptionSet = DriverSapDB.getBooleanProperty(this.connectProperties,DriverSapDB.spaceoption_C, false);
//        if(this.isSpaceoptionSet) {
//            this.isUnicode = true;
//        }
        this.doConnect (this.connectProperties);
        this.statementContainer = new java.util.ArrayList();
    }
    /**
     *
     * @param warning java.sql.SQLWarning
     */
    final void addWarning (SQLWarning warning)
    {
        if (this.warningList == null) {
            this.warningList = warning;
        }
        else {
            this.warningList.setNextWarning (warning);
        }
    }
    /**
     * asserts that the current connection is still open.
     *
     * @exception ObjectIsClosedException
     */
    protected void assertOpen ()
        throws ObjectIsClosedException
    {
        if (this.session == null) {
            throw new ObjectIsClosedException (this);
        }
    }
    /**
     *
     * @exception java.sql.SQLException The exception description.
     */
    final public void cancel (Object requestingObject)
    throws SQLException
    {
        if (this.executingObject == requestingObject) {
            this.session.cancel ();
        }
    }
    /**
     * clearWarnings method comment.
     */
    final public void clearWarnings()
    throws java.sql.SQLException
    {
        this.warningList = null;
    }
    /**
     * close the current connection.
     * <P>
     * An implicit ROLLBACK is performed.
     *
     * @exception java.sql.SQLException
     */
    public synchronized void close()
    throws java.sql.SQLException
    {
        if (this.session != null) {
            try {
                if (this.garbageCursors!=null)
                  this.garbageCursors.emptyCan();
                if (this.garbageParseids!=null)
                  this.garbageParseids.emptyCan();
                this.executeSQLString ("ROLLBACK WORK RELEASE", ConnectionSapDB.GC_NONE);
            }
            catch (SQLException sqlExc) {
              TimeoutException.println("IGNORING EXCEPTION CLOSE:"+sqlExc.toString());
              // ignore
            }
            catch (RuntimeException sqlExc) {
              TimeoutException.println("IGNORING EXCEPTION CLOSE:"+sqlExc.toString());
              // ignore
            }finally{
                this.releaseSession();
            }
        }
    }

    void releaseSession(){
        this.session.release ();
        this.session = null;
        this.DatabaseMetaData = null;
    } 
    
    boolean closeCursorAtCommit()throws java.sql.SQLException{
        /*close all cursor at commit*/
        boolean forceGC = false;
        int sz = this.statementContainer.size();
        for (int i = 0; i < sz; i++) {
          StatementSapDB st = (StatementSapDB)((WeakReference)this.statementContainer.get(i)).get();
          if (st != null){
            ResultSet rs = st.currentResultSet;
            if (st.getResultSetHoldability()==ResultSet.CLOSE_CURSORS_AT_COMMIT
                && rs!= null){
              forceGC = true;
              rs.close();
            }
          }
        }
        this.statementContainer.clear();
        if (forceGC && this.garbageCursors != null)
          this.garbageCursors.forceGarbageCollection();
        /*send commit*/
        return forceGC;
        
    }
    /**
     * commits the current transaction.
     *
     * @exception java.sql.SQLException
     */
    public synchronized void commit () throws java.sql.SQLException {
        this.assertOpen();
        this.closeCursorAtCommit();
        this.executeSQLString("COMMIT WORK", ConnectionSapDB.GC_ALLOWED);
        this.inTransaction = false;
    }
    /**
     * createStatement method comment.
     */
    public java.sql.Statement createStatement() throws java.sql.SQLException {
        this.assertOpen ();
        return new StatementSapDB (this);
    }
    /**
     *
     * @return java.sql.Statement
     * @param resultSetType int
     * @param resultSetConcurrency int
     * @exception java.sql.SQLException The exception description.
     */
    public Statement createStatement(
        int resultSetType,
        int resultSetConcurrency)
    throws SQLException
    {
        this.assertOpen ();
        return new StatementSapDB (this, resultSetType, resultSetConcurrency, StatementSapDB.defaultHoldability_C);
    }
    
    private String getTermID(){
      StringBuffer termidsb = new StringBuffer("java@");
      termidsb.append(Integer.toHexString(hashCode())); 
      while (termidsb.length() < 18){
        termidsb.append(' ');          
      }      
      return termidsb.toString();  
    }
    private boolean initiateChallengeResponse(String user, Authentication auth, boolean isUserPasswdAscii) throws SQLException{
      RequestPacket requestPacket = this.getRequestPacket(! isUserPasswdAscii);  
      boolean initSuccess = requestPacket.initChallengeResponse(user, auth.getClientchallenge());
      if (initSuccess){
         ReplyPacket replyPacket = this.execute (requestPacket, this, ConnectionSapDB.GC_DELAYED); 
         auth.parseServerChallengeReply(replyPacket.getVarDataPart());
         return true;
      }  else {
         return false;
      }
    }
    
    /**
     *
     * @param info   java.util.Properties
     *
     * @exception SQLException
     */
    protected void doConnect (
        java.util.Properties info)
    throws SQLException
    {
        String user = info.getProperty (DriverSapDB.userName_C);
        if (user == null) {
            throw new SQLExceptionSapDB (MessageTranslator.translate(MessageKey.ERROR_NOUSER));
        }
        char firstChar = user.charAt (0);
        char lastChar = user.charAt (user.length () - 1);
        if (! ((firstChar == '"') && (lastChar == '"'))) {
            user = user.toUpperCase ();
            info.put (DriverSapDB.userName_C, user);
        }
        String passwd = info.getProperty (DriverSapDB.passwordName_C);
        if (passwd == null) {
            throw new SQLExceptionSapDB (MessageTranslator.translate(MessageKey.ERROR_NOPASSWORD));
        }
        boolean isUserPasswdAscii = StringUtil.isIso8859_1(passwd);
        if (isUserPasswdAscii){
            isUserPasswdAscii = StringUtil.isIso8859_1(user);  
        }
        byte[] passwdByte = NameHandling.preprocessPassword(passwd, !isUserPasswdAscii);
        String sqlMode = info.getProperty (DriverSapDB.sqlmodeName_C, "INTERNAL");
        String cacheLimit = info.getProperty (DriverSapDB.cachelimitName_C);
        String timeout = info.getProperty (DriverSapDB.timeoutName_C);
        String isolationLevel = info.getProperty (DriverSapDB.isolationName_C);
        String connectCmd;
        byte [] crypted;
        RequestPacket requestPacket = this.getRequestPacket (!isUserPasswdAscii);
        Authentication auth = null;
        boolean isChallengeResponseSupported = false;
        if  (this.session. isChallengeResponseSupported()){
            //suppress Challenge-Response for NIConnections because it needs 2 sockets
            //and you cannot reuse a SAP router string.
            try {
                auth = new Authentication();
                isChallengeResponseSupported = this.initiateChallengeResponse( user, auth, isUserPasswdAscii);
                if (passwd.length() > auth.getMaxpasswordLen() && auth.getMaxpasswordLen() > 0){
                    passwd = passwd.substring(0,auth.getMaxpasswordLen());  
                }
            } catch (java.security.NoSuchAlgorithmException e) {
                isChallengeResponseSupported = false;
            } catch (SQLExceptionSapDB e) {
                isChallengeResponseSupported = false;
                if (e.getErrorCode() == -5015){
                    try {
                        this.session.reconnect();
                    } catch (RTEException rteEx) {
                        throw new ConnectionException (rteEx);
                    }
                } else {
                    throw e;
                }
            }
        }
        if ( DriverSapDB.getBooleanProperty(info,DriverSapDB.authentication_C, false) && ! isChallengeResponseSupported){
            throw new SQLExceptionSapDB (MessageTranslator.translate(MessageKey.ERROR_CONNECTION_CHALLENGERESPONSENOTSUPPORTED));
        }

        /*
         * build connect statement
         */
        connectCmd = "Connect " + user + " identified by :PW "
            + "SQLMODE " + sqlMode;
        if (timeout != null) {
            connectCmd += " TIMEOUT " + timeout;
        }
        if (isolationLevel != null) {
            this.isolationLevel = DriverSapDB.isolevelString2Jdbc(isolationLevel);
            connectCmd += " ISOLATION LEVEL "
                + DriverSapDB.isolevelJdbc2native (this.isolationLevel);
        }
        if (cacheLimit != null) {
            connectCmd += " CACHELIMIT " + cacheLimit;
        }
        if (this.isSpaceoptionSet) {
            connectCmd += " SPACE OPTION ";
            this.setKernelFeatureRequest(Feature.sp1f_space_option);
        }
        requestPacket.initDbsCommand (false, connectCmd, ResultSet.TYPE_FORWARD_ONLY);
        
        if (!isChallengeResponseSupported){
	        try {
	            crypted = NameHandling.mangle (passwd, !isUserPasswdAscii);
	        }
	        catch (ArrayIndexOutOfBoundsException exc) {
	            throw new SQLExceptionSapDB (MessageTranslator.translate(MessageKey.ERROR_INVALIDPASSWORD));
	        }
	        requestPacket.newPart (PartKind.Data_C);
	        requestPacket.addDataBytes (crypted);
	        requestPacket.addDataString (this.getTermID());
	        requestPacket.incrPartArguments ();
        } else {
            requestPacket.addClientProofPart(auth.getClientProof(passwdByte)); 
            requestPacket.addClientIDPart(this.getTermID());
        }
        
         
        /*feature request part*/
        System.arraycopy( defaultFeatureSet,0, kernelFeatures,0,defaultFeatureSet.length );

        this.setKernelFeatureRequest(Feature.sp1f_variable_input);
        this.setKernelFeatureRequest(Feature.sp1f_multiple_drop_parseid);
        this.setKernelFeatureRequest(Feature.sp1f_check_scrollableoption);
        this.setKernelFeatureRequest(Feature.sp1f_ascii_in_and_output);
        requestPacket.addFeatureRequestPart(this.kernelFeatures);
        /*
         * execute
         */
        ReplyPacket replyPacket = this.execute (requestPacket, this, ConnectionSapDB.GC_DELAYED);
        this.sessionID = replyPacket.getSessionID ();
        VersionInfo vi = new VersionInfo(replyPacket.getKernelMajorVersion(),
                                         replyPacket.getKernelMinorVersion(),
                                         replyPacket.getKernelCorrectionLevel(),
                                         0, null);
        if(vi.getMajorVersion() >= 7 &&
           vi.getMinorVersion() >= 6) {
                        this.DatabaseMetaData = new DatabaseMetaDataMaxDB(this, vi);
        } else {
                        this.DatabaseMetaData = new DatabaseMetaDataSapDB(this, vi);
        }
       	this.releaseSavePointSupported = true;
        	
        this.kernelversion = vi.getMajorVersion() * 10000 + 100 * vi.getMinorVersion() + vi.getMinorMinorVersion();
        byte[] featureReturn = replyPacket.getFeatures();

        if (featureReturn != null){
          this.kernelFeatures = featureReturn;
        } else {
          System.arraycopy( defaultFeatureSet,0, kernelFeatures,0,defaultFeatureSet.length );
        }

//        if ( (10000 * vi.getMajorVersion()+
//             100 * vi.getMinorVersion() +
//             vi.getMinorMinorVersion())
//             >= 70400)
//             this.applID = "JDBC";
        /*
         * use remaining properties
         */
        this.autocommit = DriverSapDB.getBooleanProperty(
            info, DriverSapDB.autocommitName_C, this.autocommit);
        //this.keepGarbage = DriverSapDB.getBooleanProperty(
        //    info, "keepgarbage", false);
        if (info.containsKey(DriverSapDB.cacheName_C)) {
            this.parseCache = new ParseinfoCache (info);
            /*
             * don't use the dbsCache, the overhead is probably not worth it
             * this.dbsCache = new DbsCache (info);
             */

        }
//        TimeoutException.println("New Connection established:"+this+" Version: \""
//            +(10000 * vi.getMajorVersion()+
//             100 * vi.getMinorVersion() +
//             vi.getMinorMinorVersion()) +
//             ((this.autocommit)?"\" autocommit \"on\"":"\" autocommit \"off\"")+
//             ((this.autocommit)?"\" autocommit \"on\"":"\" autocommit \"off\"")+
//             ((this.parseCache !=null)?" PICache \"on\"":" PICache \"off\"")+
//             ((this.inTransaction)?" inTransaction \"true\"":" inTransaction \"false\"")
//             );
    }
    /**
     *
     * @exception java.sql.SQLException The exception description.
     */
    public ReplyPacket
    execute (
            RequestPacket requestPacket,
            Object executingObject,
            int gcFlags)
        throws SQLException
    {
        return this.execute (requestPacket, false, false, executingObject, gcFlags);
    }

    public ReplyPacket sendStreamErrorPacket(SQLException sqlEx)
    {
        try {
            RequestPacket requestPacket = getRequestPacket(false);
            requestPacket.initDbs(this.autocommit, ResultSet.TYPE_FORWARD_ONLY);
            if(sqlEx.getMessage() == null || sqlEx.getMessage().length()==0) {
                requestPacket.addErrorTextPart(MessageTranslator.translate(MessageKey.ERROR_MESSAGE_NOT_AVAILABLE));
            } else {
                requestPacket.addErrorTextPart(sqlEx.getMessage()); 
            }
            if(sqlEx.getErrorCode() == 0) {
                requestPacket.setErrorCode(-9999);
                requestPacket.setSQLState("S9999");
            } else {
                requestPacket.setErrorCode(sqlEx.getErrorCode());
                requestPacket.setSQLState(sqlEx.getSQLState());
            }
            return execute(requestPacket, this, GC_NONE);
            
        } catch(Exception ex) {
            // as this is already sent during an exception, don't 
            // send this exception
            return null;
        }
    }


    /**
     *
     * @exception java.sql.SQLException The exception description.
     */
    public synchronized ReplyPacket
    execute (
            RequestPacket requestPacket,
            boolean ignoreErrors,
            boolean isParse,
            Object executingObject,
            int    gcFlags)
        throws SQLException
    {
        int requestLen;
        ReplyPacket replyPacket = null;
        int localWeakReturnCode = 0;

        this.assertOpen ();

        if(gcFlags == GC_ALLOWED) {
            boolean spaceleft = true;
            if (this.garbageCursors != null
                && this.garbageCursors.isPending()) {
                spaceleft = this.garbageCursors.emptyCan(requestPacket);
            }
            if (spaceleft
                && this.garbageParseids != null
                && this.garbageParseids.isPending()) {
                this.garbageParseids.emptyCan(requestPacket);
            }
        } else {
             if((this.garbageParseids!=null && this.garbageParseids.isPending())) {
                nonRecyclingExecutions ++;
            }
        }
        requestPacket.closePacket ();

        requestLen = requestPacket.length ();
        if (Tracer.traceAny_C && Tracer.isOn (5)) {
            Tracer.traceObject (null, requestPacket, 6);
        }
        try {
            this.executingObject = executingObject;
              replyPacket = ReplyPacketFactory.getReplyPacket(
            this.session.execute (requestPacket.getBase (), requestLen), this.isKernelFeaturesupported(Feature.sp1f_ascii_in_and_output));

            /*get Returncode*/
            replyPacket.firstSegment ();
            localWeakReturnCode = replyPacket.weakReturnCode();

            if(localWeakReturnCode != -8) {
                this.freeRequestPacket(requestPacket);
            }

            if (! this.autocommit
                && ! isParse) {
                this.inTransaction = true;
            }

            // if it is not completely forbidden, we will send the drop
            if(gcFlags != GC_NONE) {
                if (this.garbageCursors != null
                        && this.garbageCursors.isPending()
                        && localWeakReturnCode == 0) {
                        this.garbageCursors.emptyCan(this);
                }

                if(nonRecyclingExecutions > 20
                        && localWeakReturnCode == 0) {
                        nonRecyclingExecutions=0;
                        if (this.garbageParseids != null
                        && this.garbageParseids.isPending()) {
                        this.garbageParseids.emptyCan(this);
                        }
                        nonRecyclingExecutions=0;
                }
                        }

        }
        catch (RTEException rteExc) {
            // if a reconnect is forbidden or we are in the process of a
            // reconnect or we are in a (now rolled back) transaction
            if (! DriverSapDB.getBooleanProperty(this.connectProperties,DriverSapDB.reconnect_C, true)
                || this.inReconnect || this.inTransaction) {
                throw new ConnectionException (rteExc);
            }
            else {
                //Tracer.println ("    trying reconnect"); //#print
                //Tracer.whereAmI ();
                this.tryReconnect (rteExc);
                this.inTransaction = false;
            }
        }
        finally {
            this.executingObject = null;
        }
        if (Tracer.traceAny_C && Tracer.isOn (5)) {
            Tracer.traceObject (null, replyPacket, 6);
        }
        if (!ignoreErrors && (localWeakReturnCode != 0)) {
            this.throwSQLError (replyPacket);
        }
        return replyPacket;
    }
    /**
     *
     * @param cmd java.lang.String
     * @exception java.sql.SQLException The exception description.
     */
    private void
    executeSQLString (
        String cmd,
        int gcFlags)
    throws SQLException
    {
        RequestPacket requestPacket = this.getRequestPacket (false);
        try {
            requestPacket.initDbs (this.autocommit, ResultSet.TYPE_FORWARD_ONLY);
            requestPacket.addStringThrowExc(cmd);
        } catch (ConversionExceptionSapDB e) {
            this.freeRequestPacket(requestPacket);
            requestPacket = this.getRequestPacket (true);
            requestPacket.initDbs (this.autocommit, ResultSet.TYPE_FORWARD_ONLY);
            requestPacket.addStringThrowExc(cmd);
        }
        try {
          this.execute (requestPacket, this, gcFlags);
        }
        catch (TimeoutException ignore) {
          TimeoutException.println(this.toString()+" Inner Timeout "+ignore.toString());
        }
    }
    
    /**
	 * The finalizer will clean up the connection, if it hadn't been done 
	 * yet. This will possibly even send a ROLLBACK to the database.
	 */
	public void finalize() throws Throwable {
		try {
			// avoid a reconnect during the ROLLBACK WORK RELEASE sent
			this.inReconnect = true;
			this.close();
		} catch (SQLException sqlExc) {
			// ignore
		}
		super.finalize();
	}
	
    /**
	 * 
	 * @param requestPacket
	 *            com.sap.dbtech.jdbc.packet.RequestPacket
	 */
    public void freeRequestPacket (RequestPacket requestPacket) {
        requestPacket.setAvailability(false);
        if (requestPacket.isUnicodePacket()){
            this.packetPoolUnicode.push (requestPacket);
        } else{
            this.packetPool.push (requestPacket);
        }
    }
    /**
     * getAutoCommit method comment.
     */
    final public boolean getAutoCommit() throws java.sql.SQLException {
        return this.autocommit;
    }
    /**
     * getCatalog method comment.
     */
    final public String getCatalog() throws java.sql.SQLException {
        return null;
    }
    /**
     *
     * @return java.lang.String
     * @param key java.lang.String
     */
    final String getConnectProperty (String key) {
        return this.connectProperties.getProperty (key, "");
    }
    /**
     * getMetaData method comment.
     */
    final public java.sql.DatabaseMetaData getMetaData() throws java.sql.SQLException {
        this.assertOpen ();
        return  this.DatabaseMetaData;
    }
    /**
     *
     * @return com.sap.dbtech.jdbc.packet.RequestPacket
     */
    final public synchronized RequestPacket getRequestPacket(
            boolean forceUnicode) throws SQLException {
        RequestPacket result;
        String applID = this.connectProperties.getProperty(
                DriverSapDB.application_C, null);
        String applVers = this.connectProperties.getProperty(
                DriverSapDB.appversion_C, null);

        try {
            if (forceUnicode) {
                if (this.packetPoolUnicode.isEmpty()) {
                    result = new RequestPacketUnicode(this.session
                            .getRequestPacket(), applID, applVers);
                } else {
                    result = (RequestPacket) this.packetPoolUnicode.pop();
                }
            } else {
                if (this.packetPool.isEmpty()) {
                    result = new RequestPacket(this.session.getRequestPacket(),
                            RteC.asciiClient_C, applID, applVers);
                } else {
                    result = (RequestPacket) this.packetPool.pop();
                }
            }
        } catch (RTEException rteExc) {
            throw new SQLExceptionSapDB(rteExc.toString());
        }
        result.setAvailability(true);
        return result;
    }
    /**
     * getTransactionIsolation method comment.
     */
    final public int
    getTransactionIsolation()
    throws java.sql.SQLException
    {
        return this.isolationLevel;
    }
    /**
     *
     * @return java.sql.Map
     * @exception java.sql.SQLException The exception description.
     */
    final public Map getTypeMap() throws SQLException {
        return this.typeMap;
    }
    /**
     * getWarnings method comment.
     */
    final public java.sql.SQLWarning getWarnings() throws java.sql.SQLException {
        return warningList;
    }
    /**
     * isClosed method comment.
     */
    public boolean isClosed() throws java.sql.SQLException {
        if (session == null) {
            return true;
        }
        try {
          RequestPacket requestPacket = this.getRequestPacket (false);
          requestPacket.initHello ();
          this.execute (requestPacket, this, ConnectionSapDB.GC_ALLOWED);
        }
        catch (TimeoutException ignore){
             TimeoutException.println(this.toString()+" Inner Timeout "+ignore.toString());
        }
        catch (SQLException exc) {
          TimeoutException.println(this.toString()+" Inner SQLException "+exc.toString());
          try{
            this.session.release ();
          } catch(Exception ignore){
            TimeoutException.println(this+exc.toString());
          }
          this.session = null;
          this.DatabaseMetaData = null;
          return true;
        }
        return session == null;
    }
    /**
     * isReadOnly method comment.
     */
    final public boolean isReadOnly() throws java.sql.SQLException {
        return false;
    }
    /**
     *
     */
    boolean
    isInTransaction ()
    {

        return (!this.autocommit && this.inTransaction);
    }
    /**
     *
     * @return int
     */
    final synchronized int maxStatementLength ()
    throws SQLException
    {
        RequestPacket requestPacket = this.getRequestPacket (false);
        int packetSize = requestPacket.size ();
        int result = packetSize - Packet.Segment_O - Segment.Part_O - Part.Data_O;
        this.freeRequestPacket(requestPacket);
        return result;
    }
    /**
     * nativeSQL method comment.
     */
    final public String
    nativeSQL(
        String sql)
    throws java.sql.SQLException
    {
        return sql;
    }
    /**
     *
     * @return java.lang.String
     */
    final String nextCursorName () {
      return this.UniqueID.getNextID(cursorPrefix);
    }
    /**
     *
     */
    final protected void setCursorPrefix (String prefix) {
        this.cursorPrefix = prefix;
    }
    /**
     * prepareCall method comment.
     */
    final public java.sql.CallableStatement prepareCall(String sql) throws java.sql.SQLException {
        this.assertOpen ();
        return new CallableStatementSapDB (this, sql);
    }
    /**
     *
     * @return java.sql.CallableStatement
     * @param sql java.lang.String
     * @param resultSetType int
     * @param resultSetConcurrency int
     * @exception java.sql.SQLException The exception description.
     */
    public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
        this.assertOpen ();
        return new CallableStatementSapDB (this, sql, resultSetType, resultSetConcurrency, StatementSapDB.defaultHoldability_C);
    }
    /**
     * prepareStatement method comment.
     */
    public java.sql.PreparedStatement prepareStatement(
        String sql)
    throws java.sql.SQLException
    {
        this.assertOpen ();
        return new CallableStatementSapDB (this, sql);
    }
    /**
     *
     * @return java.sql.PreparedStatement
     * @param sql java.lang.String
     * @param resultSetType int
     * @param resultSetConcurrency int
     * @exception java.sql.SQLException The exception description.
     */
    public java.sql.PreparedStatement prepareStatement(
        String sql,
        int resultSetType,
        int resultSetConcurrency)
    throws SQLException
    {
        this.assertOpen ();
        return new CallableStatementSapDB (this, sql, resultSetType, resultSetConcurrency,StatementSapDB.defaultHoldability_C);
    }
    /**
     * rollback method comment.
     */
    public void rollback()
        throws java.sql.SQLException
    {
        this.assertOpen ();
        this.executeSQLString ("ROLLBACK WORK", ConnectionSapDB.GC_ALLOWED);
        this.inTransaction = false;
    }
    /**
     * setAutoCommit method comment.
     */
    public void setAutoCommit(boolean autoCommit)
        throws java.sql.SQLException
    {
        this.assertOpen ();
        if (autoCommit){
            this.commit();
        }
        this.autocommit = autoCommit;
    }
    /**
     * setCatalog method comment.
     */
    final public void setCatalog(
        String catalog)
    throws java.sql.SQLException
    {
    }
    /**
     * setReadOnly method comment.
     */
    final public void
    setReadOnly(
        boolean readOnly)
    throws java.sql.SQLException
    {
        this.assertOpen ();
    }
    /**
     * setTransactionIsolation method comment.
     */
    final public void
    setTransactionIsolation(
        int level)
    throws java.sql.SQLException
    {
        if (this.isolationLevel != level){
          String sapdbEncoding = DriverSapDB.isolevelJdbc2native (level);
          this.assertOpen ();
          String cmd = "SET ISOLATION LEVEL " + sapdbEncoding;
          Statement setIso = new InternalStatementSapDB (this);
          setIso.executeUpdate (cmd);
          this.isolationLevel = level;
        }
    }
    /**
     *
     * @param map java.sql.Map
     * @exception java.sql.SQLException The exception description.
     */
    final public void setTypeMap(Map map) throws SQLException {
        this.typeMap = map;
    }
    /**
     *
     * @exception com.sap.dbtech.jdbc.SQLExceptionSapDBTech The exception description.
     */
    final void
    throwBatchException (
        ReplyPacket replyPacket,
        int [] codes,
        int segmentsProcessed)
    throws java.sql.BatchUpdateException
    {
        String state = replyPacket.sqlState ();
        int rc = replyPacket.returnCode ();
        String errmsg = replyPacket.getErrorMsg ();
        int [] firstCodes = new int [segmentsProcessed];
        System.arraycopy(codes, 0, firstCodes, 0, segmentsProcessed);

        throw new java.sql.BatchUpdateException (errmsg, state, rc, firstCodes);
    }
    /**
     *
     * @exception com.sap.dbtech.jdbc.SQLExceptionSapDBTech The exception description.
     */
    final private void throwSQLError (
        ReplyPacket replyPacket)
    throws SQLExceptionSapDB
    {
        SQLExceptionSapDB exc = replyPacket.createException();
        throw exc;
    }
    /**
     *
     * @exception java.sql.SQLException The exception description.
     */
    protected void tryReconnect (
        com.sap.dbtech.rte.comm.RTEException outerRteExc)
    throws SQLException
    {
        Object localSync = (TimeoutException.extendedTrace==null)?syncObj:(Object)TimeoutException.extendedTrace;
        synchronized (localSync)
        {
            TimeoutException timeout = new TimeoutException (outerRteExc);
            if (this.parseCache != null) {
                this.parseCache.clear ();
            }
            if (this.dbsCache != null) {
                this.dbsCache.clear ();
            }
            this.packetPool.setSize (0);
            this.packetPoolUnicode.setSize (0);
            this.inReconnect = true;
            try {
                this.session.reconnect ();
                this.doConnect (this.connectProperties);
                    TimeoutException.println ("+++ connected again +++");
                }
            catch (RTEException rteExc) {
                    TimeoutException.println ("--- reconnect failed: "
                        + rteExc.getMessage () + " ---");
                throw new ConnectionException (rteExc);
            }
            finally {
                this.inReconnect = false;
            }
            throw timeout;
        }
    }




    /**
     * queues an old parseid for dropping it.
     * <UL>
     * <LI>dropping of parseids is mostly done
     * during garbage collection
     * <LI>when asynchronous garbage collection is
     * disabled, the garbage collector is called
     * during a blocking socket call
     * <LI>sending the DROP PARSEID command as
     * part of the <i>finalize</i> method will
     * interfere with the pending socket request
     * <LI>synchronization of the connection does
     * not work as both requests happen in the
     * same thread
     * <LI>parseids are therefor queued and dropped after a regular SQL request
     * succeeded
     * <LI>besides, sending multiple DROP PARSEIDs in one
     * request is more efficient
     * </UL>
     *
     * @param pid    the parseid
     */
    final public void
    dropParseid (byte [] pid)
    {
        if (!this.keepGarbage) {
            if (pid == null) {
                return;
            }
            if (this.garbageParseids == null) {
                this.garbageParseids = new com.sap.dbtech.util.GarbageParseid(this.isKernelFeaturesupported(Feature.sp1f_multiple_drop_parseid));
            }
            this.garbageParseids.throwIntoGarbageCan(pid);
        }
    }

    /**
     * queues an old cursor for dropping it.
     * <UL>
     * <LI>dropping of cursor is sometimes done
     * during garbage collection
     * <LI>when asynchronous garbage collection is
     * disabled, the garbage collector is called
     * during a blocking socket call
     * <LI>sending the CLOSE CURSOR command as
     * part of the <i>finalize</i> method will
     * interfere with the pending socket request
     * <LI>synchronization of the connection does
     * not work as both requests happen in the
     * same thread
     * <LI>cursors are therefor queued and dropped after a regular SQL request
     * succeeded
     * <LI>besides, sending multiple CLOSE CURSORs in one
     * request is more efficient
     * </UL>
     *
     * @param cursorname    the cursorname
     */
    final public void dropCursor (String cursorname) {
        synchronized(this) {
            if (this.garbageCursors == null) {
                this.garbageCursors = new com.sap.dbtech.util.GarbageCursor();
            }
            this.garbageCursors.throwIntoGarbageCan(cursorname);
        }
    }

    final public boolean restoreCursor(String cursorname) {
        synchronized(this) {
                if(this.garbageCursors != null) {
                        return this.garbageCursors.restoreFromGarbageCan(cursorname);
                } else {
                        return false;
                }
        }
    }

    /**
     *
     */
    public void
    printCacheStats (
        java.io.PrintStream stream)
    {
        if (this.parseCache == null) {
            stream.println ("no cache available");
        }
        else {
            this.parseCache.dumpStats (stream);
        }
    }
    /**
     *
     */
    public void
    printCacheStats (
        java.io.PrintWriter stream)
    {
        if (this.parseCache == null) {
            stream.println ("no cache available");
        }
        else {
            this.parseCache.dumpStats (stream);
        }
    }
    public boolean isSQLModeOracle (){
      return this.isSQLModeOracle;
    }

    /**
     * Changes the holdability of <code>ResultSet</code> objects
     * created using this <code>Connection</code> object to the given
     * holdability.
     *
     * @param holdability a <code>ResultSet</code> holdability constant; one of
     *        <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
     *        <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
     * @throws SQLException if a database access occurs, the given parameter
     *         is not a <code>ResultSet</code> constant indicating holdability,
     *         or the given holdability is not supported
     * @see #getHoldability
     * @see ResultSet
     * @since 1.4
     */
    public void setHoldability (int holdability) throws SQLException {
        this.resultSetHoldability = holdability;
    }

    /**
     * Retrieves the current holdability of <code>ResultSet</code> objects
     * created using this <code>Connection</code> object.
     *
     * @return the holdability, one of
     *        <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
     *        <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
     * @throws SQLException if a database access occurs
     * @see #setHoldability
     * @see ResultSet
     * @since 1.4
     */
    public int getHoldability () throws SQLException {
        return  this.resultSetHoldability;
    }

    /**
     * Creates an unnamed savepoint in the current transaction and
     * returns the new <code>Savepoint</code> object that represents it.
     *
     * @return the new <code>Savepoint</code> object
     * @exception SQLException if a database access error occurs
     *            or this <code>Connection</code> object is currently in
     *            auto-commit mode
     * @see Savepoint
     * @since 1.4
     */
    public java.sql.Savepoint setSavepoint () throws java.sql.SQLException {
        if (this.getAutoCommit())
            throw  new SQLExceptionSapDB(MessageTranslator.translate(MessageKey.ERROR_CONNECTION_AUTOCOMMIT));
        return  com.sap.dbtech.jdbc.SavepointSapDB.setSavepoint(this);
    }

    /**
     * Creates a savepoint with the given name in the current transaction
     * and returns the new <code>Savepoint</code> object that represents it.
     *
     * @param name a <code>String</code> containing the name of the savepoint
     * @return the new <code>Savepoint</code> object
     * @exception SQLException if a database access error occurs
     *            or this <code>Connection</code> object is currently in
     *            auto-commit mode
     * @see Savepoint
     * @since 1.4
     */
    public java.sql.Savepoint setSavepoint (String SavepointName) throws java.sql.SQLException {
        if (this.getAutoCommit())
            throw  new SQLExceptionSapDB(MessageTranslator.translate(MessageKey.ERROR_CONNECTION_AUTOCOMMIT));
        return  com.sap.dbtech.jdbc.SavepointSapDB.setSavepoint(SavepointName, this);
    }

    /**
     * Undoes all changes made after the given <code>Savepoint</code> object
     * was set.
     * <P>
     * This method should be used only when auto-commit has been disabled.
     *
     * @param savepoint the <code>Savepoint</code> object to roll back to
     * @exception SQLException if a database access error occurs,
     *            the <code>Savepoint</code> object is no longer valid,
     *            or this <code>Connection</code> object is currently in
     *            auto-commit mode
     * @see Savepoint
     * @see #rollback
     * @since 1.4
     */
    public void rollback (java.sql.Savepoint savepoint) throws java.sql.SQLException {
        if (this.getAutoCommit())
            throw  new SQLExceptionSapDB(MessageTranslator.translate(MessageKey.ERROR_CONNECTION_AUTOCOMMIT));
        com.sap.dbtech.jdbc.SavepointSapDB.rollback(savepoint);
    }

    /**
     * Removes the given <code>Savepoint</code> object from the current
     * transaction. Any reference to the savepoint after it have been removed
     * will cause an <code>SQLException</code> to be thrown.
     *
     * @param savepoint the <code>Savepoint</code> object to be removed
     * @exception SQLException if a database access error occurs or
     *            the given <code>Savepoint</code> object is not a valid
     *            savepoint in the current transaction
     * @since 1.4
     */
    public void releaseSavepoint (java.sql.Savepoint savepoint) throws java.sql.SQLException {
        com.sap.dbtech.jdbc.SavepointSapDB.releaseSavepoint(savepoint);
    }

    /**
     * Creates a <code>Statement</code> object that will generate
     * <code>ResultSet</code> objects with the given type, concurrency,
     * and holdability.
     * This method is the same as the <code>createStatement</code> method
     * above, but it allows the default result set
     * type, concurrency, and holdability to be overridden.
     *
     * @param resultSetType one of the following <code>ResultSet</code>
     *        constants:
     *         <code>ResultSet.TYPE_FORWARD_ONLY</code>,
     *         <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
     *         <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
     * @param resultSetConcurrency one of the following <code>ResultSet</code>
     *        constants:
     *         <code>ResultSet.CONCUR_READ_ONLY</code> or
     *         <code>ResultSet.CONCUR_UPDATABLE</code>
     * @param resultSetHoldability one of the following <code>ResultSet</code>
     *        constants:
     *         <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
     *         <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
     * @return a new <code>Statement</code> object that will generate
     *         <code>ResultSet</code> objects with the given type,
     *         concurrency, and holdability
     * @exception SQLException if a database access error occurs
     *            or the given parameters are not <code>ResultSet</code>
     *            constants indicating type, concurrency, and holdability
     * @see ResultSet
     * @since 1.4
     */
    public Statement createStatement (int resultSetType, int resultSetConcurrency,
            int resultSetHoldability) throws SQLException {
        this.assertOpen();
        return  new StatementSapDB(this, resultSetType, resultSetConcurrency,
                resultSetHoldability);
    }

    /**
     * Creates a <code>PreparedStatement</code> object that will generate
     * <code>ResultSet</code> objects with the given type, concurrency,
     * and holdability.
     * <P>
     * This method is the same as the <code>prepareStatement</code> method
     * above, but it allows the default result set
     * type, concurrency, and holdability to be overridden.
     *
     * @param sql a <code>String</code> object that is the SQL statement to
     *            be sent to the database; may contain one or more ? IN
     *            parameters
     * @param resultSetType one of the following <code>ResultSet</code>
     *        constants:
     *         <code>ResultSet.TYPE_FORWARD_ONLY</code>,
     *         <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
     *         <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
     * @param resultSetConcurrency one of the following <code>ResultSet</code>
     *        constants:
     *         <code>ResultSet.CONCUR_READ_ONLY</code> or
     *         <code>ResultSet.CONCUR_UPDATABLE</code>
     * @param resultSetHoldability one of the following <code>ResultSet</code>
     *        constants:
     *         <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
     *         <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
     * @return a new <code>PreparedStatement</code> object, containing the
     *         pre-compiled SQL statement, that will generate
     *         <code>ResultSet</code> objects with the given type,
     *         concurrency, and holdability
     * @exception SQLException if a database access error occurs
     *            or the given parameters are not <code>ResultSet</code>
     *            constants indicating type, concurrency, and holdability
     * @see ResultSet
     * @since 1.4
     */
    public PreparedStatement prepareStatement (String sql, int resultSetType,
            int resultSetConcurrency, int resultSetHoldability) throws SQLException {
        this.assertOpen();
        return  new CallableStatementSapDB(this, sql, resultSetType, resultSetConcurrency,
                resultSetHoldability);
    }

    /**
     * Creates a <code>CallableStatement</code> object that will generate
     * <code>ResultSet</code> objects with the given type and concurrency.
     * This method is the same as the <code>prepareCall</code> method
     * above, but it allows the default result set
     * type, result set concurrency type and holdability to be overridden.
     *
     * @param sql a <code>String</code> object that is the SQL statement to
     *            be sent to the database; may contain on or more ? parameters
     * @param resultSetType one of the following <code>ResultSet</code>
     *        constants:
     *         <code>ResultSet.TYPE_FORWARD_ONLY</code>,
     *         <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
     *         <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
     * @param resultSetConcurrency one of the following <code>ResultSet</code>
     *        constants:
     *         <code>ResultSet.CONCUR_READ_ONLY</code> or
     *         <code>ResultSet.CONCUR_UPDATABLE</code>
     * @param resultSetHoldability one of the following <code>ResultSet</code>
     *        constants:
     *         <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
     *         <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
     * @return a new <code>CallableStatement</code> object, containing the
     *         pre-compiled SQL statement, that will generate
     *         <code>ResultSet</code> objects with the given type,
     *         concurrency, and holdability
     * @exception SQLException if a database access error occurs
     *            or the given parameters are not <code>ResultSet</code>
     *            constants indicating type, concurrency, and holdability
     * @see ResultSet
     * @since 1.4
     */
    public CallableStatement prepareCall (String sql, int resultSetType, int resultSetConcurrency,
            int resultSetHoldability) throws SQLException {
        this.assertOpen();
        return  new CallableStatementSapDB(this, sql, resultSetType, resultSetConcurrency,
                resultSetHoldability);
    }

    /**
     * Creates a default <code>PreparedStatement</code> object that has
     * the capability to retrieve auto-generated keys. The given constant
     * tells the driver whether it should make auto-generated keys
     * available for retrieval.  This parameter is ignored if the SQL
     * statement is not an <code>INSERT</code> statement.
     * <P>
     * <B>Note:</B> This method is optimized for handling
     * parametric SQL statements that benefit from precompilation. If
     * the driver supports precompilation,
     * the method <code>prepareStatement</code> will send
     * the statement to the database for precompilation. Some drivers
     * may not support precompilation. In this case, the statement may
     * not be sent to the database until the <code>PreparedStatement</code>
     * object is executed.  This has no direct effect on users; however, it does
     * affect which methods throw certain SQLExceptions.
     * <P>
     * Result sets created using the returned <code>PreparedStatement</code>
     * object will by default be type <code>TYPE_FORWARD_ONLY</code>
     * and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
     *
     * @param sql an SQL statement that may contain one or more '?' IN
     *        parameter placeholders
     * @param autoGeneratedKeys a flag indicating whether auto-generated keys
     *        should be returned; one of the following <code>Statement</code>
     *        constants:
     * @param autoGeneratedKeys a flag indicating that auto-generated keys should be returned, one of
     *        <code>Statement.RETURN_GENERATED_KEYS</code> or
     *	      <code>Statement.NO_GENERATED_KEYS</code>.
     * @return a new <code>PreparedStatement</code> object, containing the
     *         pre-compiled SQL statement, that will have the capability of
     *         returning auto-generated keys
     * @exception SQLException if a database access error occurs
     *         or the given parameter is not a <code>Statement</code>
     *         constant indicating whether auto-generated keys should be
     *         returned
     * @since 1.4
     */
    public PreparedStatement prepareStatement (String sql, int autoGeneratedKeys)
        throws SQLException
    {

        /**@todo: Implement this java.sql.Connection method*/
        throw  new UnsupportedOperationException
            (MessageTranslator.translate(MessageKey.ERROR_PREPARESTATEMENT_NOTIMPLEMENTED));
    }

    /**
     * Creates a default <code>PreparedStatement</code> object capable
     * of returning the auto-generated keys designated by the given array.
     * This array contains the indexes of the columns in the target
     * table that contain the auto-generated keys that should be made
     * available. This array is ignored if the SQL
     * statement is not an <code>INSERT</code> statement.
     * <P>
     * An SQL statement with or without IN parameters can be
     * pre-compiled and stored in a <code>PreparedStatement</code> object. This
     * object can then be used to efficiently execute this statement
     * multiple times.
     * <P>
     * <B>Note:</B> This method is optimized for handling
     * parametric SQL statements that benefit from precompilation. If
     * the driver supports precompilation,
     * the method <code>prepareStatement</code> will send
     * the statement to the database for precompilation. Some drivers
     * may not support precompilation. In this case, the statement may
     * not be sent to the database until the <code>PreparedStatement</code>
     * object is executed.  This has no direct effect on users; however, it does
     * affect which methods throw certain SQLExceptions.
     * <P>
     * Result sets created using the returned <code>PreparedStatement</code>
     * object will by default be type <code>TYPE_FORWARD_ONLY</code>
     * and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
     *
     * @param sql an SQL statement that may contain one or more '?' IN
     *        parameter placeholders
     * @param columnIndexes an array of column indexes indicating the columns
     *        that should be returned from the inserted row or rows
     * @return a new <code>PreparedStatement</code> object, containing the
     *         pre-compiled statement, that is capable of returning the
     *         auto-generated keys designated by the given array of column
     *         indexes
     * @exception SQLException if a database access error occurs
     *
     * @since 1.4
     */
    public PreparedStatement prepareStatement (String sql, int columnIndexes[])
        throws SQLException
    {

        /**@todo: Implement this java.sql.Connection method*/
        throw  new UnsupportedOperationException
            (MessageTranslator.translate(MessageKey.ERROR_PREPARESTATEMENT_NOTIMPLEMENTED));
    }

    /**
     * Creates a default <code>PreparedStatement</code> object capable
     * of returning the auto-generated keys designated by the given array.
     * This array contains the names of the columns in the target
     * table that contain the auto-generated keys that should be returned.
     * This array is ignored if the SQL
     * statement is not an <code>INSERT</code> statement.
     * <P>
     * An SQL statement with or without IN parameters can be
     * pre-compiled and stored in a <code>PreparedStatement</code> object. This
     * object can then be used to efficiently execute this statement
     * multiple times.
     * <P>
     * <B>Note:</B> This method is optimized for handling
     * parametric SQL statements that benefit from precompilation. If
     * the driver supports precompilation,
     * the method <code>prepareStatement</code> will send
     * the statement to the database for precompilation. Some drivers
     * may not support precompilation. In this case, the statement may
     * not be sent to the database until the <code>PreparedStatement</code>
     * object is executed.  This has no direct effect on users; however, it does
     * affect which methods throw certain SQLExceptions.
     * <P>
     * Result sets created using the returned <code>PreparedStatement</code>
     * object will by default be type <code>TYPE_FORWARD_ONLY</code>
     * and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
     *
     * @param sql an SQL statement that may contain one or more '?' IN
     *        parameter placeholders
     * @param columnNames an array of column names indicating the columns
     *        that should be returned from the inserted row or rows
     * @return a new <code>PreparedStatement</code> object, containing the
     *         pre-compiled statement, that is capable of returning the
     *         auto-generated keys designated by the given array of column
     *         names
     * @exception SQLException if a database access error occurs
     *
     * @since 1.4
     */
    public PreparedStatement prepareStatement (String sql, String columnNames[])
        throws SQLException
    {
        /**@todo: Implement this java.sql.Connection method*/
        throw  new UnsupportedOperationException
            (MessageTranslator.translate(MessageKey.ERROR_PREPARESTATEMENT_NOTIMPLEMENTED));
    }

    /**
     * Sets this connection back to 'factory settings', i.e. restores what
     * was either default setting or connection property setting.
     */
   public void reinitialize()
        throws SQLException
    {
        if(this.parseCache!=null) {
            Object[] parseInfos=this.parseCache.clearAll();
            for(int i=0; i<parseInfos.length; ++i) {
                ((Parseinfo)parseInfos[i]).dropParseIDs();
            }
        }

        // reset the isolation level
        String isolation=this.connectProperties.getProperty(DriverSapDB.isolationName_C);
        int    preset_isolationlevel= isolation==null
            ? Connection.TRANSACTION_READ_COMMITTED
            : DriverSapDB.isolevelString2Jdbc(isolation);
        if(preset_isolationlevel != getTransactionIsolation()) {
            setTransactionIsolation(preset_isolationlevel);
        }
        setAutoCommit(DriverSapDB.getBooleanProperty(this.connectProperties,
                                                     DriverSapDB.autocommitName_C,
                                                     true));
        this.resultSetHoldability = StatementSapDB.defaultHoldability_C;
        this.typeMap=null;
    }

    int getKernelVersion() {
        return this.kernelversion;
    }

    private void setKernelFeatureRequest(int feature){
       this.kernelFeatures[2*(feature-1)+1]=1;
    }

    public boolean isKernelFeaturesupported(int feature){
       boolean erg =  (this.kernelFeatures[2*(feature-1)+1]==1)?true:false;
       return erg;
    }
    
    void stopKernelTrace(){
        try {
            this.executeSQLString("DIAGNOSE VTRACE FLUSH", ConnectionSapDB.GC_ALLOWED);
        } catch (Exception e) {
            // TODO: handle exception
        }
    }
    
    public Properties getConnectProperties(){
        return this.connectProperties;   
     }

    public boolean isReleaseSavePointSupported() {
    	return this.releaseSavePointSupported;
	}
    
    public void setReleaseSavePointSupported(boolean value) {
    	this.releaseSavePointSupported = false;
    }
    void setInTransaction(boolean inTransaction) {
        this.inTransaction = inTransaction;
    }
}