1 22 package org.jboss.ejb.plugins.cmp.ejbql; 23 24 import org.jboss.ejb.plugins.cmp.jdbc.SQLUtil; 25 26 34 public class BasicVisitor implements JBossQLParserVisitor 35 { 36 public Object visit(SimpleNode node, Object data) 37 { 38 return data; 39 } 40 41 public Object visit(ASTEJBQL node, Object data) 42 { 43 StringBuffer buf = (StringBuffer )data; 44 for(int i = 0; i < node.jjtGetNumChildren(); i++) 45 { 46 if(i > 0) 47 { 48 buf.append(' '); 49 } 50 node.jjtGetChild(i).jjtAccept(this, data); 51 } 52 return data; 53 } 54 55 public Object visit(ASTFrom node, Object data) 56 { 57 StringBuffer buf = (StringBuffer )data; 58 buf.append(SQLUtil.FROM); 59 for(int i = 0; i < node.jjtGetNumChildren(); i++) 60 { 61 if(i > 0) 62 { 63 buf.append(SQLUtil.COMMA); 64 } 65 node.jjtGetChild(i).jjtAccept(this, data); 66 } 67 return data; 68 } 69 70 public Object visit(ASTCollectionMemberDeclaration node, Object data) 71 { 72 StringBuffer buf = (StringBuffer )data; 73 buf.append(SQLUtil.IN).append('('); 74 node.jjtGetChild(0).jjtAccept(this, data); 75 buf.append(')').append(' '); 76 node.jjtGetChild(1).jjtAccept(this, data); 77 return data; 78 } 79 80 public Object visit(ASTRangeVariableDeclaration node, Object data) 81 { 82 StringBuffer buf = (StringBuffer )data; 83 node.jjtGetChild(0).jjtAccept(this, data); 84 buf.append(' '); 85 node.jjtGetChild(1).jjtAccept(this, data); 86 return data; 87 } 88 89 public Object visit(ASTSelect node, Object data) 90 { 91 StringBuffer buf = (StringBuffer )data; 92 buf.append(SQLUtil.SELECT); 93 node.jjtGetChild(0).jjtAccept(this, data); 94 return data; 95 } 96 97 public Object visit(ASTWhere node, Object data) 98 { 99 StringBuffer buf = (StringBuffer )data; 100 buf.append(SQLUtil.WHERE); 101 node.jjtGetChild(0).jjtAccept(this, data); 102 return data; 103 } 104 105 public Object visit(ASTOr node, Object data) 106 { 107 StringBuffer buf = (StringBuffer )data; 108 node.jjtGetChild(0).jjtAccept(this, data); 109 for(int i = 1; i < node.jjtGetNumChildren(); ++i) 110 { 111 buf.append(SQLUtil.OR); 112 node.jjtGetChild(i).jjtAccept(this, data); 113 } 114 return data; 115 } 116 117 public Object visit(ASTWhereConditionalTerm node, Object data) 118 { 119 for(int i = 0; i < node.jjtGetNumChildren(); ++i) 120 { 121 node.jjtGetChild(i).jjtAccept(this, data); 122 } 123 return data; 124 } 125 126 public Object visit(ASTAnd node, Object data) 127 { 128 StringBuffer buf = (StringBuffer )data; 129 node.jjtGetChild(0).jjtAccept(this, data); 130 for(int i = 1; i < node.jjtGetNumChildren(); i++) 131 { 132 buf.append(SQLUtil.AND); 133 node.jjtGetChild(i).jjtAccept(this, data); 134 } 135 return data; 136 } 137 138 public Object visit(ASTNot node, Object data) 139 { 140 StringBuffer buf = (StringBuffer )data; 141 buf.append(SQLUtil.NOT); 142 node.jjtGetChild(0).jjtAccept(this, data); 143 return data; 144 } 145 146 public Object visit(ASTConditionalParenthetical node, Object data) 147 { 148 StringBuffer buf = (StringBuffer )data; 149 buf.append('('); 150 node.jjtGetChild(0).jjtAccept(this, data); 151 buf.append(')'); 152 return data; 153 } 154 155 public Object visit(ASTBetween node, Object data) 156 { 157 StringBuffer buf = (StringBuffer )data; 158 node.jjtGetChild(0).jjtAccept(this, data); 159 if(node.not) 160 { 161 buf.append(SQLUtil.NOT); 162 } 163 buf.append(SQLUtil.BETWEEN); 164 node.jjtGetChild(1).jjtAccept(this, data); 165 buf.append(SQLUtil.AND); 166 node.jjtGetChild(2).jjtAccept(this, data); 167 return data; 168 } 169 170 public Object visit(ASTIn node, Object data) 171 { 172 StringBuffer buf = (StringBuffer )data; 173 node.jjtGetChild(0).jjtAccept(this, data); 174 if(node.not) 175 { 176 buf.append(SQLUtil.NOT); 177 } 178 buf.append(SQLUtil.IN).append('('); 179 node.jjtGetChild(1).jjtAccept(this, data); 180 for(int i = 2; i < node.jjtGetNumChildren(); i++) 181 { 182 buf.append(SQLUtil.COMMA); 183 node.jjtGetChild(i).jjtAccept(this, data); 184 } 185 buf.append(')'); 186 return data; 187 } 188 189 public Object visit(ASTLike node, Object data) 190 { 191 StringBuffer buf = (StringBuffer )data; 192 node.jjtGetChild(0).jjtAccept(this, data); 193 if(node.not) 194 { 195 buf.append(SQLUtil.NOT); 196 } 197 buf.append(SQLUtil.LIKE); 198 node.jjtGetChild(1).jjtAccept(this, data); 199 if(node.jjtGetNumChildren() == 3) 200 { 201 buf.append(SQLUtil.ESCAPE); 202 node.jjtGetChild(2).jjtAccept(this, data); 203 } 204 return data; 205 } 206 207 208 public Object visit(ASTNullComparison node, Object data) 209 { 210 StringBuffer buf = (StringBuffer )data; 211 node.jjtGetChild(0).jjtAccept(this, data); 212 buf.append(SQLUtil.IS); 213 if(node.not) 214 { 215 buf.append(SQLUtil.NOT); 216 } 217 buf.append(SQLUtil.NULL); 218 return data; 219 } 220 221 public Object visit(ASTIsEmpty node, Object data) 222 { 223 StringBuffer buf = (StringBuffer )data; 224 node.jjtGetChild(0).jjtAccept(this, data); 225 buf.append(SQLUtil.IS); 226 if(node.not) 227 { 228 buf.append(SQLUtil.NOT); 229 } 230 buf.append(SQLUtil.EMPTY); 231 return data; 232 } 233 234 public Object visit(ASTMemberOf node, Object data) 235 { 236 StringBuffer buf = (StringBuffer )data; 237 node.jjtGetChild(0).jjtAccept(this, data); 238 if(node.not) 239 { 240 buf.append(SQLUtil.NOT); 241 } 242 buf.append(SQLUtil.MEMBER_OF); 243 node.jjtGetChild(1).jjtAccept(this, data); 244 return data; 245 } 246 247 public Object visit(ASTStringComparison node, Object data) 248 { 249 StringBuffer buf = (StringBuffer )data; 250 node.jjtGetChild(0).jjtAccept(this, data); 251 buf.append(' ').append(node.opp).append(' '); 252 node.jjtGetChild(1).jjtAccept(this, data); 253 return data; 254 } 255 256 public Object visit(ASTBooleanComparison node, Object data) 257 { 258 StringBuffer buf = (StringBuffer )data; 259 node.jjtGetChild(0).jjtAccept(this, data); 260 if(node.jjtGetNumChildren() == 2) 261 { 262 buf.append(' ').append(node.opp).append(' '); 263 node.jjtGetChild(1).jjtAccept(this, data); 264 } 265 return data; 266 } 267 268 public Object visit(ASTDatetimeComparison node, Object data) 269 { 270 StringBuffer buf = (StringBuffer )data; 271 node.jjtGetChild(0).jjtAccept(this, data); 272 buf.append(' ').append(node.opp).append(' '); 273 node.jjtGetChild(1).jjtAccept(this, data); 274 return data; 275 } 276 277 public Object visit(ASTEntityComparison node, Object data) 278 { 279 StringBuffer buf = (StringBuffer )data; 280 node.jjtGetChild(0).jjtAccept(this, data); 281 buf.append(' ').append(node.opp).append(' '); 282 node.jjtGetChild(1).jjtAccept(this, data); 283 return data; 284 } 285 286 public Object visit(ASTValueClassComparison node, Object data) 287 { 288 StringBuffer buf = (StringBuffer )data; 289 node.jjtGetChild(0).jjtAccept(this, data); 290 buf.append(' ').append(node.opp).append(' '); 291 node.jjtGetChild(1).jjtAccept(this, data); 292 return data; 293 } 294 295 public Object visit(ASTArithmeticComparison node, Object data) 296 { 297 StringBuffer buf = (StringBuffer )data; 298 node.jjtGetChild(0).jjtAccept(this, data); 299 buf.append(' ').append(node.opp).append(' '); 300 node.jjtGetChild(1).jjtAccept(this, data); 301 return data; 302 } 303 304 public Object visit(ASTPlusMinus node, Object data) 305 { 306 StringBuffer buf = (StringBuffer )data; 307 for(int i = 0; i < node.jjtGetNumChildren(); i++) 308 { 309 if(i > 0) 310 { 311 buf.append(' ').append(node.opps.get(i - 1)).append(' '); 312 } 313 node.jjtGetChild(i).jjtAccept(this, data); 314 } 315 return data; 316 } 317 318 public Object visit(ASTMultDiv node, Object data) 319 { 320 StringBuffer buf = (StringBuffer )data; 321 for(int i = 0; i < node.jjtGetNumChildren(); i++) 322 { 323 if(i > 0) 324 { 325 buf.append(' ').append(node.opps.get(i - 1)).append(' '); 326 } 327 node.jjtGetChild(i).jjtAccept(this, data); 328 } 329 return data; 330 } 331 332 public Object visit(ASTNegation node, Object data) 333 { 334 StringBuffer buf = (StringBuffer )data; 335 buf.append('-'); 336 node.jjtGetChild(0).jjtAccept(this, data); 337 return data; 338 } 339 340 public Object visit(ASTArithmeticParenthetical node, Object data) 341 { 342 StringBuffer buf = (StringBuffer )data; 343 buf.append('('); 344 node.jjtGetChild(0).jjtAccept(this, data); 345 buf.append(')'); 346 return data; 347 } 348 349 public Object visit(ASTStringParenthetical node, Object data) 350 { 351 StringBuffer buf = (StringBuffer )data; 352 buf.append('('); 353 node.jjtGetChild(0).jjtAccept(this, data); 354 buf.append(')'); 355 return data; 356 } 357 358 public Object visit(ASTConcat node, Object data) 359 { 360 StringBuffer buf = (StringBuffer )data; 361 buf.append(SQLUtil.CONCAT).append('('); 362 node.jjtGetChild(0).jjtAccept(this, data); 363 buf.append(SQLUtil.COMMA); 364 node.jjtGetChild(1).jjtAccept(this, data); 365 buf.append(')'); 366 return data; 367 } 368 369 public Object visit(ASTSubstring node, Object data) 370 { 371 StringBuffer buf = (StringBuffer )data; 372 buf.append(SQLUtil.SUBSTRING).append('('); 373 node.jjtGetChild(0).jjtAccept(this, data); 374 buf.append(SQLUtil.COMMA); 375 node.jjtGetChild(1).jjtAccept(this, data); 376 buf.append(SQLUtil.COMMA); 377 node.jjtGetChild(2).jjtAccept(this, data); 378 buf.append(')'); 379 return data; 380 } 381 382 public Object visit(ASTLCase node, Object data) 383 { 384 StringBuffer buf = (StringBuffer )data; 385 buf.append(SQLUtil.LCASE).append('('); 386 node.jjtGetChild(0).jjtAccept(this, data); 387 buf.append(')'); 388 return data; 389 } 390 391 public Object visit(ASTUCase node, Object data) 392 { 393 StringBuffer buf = (StringBuffer )data; 394 buf.append(SQLUtil.UCASE).append('('); 395 node.jjtGetChild(0).jjtAccept(this, data); 396 buf.append(')'); 397 return data; 398 } 399 400 public Object visit(ASTLength node, Object data) 401 { 402 StringBuffer buf = (StringBuffer )data; 403 buf.append(SQLUtil.LENGTH).append('('); 404 node.jjtGetChild(0).jjtAccept(this, data); 405 buf.append(')'); 406 return data; 407 } 408 409 public Object visit(ASTLocate node, Object data) 410 { 411 StringBuffer buf = (StringBuffer )data; 412 buf.append(SQLUtil.LOCATE).append('('); 413 node.jjtGetChild(0).jjtAccept(this, data); 414 buf.append(SQLUtil.COMMA); 415 node.jjtGetChild(1).jjtAccept(this, data); 416 if(node.jjtGetNumChildren() == 3) 417 { 418 buf.append(SQLUtil.COMMA); 419 node.jjtGetChild(2).jjtAccept(this, data); 420 } 421 buf.append(')'); 422 return data; 423 } 424 425 public Object visit(ASTAbs node, Object data) 426 { 427 StringBuffer buf = (StringBuffer )data; 428 buf.append(SQLUtil.ABS).append('('); 429 node.jjtGetChild(0).jjtAccept(this, data); 430 buf.append(')'); 431 return data; 432 } 433 434 public Object visit(ASTSqrt node, Object data) 435 { 436 StringBuffer buf = (StringBuffer )data; 437 buf.append(SQLUtil.SQRT).append('('); 438 node.jjtGetChild(0).jjtAccept(this, data); 439 buf.append(')'); 440 return data; 441 } 442 443 public Object visit(ASTCount node, Object data) 444 { 445 StringBuffer buf = (StringBuffer )data; 446 buf.append(SQLUtil.COUNT).append('('); 447 ASTPath path = (ASTPath)node.jjtGetChild(0); 448 path.children[0].jjtAccept(this, data); 449 buf.append(')'); 450 return data; 451 } 452 453 public Object visit(ASTMax node, Object data) 454 { 455 StringBuffer buf = (StringBuffer )data; 456 buf.append(SQLUtil.MAX).append('('); 457 ASTPath path = (ASTPath)node.jjtGetChild(0); 458 path.children[0].jjtAccept(this, data); 459 buf.append(')'); 460 return data; 461 } 462 463 public Object visit(ASTMin node, Object data) 464 { 465 StringBuffer buf = (StringBuffer )data; 466 buf.append(SQLUtil.MIN).append('('); 467 ASTPath path = (ASTPath)node.jjtGetChild(0); 468 path.children[0].jjtAccept(this, data); 469 buf.append(')'); 470 return data; 471 } 472 473 public Object visit(ASTAvg node, Object data) 474 { 475 StringBuffer buf = (StringBuffer )data; 476 buf.append(SQLUtil.AVG).append('('); 477 ASTPath path = (ASTPath)node.jjtGetChild(0); 478 path.children[0].jjtAccept(this, data); 479 buf.append(')'); 480 return data; 481 } 482 483 public Object visit(ASTSum node, Object data) 484 { 485 StringBuffer buf = (StringBuffer )data; 486 buf.append(SQLUtil.SUM).append('('); 487 ASTPath path = (ASTPath)node.jjtGetChild(0); 488 path.children[0].jjtAccept(this, data); 489 buf.append(')'); 490 return data; 491 } 492 493 public Object visit(ASTOrderBy node, Object data) 494 { 495 StringBuffer buf = (StringBuffer )data; 496 for(int i = 0; i < node.jjtGetNumChildren(); i++) 497 { 498 if(i > 0) 499 { 500 buf.append(SQLUtil.COMMA); 501 } 502 node.jjtGetChild(i).jjtAccept(this, data); 503 } 504 return data; 505 } 506 507 public Object visit(ASTOrderByPath node, Object data) 508 { 509 StringBuffer buf = (StringBuffer )data; 510 511 node.jjtGetChild(0).jjtAccept(this, data); 512 if(node.ascending) 513 { 514 buf.append(SQLUtil.ASC); 515 } 516 else 517 { 518 buf.append(SQLUtil.DESC); 519 } 520 return data; 521 } 522 523 public Object visit(ASTPath node, Object data) 524 { 525 StringBuffer buf = (StringBuffer )data; 526 buf.append(node.getPath()); 527 return data; 528 } 529 530 public Object visit(ASTIdentifier node, Object data) 531 { 532 StringBuffer buf = (StringBuffer )data; 533 buf.append(node.identifier); 534 return data; 535 } 536 537 public Object visit(ASTAbstractSchema node, Object data) 538 { 539 StringBuffer buf = (StringBuffer )data; 540 buf.append(node.abstractSchemaName); 541 return data; 542 } 543 544 public Object visit(ASTParameter node, Object data) 545 { 546 StringBuffer buf = (StringBuffer )data; 547 buf.append("?").append(node.number); 548 return data; 549 } 550 551 public Object visit(ASTExactNumericLiteral node, Object data) 552 { 553 StringBuffer buf = (StringBuffer )data; 554 buf.append(node.literal); 555 return data; 556 } 557 558 public Object visit(ASTApproximateNumericLiteral node, Object data) 559 { 560 StringBuffer buf = (StringBuffer )data; 561 buf.append(node.literal); 562 return data; 563 } 564 565 public Object visit(ASTStringLiteral node, Object data) 566 { 567 StringBuffer buf = (StringBuffer )data; 568 buf.append(node.value); 569 return data; 570 } 571 572 public Object visit(ASTBooleanLiteral node, Object data) 573 { 574 StringBuffer buf = (StringBuffer )data; 575 buf.append(node.value); 576 return data; 577 } 578 579 public Object visit(ASTLimitOffset node, Object data) 580 { 581 StringBuffer buf = (StringBuffer )data; 582 int child = 0; 583 if(node.hasOffset) 584 { 585 buf.append(SQLUtil.OFFSET); 586 node.jjtGetChild(child++).jjtAccept(this, data); 587 } 588 if(node.hasLimit) 589 { 590 buf.append(SQLUtil.LIMIT); 591 node.jjtGetChild(child).jjtAccept(this, data); 592 } 593 return data; 594 } 595 596 public Object visit(ASTMod node, Object data) 597 { 598 StringBuffer buf = (StringBuffer )data; 599 buf.append(SQLUtil.MOD).append('('); 600 node.jjtGetChild(0).jjtAccept(this, data); 601 buf.append(SQLUtil.COMMA); 602 node.jjtGetChild(1).jjtAccept(this, data); 603 buf.append(')'); 604 return data; 605 } 606 } 607 | Popular Tags |