1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.sql.execute.ExecutionFactory; 25 import org.apache.derby.impl.sql.compile.ActivationClassBuilder; 26 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder; 27 import org.apache.derby.impl.sql.execute.GenericConstantActionFactory; 28 import org.apache.derby.impl.sql.execute.GenericExecutionFactory; 29 import org.apache.derby.iapi.util.ByteArray; 30 import org.apache.derby.iapi.services.loader.ClassFactory; 31 import org.apache.derby.iapi.services.loader.ClassInspector; 32 import org.apache.derby.iapi.services.loader.GeneratedClass; 33 import org.apache.derby.iapi.services.context.ContextManager; 34 import org.apache.derby.iapi.services.compiler.MethodBuilder; 35 import org.apache.derby.iapi.services.monitor.Monitor; 36 import org.apache.derby.iapi.services.sanity.SanityManager; 37 import org.apache.derby.iapi.services.io.StoredFormatIds; 38 import org.apache.derby.iapi.error.StandardException; 39 import org.apache.derby.iapi.sql.compile.CompilerContext; 40 import org.apache.derby.iapi.sql.compile.NodeFactory; 41 import org.apache.derby.iapi.sql.compile.Parser; 42 import org.apache.derby.iapi.sql.compile.Visitable; 43 import org.apache.derby.iapi.sql.compile.Visitor; 44 import org.apache.derby.iapi.sql.compile.C_NodeTypes; 45 import org.apache.derby.iapi.sql.compile.NodeFactory; 46 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 47 import org.apache.derby.iapi.sql.conn.LanguageConnectionFactory; 48 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 49 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext; 50 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 51 import org.apache.derby.iapi.sql.dictionary.AliasDescriptor; 52 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 53 import org.apache.derby.iapi.reference.SQLState; 54 import org.apache.derby.iapi.sql.execute.ConstantAction; 55 import org.apache.derby.iapi.types.DataTypeDescriptor; 56 import org.apache.derby.iapi.types.TypeId; 57 import org.apache.derby.iapi.types.DataValueDescriptor; 58 import org.apache.derby.iapi.sql.compile.TypeCompiler; 59 import org.apache.derby.iapi.sql.ResultDescription; 60 import org.apache.derby.iapi.sql.StatementType; 61 import org.apache.derby.iapi.sql.Activation; 62 import org.apache.derby.iapi.services.classfile.VMOpcode; 63 import org.apache.derby.iapi.sql.depend.DependencyManager; 64 import org.apache.derby.iapi.sql.dictionary.AliasDescriptor; 65 import org.apache.derby.catalog.AliasInfo; 66 import org.apache.derby.catalog.types.SynonymAliasInfo; 67 import java.util.Properties ; 68 import java.util.Vector ; 69 import java.sql.Types ; 70 import org.apache.derby.iapi.reference.ClassName; 71 72 79 80 public abstract class QueryTreeNode implements Visitable 81 { 82 public static final int AUTOINCREMENT_START_INDEX = 0; 83 public static final int AUTOINCREMENT_INC_INDEX = 1; 84 public static final int AUTOINCREMENT_IS_AUTOINCREMENT_INDEX = 2; 85 public static final int AUTOINCREMENT_CREATE_MODIFY = 3; 88 89 private int beginOffset = -1; private int endOffset = -1; 92 93 private int nodeType; 94 private ContextManager cm; 95 private LanguageConnectionContext lcc; 96 private GenericConstantActionFactory constantActionFactory; 97 98 120 boolean isPrivilegeCollectionRequired = true; 121 122 127 public void setContextManager(ContextManager cm) 128 { 129 this.cm = cm; 130 131 if (SanityManager.DEBUG) 132 { 133 SanityManager.ASSERT(cm != null, 134 "cm not expected to be null"); 135 } 136 } 137 138 143 public final ContextManager getContextManager() 144 { 145 if (SanityManager.DEBUG) { 146 if (cm == null) 147 SanityManager.THROWASSERT("Null context manager in QueryTreeNode of type :" + this.getClass()); 148 } 149 return cm; 150 } 151 152 158 public final NodeFactory getNodeFactory() 159 { 160 return getLanguageConnectionContext().getLanguageConnectionFactory(). 161 getNodeFactory(); 162 } 163 164 165 170 public final GenericConstantActionFactory getGenericConstantActionFactory() 171 { 172 if ( constantActionFactory == null ) 173 { 174 GenericExecutionFactory execFactory = (GenericExecutionFactory) getExecutionFactory(); 175 constantActionFactory = execFactory.getConstantActionFactory(); 176 } 177 178 return constantActionFactory; 179 } 180 181 public final ExecutionFactory getExecutionFactory() 182 { 183 ExecutionFactory ef = getLanguageConnectionContext().getLanguageConnectionFactory().getExecutionFactory(); 184 185 return ef; 186 } 187 188 191 protected final ClassFactory getClassFactory() { 192 return getLanguageConnectionContext().getLanguageConnectionFactory(). 193 getClassFactory(); 194 } 195 196 202 protected final LanguageConnectionContext getLanguageConnectionContext() 203 { 204 if (lcc == null) 205 { 206 lcc = (LanguageConnectionContext) getContextManager(). 207 getContext(LanguageConnectionContext.CONTEXT_ID); 208 } 209 return lcc; 210 } 211 212 219 public String getSPSName() 220 { 221 return null; 222 } 223 224 231 public int getBeginOffset() { return beginOffset; } 232 233 240 public void setBeginOffset( int beginOffset ) 241 { 242 this.beginOffset = beginOffset; 243 } 244 245 252 public int getEndOffset() { return endOffset; } 253 254 261 public void setEndOffset( int endOffset ) 262 { 263 this.endOffset = endOffset; 264 } 265 266 267 274 275 protected String nodeHeader() 276 { 277 if (SanityManager.DEBUG) 278 { 279 return "\n" + this.getClass().getName() + '@' + 280 Integer.toHexString(hashCode()) + "\n"; 281 } 282 else 283 { 284 return ""; 285 } 286 } 287 288 299 300 public static String formatNodeString(String nodeString, int depth) 301 { 302 if (SanityManager.DEBUG) 303 { 304 StringBuffer nodeStringBuffer = new StringBuffer (nodeString); 305 int pos; 306 char c; 307 char[] indent = new char[depth]; 308 309 312 while (depth > 0) 313 { 314 indent[depth - 1] = '\t'; 315 depth--; 316 } 317 318 319 nodeStringBuffer.insert(0, indent); 320 321 325 for (pos = 0; pos < nodeStringBuffer.length() - 1; pos++) 326 { 327 c = nodeStringBuffer.charAt(pos); 328 if (c == '\n') 329 { 330 331 nodeStringBuffer.insert(pos + 1, indent); 332 } 333 } 334 335 return nodeStringBuffer.toString(); 336 } 337 else 338 { 339 return ""; 340 } 341 } 342 343 348 349 public void treePrint() 350 { 351 if (SanityManager.DEBUG) 352 { 353 debugPrint(nodeHeader()); 354 debugPrint(formatNodeString(this.toString(), 0)); 355 printSubNodes(0); 356 debugFlush(); 357 } 358 } 359 360 368 369 public void treePrint(int depth) 370 { 371 if (SanityManager.DEBUG) 372 { 373 debugPrint(formatNodeString(nodeHeader(), depth)); 374 debugPrint(formatNodeString(this.toString(), depth)); 375 printSubNodes(depth); 376 } 377 } 378 379 384 385 public static void debugPrint(String outputString) 386 { 387 if (SanityManager.DEBUG) { 388 SanityManager.GET_DEBUG_STREAM().print(outputString); 389 } 390 } 391 392 395 protected static void debugFlush() 396 { 397 if (SanityManager.DEBUG) { 398 SanityManager.GET_DEBUG_STREAM().flush(); 399 } 400 } 401 402 426 427 public void printSubNodes(int depth) 428 { 429 } 430 431 448 449 public String toString() 450 { 451 return ""; 452 } 453 454 461 462 public void printLabel(int depth, String label) 463 { 464 if (SanityManager.DEBUG) 465 { 466 debugPrint(formatNodeString(label, depth)); 467 } 468 } 469 470 484 485 public QueryTreeNode bind() throws StandardException 486 { 487 return this; 488 } 489 490 497 public boolean referencesSessionSchema() 498 throws StandardException 499 { 500 return false; 501 } 502 503 510 final boolean isSessionSchema(SchemaDescriptor sd) 511 { 512 return isSessionSchema(sd.getSchemaName()); 513 } 514 515 522 final boolean isSessionSchema(String schemaName) 523 { 524 return SchemaDescriptor.STD_DECLARED_GLOBAL_TEMPORARY_TABLES_SCHEMA_NAME.equals(schemaName); 525 } 526 527 537 public void disablePrivilegeCollection() 538 { 539 isPrivilegeCollectionRequired = false; 540 } 541 542 555 public boolean isPrivilegeCollectionRequired() 556 { 557 return(isPrivilegeCollectionRequired); 558 } 559 560 571 572 public long getRowEstimate() 573 { 574 return 0L; 575 } 576 577 595 public QueryTreeNode optimize() throws StandardException 596 { 597 return this; 598 } 599 600 615 public GeneratedClass generate(ByteArray ignored) throws StandardException 616 { 617 throw StandardException.newException(SQLState.LANG_UNABLE_TO_GENERATE, 618 this.nodeHeader()); 619 } 620 621 630 631 protected void generate( 632 ActivationClassBuilder acb, 633 MethodBuilder mb) 634 throws StandardException 635 { 636 throw StandardException.newException(SQLState.LANG_UNABLE_TO_GENERATE, 637 this.nodeHeader()); 638 } 639 640 649 public ResultDescription makeResultDescription() 650 throws StandardException 651 { 652 return null; 653 } 654 655 664 public DataTypeDescriptor[] getParameterTypes() 665 throws StandardException 666 { 667 return getCompilerContext().getParameterTypes(); 668 } 669 670 678 public ConstantAction makeConstantAction() throws StandardException 679 { 680 return null; 681 } 682 683 693 public boolean needsSavepoint() 694 { 695 return true; 696 } 697 698 703 public String executeStatementName() 704 { 705 return null; 706 } 707 708 713 public String executeSchemaName() 714 { 715 return null; 716 } 717 718 723 public void setNodeType(int nodeType) 724 { 725 this.nodeType = nodeType; 726 } 727 728 protected int getNodeType() 729 { 730 return nodeType; 731 } 732 733 742 protected boolean isInstanceOf(int nodeType) 743 { 744 return (this.nodeType == nodeType); 745 } 746 747 753 public final DataDictionary getDataDictionary() 754 { 755 return getLanguageConnectionContext().getDataDictionary(); 756 } 757 758 public final DependencyManager getDependencyManager() 759 { 760 return getDataDictionary().getDependencyManager(); 761 } 762 763 768 protected final CompilerContext getCompilerContext() 769 { 770 return (CompilerContext) getContextManager(). 771 getContext(CompilerContext.CONTEXT_ID); 772 } 773 774 782 protected final TypeCompiler getTypeCompiler(TypeId typeId) 783 { 784 return 785 getCompilerContext().getTypeCompilerFactory().getTypeCompiler(typeId); 786 } 787 788 796 public Visitable accept(Visitor v) 797 throws StandardException 798 { 799 return v.visit(this); 800 } 801 802 812 protected int getIntProperty(String value, String key) 813 throws StandardException 814 { 815 int intVal = -1; 816 try 817 { 818 intVal = Integer.parseInt(value); 819 } 820 catch (NumberFormatException nfe) 821 { 822 throw StandardException.newException(SQLState.LANG_INVALID_NUMBER_FORMAT_FOR_OVERRIDE, 823 value, key); 824 } 825 return intVal; 826 } 827 828 843 public static QueryTreeNode 844 parseQueryText 845 ( 846 CompilerContext compilerContext, 847 String queryText, 848 Object [] paramDefaults, 849 LanguageConnectionContext lcc 850 ) 851 throws StandardException 852 { 853 LanguageConnectionFactory lcf; 854 Parser p; 855 QueryTreeNode qtn; 856 857 p = compilerContext.getParser(); 858 859 860 lcf = lcc.getLanguageConnectionFactory(); 861 862 863 qtn = (QueryTreeNode)p.parseStatement(queryText, paramDefaults); 864 return qtn; 865 } 866 867 873 protected int getStatementType() 874 { 875 return StatementType.UNKNOWN; 876 } 877 878 public boolean foundString(String [] list, String search) 879 { 880 if (list == null) 881 { 882 return false; 883 } 884 885 for (int i = 0; i < list.length; i++) 886 { 887 if (list[i].equals(search)) 888 { 889 return true; 890 } 891 } 892 return false; 893 } 894 895 905 public ConstantNode getNullNode(TypeId typeId, 906 ContextManager cm) 907 throws StandardException 908 { 909 QueryTreeNode constantNode = null; 910 NodeFactory nf = getNodeFactory(); 911 912 switch (typeId.getJDBCTypeId()) 913 { 914 case Types.VARCHAR: 915 constantNode = nf.getNode( 916 C_NodeTypes.VARCHAR_CONSTANT_NODE, 917 typeId, 918 cm); 919 break; 920 921 case Types.CHAR: 922 constantNode = nf.getNode( 923 C_NodeTypes.CHAR_CONSTANT_NODE, 924 typeId, 925 cm); 926 break; 927 928 case Types.TINYINT: 929 constantNode = nf.getNode( 930 C_NodeTypes.TINYINT_CONSTANT_NODE, 931 typeId, 932 cm); 933 break; 934 935 case Types.SMALLINT: 936 constantNode = nf.getNode( 937 C_NodeTypes.SMALLINT_CONSTANT_NODE, 938 typeId, 939 cm); 940 break; 941 942 case Types.INTEGER: 943 constantNode = nf.getNode( 944 C_NodeTypes.INT_CONSTANT_NODE, 945 typeId, 946 cm); 947 break; 948 949 case Types.BIGINT: 950 constantNode = nf.getNode( 951 C_NodeTypes.LONGINT_CONSTANT_NODE, 952 typeId, 953 cm); 954 break; 955 956 case Types.REAL: 957 constantNode = nf.getNode( 958 C_NodeTypes.FLOAT_CONSTANT_NODE, 959 typeId, 960 cm); 961 break; 962 963 case Types.DOUBLE: 964 constantNode = nf.getNode( 965 C_NodeTypes.DOUBLE_CONSTANT_NODE, 966 typeId, 967 cm); 968 break; 969 970 case Types.NUMERIC: 971 case Types.DECIMAL: 972 constantNode = nf.getNode( 973 C_NodeTypes.DECIMAL_CONSTANT_NODE, 974 typeId, 975 cm); 976 break; 977 978 case Types.DATE: 979 case Types.TIME: 980 case Types.TIMESTAMP: 981 constantNode = nf.getNode( 982 C_NodeTypes.USERTYPE_CONSTANT_NODE, 983 typeId, 984 cm); 985 break; 986 987 case Types.BINARY: 988 constantNode = nf.getNode( 989 C_NodeTypes.BIT_CONSTANT_NODE, 990 typeId, 991 cm); 992 break; 993 994 case Types.VARBINARY: 995 constantNode = nf.getNode( 996 C_NodeTypes.VARBIT_CONSTANT_NODE, 997 typeId, 998 cm); 999 break; 1000 1001 case Types.LONGVARCHAR: 1002 constantNode = nf.getNode( 1003 C_NodeTypes.LONGVARCHAR_CONSTANT_NODE, 1004 typeId, 1005 cm); 1006 break; 1007 1008 case Types.CLOB: 1009 constantNode = nf.getNode( 1010 C_NodeTypes.CLOB_CONSTANT_NODE, 1011 typeId, 1012 cm); 1013 break; 1014 1015 case Types.LONGVARBINARY: 1016 constantNode = nf.getNode( 1017 C_NodeTypes.LONGVARBIT_CONSTANT_NODE, 1018 typeId, 1019 cm); 1020 break; 1021 1022 case Types.BLOB: 1023 constantNode = nf.getNode( 1024 C_NodeTypes.BLOB_CONSTANT_NODE, 1025 typeId, 1026 cm); 1027 break; 1028 1029 case StoredFormatIds.XML_TYPE_ID: 1030 constantNode = nf.getNode( 1031 C_NodeTypes.XML_CONSTANT_NODE, 1032 typeId, 1033 cm); 1034 break; 1035 1036 default: 1037 if (typeId.getSQLTypeName().equals("BOOLEAN")) 1038 { 1039 constantNode = nf.getNode( 1040 C_NodeTypes.BOOLEAN_CONSTANT_NODE, 1041 typeId, 1042 cm); 1043 } 1044 else if (typeId.userType()) 1045 { 1046 constantNode = nf.getNode( 1047 C_NodeTypes.USERTYPE_CONSTANT_NODE, 1048 typeId, 1049 cm); 1050 } 1051 else 1052 { 1053 if (SanityManager.DEBUG) 1054 SanityManager.THROWASSERT( "Unknown type " + 1055 typeId.getSQLTypeName() + " in getNullNode"); 1056 return null; 1057 } 1058 } 1059 1060 return (ConstantNode) constantNode; 1061 } 1062 1063 1070 public DataValueDescriptor convertDefaultNode(DataTypeDescriptor typeDescriptor) 1071 throws StandardException 1072 { 1073 1077 return null; 1078 } 1079 1080 1081 1082 1087 public void init(Object arg1) throws StandardException 1088 { 1089 if (SanityManager.DEBUG) 1090 { 1091 SanityManager.THROWASSERT("Single-argument init() not implemented for " + getClass().getName()); 1092 } 1093 } 1094 1095 1096 1101 public void init(Object arg1, 1102 Object arg2) throws StandardException 1103 { 1104 if (SanityManager.DEBUG) 1105 { 1106 SanityManager.THROWASSERT("Two-argument init() not implemented for " + getClass().getName()); 1107 } 1108 } 1109 1110 1115 public void init(Object arg1, 1116 Object arg2, 1117 Object arg3) throws StandardException 1118 { 1119 if (SanityManager.DEBUG) 1120 { 1121 SanityManager.THROWASSERT("Three-argument init() not implemented for " + getClass().getName()); 1122 } 1123 } 1124 1125 1130 public void init(Object arg1, 1131 Object arg2, 1132 Object arg3, 1133 Object arg4) throws StandardException 1134 { 1135 if (SanityManager.DEBUG) 1136 { 1137 SanityManager.THROWASSERT("Four-argument init() not implemented for " + getClass().getName()); 1138 } 1139 } 1140 1141 1146 public void init(Object arg1, 1147 Object arg2, 1148 Object arg3, 1149 Object arg4, 1150 Object arg5) throws StandardException 1151 { 1152 if (SanityManager.DEBUG) 1153 { 1154 SanityManager.THROWASSERT("Five-argument init() not implemented for " + getClass().getName()); 1155 } 1156 } 1157 1158 1163 public void init(Object arg1, 1164 Object arg2, 1165 Object arg3, 1166 Object arg4, 1167 Object arg5, 1168 Object arg6) throws StandardException 1169 { 1170 if (SanityManager.DEBUG) 1171 { 1172 SanityManager.THROWASSERT("Six-argument init() not implemented for " + getClass().getName()); 1173 } 1174 } 1175 1176 1181 public void init(Object arg1, 1182 Object arg2, 1183 Object arg3, 1184 Object arg4, 1185 Object arg5, 1186 Object arg6, 1187 Object arg7) throws StandardException 1188 { 1189 if (SanityManager.DEBUG) 1190 { 1191 SanityManager.THROWASSERT("Seven-argument init() not implemented for " + getClass().getName()); 1192 } 1193 } 1194 1195 1200 public void init(Object arg1, 1201 Object arg2, 1202 Object arg3, 1203 Object arg4, 1204 Object arg5, 1205 Object arg6, 1206 Object arg7, 1207 Object arg8) throws StandardException 1208 { 1209 if (SanityManager.DEBUG) 1210 { 1211 SanityManager.THROWASSERT("Eight-argument init() not implemented for " + getClass().getName()); 1212 } 1213 } 1214 1215 1220 public void init(Object arg1, 1221 Object arg2, 1222 Object arg3, 1223 Object arg4, 1224 Object arg5, 1225 Object arg6, 1226 Object arg7, 1227 Object arg8, 1228 Object arg9) throws StandardException 1229 { 1230 if (SanityManager.DEBUG) 1231 { 1232 SanityManager.THROWASSERT("Nine-argument init() not implemented for " + getClass().getName()); 1233 } 1234 } 1235 1236 1241 public void init(Object arg1, 1242 Object arg2, 1243 Object arg3, 1244 Object arg4, 1245 Object arg5, 1246 Object arg6, 1247 Object arg7, 1248 Object arg8, 1249 Object arg9, 1250 Object arg10) throws StandardException 1251 { 1252 if (SanityManager.DEBUG) 1253 { 1254 SanityManager.THROWASSERT("Ten-argument init() not implemented for " + getClass().getName()); 1255 } 1256 } 1257 1258 1263 public void init(Object arg1, 1264 Object arg2, 1265 Object arg3, 1266 Object arg4, 1267 Object arg5, 1268 Object arg6, 1269 Object arg7, 1270 Object arg8, 1271 Object arg9, 1272 Object arg10, 1273 Object arg11) throws StandardException 1274 { 1275 if (SanityManager.DEBUG) 1276 { 1277 SanityManager.THROWASSERT("Eleven-argument init() not implemented for " + getClass().getName()); 1278 } 1279 } 1280 1281 1286 public void init(Object arg1, 1287 Object arg2, 1288 Object arg3, 1289 Object arg4, 1290 Object arg5, 1291 Object arg6, 1292 Object arg7, 1293 Object arg8, 1294 Object arg9, 1295 Object arg10, 1296 Object arg11, 1297 Object arg12) throws StandardException 1298 { 1299 if (SanityManager.DEBUG) 1300 { 1301 SanityManager.THROWASSERT("Twelve-argument init() not implemented for " + getClass().getName()); 1302 } 1303 } 1304 1305 1310 public void init(Object arg1, 1311 Object arg2, 1312 Object arg3, 1313 Object arg4, 1314 Object arg5, 1315 Object arg6, 1316 Object arg7, 1317 Object arg8, 1318 Object arg9, 1319 Object arg10, 1320 Object arg11, 1321 Object arg12, 1322 Object arg13) throws StandardException 1323 { 1324 if (SanityManager.DEBUG) 1325 { 1326 SanityManager.THROWASSERT("Thirteen-argument init() not implemented for " + getClass().getName()); 1327 } 1328 } 1329 1330 1335 public void init(Object arg1, 1336 Object arg2, 1337 Object arg3, 1338 Object arg4, 1339 Object arg5, 1340 Object arg6, 1341 Object arg7, 1342 Object arg8, 1343 Object arg9, 1344 Object arg10, 1345 Object arg11, 1346 Object arg12, 1347 Object arg13, 1348 Object arg14) throws StandardException 1349 { 1350 if (SanityManager.DEBUG) 1351 { 1352 SanityManager.THROWASSERT("Fourteen-argument init() not implemented for " + getClass().getName()); 1353 } 1354 } 1355 1356 public TableName makeTableName 1357 ( 1358 String schemaName, 1359 String flatName 1360 ) 1361 throws StandardException 1362 { 1363 return (TableName) getNodeFactory().getNode 1364 ( 1365 C_NodeTypes.TABLE_NAME, 1366 schemaName, 1367 flatName, 1368 getContextManager() 1369 ); 1370 } 1371 1372 public boolean isAtomic() throws StandardException 1373 { 1374 if (SanityManager.DEBUG) 1375 { 1376 SanityManager.THROWASSERT("isAtomic should not be called for this class: " + getClass().getName()); 1377 } 1378 1379 return false; 1380 } 1381 1382 public Object getCursorInfo() throws StandardException 1383 { 1384 return null; 1385 } 1386 1387 1409 protected final TableDescriptor getTableDescriptor(String tableName, 1410 SchemaDescriptor schema) 1411 throws StandardException 1412 { 1413 TableDescriptor retval; 1414 1415 if (isSessionSchema(schema)) 1417 { 1418 retval = getLanguageConnectionContext().getTableDescriptorForDeclaredGlobalTempTable(tableName); 1420 if (retval != null) 1421 return retval; } 1423 1424 if (schema.getUUID() == null) 1428 return null; 1429 1430 TableDescriptor td = getDataDictionary().getTableDescriptor(tableName, schema); 1432 if (td == null || td.isSynonymDescriptor()) 1433 return null; 1434 return td; 1435 } 1436 1437 1453 final SchemaDescriptor getSchemaDescriptor(String schemaName) 1454 throws StandardException 1455 { 1456 return getSchemaDescriptor(schemaName, true); 1458 } 1459 final SchemaDescriptor getSchemaDescriptor(String schemaName, boolean raiseError) 1460 throws StandardException 1461 { 1462 1478 1479 1480 SchemaDescriptor sd = null; 1481 boolean isCurrent = false; 1482 boolean isCompilation = false; 1483 if (schemaName == null) { 1484 1485 CompilerContext cc = getCompilerContext(); 1486 sd = cc.getCompilationSchema(); 1487 1488 if (sd == null) { 1489 sd = getLanguageConnectionContext().getDefaultSchema(); 1492 1493 isCurrent = true; 1494 1495 cc.setCompilationSchema(sd); 1496 } 1497 else 1498 { 1499 isCompilation = true; 1500 } 1501 schemaName = sd.getSchemaName(); 1502 } 1503 1504 DataDictionary dataDictionary = getDataDictionary(); 1505 SchemaDescriptor sdCatalog = dataDictionary.getSchemaDescriptor(schemaName, 1506 getLanguageConnectionContext().getTransactionCompile(), raiseError); 1507 1508 if (isCurrent || isCompilation) { 1509 if (sdCatalog != null && sdCatalog.getUUID() != null) 1515 { 1516 if (!sdCatalog.getUUID().equals(sd.getUUID())) 1519 { 1520 if (isCurrent) 1521 getLanguageConnectionContext().setDefaultSchema(sdCatalog); 1522 getCompilerContext().setCompilationSchema(sdCatalog); 1523 } 1524 } 1525 else 1526 { 1527 sd.setUUID(null); 1529 sdCatalog = sd; 1530 } 1531 } 1532 return sdCatalog; 1533 } 1534 1535 1544 public TableName resolveTableToSynonym(TableName tabName) throws StandardException 1545 { 1546 DataDictionary dd = getDataDictionary(); 1547 String nextSynonymTable = tabName.getTableName(); 1548 String nextSynonymSchema = tabName.getSchemaName(); 1549 boolean found = false; 1550 CompilerContext cc = getCompilerContext(); 1551 1552 for (;;) 1555 { 1556 SchemaDescriptor nextSD = getSchemaDescriptor(nextSynonymSchema, false); 1557 if (nextSD == null || nextSD.getUUID() == null) 1558 break; 1559 1560 AliasDescriptor nextAD = dd.getAliasDescriptor(nextSD.getUUID().toString(), 1561 nextSynonymTable, AliasInfo.ALIAS_NAME_SPACE_SYNONYM_AS_CHAR); 1562 if (nextAD == null) 1563 break; 1564 1565 1566 cc.createDependency(nextAD); 1567 1568 found = true; 1569 SynonymAliasInfo info = ((SynonymAliasInfo)nextAD.getAliasInfo()); 1570 nextSynonymTable = info.getSynonymTable(); 1571 nextSynonymSchema = info.getSynonymSchema(); 1572 } 1573 1574 if (!found) 1575 return null; 1576 1577 TableName tableName = new TableName(); 1578 tableName.init(nextSynonymSchema, nextSynonymTable); 1579 return tableName; 1580 } 1581 1582 1592 String verifyClassExist(String javaClassName, boolean convertCase) 1593 throws StandardException 1594 { 1595 1596 1597 ClassInspector classInspector = getClassFactory().getClassInspector(); 1598 1599 1602 1603 Throwable reason = null; 1604 boolean foundMatch = false; 1605 try { 1606 1607 foundMatch = classInspector.accessible(javaClassName); 1608 1609 } catch (ClassNotFoundException cnfe) { 1610 1611 reason = cnfe; 1612 } 1613 1614 if (!foundMatch) 1615 throw StandardException.newException(SQLState.LANG_TYPE_DOESNT_EXIST2, reason, javaClassName); 1616 1617 if (ClassInspector.primitiveType(javaClassName)) 1618 throw StandardException.newException(SQLState.LANG_TYPE_DOESNT_EXIST3, javaClassName); 1619 1620 return javaClassName; 1621 } 1622 1623 1627 public void setRefActionInfo(long fkIndexConglomId, 1628 int[]fkColArray, 1629 String parentResultSetId, 1630 boolean dependentScan) 1631 { 1632 if (SanityManager.DEBUG) 1633 { 1634 SanityManager.THROWASSERT( 1635 "setRefActionInfo() not expected to be called for " + 1636 getClass().getName()); 1637 } 1638 } 1639 1640 1643 void generateAuthorizeCheck(ActivationClassBuilder acb, 1644 MethodBuilder mb, 1645 int sqlOperation) { 1646 acb.pushThisAsActivation(mb); 1648 mb.callMethod(VMOpcode.INVOKEINTERFACE, null, "getLanguageConnectionContext", 1649 ClassName.LanguageConnectionContext, 0); 1650 mb.callMethod(VMOpcode.INVOKEINTERFACE, null, "getAuthorizer", 1651 ClassName.Authorizer, 0); 1652 1653 acb.pushThisAsActivation(mb); 1654 mb.push(sqlOperation); 1655 mb.callMethod(VMOpcode.INVOKEINTERFACE, null, "authorize", 1656 "void", 2); 1657 } 1658 1659 1660} 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 | Popular Tags |