1 21 22 package org.apache.derby.client.net; 23 24 25 import javax.transaction.xa.Xid ; 26 27 import org.apache.derby.client.am.SqlException; 28 import org.apache.derby.client.am.ClientMessageId; 29 import org.apache.derby.client.am.Utils; 30 import org.apache.derby.shared.common.reference.SQLState; 31 32 public class NetConnectionRequest extends Request implements ConnectionRequestInterface { 33 NetConnectionRequest(NetAgent netAgent, CcsidManager ccsidManager, int bufferSize) { 34 super(netAgent, ccsidManager, bufferSize); 35 } 36 38 void writeExchangeServerAttributes(String externalName, 39 int targetAgent, 40 int targetSqlam, 41 int targetRdb, 42 int targetSecmgr, 43 int targetCmntcpip, 44 int targetCmnappc, 45 int targetXamgr, 46 int targetSyncptmgr, 47 int targetRsyncmgr) throws SqlException { 48 buildEXCSAT(externalName, 52 targetAgent, 53 targetSqlam, 54 targetRdb, 55 targetSecmgr, 56 targetCmntcpip, 57 targetCmnappc, 58 targetXamgr, 59 targetSyncptmgr, 60 targetRsyncmgr); 61 62 } 63 64 void writeDummyExchangeServerAttributes() throws SqlException { 65 buildDummyEXCSAT(); 68 } 69 70 void writeAccessSecurity(int securityMechanism, 71 String databaseName, 72 byte[] publicKey) throws SqlException { 73 buildACCSEC(securityMechanism, databaseName, publicKey); 74 } 75 76 void writeSecurityCheck(int securityMechanism, 77 String databaseName, 78 String userid, 79 String password, 80 byte[] encryptedUserid, 81 byte[] encryptedPassword) throws SqlException { 82 buildSECCHK(securityMechanism, 83 databaseName, 84 userid, 85 password, 86 encryptedUserid, 87 encryptedPassword); 88 } 89 90 void writeAccessDatabase(String rdbnam, 91 boolean readOnly, 92 byte[] correlationToken, 93 byte[] productData, 94 Typdef typdef) throws SqlException { 95 buildACCRDB(rdbnam, 96 readOnly, 97 correlationToken, 98 productData, 99 typdef); 100 } 101 102 103 public void writeCommitSubstitute(NetConnection connection) throws SqlException { 104 buildDummyEXCSAT(); 105 } 106 107 public void writeLocalCommit(NetConnection connection) throws SqlException { 108 buildRDBCMM(); 109 } 110 111 public void writeLocalRollback(NetConnection connection) throws SqlException { 112 buildRDBRLLBCK(); 113 } 114 115 public void writeLocalXAStart(NetConnection connection) throws SqlException { 116 } 117 118 119 public void writeLocalXACommit(NetConnection conn) throws SqlException { 121 } 122 123 public void writeLocalXARollback(NetConnection conn) throws SqlException { 125 } 126 127 public void writeXaStartUnitOfWork(NetConnection conn) throws SqlException { 128 } 129 130 public void writeXaEndUnitOfWork(NetConnection conn) throws SqlException { 131 } 132 133 protected void writeXaPrepare(NetConnection conn) throws SqlException { 134 } 135 136 protected void writeXaCommit(NetConnection conn, Xid xid) throws SqlException { 137 } 138 139 protected void writeXaRollback(NetConnection conn, Xid xid) throws SqlException { 140 } 141 142 protected void writeXaRecover(NetConnection conn, int flag) throws SqlException { 143 } 144 145 protected void writeXaForget(NetConnection conn, Xid xid) throws SqlException { 146 } 147 148 public void writeSYNCType(int codepoint, int syncType) { 149 writeScalar1Byte(codepoint, syncType); 150 } 151 152 public void writeForget(int codepoint, int value) { 153 } 154 155 public void writeReleaseConversation(int codepoint, int value) { 156 } 157 158 void writeNullXID(int codepoint) { 159 } 160 161 void writeXID(int codepoint, Xid xid) throws SqlException { 162 } 163 164 165 void writeXAFlags(int codepoint, int xaFlags) { 166 } 167 168 169 174 void buildRDBCMM() throws SqlException { 181 createCommand(); 182 writeLengthCodePoint(0x04, CodePoint.RDBCMM); 183 } 184 185 void buildRDBRLLBCK() throws SqlException { 192 createCommand(); 193 writeLengthCodePoint(0x04, CodePoint.RDBRLLBCK); 194 } 195 196 void buildEXCSAT(String externalName, 204 int targetAgent, 205 int targetSqlam, 206 int targetRdb, 207 int targetSecmgr, 208 int targetCmntcpip, 209 int targetCmnappc, 210 int targetXamgr, 211 int targetSyncptmgr, 212 int targetRsyncmgr) throws SqlException { 213 createCommand(); 214 215 markLengthBytes(CodePoint.EXCSAT); 219 220 buildEXTNAM(externalName); 223 224 buildSRVNAM("Derby"); 226 227 buildSRVRLSLV(); 230 231 236 buildMGRLVLLS(targetAgent, 244 targetSqlam, 245 targetRdb, 246 targetSecmgr, 247 targetXamgr, 248 targetSyncptmgr, 249 targetRsyncmgr); 250 251 252 buildSRVCLSNM(); 255 256 updateLengthBytes(); 260 } 261 262 void buildDummyEXCSAT() throws SqlException { 263 createCommand(); 264 265 markLengthBytes(CodePoint.EXCSAT); 269 270 updateLengthBytes(); 274 } 275 276 void buildACCSEC(int secmec, 277 String rdbnam, 278 byte[] sectkn) throws SqlException { 279 createCommand(); 280 281 markLengthBytes(CodePoint.ACCSEC); 284 285 buildSECMEC(secmec); 288 289 buildRDBNAM(rdbnam); 294 295 if (sectkn != null) { 296 buildSECTKN(sectkn); 297 } 298 299 updateLengthBytes(); 302 } 303 304 void buildSECCHK(int secmec, 305 String rdbnam, 306 String user, 307 String password, 308 byte[] sectkn, 309 byte[] sectkn2) throws SqlException { 310 createCommand(); 311 markLengthBytes(CodePoint.SECCHK); 312 313 buildSECMEC(secmec); 315 316 buildRDBNAM(rdbnam); 321 if (user != null) { 322 buildUSRID(user); 323 } 324 if (password != null) { 325 buildPASSWORD(password); 326 } 327 if (sectkn != null) { 328 buildSECTKN(sectkn); 329 } 330 if (sectkn2 != null) { 331 buildSECTKN(sectkn2); 332 } 333 updateLengthBytes(); 334 335 } 336 337 void buildACCRDB(String rdbnam, 343 boolean readOnly, 344 byte[] crrtkn, 345 byte[] prddta, 346 Typdef typdef) throws SqlException { 347 createCommand(); 348 349 markLengthBytes(CodePoint.ACCRDB); 350 351 buildRDBNAM(rdbnam); 357 358 buildRDBACCCL(); 363 364 buildPRDID(); 368 369 buildPRDDTA(prddta); 376 377 378 buildTYPDEFNAM(typdef.getTypdefnam()); 381 382 if (crrtkn == null) { 383 netAgent_.netConnection_.constructCrrtkn(); 384 } 385 386 buildCRRTKN(netAgent_.netConnection_.crrtkn_); 387 388 buildTYPDEFOVR(typdef.isCcsidSbcSet(), 393 typdef.getCcsidSbc(), 394 typdef.isCcsidDbcSet(), 395 typdef.getCcsidDbc(), 396 typdef.isCcsidMbcSet(), 397 typdef.getCcsidMbc()); 398 399 buildRDBALWUPD(readOnly); 404 405 406 407 412 updateLengthBytes(); 415 } 416 417 418 void buildSYNCCTLMigrate() throws SqlException { 419 } 420 421 void buildSYNCCTLCommit(int xaFlags, Xid xid) throws SqlException { 422 } 423 424 void buildSYNCCTLRollback(int xaFlags) throws SqlException { 425 } 426 427 428 private void buildEXTNAM(String extnam) throws SqlException { 431 int extnamTruncateLength = Utils.min(extnam.length(), 432 NetConfiguration.EXTNAM_MAXSIZE); 433 434 writeScalarString(CodePoint.EXTNAM, 435 extnam.substring(0, extnamTruncateLength)); 436 } 437 438 private void buildSRVNAM(String srvnam) throws SqlException { 440 int srvnamTruncateLength = Utils.min(srvnam.length(), 441 NetConfiguration.SRVNAM_MAXSIZE); 442 writeScalarString(CodePoint.SRVNAM, 443 srvnam.substring(0, srvnamTruncateLength)); 444 } 445 446 private void buildSRVRLSLV() throws SqlException { 449 writeScalarString(CodePoint.SRVRLSLV, NetConfiguration.SRVRLSLV); 451 } 452 453 private void buildSRVCLSNM() throws SqlException { 454 writeScalarString(CodePoint.SRVCLSNM, NetConfiguration.SRVCLSNM_JVM); 456 } 457 458 private void buildSECMEC(int secmec) throws SqlException { 460 writeScalar2Bytes(CodePoint.SECMEC, secmec); 461 } 462 463 private void buildRDBNAM(String rdbnam) throws SqlException { 471 474 int rdbnamLength = rdbnam.length(); 475 if (rdbnamLength <= NetConfiguration.PKG_IDENTIFIER_FIXED_LEN) { 476 writeScalarPaddedString(CodePoint.RDBNAM, 477 rdbnam, 478 NetConfiguration.PKG_IDENTIFIER_FIXED_LEN); } else { 480 if (rdbnamLength <= NetConfiguration.PKG_IDENTIFIER_MAX_LEN) { 481 writeScalarString(CodePoint.RDBNAM, rdbnam); 482 } else { 483 throw new SqlException(netAgent_.logWriter_, 484 new ClientMessageId(SQLState.NET_DBNAME_TOO_LONG), rdbnam); 485 } 486 } 488 } 489 490 private void buildSECTKN(byte[] sectkn) throws SqlException { 491 if (sectkn.length > NetConfiguration.SECTKN_MAXSIZE) { 492 throw new SqlException(netAgent_.logWriter_, 493 new ClientMessageId(SQLState.NET_SECTKN_TOO_LONG)); 494 } 495 writeScalarBytes(CodePoint.SECTKN, sectkn); 496 } 497 498 private void buildUSRID(String usrid) throws SqlException { 499 int usridLength = usrid.length(); 500 if ((usridLength == 0) || (usridLength > NetConfiguration.USRID_MAXSIZE)) { 501 throw new SqlException(netAgent_.logWriter_, 502 new ClientMessageId(SQLState.NET_USERID_TOO_LONG)); 503 } 504 505 writeScalarString(CodePoint.USRID, usrid); 506 } 507 508 private void buildPASSWORD(String password) throws SqlException { 509 int passwordLength = password.length(); 510 if ((passwordLength == 0) || (passwordLength > NetConfiguration.PASSWORD_MAXSIZE)) { 511 throw new SqlException(netAgent_.logWriter_, 512 new ClientMessageId(SQLState.NET_PASSWORD_TOO_LONG)); 513 } 514 if (netAgent_.logWriter_ != null) { 515 passwordIncluded_ = true; 518 passwordStart_ = offset_ + 4; 519 passwordLength_ = passwordLength; 520 } 521 writeScalarString(CodePoint.PASSWORD, password); 522 } 523 524 private void buildRDBACCCL() throws SqlException { 525 writeScalar2Bytes(CodePoint.RDBACCCL, CodePoint.SQLAM); 526 } 527 528 529 private void buildPRDID() throws SqlException { 530 writeScalarString(CodePoint.PRDID, NetConfiguration.PRDID); } 532 533 private void buildPRDDTA(byte[] prddta) throws SqlException { 534 int prddtaLength = (prddta[NetConfiguration.PRDDTA_LEN_BYTE] & 0xff) + 1; 535 writeScalarBytes(CodePoint.PRDDTA, prddta, 0, prddtaLength); 536 } 537 538 private void buildTYPDEFNAM(String typdefnam) throws SqlException { 539 writeScalarString(CodePoint.TYPDEFNAM, typdefnam); 540 } 541 542 void buildTYPDEFOVR(boolean sendCcsidSbc, 543 int ccsidSbc, 544 boolean sendCcsidDbc, 545 int ccsidDbc, 546 boolean sendCcsidMbc, 547 int ccsidMbc) throws SqlException { 548 markLengthBytes(CodePoint.TYPDEFOVR); 549 if (sendCcsidSbc) { 551 writeScalar2Bytes(CodePoint.CCSIDSBC, ccsidSbc); 552 } 553 554 if (sendCcsidDbc) { 556 writeScalar2Bytes(CodePoint.CCSIDDBC, ccsidDbc); 557 } 558 559 if (sendCcsidMbc) { 561 writeScalar2Bytes(CodePoint.CCSIDMBC, ccsidMbc); 562 } 563 564 updateLengthBytes(); 565 566 } 567 568 private void buildMGRLVLLS(int agent, 569 int sqlam, 570 int rdb, 571 int secmgr, 572 int xamgr, 573 int syncptmgr, 574 int rsyncmgr) throws SqlException { 575 markLengthBytes(CodePoint.MGRLVLLS); 576 577 writeCodePoint4Bytes(CodePoint.AGENT, agent); 579 writeCodePoint4Bytes(CodePoint.SQLAM, sqlam); 580 writeCodePoint4Bytes(CodePoint.RDB, rdb); 581 writeCodePoint4Bytes(CodePoint.SECMGR, secmgr); 582 583 if (netAgent_.netConnection_.isXAConnection()) { 584 if (xamgr != NetConfiguration.MGRLVL_NA) { 585 writeCodePoint4Bytes(CodePoint.XAMGR, xamgr); 586 } 587 if (syncptmgr != NetConfiguration.MGRLVL_NA) { 588 writeCodePoint4Bytes(CodePoint.SYNCPTMGR, syncptmgr); 589 } 590 if (rsyncmgr != NetConfiguration.MGRLVL_NA) { 591 writeCodePoint4Bytes(CodePoint.RSYNCMGR, rsyncmgr); 592 } 593 } 594 updateLengthBytes(); 595 } 596 597 private void buildCRRTKN(byte[] crrtkn) throws SqlException { 598 writeScalarBytes(CodePoint.CRRTKN, crrtkn); 599 } 600 601 private void buildRDBALWUPD(boolean readOnly) throws SqlException { 602 if (readOnly) { 603 writeScalar1Byte(CodePoint.RDBALWUPD, CodePoint.FALSE); 604 } 605 } 606 607 } 608 609 610 611 | Popular Tags |