1 21 package oracle.toplink.essentials.queryframework; 23 24 import java.util.*; 25 import java.io.*; 26 import oracle.toplink.essentials.internal.helper.*; 27 import oracle.toplink.essentials.expressions.*; 28 import oracle.toplink.essentials.internal.expressions.*; 29 import oracle.toplink.essentials.internal.databaseaccess.*; 30 import oracle.toplink.essentials.internal.queryframework.*; 31 import oracle.toplink.essentials.exceptions.*; 32 import oracle.toplink.essentials.sessions.Record; 33 import oracle.toplink.essentials.sessions.DatabaseRecord; 34 import oracle.toplink.essentials.internal.parsing.ejbql.EJBQLCallQueryMechanism; 35 import oracle.toplink.essentials.sessions.SessionProfiler; 36 import oracle.toplink.essentials.internal.sessions.AbstractRecord; 37 import oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl; 38 import oracle.toplink.essentials.internal.sessions.AbstractSession; 39 import oracle.toplink.essentials.descriptors.ClassDescriptor; 40 41 58 public abstract class DatabaseQuery implements Cloneable , Serializable, FalseUndefinedTrue { 59 60 61 protected String name; 62 63 64 protected Vector arguments; 65 66 67 protected Vector argumentValues; 68 69 70 protected Vector argumentTypes; 71 72 73 protected Vector argumentTypeNames; 74 75 76 protected transient ClassDescriptor descriptor; 77 78 79 protected DatabaseQueryMechanism queryMechanism; 80 81 82 protected boolean shouldMaintainCache; 84 85 86 protected Hashtable properties; 87 88 89 protected transient AbstractSession session; 90 91 92 protected transient Accessor accessor; 93 94 95 protected AbstractRecord translationRow; 96 97 98 protected boolean isUserDefined; 99 100 101 protected int cascadePolicy; 102 103 104 protected String sessionName; 105 106 107 protected boolean isPrepared; 108 109 110 protected boolean shouldPrepare; 111 112 113 114 protected int shouldBindAllParameters; 117 118 119 120 protected int shouldCacheStatement; 123 124 125 protected boolean shouldUseWrapperPolicy; 126 127 128 public static final int NoCascading = 1; 129 130 131 public static final int CascadePrivateParts = 2; 132 133 134 public static final int CascadeAllParts = 3; 135 136 137 public static final int CascadeDependentParts = 4; 138 139 144 public static final int CascadeAggregateDelete = 5; 145 146 150 public static final int CascadeByMapping = 6; 151 152 156 protected Boolean flushOnExecute; 157 158 162 public DatabaseQuery() { 163 this.shouldMaintainCache = true; 164 this.isUserDefined = false; 167 this.cascadePolicy = NoCascading; 168 this.isPrepared = false; 169 this.shouldUseWrapperPolicy = true; 170 this.shouldPrepare = true; 171 this.shouldBindAllParameters = Undefined; 172 this.shouldCacheStatement = Undefined; 173 } 174 175 181 public void addArgument(String argumentName) { 182 addArgument(argumentName, java.lang.Object .class); 185 } 186 187 195 public void addArgument(String argumentName, Class type) { 196 getArguments().addElement(argumentName); 197 getArgumentTypes().addElement(type); 198 getArgumentTypeNames().addElement(type.getName()); 199 } 200 201 209 public void addArgument(String argumentName, String typeAsString) { 210 getArguments().addElement(argumentName); 211 getArgumentTypes().addElement(Helper.getObjectClass(ConversionManager.loadClass(typeAsString))); 213 getArgumentTypeNames().addElement(typeAsString); 214 } 215 216 222 public void addArgumentByTypeName(String argumentName, String typeAsString) { 223 getArguments().addElement(argumentName); 224 getArgumentTypeNames().addElement(typeAsString); 225 } 226 227 232 public void addArgumentValue(Object argumentValue) { 233 getArgumentValues().addElement(argumentValue); 234 } 235 236 241 public void addArgumentValues(Vector theArgumentValues) { 242 setArgumentValues(theArgumentValues); 243 } 244 245 251 public void addCall(Call call) { 252 setQueryMechanism(call.buildQueryMechanism(this, getQueryMechanism())); 253 setIsPrepared(false); 255 } 256 257 263 public void addStatement(SQLStatement statement) { 264 if (!hasQueryMechanism()) { 266 setQueryMechanism(new StatementQueryMechanism(this)); 267 } else if (!getQueryMechanism().isStatementQueryMechanism()) { 268 setQueryMechanism(new StatementQueryMechanism(this)); 269 } 270 ((StatementQueryMechanism)getQueryMechanism()).getSQLStatements().addElement(statement); 271 setIsPrepared(false); 273 } 274 275 279 public void bindAllParameters() { 280 setShouldBindAllParameters(true); 281 } 282 283 287 protected void buildSelectionCriteria(AbstractSession session) { 288 this.getQueryMechanism().buildSelectionCriteria(session); 289 } 290 291 295 public void cacheStatement() { 296 setShouldCacheStatement(true); 297 } 298 299 307 public void cascadeAllParts() { 308 setCascadePolicy(CascadeAllParts); 309 } 310 311 316 public void cascadeByMapping() { 317 setCascadePolicy(CascadeByMapping); 318 } 319 320 324 public void cascadeOnlyDependentParts() { 325 setCascadePolicy(CascadeDependentParts); 326 } 327 328 335 public void cascadePrivateParts() { 336 setCascadePolicy(CascadePrivateParts); 337 } 338 339 343 public void checkDescriptor(AbstractSession session) throws QueryException { 344 } 345 346 350 public Object checkEarlyReturn(AbstractSession session, AbstractRecord translationRow) { 351 return null; 352 } 353 354 360 protected DatabaseQuery checkForCustomQuery(AbstractSession session, AbstractRecord translationRow) { 361 return null; 362 } 363 364 369 public void checkPrepare(AbstractSession session, AbstractRecord translationRow) { 370 if (!isPrepared()) { synchronized (this) { 374 if (!isPrepared()) { 375 if ((isReadQuery() || isDataModifyQuery()) && isCallQuery() && (getQueryMechanism() instanceof CallQueryMechanism) && ((translationRow == null) || translationRow.isEmpty())) { 379 if (isReadObjectQuery() || isUserDefined()) { 381 ((CallQueryMechanism)getQueryMechanism()).setCallHasCustomSQLArguments(); 382 } 383 } else if (isCallQuery() && (getQueryMechanism() instanceof CallQueryMechanism)) { 384 ((CallQueryMechanism)getQueryMechanism()).setCallHasCustomSQLArguments(); 385 } 386 setSession(session); prepare(); 388 setSession(null); 389 setIsPrepared(true); } 391 } 392 } 393 } 394 395 399 public Object clone() { 400 try { 401 DatabaseQuery cloneQuery = (DatabaseQuery)super.clone(); 402 403 if (cloneQuery.properties != null) { 406 if (cloneQuery.properties.isEmpty()) { 407 cloneQuery.setProperties(null); 408 } else { 409 cloneQuery.setProperties((Hashtable)getProperties().clone()); 410 } 411 } 412 413 if (hasQueryMechanism()) { 416 cloneQuery.setQueryMechanism(getQueryMechanism().clone(cloneQuery)); 417 } 418 cloneQuery.setIsPrepared(isPrepared()); return cloneQuery; 420 } catch (CloneNotSupportedException e) { 421 return null; 422 } 423 } 424 425 430 protected void clonedQueryExecutionComplete(DatabaseQuery query, AbstractSession session) { 431 } 433 434 441 public void convertClassNamesToClasses(ClassLoader classLoader){ 442 }; 445 446 452 public void deploymentSetShouldMaintainCache(int maintainCache) { 453 if (maintainCache == FalseUndefinedTrue.True) { 455 setShouldMaintainCache(true); 456 } else if (maintainCache == FalseUndefinedTrue.False) { 457 setShouldMaintainCache(false); 458 } 459 } 460 461 467 public int deploymentShouldMaintainCache() { 468 if (shouldMaintainCache()) { 469 return FalseUndefinedTrue.True; 470 } else { 471 return FalseUndefinedTrue.False; 472 } 473 } 474 475 479 public void dontBindAllParameters() { 480 setShouldBindAllParameters(false); 481 } 482 483 487 public void dontCacheStatement() { 488 setShouldCacheStatement(false); 489 } 490 491 498 public void dontCascadeParts() { 499 setCascadePolicy(NoCascading); 500 } 501 502 509 public void dontMaintainCache() { 510 setShouldMaintainCache(false); 511 } 512 513 521 public abstract Object executeDatabaseQuery() throws DatabaseException, OptimisticLockException; 522 523 535 public Object executeInUnitOfWork(UnitOfWorkImpl unitOfWork, AbstractRecord translationRow) throws DatabaseException, OptimisticLockException { 536 return execute(unitOfWork, translationRow); 537 } 538 539 549 public Object execute(AbstractSession session, AbstractRecord translationRow) throws DatabaseException, OptimisticLockException { 550 DatabaseQuery queryToExecute = this; 551 552 session.startOperationProfile(SessionProfiler.QUERY_PREPARE); 554 555 Object earlyReturn = queryToExecute.checkEarlyReturn(session, translationRow); 557 if ((earlyReturn != null) || (isReadObjectQuery() && ((ReadObjectQuery)this).shouldCheckCacheOnly())) { 558 session.endOperationProfile(SessionProfiler.QUERY_PREPARE); 560 return earlyReturn; 561 } 562 563 boolean hasCustomQuery = false; 564 if (!isPrepared() && shouldPrepare()) { 565 DatabaseQuery customQuery = checkForCustomQuery(session, translationRow); 567 if (customQuery != null) { 568 hasCustomQuery = true; 569 queryToExecute = customQuery; 571 } 572 } 573 574 boolean alreadyClonedQuery = false; 580 DatabaseQuery sessionPreparedQuery = session.prepareDatabaseQuery(queryToExecute); 581 if (sessionPreparedQuery != queryToExecute) { 582 queryToExecute = sessionPreparedQuery; 583 alreadyClonedQuery = true; 584 } 585 586 if (queryToExecute.shouldPrepare()) { 587 queryToExecute.checkPrepare(session, translationRow); 588 } 589 590 if (!alreadyClonedQuery) { 592 queryToExecute = (DatabaseQuery)queryToExecute.clone(); 593 } 594 queryToExecute.setTranslationRow(translationRow); 595 if (!queryToExecute.shouldPrepare()) { 597 queryToExecute.checkPrepare(session, translationRow); 598 } 599 queryToExecute.setSession(session); 600 if (hasCustomQuery) { 601 prepareCustomQuery(queryToExecute); 602 } 603 queryToExecute.prepareForExecution(); 604 605 session.endOperationProfile(SessionProfiler.QUERY_PREPARE); 607 608 Object result = queryToExecute.executeDatabaseQuery(); 610 611 clonedQueryExecutionComplete(queryToExecute, session); 613 return result; 614 } 615 616 620 public Accessor getAccessor() { 621 return accessor; 622 } 623 624 628 public Vector getArguments() { 629 if (arguments == null) { 630 arguments = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(); 631 } 632 return arguments; 633 } 634 635 639 public Vector getArgumentTypes() { 640 if ((argumentTypes == null) || argumentTypes.isEmpty()) { 641 argumentTypes = new Vector(); 642 if (argumentTypeNames != null) { 644 Iterator args = argumentTypeNames.iterator(); 645 while (args.hasNext()) { 646 String argumentTypeName = (String )args.next(); 647 argumentTypes.addElement(Helper.getObjectClass(ConversionManager.loadClass(argumentTypeName))); 648 } 649 } 650 } 651 return argumentTypes; 652 } 653 654 659 public Vector getArgumentTypeNames() { 660 if (argumentTypeNames == null) { 661 argumentTypeNames = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(); 662 } 663 return argumentTypeNames; 664 } 665 666 670 public void setArgumentTypes(Vector argumentTypes) { 671 this.argumentTypes = argumentTypes; 672 getArgumentTypeNames().clear(); 674 Iterator types = argumentTypes.iterator(); 675 while (types.hasNext()) { 676 argumentTypeNames.addElement(((Class )types.next()).getName()); 677 } 678 } 679 680 684 public void setArgumentTypeNames(Vector argumentTypeNames) { 685 this.argumentTypeNames = argumentTypeNames; 686 } 687 688 693 public void setArguments(Vector arguments) { 694 for (Enumeration enumtr = arguments.elements(); enumtr.hasMoreElements();) { 695 addArgument((String )enumtr.nextElement()); 697 } 698 } 699 700 705 public Vector getArgumentValues() { 706 if (argumentValues == null) { 707 argumentValues = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(); 708 } 709 return argumentValues; 710 } 711 712 717 public void setArgumentValues(Vector theArgumentValues) { 718 argumentValues = theArgumentValues; 719 } 720 721 727 public DatabaseCall getCall() { 728 Call call = getDatasourceCall(); 729 if (call instanceof DatabaseCall) { 730 return (DatabaseCall)call; 731 } else { 732 return null; 733 } 734 } 735 736 742 public Call getDatasourceCall() { 743 Call call = null; 744 if (getQueryMechanism() instanceof DatasourceCallQueryMechanism) { 745 DatasourceCallQueryMechanism mechanism = (DatasourceCallQueryMechanism)getQueryMechanism(); 746 call = mechanism.getCall(); 747 if (mechanism.hasMultipleCalls()) { 749 call = (Call)mechanism.getCalls().get(0); 750 } 751 } 752 if ((call == null) && getQueryMechanism().isEJBQLCallQueryMechanism()) { 753 call = ((EJBQLCallQueryMechanism)getQueryMechanism()).getEJBQLCall(); 754 } 755 return call; 756 } 757 758 764 public List getDatasourceCalls() { 765 List calls = new Vector(); 766 if (getQueryMechanism() instanceof DatasourceCallQueryMechanism) { 767 DatasourceCallQueryMechanism mechanism = (DatasourceCallQueryMechanism)getQueryMechanism(); 768 769 if (mechanism.hasMultipleCalls()) { 771 calls = mechanism.getCalls(); 772 } else { 773 calls.add(mechanism.getCall()); 774 } 775 } 776 if ((calls.isEmpty()) && getQueryMechanism().isEJBQLCallQueryMechanism()) { 777 calls.add(((EJBQLCallQueryMechanism)getQueryMechanism()).getEJBQLCall()); 778 } 779 return calls; 780 } 781 782 786 public int getCascadePolicy() { 787 return cascadePolicy; 788 } 789 790 794 public ClassDescriptor getDescriptor() { 795 return descriptor; 796 } 797 798 802 public String getName() { 803 return name; 804 } 805 806 810 public Hashtable getProperties() { 811 if (properties == null) { properties = new Hashtable(5); 813 } 814 return properties; 815 } 816 817 821 public synchronized Object getProperty(Object property) { 822 if (properties == null) { 823 return null; 824 } 825 return getProperties().get(property); 826 } 827 828 832 public DatabaseQueryMechanism getQueryMechanism() { 833 if (queryMechanism == null) { 835 queryMechanism = new ExpressionQueryMechanism(this); 836 } 837 return queryMechanism; 838 } 839 840 844 public boolean hasQueryMechanism() { 845 return (queryMechanism != null); 846 } 847 848 853 public Class getReferenceClass() { 854 return null; 855 } 856 857 862 public String getReferenceClassName() { 863 return null; 864 } 865 866 871 public Expression getSelectionCriteria() { 872 return getQueryMechanism().getSelectionCriteria(); 873 } 874 875 879 public AbstractSession getSession() { 880 return session; 881 } 882 883 888 public String getSessionName() { 889 return sessionName; 890 } 891 892 897 public SQLStatement getSQLStatement() { 898 return ((StatementQueryMechanism)getQueryMechanism()).getSQLStatement(); 899 } 900 901 909 public String getEJBQLString() { 910 if (!(getQueryMechanism().isEJBQLCallQueryMechanism())) { 911 return null; 912 } 913 EJBQLCall call = (EJBQLCall)((EJBQLCallQueryMechanism)getQueryMechanism()).getEJBQLCall(); 914 return call.getEjbqlString(); 915 } 916 917 925 public String getSQLString() { 926 Call call = getDatasourceCall(); 927 if (call == null) { 928 return null; 929 } 930 if (!(call instanceof SQLCall)) { 931 return null; 932 } 933 934 return ((SQLCall)call).getSQLString(); 935 } 936 937 945 public List getSQLStrings() { 946 List calls = getDatasourceCalls(); 947 if ((calls == null) || calls.isEmpty()) { 948 return null; 949 } 950 Vector returnSQL = new Vector(calls.size()); 951 Iterator iterator = calls.iterator(); 952 while (iterator.hasNext()) { 953 Call call = (Call)iterator.next(); 954 if (!(call instanceof SQLCall)) { 955 return null; 956 } 957 returnSQL.addElement(((SQLCall)call).getSQLString()); 958 } 959 return returnSQL; 960 } 961 962 967 public int getShouldBindAllParameters() { 968 return this.shouldBindAllParameters; 969 } 970 971 977 public String getTranslatedSQLString(oracle.toplink.essentials.sessions.Session session, Record translationRow) { 978 CallQueryMechanism queryMechanism = (CallQueryMechanism)getQueryMechanism(); 980 if (queryMechanism.getCall() == null) { 981 return null; 982 } 983 SQLCall call = (SQLCall)queryMechanism.getCall().clone(); 984 call.translate((AbstractRecord)translationRow, queryMechanism.getModifyRow(), (AbstractSession)session); 985 return call.getSQLString(); 986 } 987 988 994 public List getTranslatedSQLStrings(oracle.toplink.essentials.sessions.Session session, Record translationRow) { 995 CallQueryMechanism queryMechanism = (CallQueryMechanism)getQueryMechanism(); 996 if ((queryMechanism.getCalls() == null) || queryMechanism.getCalls().isEmpty()) { 997 return null; 998 } 999 Vector calls = new Vector(queryMechanism.getCalls().size()); 1000 Iterator iterator = queryMechanism.getCalls().iterator(); 1001 while (iterator.hasNext()) { 1002 SQLCall call = (SQLCall)iterator.next(); 1003 call = (SQLCall)call.clone(); 1004 call.translate((AbstractRecord)translationRow, queryMechanism.getModifyRow(), (AbstractSession)session); 1005 calls.addElement(call.getSQLString()); 1006 } 1007 return calls; 1008 } 1009 1010 1014 public AbstractRecord getTranslationRow() { 1015 return translationRow; 1016 } 1017 1018 1023 public boolean hasAccessor() { 1024 return accessor != null; 1025 } 1026 1027 1031 public boolean hasProperties() { 1032 return (properties != null) && (!properties.isEmpty()); 1033 } 1034 1035 1040 public boolean hasSessionName() { 1041 return sessionName != null; 1042 } 1043 1044 1049 public void ignoreBindAllParameters() { 1050 this.shouldBindAllParameters = Undefined; 1051 } 1052 1053 1058 public void ignoreCacheStatement() { 1059 this.shouldCacheStatement = Undefined; 1060 } 1061 1062 1066 public boolean isCallQuery() { 1067 return getQueryMechanism().isCallQueryMechanism(); 1068 } 1069 1070 1076 public boolean isCascadeOfAggregateDelete() { 1077 return getCascadePolicy() == CascadeAggregateDelete; 1078 } 1079 1080 1084 public boolean isDataModifyQuery() { 1085 return false; 1086 } 1087 1088 1092 public boolean isDataReadQuery() { 1093 return false; 1094 } 1095 1096 1100 public boolean isDeleteAllQuery() { 1101 return false; 1102 } 1103 1104 1108 public boolean isDeleteObjectQuery() { 1109 return false; 1110 } 1111 1112 1116 public boolean isExpressionQuery() { 1117 return getQueryMechanism().isExpressionQueryMechanism(); 1118 } 1119 1120 1124 public boolean isModifyAllQuery() { 1125 return false; 1126 } 1127 1128 1132 public boolean isModifyQuery() { 1133 return false; 1134 } 1135 1136 1140 public boolean isUpdateAllQuery() { 1141 return false; 1142 } 1143 1144 1148 public boolean isUpdateObjectQuery() { 1149 return false; 1150 } 1151 1152 1157 public Boolean getFlushOnExecute(){ 1158 return this.flushOnExecute; 1159 } 1160 1161 1165 public boolean isInsertObjectQuery() { 1166 return false; 1167 } 1168 1169 1173 public boolean isObjectLevelModifyQuery() { 1174 return false; 1175 } 1176 1177 1181 public boolean isObjectLevelReadQuery() { 1182 return false; 1183 } 1184 1185 1189 public boolean isObjectBuildingQuery() { 1190 return true; 1191 } 1192 1193 1200 public boolean isPrepared() { 1201 return isPrepared; 1202 } 1203 1204 1208 public boolean isReadAllQuery() { 1209 return false; 1210 } 1211 1212 1216 public boolean isReadObjectQuery() { 1217 return false; 1218 } 1219 1220 1224 public boolean isReadQuery() { 1225 return false; 1226 } 1227 1228 1232 public boolean isReportQuery() { 1233 return false; 1234 } 1235 1236 1240 public boolean isSQLCallQuery() { 1241 Call call = getDatasourceCall(); 1243 return (call != null) && (call instanceof SQLCall); 1244 } 1245 1246 1250 public boolean isUserDefined() { 1251 return isUserDefined; 1252 } 1253 1254 1258 public boolean isWriteObjectQuery() { 1259 return false; 1260 } 1261 1262 1267 public void maintainCache() { 1268 setShouldMaintainCache(true); 1269 } 1270 1271 1280 protected void prepare() throws QueryException { 1281 getQueryMechanism().prepare(); 1282 } 1283 1284 1296 public void prepareCall(oracle.toplink.essentials.sessions.Session session, Record translationRow) throws QueryException { 1297 checkPrepare((AbstractSession)session, (AbstractRecord)translationRow); 1299 } 1300 1301 1305 protected void prepareCustomQuery(DatabaseQuery customQuery) { 1306 } 1308 1309 1315 public void prepareForExecution() throws QueryException { 1316 getQueryMechanism().prepareForExecution(); 1317 } 1318 1319 protected void prepareForRemoteExecution() { 1320 ; 1321 } 1322 1323 1327 public void removeProperty(Object property) { 1328 getProperties().remove(property); 1329 } 1330 1331 1335 public AbstractRecord rowFromArguments(Vector argumentValues) throws QueryException { 1336 Vector argumentNames = getArguments(); 1337 1338 if (argumentNames.size() != argumentValues.size()) { 1339 throw QueryException.argumentSizeMismatchInQueryAndQueryDefinition(this); 1340 } 1341 1342 AbstractRecord row = new DatabaseRecord(); 1343 for (int index = 0; index < argumentNames.size(); index++) { 1344 String argumentName = (String )argumentNames.elementAt(index); 1345 Object argumentValue = argumentValues.elementAt(index); 1346 row.put(new DatabaseField(argumentName), argumentValue); 1347 } 1348 1349 return row; 1350 } 1351 1352 1357 public void setAccessor(Accessor accessor) { 1358 this.accessor = accessor; 1359 } 1360 1361 1365 public void setDatasourceCall(Call call) { 1366 if (call == null) { 1367 return; 1368 } 1369 setQueryMechanism(call.buildNewQueryMechanism(this)); 1370 } 1371 1372 1376 public void setCall(Call call) { 1377 setDatasourceCall(call); 1378 } 1379 1380 1384 public void setCascadePolicy(int policyConstant) { 1385 cascadePolicy = policyConstant; 1386 } 1387 1388 1392 public void setDescriptor(ClassDescriptor descriptor) { 1393 if (this.descriptor != descriptor) { 1395 setIsPrepared(false); 1396 } 1397 this.descriptor = descriptor; 1398 } 1399 1400 1405 public void setEJBQLString(String ejbqlString) { 1406 if ((ejbqlString != null) && (!ejbqlString.equals(""))) { 1408 EJBQLCallQueryMechanism mechanism = new EJBQLCallQueryMechanism(this, new EJBQLCall(ejbqlString)); 1409 setQueryMechanism(mechanism); 1410 } 1411 } 1412 1413 1418 public void setFlushOnExecute(Boolean flushMode){ 1419 this.flushOnExecute = flushMode; 1420 } 1421 1422 1429 public void setIsPrepared(boolean isPrepared) { 1430 this.isPrepared = isPrepared; 1431 } 1432 1433 1437 public void setIsUserDefined(boolean isUserDefined) { 1438 this.isUserDefined = isUserDefined; 1439 } 1440 1441 1446 public void setName(String queryName) { 1447 name = queryName; 1448 } 1449 1450 1454 public void setProperties(Hashtable properties) { 1455 this.properties = properties; 1456 } 1457 1458 1462 public synchronized void setProperty(Object property, Object value) { 1463 getProperties().put(property, value); 1464 } 1465 1466 1469 protected void setQueryMechanism(DatabaseQueryMechanism queryMechanism) { 1470 this.queryMechanism = queryMechanism; 1471 setIsPrepared(false); 1473 } 1474 1475 1480 public void setSelectionCriteria(Expression expression) { 1481 if ((expression == null) && (!getQueryMechanism().isExpressionQueryMechanism())) { 1483 return; 1484 } 1485 if (!getQueryMechanism().isExpressionQueryMechanism()) { 1486 setQueryMechanism(new ExpressionQueryMechanism(this, expression)); 1487 } else { 1488 ((ExpressionQueryMechanism)getQueryMechanism()).setSelectionCriteria(expression); 1489 } 1490 1491 setIsPrepared(false); 1493 } 1494 1495 1499 public void setSession(AbstractSession session) { 1500 this.session = session; 1501 } 1502 1503 1508 public void setSessionName(String sessionName) { 1509 this.sessionName = sessionName; 1510 } 1511 1512 1516 public void setShouldBindAllParameters(boolean shouldBindAllParameters) { 1517 if (shouldBindAllParameters) { 1518 this.shouldBindAllParameters = True; 1519 } else { 1520 this.shouldBindAllParameters = False; 1521 } 1522 setIsPrepared(false); 1523 } 1524 1525 1530 public void setShouldBindAllParameters(int bindAllParams) { 1531 this.shouldBindAllParameters = bindAllParams; 1532 } 1533 1534 1538 public void setShouldCacheStatement(boolean shouldCacheStatement) { 1539 if (shouldCacheStatement) { 1540 this.shouldCacheStatement = True; 1541 } else { 1542 this.shouldCacheStatement = False; 1543 } 1544 setIsPrepared(false); 1545 } 1546 1547 1553 public void setShouldMaintainCache(boolean shouldMaintainCache) { 1554 this.shouldMaintainCache = shouldMaintainCache; 1555 } 1556 1557 1569 public void setShouldPrepare(boolean shouldPrepare) { 1570 this.shouldPrepare = shouldPrepare; 1571 setIsPrepared(false); 1572 } 1573 1574 1578 public void setShouldUseWrapperPolicy(boolean shouldUseWrapperPolicy) { 1579 this.shouldUseWrapperPolicy = shouldUseWrapperPolicy; 1580 } 1581 1582 1587 public void setSQLStatement(SQLStatement sqlStatement) { 1588 setQueryMechanism(new StatementQueryMechanism(this, sqlStatement)); 1589 } 1590 1591 1597 public void setSQLString(String sqlString) { 1598 if ((sqlString != null) && (!sqlString.equals(""))) { 1600 setCall(new SQLCall(sqlString)); 1601 } 1602 } 1603 1604 1608 public void setTranslationRow(AbstractRecord translationRow) { 1609 this.translationRow = translationRow; 1610 } 1611 1612 1616 public boolean shouldBindAllParameters() { 1617 return shouldBindAllParameters == True; 1618 } 1619 1620 1624 public boolean shouldCacheStatement() { 1625 return shouldCacheStatement == True; 1626 } 1627 1628 1632 public boolean shouldCascadeAllParts() { 1633 return getCascadePolicy() == CascadeAllParts; 1634 } 1635 1636 1641 public boolean shouldCascadeByMapping() { 1642 return getCascadePolicy() == CascadeByMapping; 1643 } 1644 1645 1649 public boolean shouldCascadeOnlyDependentParts() { 1650 return getCascadePolicy() == CascadeDependentParts; 1651 } 1652 1653 1657 public boolean shouldCascadeParts() { 1658 return getCascadePolicy() != NoCascading; 1659 } 1660 1661 1665 public boolean shouldCascadePrivateParts() { 1666 return (getCascadePolicy() == CascadePrivateParts) || (getCascadePolicy() == CascadeAllParts); 1667 } 1668 1669 1674 public boolean shouldIgnoreBindAllParameters() { 1675 return shouldBindAllParameters == Undefined; 1676 } 1677 1678 1683 public boolean shouldIgnoreCacheStatement() { 1684 return shouldCacheStatement == Undefined; 1685 } 1686 1687 1693 public boolean shouldMaintainCache() { 1694 return shouldMaintainCache; 1695 } 1696 1697 1709 public boolean shouldPrepare() { 1710 return shouldPrepare; 1711 } 1712 1713 1717 public boolean shouldUseWrapperPolicy() { 1718 return shouldUseWrapperPolicy; 1719 } 1720 1721 public String toString() { 1722 return Helper.getShortClassName(getClass()) + "()"; 1723 } 1724} 1725 | Popular Tags |