1 24 25 package org.objectweb.cjdbc.controller.virtualdatabase; 26 27 import java.sql.Connection ; 28 import java.sql.DatabaseMetaData ; 29 import java.sql.ResultSet ; 30 import java.sql.SQLException ; 31 import java.sql.Types ; 32 import java.util.ArrayList ; 33 import java.util.ConcurrentModificationException ; 34 import java.util.Iterator ; 35 36 import org.objectweb.cjdbc.common.exceptions.NoMoreBackendException; 37 import org.objectweb.cjdbc.common.exceptions.UnreachableBackendException; 38 import org.objectweb.cjdbc.common.log.Trace; 39 import org.objectweb.cjdbc.common.sql.schema.DatabaseColumn; 40 import org.objectweb.cjdbc.common.sql.schema.DatabaseProcedure; 41 import org.objectweb.cjdbc.common.sql.schema.DatabaseProcedureParameter; 42 import org.objectweb.cjdbc.common.sql.schema.DatabaseSchema; 43 import org.objectweb.cjdbc.common.sql.schema.DatabaseTable; 44 import org.objectweb.cjdbc.common.users.VirtualDatabaseUser; 45 import org.objectweb.cjdbc.controller.authentication.AuthenticationManager; 46 import org.objectweb.cjdbc.controller.backend.DatabaseBackend; 47 import org.objectweb.cjdbc.controller.connection.AbstractConnectionManager; 48 import org.objectweb.cjdbc.controller.requestmanager.RAIDbLevels; 49 import org.objectweb.cjdbc.controller.requestmanager.RequestManager; 50 import org.objectweb.cjdbc.driver.DriverResultSet; 51 import org.objectweb.cjdbc.driver.Field; 52 53 61 public class VirtualDatabaseDynamicMetaData 62 { 63 64 65 public static final int NULL_VALUE = -999; 66 67 private String vdbName; 68 private RequestManager requestManager; 69 70 71 private Trace logger = null; 72 73 79 public VirtualDatabaseDynamicMetaData(VirtualDatabase database) 80 { 81 this.vdbName = database.getVirtualDatabaseName(); 82 requestManager = database.getRequestManager(); 83 if (requestManager == null) 84 throw new RuntimeException ( 85 "Null request manager in VirtualDatabaseMetaData"); 86 87 this.logger = Trace 88 .getLogger("org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabaseWorkerThread." 89 + vdbName + ".metadata"); 90 } 91 92 96 public DriverResultSet getAttributes(String login, String catalog, 97 String schemaPattern, String typeNamePattern, String attributeNamePattern) 98 throws SQLException 99 { 100 try 102 { 103 int raidbLevel = requestManager.getLoadBalancer().getRAIDbLevel(); 104 if ((raidbLevel == RAIDbLevels.RAIDb1) 105 || (raidbLevel == RAIDbLevels.SingleDB)) 106 { ConnectionAndDatabaseMetaData info = null; 108 try 109 { 110 info = getMetaDataFromFirstAvailableBackend(login); 111 DatabaseMetaData m = info.getDatabaseMetaData(); 112 ResultSet cols = m.getAttributes(catalog, schemaPattern, 113 typeNamePattern, attributeNamePattern); 114 ArrayList data = new ArrayList (); 115 while (cols.next()) 116 { Object [] row = new Object [21]; 118 row[0] = cols.getObject(1); row[1] = cols.getObject(2); row[2] = cols.getObject(3); row[3] = cols.getObject(4); row[4] = cols.getObject(5); row[5] = cols.getObject(6); row[6] = cols.getObject(7); row[7] = cols.getObject(8); row[8] = cols.getObject(9); row[9] = cols.getObject(10); row[10] = cols.getObject(11); row[11] = cols.getObject(12); row[12] = cols.getObject(13); row[13] = cols.getObject(14); row[14] = cols.getObject(15); row[15] = cols.getObject(16); row[16] = cols.getObject(17); row[17] = cols.getObject(18); row[18] = cols.getObject(19); row[19] = cols.getObject(20); row[20] = cols.getObject(21); data.add(row); 140 } 141 return new DriverResultSet(getAttributesFields, data); 142 } 143 catch (SQLException e) 144 { 145 throw e; 146 } 147 finally 148 { 149 releaseConnection(info); 150 } 151 } 152 } 153 catch (NoMoreBackendException ignore) 154 { 155 } 157 158 160 ArrayList data = new ArrayList (); 161 DriverResultSet rs = new DriverResultSet(getAttributesFields, data); 162 return rs; 163 } 164 165 169 public DriverResultSet getBestRowIdentifier(String login, String catalog, 170 String schema, String table, int scope, boolean nullable) 171 throws SQLException 172 { 173 try 174 { 175 int raidbLevel = requestManager.getLoadBalancer().getRAIDbLevel(); 176 if ((raidbLevel == RAIDbLevels.RAIDb1) 177 || (raidbLevel == RAIDbLevels.SingleDB)) 178 { ConnectionAndDatabaseMetaData info = null; 180 try 181 { 182 info = getMetaDataFromFirstAvailableBackend(login); 183 DatabaseMetaData m = info.getDatabaseMetaData(); 184 ResultSet cols = m.getBestRowIdentifier(catalog, schema, table, 185 scope, nullable); 186 ArrayList data = new ArrayList (); 187 while (cols.next()) 188 { Object [] row = new Object [8]; 190 row[0] = cols.getObject(1); row[1] = cols.getObject(2); row[2] = cols.getObject(3); row[3] = cols.getObject(4); row[4] = cols.getObject(5); row[5] = cols.getObject(6); row[6] = cols.getObject(7); row[7] = cols.getObject(8); data.add(row); 199 } 200 return new DriverResultSet( 201 getBestRowIdentifierAndVersionColumnsFields, data); 202 } 203 catch (SQLException e) 204 { 205 throw e; 206 } 207 finally 208 { 209 releaseConnection(info); 210 } 211 } 212 } 213 catch (NoMoreBackendException ignore) 214 { 215 } 217 218 220 ArrayList data = new ArrayList (); 221 DriverResultSet rs = new DriverResultSet( 222 getBestRowIdentifierAndVersionColumnsFields, data); 223 return rs; 224 } 225 226 232 public DriverResultSet getCatalogs(ArrayList list) 233 { 234 int size = list.size(); 235 ArrayList data = new ArrayList (size); 236 for (int i = 0; i < size; i++) 237 { 238 Object [] row = new Object [1]; 239 row[0] = (String ) list.get(i); 240 data.add(row); 241 } 242 DriverResultSet rs = new DriverResultSet(getCatalogsFields, data); 243 return rs; 244 } 245 246 250 public DriverResultSet getColumnPrivileges(String login, String catalog, 251 String schema, String table, String columnNamePattern) 252 throws SQLException 253 { 254 try 255 { 256 int raidbLevel = requestManager.getLoadBalancer().getRAIDbLevel(); 257 if ((raidbLevel == RAIDbLevels.RAIDb1) 258 || (raidbLevel == RAIDbLevels.SingleDB)) 259 { ConnectionAndDatabaseMetaData info = null; 261 try 262 { 263 info = getMetaDataFromFirstAvailableBackend(login); 264 DatabaseMetaData m = info.getDatabaseMetaData(); 265 ResultSet cols = m.getColumnPrivileges(catalog, schema, table, 266 columnNamePattern); 267 ArrayList data = new ArrayList (); 268 while (cols.next()) 269 { Object [] row = new Object [8]; 271 row[0] = cols.getObject(1); row[1] = cols.getObject(2); row[2] = cols.getObject(3); row[3] = cols.getObject(4); row[4] = cols.getObject(5); row[5] = cols.getObject(6); row[6] = cols.getObject(7); row[7] = cols.getObject(8); data.add(row); 280 } 281 return new DriverResultSet(getColumnPrivilegesFields, data); 282 } 283 catch (SQLException e) 284 { 285 throw e; 286 } 287 finally 288 { 289 releaseConnection(info); 290 } 291 } 292 } 293 catch (NoMoreBackendException ignore) 294 { 295 } 297 298 AuthenticationManager manager = requestManager.getVirtualDatabase() 299 .getAuthenticationManager(); 300 301 DatabaseSchema dbs = requestManager.getDatabaseSchema(); 302 if (dbs == null) 303 throw new SQLException ("Unable to fetch the virtual database schema"); 304 305 if (columnNamePattern == null) 306 columnNamePattern = "%"; 308 309 DatabaseTable dbTable = dbs.getTable(table); 310 if (dbTable == null) 311 throw new SQLException ("Unable to find table " + table); 312 313 ArrayList columns = dbTable.getColumns(); 314 int size = columns.size(); 315 ArrayList data = new ArrayList (); 316 317 ArrayList virtualLogins = manager.getVirtualLogins(); 318 int vsize = virtualLogins.size(); 319 VirtualDatabaseUser vu; 320 321 for (int i = 0; i < size; i++) 322 { 323 DatabaseColumn c = (DatabaseColumn) columns.get(i); 324 if (columnNamePattern.equals("%") 325 || columnNamePattern.equals(c.getName())) 326 { 327 for (int j = 0; j < vsize; j++) 328 { 329 vu = (VirtualDatabaseUser) virtualLogins.get(0); 330 331 if (logger.isDebugEnabled()) 332 logger.debug("Found privilege for user:" + vu.getLogin() 333 + " on column:" + c.getName()); 334 Object [] row = new Object [8]; 335 row[0] = vdbName; row[1] = null; row[2] = table; row[3] = c.getName(); row[4] = null; row[5] = vu.getLogin(); row[6] = "UPDATE"; row[7] = "NO"; data.add(row); 344 } 345 } 346 } 347 348 DriverResultSet rs = new DriverResultSet(getColumnPrivilegesFields, data); 349 return rs; 350 } 351 352 356 public DriverResultSet getColumns(String login, String catalog, 357 String schemaPattern, String tableNamePattern, String columnNamePattern) 358 throws SQLException 359 { 360 if (logger.isDebugEnabled()) 361 logger.debug("Getting columns for " + vdbName); 362 363 try 364 { 365 int raidbLevel = requestManager.getLoadBalancer().getRAIDbLevel(); 366 if ((raidbLevel == RAIDbLevels.RAIDb1) 367 || (raidbLevel == RAIDbLevels.SingleDB)) 368 { ConnectionAndDatabaseMetaData info = null; 370 try 371 { 372 info = getMetaDataFromFirstAvailableBackend(login); 373 DatabaseMetaData m = info.getDatabaseMetaData(); 374 ResultSet cols = m.getColumns(catalog, schemaPattern, 375 tableNamePattern, columnNamePattern); 376 ArrayList data = new ArrayList (); 377 while (cols.next()) 378 { Object [] row = new Object [22]; 380 row[0] = cols.getObject(1); row[1] = cols.getObject(2); row[2] = cols.getObject(3); row[3] = cols.getObject(4); row[4] = cols.getObject(5); row[5] = cols.getObject(6); row[6] = cols.getObject(7); row[7] = cols.getObject(8); row[8] = cols.getObject(9); row[9] = cols.getObject(10); row[10] = cols.getObject(11); row[11] = cols.getObject(12); row[12] = cols.getObject(13); row[13] = cols.getObject(14); row[14] = cols.getObject(15); row[15] = cols.getObject(16); row[16] = cols.getObject(17); row[17] = cols.getObject(18); try 400 { 401 row[18] = cols.getObject(19); row[19] = cols.getObject(20); row[20] = cols.getObject(21); row[21] = cols.getObject(22); } 406 catch (Exception e) 407 { row[18] = null; row[19] = null; row[20] = null; row[21] = null; } 413 data.add(row); 414 } 415 return new DriverResultSet(getColumnsFields, data); 416 } 417 catch (SQLException e) 418 { 419 throw e; 420 } 421 finally 422 { 423 releaseConnection(info); 424 } 425 } 426 } 427 catch (NoMoreBackendException ignore) 428 { 429 } 431 432 DatabaseSchema dbs = requestManager.getDatabaseSchema(); 435 if (dbs == null) 436 throw new SQLException ("Unable to fetch the virtual database schema"); 437 438 if (tableNamePattern == null) 439 tableNamePattern = "%"; 442 if (columnNamePattern == null) 443 columnNamePattern = "%"; 445 ArrayList tables = dbs.getTables(); 447 int size = tables.size(); 448 ArrayList data = new ArrayList (); 449 450 for (int i = 0; i < size; i++) 451 { 452 DatabaseTable t = (DatabaseTable) tables.get(i); 453 454 if (tableNamePattern.equals("%") || tableNamePattern.equals(t.getName())) 455 { 456 if (logger.isDebugEnabled()) 457 logger.debug("Found table " + t.getName()); 458 ArrayList columns = t.getColumns(); 459 for (int j = 0; j < columns.size(); j++) 460 { 461 DatabaseColumn c = (DatabaseColumn) columns.get(j); 462 if (columnNamePattern.equals("%") 463 || columnNamePattern.equals(c.getName())) 464 { 465 if (logger.isDebugEnabled()) 466 logger.debug("Found column " + c.getName()); 467 Object [] row = new Object [22]; 468 row[0] = vdbName; row[1] = null; row[2] = t.getName(); row[3] = c.getName(); row[4] = new Integer (c.getType()); row[5] = null; row[6] = null; row[7] = null; row[8] = null; row[9] = null; row[10] = null; row[11] = null; row[12] = null; row[13] = null; row[14] = null; row[15] = null; row[16] = null; row[17] = ""; row[18] = null; row[19] = null; row[20] = null; row[21] = null; data.add(row); 491 } 492 } 493 } 494 } 495 DriverResultSet rs = new DriverResultSet(getColumnsFields, data); 496 return rs; 497 } 498 499 504 public DriverResultSet getCrossReference(String login, String primaryCatalog, 505 String primarySchema, String primaryTable, String foreignCatalog, 506 String foreignSchema, String foreignTable) throws SQLException 507 { 508 try 509 { 510 int raidbLevel = requestManager.getLoadBalancer().getRAIDbLevel(); 511 if ((raidbLevel == RAIDbLevels.RAIDb1) 512 || (raidbLevel == RAIDbLevels.SingleDB)) 513 { ConnectionAndDatabaseMetaData info = null; 515 try 516 { 517 info = getMetaDataFromFirstAvailableBackend(login); 518 DatabaseMetaData m = info.getDatabaseMetaData(); 519 ResultSet cols = m.getCrossReference(primaryCatalog, primarySchema, 520 primaryTable, foreignCatalog, foreignSchema, foreignTable); 521 ArrayList data = new ArrayList (); 522 while (cols.next()) 523 { Object [] row = new Object [14]; 525 row[0] = cols.getObject(1); row[1] = cols.getObject(2); row[2] = cols.getObject(3); row[3] = cols.getObject(4); row[4] = cols.getObject(5); row[5] = cols.getObject(6); row[6] = cols.getObject(7); row[7] = cols.getObject(8); row[8] = cols.getObject(9); row[9] = cols.getObject(10); row[10] = cols.getObject(11); row[11] = cols.getObject(12); row[12] = cols.getObject(13); row[13] = cols.getObject(14); data.add(row); 540 } 541 return new DriverResultSet( 542 getCrossReferenceOrImportExportedKeysFields, data); 543 } 544 catch (SQLException e) 545 { 546 throw e; 547 } 548 finally 549 { 550 releaseConnection(info); 551 } 552 } 553 } 554 catch (NoMoreBackendException ignore) 555 { 556 } 558 559 561 ArrayList data = new ArrayList (); 562 DriverResultSet rs = new DriverResultSet( 563 getCrossReferenceOrImportExportedKeysFields, data); 564 return rs; 565 } 566 567 571 public DriverResultSet getExportedKeys(String login, String catalog, 572 String schema, String table) throws SQLException 573 { 574 try 575 { 576 int raidbLevel = requestManager.getLoadBalancer().getRAIDbLevel(); 577 if ((raidbLevel == RAIDbLevels.RAIDb1) 578 || (raidbLevel == RAIDbLevels.SingleDB)) 579 { ConnectionAndDatabaseMetaData info = null; 581 try 582 { 583 info = getMetaDataFromFirstAvailableBackend(login); 584 DatabaseMetaData m = info.getDatabaseMetaData(); 585 ResultSet cols = m.getExportedKeys(catalog, schema, table); 586 ArrayList data = new ArrayList (); 587 while (cols.next()) 588 { Object [] row = new Object [14]; 590 row[0] = cols.getObject(1); row[1] = cols.getObject(2); row[2] = cols.getObject(3); row[3] = cols.getObject(4); row[4] = cols.getObject(5); row[5] = cols.getObject(6); row[6] = cols.getObject(7); row[7] = cols.getObject(8); row[8] = cols.getObject(9); row[9] = cols.getObject(10); row[10] = cols.getObject(11); row[11] = cols.getObject(12); row[12] = cols.getObject(13); row[13] = cols.getObject(14); data.add(row); 605 } 606 return new DriverResultSet( 607 getCrossReferenceOrImportExportedKeysFields, data); 608 } 609 catch (SQLException e) 610 { 611 throw e; 612 } 613 finally 614 { 615 releaseConnection(info); 616 } 617 } 618 } 619 catch (NoMoreBackendException ignore) 620 { 621 } 623 624 626 ArrayList data = new ArrayList (); 627 DriverResultSet rs = new DriverResultSet( 628 getCrossReferenceOrImportExportedKeysFields, data); 629 return rs; 630 } 631 632 636 public DriverResultSet getImportedKeys(String login, String catalog, 637 String schema, String table) throws SQLException 638 { 639 try 640 { 641 int raidbLevel = requestManager.getLoadBalancer().getRAIDbLevel(); 642 if ((raidbLevel == RAIDbLevels.RAIDb1) 643 || (raidbLevel == RAIDbLevels.SingleDB)) 644 { ConnectionAndDatabaseMetaData info = null; 646 try 647 { 648 info = getMetaDataFromFirstAvailableBackend(login); 649 DatabaseMetaData m = info.getDatabaseMetaData(); 650 ResultSet cols = m.getImportedKeys(catalog, schema, table); 651 ArrayList data = new ArrayList (); 652 while (cols.next()) 653 { Object [] row = new Object [14]; 655 row[0] = cols.getObject(1); row[1] = cols.getObject(2); row[2] = cols.getObject(3); row[3] = cols.getObject(4); row[4] = cols.getObject(5); row[5] = cols.getObject(6); row[6] = cols.getObject(7); row[7] = cols.getObject(8); row[8] = cols.getObject(9); row[9] = cols.getObject(10); row[10] = cols.getObject(11); row[11] = cols.getObject(12); row[12] = cols.getObject(13); row[13] = cols.getObject(14); data.add(row); 670 } 671 return new DriverResultSet( 672 getCrossReferenceOrImportExportedKeysFields, data); 673 } 674 catch (SQLException e) 675 { 676 throw e; 677 } 678 finally 679 { 680 releaseConnection(info); 681 } 682 } 683 } 684 catch (NoMoreBackendException ignore) 685 { 686 } 688 689 691 ArrayList data = new ArrayList (); 692 DriverResultSet rs = new DriverResultSet( 693 getCrossReferenceOrImportExportedKeysFields, data); 694 return rs; 695 } 696 697 701 public DriverResultSet getIndexInfo(String login, String catalog, 702 String schema, String table, boolean unique, boolean approximate) 703 throws SQLException 704 { 705 try 706 { 707 int raidbLevel = requestManager.getLoadBalancer().getRAIDbLevel(); 708 if ((raidbLevel == RAIDbLevels.RAIDb1) 709 || (raidbLevel == RAIDbLevels.SingleDB)) 710 { ConnectionAndDatabaseMetaData info = null; 712 try 713 { 714 info = getMetaDataFromFirstAvailableBackend(login); 715 DatabaseMetaData m = info.getDatabaseMetaData(); 716 ResultSet cols = m.getIndexInfo(catalog, schema, table, unique, 717 approximate); 718 ArrayList data = new ArrayList (); 719 while (cols.next()) 720 { Object [] row = new Object [13]; 722 row[0] = cols.getObject(1); row[1] = cols.getObject(2); row[2] = cols.getObject(3); row[3] = cols.getObject(4); row[4] = cols.getObject(5); row[5] = cols.getObject(6); row[6] = cols.getObject(7); row[7] = cols.getObject(8); row[8] = cols.getObject(9); row[9] = cols.getObject(10); row[10] = cols.getObject(11); row[11] = cols.getObject(12); row[12] = cols.getObject(13); data.add(row); 736 } 737 return new DriverResultSet(getIndexInfoFields, data); 738 } 739 catch (SQLException e) 740 { 741 throw e; 742 } 743 finally 744 { 745 releaseConnection(info); 746 } 747 } 748 } 749 catch (NoMoreBackendException ignore) 750 { 751 } 753 754 ArrayList data = new ArrayList (); 756 DriverResultSet rs = new DriverResultSet(getIndexInfoFields, data); 757 return rs; 758 } 759 760 767 public DriverResultSet getPrimaryKeys(String login, String catalog, 768 String schema, String table) throws SQLException 769 { 770 if (logger.isDebugEnabled()) 771 logger.debug("Getting getPrimaryKeys for " + vdbName); 772 773 try 774 { 775 int raidbLevel = requestManager.getLoadBalancer().getRAIDbLevel(); 776 if ((raidbLevel == RAIDbLevels.RAIDb1) 777 || (raidbLevel == RAIDbLevels.SingleDB)) 778 { ConnectionAndDatabaseMetaData info = null; 780 try 781 { 782 info = getMetaDataFromFirstAvailableBackend(login); 783 DatabaseMetaData m = info.getDatabaseMetaData(); 784 ResultSet pks = m.getPrimaryKeys(catalog, schema, table); 785 ArrayList data = new ArrayList (); 786 while (pks.next()) 787 { Object [] row = new Object [6]; 789 row[0] = pks.getObject(1); row[1] = pks.getObject(2); row[2] = pks.getObject(3); row[3] = pks.getObject(4); row[4] = pks.getObject(5); row[5] = pks.getObject(6); data.add(row); 796 } 797 return new DriverResultSet(getPrimaryKeysFields, data); 798 } 799 catch (SQLException e) 800 { 801 throw e; 802 } 803 finally 804 { 805 releaseConnection(info); 806 } 807 } 808 } 809 catch (NoMoreBackendException ignore) 810 { 811 } 813 814 DatabaseSchema dbs = requestManager.getDatabaseSchema(); 817 if (dbs == null) 818 throw new SQLException ("Unable to fetch the virtual database schema"); 819 820 if (table == null) 821 table = "%"; 824 ArrayList tables = dbs.getTables(); 826 int size = tables.size(); 827 ArrayList data = new ArrayList (); 828 829 for (int i = 0; i < size; i++) 830 { 831 DatabaseTable t = (DatabaseTable) tables.get(i); 832 if (table.equals("%") || table.equals(t.getName())) 833 { 834 ArrayList columns = t.getColumns(); 835 for (int j = 0; j < columns.size(); j++) 836 { 837 DatabaseColumn c = (DatabaseColumn) columns.get(j); 838 if (c.isUnique()) 839 { 840 if (logger.isDebugEnabled()) 841 logger.debug("Found primary key" + c.getName()); 842 Object [] row = new Object [6]; 843 row[0] = vdbName; row[1] = null; row[2] = t.getName(); row[3] = c.getName(); row[4] = new Integer (c.getType()); row[5] = c.getName(); data.add(row); 850 } 851 else 852 { 853 if (logger.isDebugEnabled()) 854 logger.debug("Key " + c.getName() + " is not unique"); 855 } 856 } 857 } 858 } 859 DriverResultSet rs = new DriverResultSet(getPrimaryKeysFields, data); 860 return rs; 861 } 862 863 866 public DriverResultSet getProcedureColumns(String login, String catalog, 867 String schemaPattern, String procedureNamePattern, 868 String columnNamePattern) throws SQLException 869 { 870 try 871 { 872 int raidbLevel = requestManager.getLoadBalancer().getRAIDbLevel(); 873 if ((raidbLevel == RAIDbLevels.RAIDb1) 874 || (raidbLevel == RAIDbLevels.SingleDB)) 875 { ConnectionAndDatabaseMetaData info = null; 877 try 878 { 879 info = getMetaDataFromFirstAvailableBackend(login); 880 DatabaseMetaData m = info.getDatabaseMetaData(); 881 ResultSet cols = m.getColumns(catalog, schemaPattern, 882 procedureNamePattern, columnNamePattern); 883 ArrayList data = new ArrayList (); 884 while (cols.next()) 885 { Object [] row = new Object [13]; 887 row[0] = cols.getObject(1); row[1] = cols.getObject(2); row[2] = cols.getObject(3); row[3] = cols.getObject(4); row[4] = cols.getObject(5); row[5] = cols.getObject(6); row[6] = cols.getObject(7); row[7] = cols.getObject(8); row[8] = cols.getObject(9); row[9] = cols.getObject(10); row[10] = cols.getObject(11); row[11] = cols.getObject(12); row[12] = cols.getObject(13); data.add(row); 901 } 902 return new DriverResultSet(getProcedureColumnsFields, data); 903 } 904 catch (SQLException e) 905 { 906 throw e; 907 } 908 finally 909 { 910 releaseConnection(info); 911 } 912 } 913 } 914 catch (NoMoreBackendException ignore) 915 { 916 } 918 919 DatabaseSchema dbs = requestManager.getDatabaseSchema(); 920 if (dbs == null) 921 throw new SQLException ("Unable to fetch the virtual database schema"); 922 923 if (procedureNamePattern == null) 924 procedureNamePattern = "%"; 925 926 if (columnNamePattern == null) 927 columnNamePattern = "%"; 928 929 ArrayList procedures = dbs.getProcedures(); 931 int size = procedures.size(); 932 ArrayList data = new ArrayList (); 933 for (int i = 0; i < size; i++) 934 { 935 DatabaseProcedure t = (DatabaseProcedure) procedures.get(i); 936 if (procedureNamePattern.equals("%") 937 || procedureNamePattern.equals(t.getName())) 938 { 939 if (logger.isDebugEnabled()) 940 logger.debug("Found matching procedure " + t.getName()); 941 942 ArrayList params = t.getParameters(); 943 int sizep = params.size(); 944 DatabaseProcedureParameter param; 945 for (int k = 0; k < sizep; k++) 946 { 947 param = (DatabaseProcedureParameter) params.get(k); 948 if (columnNamePattern.equals("%") 949 || columnNamePattern.equals(t.getName())) 950 { 951 if (logger.isDebugEnabled()) 952 logger.debug("Found matching procedure parameter" 953 + param.getName()); 954 955 Object [] row = new Object [13]; 956 row[0] = vdbName; row[1] = null; row[2] = t.getName(); row[3] = param.getName(); row[4] = new Integer (param.getColumnType()); row[5] = new Integer (param.getDataType()); row[6] = param.getTypeName(); row[7] = new Float (param.getPrecision()); row[8] = new Integer (param.getLength()); row[9] = new Integer (param.getScale()); row[10] = new Integer (param.getRadix()); row[11] = new Integer (param.getNullable()); row[12] = param.getRemarks(); 969 970 data.add(row); 971 } 972 } 973 } 974 } 975 DriverResultSet rs = new DriverResultSet(getProcedureColumnsFields, data); 976 return rs; 977 } 978 979 983 public DriverResultSet getProcedures(String login, String catalog, 984 String schemaPattern, String procedureNamePattern) throws SQLException 985 { 986 try 987 { 988 int raidbLevel = requestManager.getLoadBalancer().getRAIDbLevel(); 989 if ((raidbLevel == RAIDbLevels.RAIDb1) 990 || (raidbLevel == RAIDbLevels.SingleDB)) 991 { ConnectionAndDatabaseMetaData info = null; 993 try 994 { 995 info = getMetaDataFromFirstAvailableBackend(login); 996 DatabaseMetaData m = info.getDatabaseMetaData(); 997 ResultSet cols = m.getProcedures(catalog, schemaPattern, 998 procedureNamePattern); 999 ArrayList data = new ArrayList (); 1000 while (cols.next()) 1001 { Object [] row = new Object [8]; 1003 row[0] = cols.getObject(1); row[1] = cols.getObject(2); row[2] = cols.getObject(3); row[3] = cols.getObject(4); row[4] = cols.getObject(5); row[5] = cols.getObject(6); row[6] = cols.getObject(7); row[7] = cols.getObject(8); data.add(row); 1012 } 1013 return new DriverResultSet(getProceduresFields, data); 1014 } 1015 catch (SQLException e) 1016 { 1017 throw e; 1018 } 1019 finally 1020 { 1021 releaseConnection(info); 1022 } 1023 } 1024 } 1025 catch (NoMoreBackendException ignore) 1026 { 1027 } 1029 1030 DatabaseSchema dbs = requestManager.getDatabaseSchema(); 1031 if (dbs == null) 1032 throw new SQLException ("Unable to fetch the virtual database schema"); 1033 1034 if (procedureNamePattern == null) 1035 procedureNamePattern = "%"; 1038 ArrayList procedures = dbs.getProcedures(); 1040 int size = procedures.size(); 1041 ArrayList data = new ArrayList (); 1042 for (int i = 0; i < size; i++) 1043 { 1044 DatabaseProcedure t = (DatabaseProcedure) procedures.get(i); 1045 if (procedureNamePattern.equals("%") 1046 || procedureNamePattern.equals(t.getName())) 1047 { 1048 if (logger.isDebugEnabled()) 1049 logger.debug("Found procedure " + t.getName()); 1050 Object [] row = new Object [8]; 1051 row[0] = vdbName; row[1] = null; row[2] = t.getName(); row[3] = null; row[4] = null; row[5] = null; row[6] = t.getRemarks(); row[7] = new Integer (t.getProcedureType()); data.add(row); 1060 } 1061 } 1062 DriverResultSet rs = new DriverResultSet(getProceduresFields, data); 1063 return rs; 1064 } 1065 1066 1072 public DriverResultSet getSchemas(String login) throws SQLException 1073 { 1074 try 1075 { ConnectionAndDatabaseMetaData info = null; 1077 try 1078 { 1079 info = getMetaDataFromFirstAvailableBackend(login); 1080 DatabaseMetaData m = info.getDatabaseMetaData(); 1081 ResultSet cols = m.getSchemas(); 1082 ArrayList data = new ArrayList (); 1083 while (cols.next()) 1084 { Object [] row = new Object [2]; 1086 row[0] = cols.getObject(1); try 1089 { 1090 row[1] = cols.getObject(2); } 1092 catch (Exception e) 1093 { row[1] = null; } 1096 data.add(row); 1097 } 1098 return new DriverResultSet(getSchemasFields, data); 1099 } 1100 catch (SQLException e) 1101 { 1102 throw e; 1103 } 1104 finally 1105 { 1106 releaseConnection(info); 1107 } 1108 } 1109 catch (NoMoreBackendException ignore) 1110 { 1111 } 1113 1114 Object [] row = new Object [2]; 1115 row[0] = vdbName; row[1] = null; ArrayList data = new ArrayList (); 1118 data.add(row); 1119 return new DriverResultSet(getSchemasFields, data); 1120 } 1121 1122 1126 public DriverResultSet getSuperTables(String login, String catalog, 1127 String schemaPattern, String tableNamePattern) throws SQLException 1128 { 1129 try 1130 { 1131 int raidbLevel = requestManager.getLoadBalancer().getRAIDbLevel(); 1132 if ((raidbLevel == RAIDbLevels.RAIDb1) 1133 || (raidbLevel == RAIDbLevels.SingleDB)) 1134 { ConnectionAndDatabaseMetaData info = null; 1136 try 1137 { 1138 info = getMetaDataFromFirstAvailableBackend(login); 1139 DatabaseMetaData m = info.getDatabaseMetaData(); 1140 ResultSet cols = m.getSuperTables(catalog, schemaPattern, 1141 tableNamePattern); 1142 ArrayList data = new ArrayList (); 1143 while (cols.next()) 1144 { Object [] row = new Object [4]; 1146 row[0] = cols.getObject(1); row[1] = cols.getObject(2); row[2] = cols.getObject(3); row[3] = cols.getObject(4); data.add(row); 1151 } 1152 return new DriverResultSet(getSuperTablesFields, data); 1153 } 1154 catch (SQLException e) 1155 { 1156 throw e; 1157 } 1158 finally 1159 { 1160 releaseConnection(info); 1161 } 1162 } 1163 } 1164 catch (NoMoreBackendException ignore) 1165 { 1166 } 1168 1169 1171 ArrayList data = new ArrayList (); 1172 DriverResultSet rs = new DriverResultSet(getSuperTablesFields, data); 1173 return rs; 1174 } 1175 1176 1180 public DriverResultSet getSuperTypes(String login, String catalog, 1181 String schemaPattern, String tableNamePattern) throws SQLException 1182 { 1183 try 1184 { 1185 int raidbLevel = requestManager.getLoadBalancer().getRAIDbLevel(); 1186 if ((raidbLevel == RAIDbLevels.RAIDb1) 1187 || (raidbLevel == RAIDbLevels.SingleDB)) 1188 { ConnectionAndDatabaseMetaData info = null; 1190 try 1191 { 1192 info = getMetaDataFromFirstAvailableBackend(login); 1193 DatabaseMetaData m = info.getDatabaseMetaData(); 1194 ResultSet cols = m.getSuperTypes(catalog, schemaPattern, 1195 tableNamePattern); 1196 ArrayList data = new ArrayList (); 1197 while (cols.next()) 1198 { Object [] row = new Object [5]; 1200 row[0] = cols.getObject(1); row[1] = cols.getObject(2); row[2] = cols.getObject(3); row[3] = cols.getObject(4); row[4] = cols.getObject(5); data.add(row); 1206 } 1207 return new DriverResultSet(getSuperTypesFields, data); 1208 } 1209 catch (SQLException e) 1210 { 1211 throw e; 1212 } 1213 finally 1214 { 1215 releaseConnection(info); 1216 } 1217 } 1218 } 1219 catch (NoMoreBackendException ignore) 1220 { 1221 } 1223 1224 1226 ArrayList data = new ArrayList (); 1227 DriverResultSet rs = new DriverResultSet(getSuperTypesFields, data); 1228 return rs; 1229 } 1230 1231 1235 public DriverResultSet getTablePrivileges(String login, String catalog, 1236 String schemaPattern, String tableNamePattern) throws SQLException 1237 { 1238 try 1239 { 1240 int raidbLevel = requestManager.getLoadBalancer().getRAIDbLevel(); 1241 if ((raidbLevel == RAIDbLevels.RAIDb1) 1242 || (raidbLevel == RAIDbLevels.SingleDB)) 1243 { ConnectionAndDatabaseMetaData info = null; 1245 try 1246 { 1247 info = getMetaDataFromFirstAvailableBackend(login); 1248 DatabaseMetaData m = info.getDatabaseMetaData(); 1249 ResultSet cols = m.getTablePrivileges(catalog, schemaPattern, 1250 tableNamePattern); 1251 ArrayList data = new ArrayList (); 1252 while (cols.next()) 1253 { Object [] row = new Object [7]; 1255 row[0] = cols.getObject(1); row[1] = cols.getObject(2); row[2] = cols.getObject(3); row[3] = cols.getObject(4); row[4] = cols.getObject(5); row[5] = cols.getObject(6); row[6] = cols.getObject(7); data.add(row); 1263 } 1264 return new DriverResultSet(getTablePrivilegesFields, data); 1265 } 1266 catch (SQLException e) 1267 { 1268 throw e; 1269 } 1270 finally 1271 { 1272 releaseConnection(info); 1273 } 1274 } 1275 } 1276 catch (NoMoreBackendException ignore) 1277 { 1278 } 1280 1281 AuthenticationManager manager = requestManager.getVirtualDatabase() 1282 .getAuthenticationManager(); 1283 1284 DatabaseSchema dbs = requestManager.getDatabaseSchema(); 1285 if (dbs == null) 1286 throw new SQLException ("Unable to fetch the virtual database schema"); 1287 1288 if (tableNamePattern == null) 1289 tableNamePattern = "%"; 1291 1292 ArrayList tables = dbs.getTables(); 1293 int size = tables.size(); 1294 ArrayList data = new ArrayList (); 1295 1296 ArrayList virtualLogins = manager.getVirtualLogins(); 1297 int vsize = virtualLogins.size(); 1298 VirtualDatabaseUser vu; 1299 1300 for (int i = 0; i < size; i++) 1301 { 1302 DatabaseTable t = (DatabaseTable) tables.get(i); 1303 if (tableNamePattern.equals("%") || tableNamePattern.equals(t.getName())) 1304 { 1305 for (int j = 0; j < vsize; j++) 1306 { 1307 vu = (VirtualDatabaseUser) virtualLogins.get(0); 1308 1309 if (logger.isDebugEnabled()) 1310 logger.debug("Found privilege for user:" + vu.getLogin() 1311 + " on table:" + t.getName()); 1312 Object [] row = new Object [7]; 1313 row[0] = vdbName; row[1] = null; row[2] = t.getName(); row[3] = null; row[4] = vu.getLogin(); row[5] = "UPDATE"; row[6] = "NO"; data.add(row); 1321 } 1322 } 1323 } 1324 1325 DriverResultSet rs = new DriverResultSet(getTablePrivilegesFields, data); 1326 return rs; 1327 } 1328 1329 1333 public DriverResultSet getTables(String login, String catalog, 1334 String schemaPattern, String tableNamePattern, String [] types) 1335 throws SQLException 1336 { 1337 try 1338 { 1339 int raidbLevel = requestManager.getLoadBalancer().getRAIDbLevel(); 1340 if ((raidbLevel == RAIDbLevels.RAIDb1) 1341 || (raidbLevel == RAIDbLevels.SingleDB)) 1342 { ConnectionAndDatabaseMetaData info = null; 1344 try 1345 { 1346 info = getMetaDataFromFirstAvailableBackend(login); 1347 DatabaseMetaData m = info.getDatabaseMetaData(); 1348 ResultSet cols = m.getTables(catalog, schemaPattern, 1349 tableNamePattern, types); 1350 ArrayList data = new ArrayList (); 1351 while (cols.next()) 1352 { Object [] row = new Object [10]; 1354 row[0] = cols.getObject(1); row[1] = cols.getObject(2); row[2] = cols.getObject(3); row[3] = cols.getObject(4); row[4] = cols.getObject(5); 1360 try 1362 { 1363 row[5] = cols.getObject(6); row[6] = cols.getObject(7); row[7] = cols.getObject(8); row[8] = cols.getObject(9); row[9] = cols.getObject(10); } 1369 catch (Exception e) 1370 { row[5] = null; 1372 row[6] = null; 1373 row[7] = null; 1374 row[8] = null; 1375 row[9] = null; 1376 } 1377 data.add(row); 1378 } 1379 return new DriverResultSet(getTablesFields, data); 1380 } 1381 catch (SQLException e) 1382 { 1383 throw e; 1384 } 1385 finally 1386 { 1387 releaseConnection(info); 1388 } 1389 } 1390 } 1391 catch (NoMoreBackendException ignore) 1392 { 1393 } 1395 1396 DatabaseSchema dbs = requestManager.getDatabaseSchema(); 1397 if (dbs == null) 1398 throw new SQLException ("Unable to fetch the virtual database schema"); 1399 1400 if (tableNamePattern == null) 1401 tableNamePattern = "%"; 1403 1404 ArrayList tables = dbs.getTables(); 1406 int size = tables.size(); 1407 ArrayList data = new ArrayList (); 1408 for (int i = 0; i < size; i++) 1409 { 1410 DatabaseTable t = (DatabaseTable) tables.get(i); 1411 if (tableNamePattern.equals("%") 1412 || t.getName().indexOf(tableNamePattern) != -1) 1413 { 1414 if (logger.isDebugEnabled()) 1415 logger.debug("Found table " + t.getName()); 1416 Object [] row = new Object [10]; 1417 row[0] = vdbName; row[1] = null; row[2] = t.getName(); row[3] = "TABLE"; row[4] = null; row[5] = null; row[6] = null; row[7] = null; row[8] = null; row[9] = "SYSTEM"; data.add(row); 1428 } 1429 } 1430 DriverResultSet rs = new DriverResultSet(getTablesFields, data); 1431 return rs; 1432 } 1433 1434 1437 public DriverResultSet getTableTypes(String login) throws SQLException 1438 { 1439 try 1440 { 1441 int raidbLevel = requestManager.getLoadBalancer().getRAIDbLevel(); 1442 if ((raidbLevel == RAIDbLevels.RAIDb1) 1443 || (raidbLevel == RAIDbLevels.SingleDB)) 1444 { ConnectionAndDatabaseMetaData info = null; 1446 try 1447 { 1448 info = getMetaDataFromFirstAvailableBackend(login); 1449 DatabaseMetaData m = info.getDatabaseMetaData(); 1450 ResultSet cols = m.getTableTypes(); 1451 ArrayList data = new ArrayList (); 1452 while (cols.next()) 1453 { Object [] row = new Object [1]; 1455 row[0] = cols.getObject(1); data.add(row); 1457 } 1458 return new DriverResultSet(getTableTypesFields, data); 1459 } 1460 catch (SQLException e) 1461 { 1462 throw e; 1463 } 1464 finally 1465 { 1466 releaseConnection(info); 1467 } 1468 } 1469 } 1470 catch (NoMoreBackendException ignore) 1471 { 1472 } 1474 1475 ArrayList list = new ArrayList (1); 1476 Object [] row = new Object [1]; 1477 row[0] = "TABLE"; list.add(row); 1479 DriverResultSet rs = new DriverResultSet(getTableTypesFields, list); 1480 return rs; 1481 } 1482 1483 1486 public DriverResultSet getTypeInfo(String login) throws SQLException 1487 { 1488 try 1489 { 1490 int raidbLevel = requestManager.getLoadBalancer().getRAIDbLevel(); 1491 if ((raidbLevel == RAIDbLevels.RAIDb1) 1492 || (raidbLevel == RAIDbLevels.SingleDB)) 1493 { ConnectionAndDatabaseMetaData info = null; 1495 try 1496 { 1497 info = getMetaDataFromFirstAvailableBackend(login); 1498 DatabaseMetaData m = info.getDatabaseMetaData(); 1499 ResultSet cols = m.getTypeInfo(); 1500 ArrayList data = new ArrayList (); 1501 while (cols.next()) 1502 { Object [] row = new Object [18]; 1504 row[0] = cols.getObject(1); row[1] = cols.getObject(2); row[2] = cols.getObject(3); row[3] = cols.getObject(4); row[4] = cols.getObject(5); row[5] = cols.getObject(6); row[6] = cols.getObject(7); row[7] = cols.getObject(8); row[8] = cols.getObject(9); row[9] = cols.getObject(10); row[10] = cols.getObject(11); row[11] = cols.getObject(12); row[12] = cols.getObject(13); row[13] = cols.getObject(14); row[14] = cols.getObject(15); row[15] = cols.getObject(16); row[16] = cols.getObject(17); row[17] = cols.getObject(18); data.add(row); 1523 } 1524 return new DriverResultSet(getTypeInfoFields, data); 1525 } 1526 catch (SQLException e) 1527 { 1528 throw e; 1529 } 1530 finally 1531 { 1532 releaseConnection(info); 1533 } 1534 } 1535 } 1536 catch (NoMoreBackendException ignore) 1537 { 1538 } 1540 1541 1543 ArrayList data = new ArrayList (); 1544 DriverResultSet rs = new DriverResultSet(getTypeInfoFields, data); 1545 return rs; 1546 } 1547 1548 1552 public DriverResultSet getUDTs(String login, String catalog, 1553 String schemaPattern, String tableNamePattern, int[] types) 1554 throws SQLException 1555 { 1556 try 1557 { 1558 int raidbLevel = requestManager.getLoadBalancer().getRAIDbLevel(); 1559 if ((raidbLevel == RAIDbLevels.RAIDb1) 1560 || (raidbLevel == RAIDbLevels.SingleDB)) 1561 { ConnectionAndDatabaseMetaData info = null; 1563 try 1564 { 1565 info = getMetaDataFromFirstAvailableBackend(login); 1566 DatabaseMetaData m = info.getDatabaseMetaData(); 1567 ResultSet cols = m.getUDTs(catalog, schemaPattern, tableNamePattern, 1568 types); 1569 ArrayList data = new ArrayList (); 1570 while (cols.next()) 1571 { Object [] row = new Object [6]; 1573 row[0] = cols.getObject(1); row[1] = cols.getObject(2); row[2] = cols.getObject(3); row[3] = cols.getObject(4); row[4] = cols.getObject(5); row[5] = cols.getObject(6); 1580 try 1582 { 1583 row[6] = cols.getObject(7); } 1585 catch (Exception e) 1586 { row[6] = null; } 1589 1590 data.add(row); 1591 } 1592 return new DriverResultSet(getUDTsFields, data); 1593 } 1594 catch (SQLException e) 1595 { 1596 throw e; 1597 } 1598 finally 1599 { 1600 releaseConnection(info); 1601 } 1602 } 1603 } 1604 catch (NoMoreBackendException ignore) 1605 { 1606 } 1608 1609 1611 ArrayList data = new ArrayList (); 1612 DriverResultSet rs = new DriverResultSet(getUDTsFields, data); 1613 return rs; 1614 } 1615 1616 1620 public DriverResultSet getVersionColumns(String login, String catalog, 1621 String schema, String table) throws SQLException 1622 { 1623 try 1624 { 1625 int raidbLevel = requestManager.getLoadBalancer().getRAIDbLevel(); 1626 if ((raidbLevel == RAIDbLevels.RAIDb1) 1627 || (raidbLevel == RAIDbLevels.SingleDB)) 1628 { ConnectionAndDatabaseMetaData info = null; 1630 try 1631 { 1632 info = getMetaDataFromFirstAvailableBackend(login); 1633 DatabaseMetaData m = info.getDatabaseMetaData(); 1634 ResultSet cols = m.getVersionColumns(catalog, schema, table); 1635 ArrayList data = new ArrayList (); 1636 while (cols.next()) 1637 { Object [] row = new Object [8]; 1639 row[0] = cols.getObject(1); row[1] = cols.getObject(2); row[2] = cols.getObject(3); row[3] = cols.getObject(4); row[4] = cols.getObject(5); row[5] = cols.getObject(6); row[6] = cols.getObject(7); row[7] = cols.getObject(8); data.add(row); 1648 } 1649 return new DriverResultSet( 1650 getBestRowIdentifierAndVersionColumnsFields, data); 1651 } 1652 catch (SQLException e) 1653 { 1654 throw e; 1655 } 1656 finally 1657 { 1658 releaseConnection(info); 1659 } 1660 } 1661 } 1662 catch (NoMoreBackendException ignore) 1663 { 1664 } 1666 1667 1669 ArrayList data = new ArrayList (); 1670 DriverResultSet rs = new DriverResultSet( 1671 getBestRowIdentifierAndVersionColumnsFields, data); 1672 return rs; 1673 } 1674 1675 1680 private DatabaseBackend getFirstAvailableBackend() 1681 { 1682 ArrayList backends = requestManager.getVirtualDatabase().getBackends(); 1684 try 1685 { 1686 for (Iterator iter = backends.iterator(); iter.hasNext();) 1687 { 1688 DatabaseBackend b = (DatabaseBackend) iter.next(); 1689 if (b.isReadEnabled()) 1690 return b; 1691 } 1692 } 1693 catch (ConcurrentModificationException e) 1694 { 1695 return getFirstAvailableBackend(); 1696 } 1697 1698 return null; 1699 } 1700 1701 1710 private ConnectionAndDatabaseMetaData getMetaDataFromFirstAvailableBackend( 1711 String login) throws NoMoreBackendException, SQLException 1712 { 1713 DatabaseBackend b = getFirstAvailableBackend(); 1714 if (b == null) 1715 throw new NoMoreBackendException( 1716 "No backend is enabled in virtual database " + vdbName); 1717 AbstractConnectionManager cm = b.getConnectionManager(login); 1718 if (cm == null) 1719 throw new SQLException ("Invalid login " + login + " on backend " 1720 + b.getName()); 1721 Connection c; 1722 try 1723 { 1724 c = cm.getConnection(); 1725 } 1726 catch (UnreachableBackendException e) 1727 { 1728 throw new SQLException ("Unable to get a connection for login " + login); 1729 } 1730 return new ConnectionAndDatabaseMetaData(c, cm, c.getMetaData()); 1731 } 1732 1733 1740 private void releaseConnection(ConnectionAndDatabaseMetaData info) 1741 { 1742 if (info == null) 1743 return; 1744 info.getConnectionManager().releaseConnection(info.getConnection()); 1745 } 1746 1747 1755 private class ConnectionAndDatabaseMetaData 1756 { 1757 DatabaseMetaData databaseMetaData; 1758 AbstractConnectionManager connectionManager; 1759 Connection connection; 1760 1761 1768 public ConnectionAndDatabaseMetaData(Connection c, 1769 AbstractConnectionManager cm, DatabaseMetaData metadata) 1770 { 1771 this.connection = c; 1772 this.connectionManager = cm; 1773 this.databaseMetaData = metadata; 1774 } 1775 1776 1781 public Connection getConnection() 1782 { 1783 return connection; 1784 } 1785 1786 1791 public AbstractConnectionManager getConnectionManager() 1792 { 1793 return connectionManager; 1794 } 1795 1796 1801 public DatabaseMetaData getDatabaseMetaData() 1802 { 1803 return databaseMetaData; 1804 } 1805 1806 } 1807 1808 1812 private static Field[] getAttributesFields = new Field[]{ 1813 new Field("TYPE_CAT", "TYPE_CAT", 9, Types.VARCHAR, "VARCHAR", "String"), 1814 new Field("TYPE_SCHEM", "TYPE_SCHEM", 10, Types.VARCHAR, "VARCHAR", 1815 "String"), 1816 new Field("TYPE_NAME", "TYPE_NAME", 10, Types.VARCHAR, "VARCHAR", 1817 "String"), 1818 new Field("DATA_TYPE", "DATA_TYPE", 10, Types.SMALLINT, "SMALLINT", 1819 "Short"), 1820 new Field("ATTR_NAME", "ATTR_NAME", 10, Types.VARCHAR, "VARCHAR", 1821 "String"), 1822 new Field("ATTR_TYPE_NAME", "ATTR_TYPE_NAME", 10, Types.VARCHAR, 1823 "VARCHAR", "String"), 1824 new Field("ATTR_SIZE", "ATTR_SIZE", 10, Types.INTEGER, "INTEGER", 1825 "Integer"), 1826 new Field("DECIMAL_DIGITS", "DECIMAL_DIGITS", 10, Types.INTEGER, 1827 "INTEGER", "Integer"), 1828 new Field("NUM_PREC_RADIX", "NUM_PREC_RADIX", 10, Types.INTEGER, 1829 "INTEGER", "Integer"), 1830 new Field("NULLABLE", "NULLABLE", 10, Types.INTEGER, "INTEGER", "Integer"), 1831 new Field("REMARKS", "REMARKS", 10, Types.VARCHAR, "VARCHAR", "String"), 1832 new Field("ATTR_DEF", "ATTR_DEF", 10, Types.VARCHAR, "VARCHAR", "String"), 1833 new Field("SQL_DATA_TYPE", "SQL_DATA_TYPE", 10, Types.INTEGER, "INTEGER", 1834 "Integer"), 1835 new Field("SQL_DATETIME_SUB", "SQL_DATETIME_SUB", 10, Types.INTEGER, 1836 "INTEGER", "Integer"), 1837 new Field("CHAR_OCTET_LENGTH", "CHAR_OCTET_LENGTH", 10, Types.INTEGER, 1838 "INTEGER", "Integer"), 1839 new Field("ORDINAL_POSITION", "ORDINAL_POSITION", 10, Types.INTEGER, 1840 "INTEGER", "Integer"), 1841 new Field("IS_NULLABLE", "IS_NULLABLE", 10, Types.VARCHAR, "VARCHAR", 1842 "String"), 1843 new Field("SCOPE_CATALOG", "SCOPE_CATALOG", 10, Types.VARCHAR, "VARCHAR", 1844 "String"), 1845 new Field("SCOPE_SCHEMA", "SCOPE_SCHEMA", 10, Types.VARCHAR, "VARCHAR", 1846 "String"), 1847 new Field("SCOPE_TABLE", "SCOPE_TABLE", 10, Types.VARCHAR, "VARCHAR", 1848 "String") }; 1849 1850 1854 private static Field[] getBestRowIdentifierAndVersionColumnsFields = new Field[]{ 1855 new Field("SCOPE", "SCOPE", 10, Types.SMALLINT, "SMALLINT", "Short"), 1856 new Field("COLUMN_NAME", "COLUMN_NAME", 10, Types.VARCHAR, "VARCHAR", 1857 "String"), 1858 new Field("DATA_TYPE", "DATA_TYPE", 10, Types.SMALLINT, "SMALLINT", 1859 "Short"), 1860 new Field("TYPE_NAME", "TYPE_NAME", 10, Types.VARCHAR, "VARCHAR", 1861 "String"), 1862 new Field("COLUMN_SIZE", "COLUMN_SIZE", 10, Types.INTEGER, "INTEGER", 1863 "Integer"), 1864 new Field("BUFFER_LENGTH", "BUFFER_LENGTH", 10, Types.INTEGER, "INTEGER", 1865 "Integer"), 1866 new Field("DECIMAL_DIGITS", "DECIMAL_DIGITS", 10, Types.SMALLINT, 1867 "SMALLINT", "Short"), 1868 new Field("PSEUDO_COLUMN", "PSEUDO_COLUMN", 10, Types.SMALLINT, 1869 "SMALLINT", "Short") }; 1870 1871 1874 private static Field[] getCatalogsFields = new Field[]{new Field( 1875 "TABLE_CAT", 1876 "TABLE_CAT", 1877 9, 1878 Types.VARCHAR, 1879 "VARCHAR", 1880 "String")}; 1881 1882 1886 private static Field[] getColumnPrivilegesFields = new Field[]{ 1887 new Field("TABLE_CAT", "TABLE_CAT", 9, Types.VARCHAR, "VARCHAR", "String"), 1888 new Field("TABLE_SCHEM", "TABLE_SCHEM", 10, Types.VARCHAR, "VARCHAR", 1889 "String"), 1890 new Field("TABLE_NAME", "TABLE_NAME", 10, Types.VARCHAR, "VARCHAR", 1891 "String"), 1892 new Field("COLUMN_NAME", "COLUMN_NAME", 10, Types.VARCHAR, "VARCHAR", 1893 "String"), 1894 new Field("GRANTOR", "GRANTOR", 10, Types.VARCHAR, "VARCHAR", "String"), 1895 new Field("GRANTEE", "GRANTEE", 10, Types.VARCHAR, "VARCHAR", "String"), 1896 new Field("PRIVILEGE", "PRIVILEGE", 10, Types.VARCHAR, "VARCHAR", 1897 "String"), 1898 new Field("IS_GRANTABLE", "IS_GRANTABLE", 10, Types.VARCHAR, "VARCHAR", 1899 "String"), }; 1900 1901 1905 private static Field[] getColumnsFields = new Field[]{ 1906 new Field("TABLE_CAT", "TABLE_CAT", 9, Types.VARCHAR, "VARCHAR", "String"), 1907 new Field("TABLE_SCHEM", "TABLE_SCHEM", 10, Types.VARCHAR, "VARCHAR", 1908 "String"), 1909 new Field("TABLE_NAME", "TABLE_NAME", 10, Types.VARCHAR, "VARCHAR", 1910 "String"), 1911 new Field("COLUMN_NAME", "COLUMN_NAME", 10, Types.VARCHAR, "VARCHAR", 1912 "String"), 1913 new Field("DATA_TYPE", "DATA_TYPE", 10, Types.SMALLINT, "SMALLINT", 1914 "Short"), 1915 new Field("TYPE_NAME", "TYPE_NAME", 10, Types.VARCHAR, "VARCHAR", 1916 "String"), 1917 new Field("COLUMN_SIZE", "COLUMN_SIZE", 10, Types.INTEGER, "INTEGER", 1918 "Integer"), 1919 new Field("BUFFER_LENGTH", "BUFFER_LENGTH", 10, Types.INTEGER, "INTEGER", 1920 "Integer"), 1921 new Field("DECIMAL_DIGITS", "DECIMAL_DIGITS", 10, Types.INTEGER, 1922 "INTEGER", "Integer"), 1923 new Field("NUM_PREC_RADIX", "NUM_PREC_RADIX", 10, Types.INTEGER, 1924 "INTEGER", "Integer"), 1925 new Field("NULLABLE", "NULLABLE", 10, Types.INTEGER, "INTEGER", "Integer"), 1926 new Field("REMARKS", "REMARKS", 10, Types.VARCHAR, "VARCHAR", "String"), 1927 new Field("COLUMN_DEF", "COLUMN_DEF", 10, Types.VARCHAR, "VARCHAR", 1928 "String"), 1929 new Field("SQL_DATA_TYPE", "SQL_DATA_TYPE", 10, Types.INTEGER, "INTEGER", 1930 "Integer"), 1931 new Field("SQL_DATETIME_SUB", "SQL_DATETIME_SUB", 10, Types.INTEGER, 1932 "INTEGER", "Integer"), 1933 new Field("CHAR_OCTET_LENGTH", "CHAR_OCTET_LENGTH", 10, Types.INTEGER, 1934 "INTEGER", "Integer"), 1935 new Field("ORDINAL_POSITION", "ORDINAL_POSITION", 10, Types.INTEGER, 1936 "INTEGER", "Integer"), 1937 new Field("IS_NULLABLE", "IS_NULLABLE", 10, Types.VARCHAR, "VARCHAR", 1938 "String"), 1939 new Field("SCOPE_CATALOG", "SCOPE_CATALOG", 10, Types.VARCHAR, "VARCHAR", 1940 "String"), 1941 new Field("SCOPE_SCHEMA", "SCOPE_SCHEMA", 10, Types.VARCHAR, "VARCHAR", 1942 "String"), 1943 new Field("SCOPE_TABLE", "SCOPE_TABLE", 10, Types.VARCHAR, "VARCHAR", 1944 "String"), 1945 new Field("SOURCE_DATA_TYPE", "SOURCE_DATA_TYPE", 10, Types.SMALLINT, 1946 "SMALLINT", "Short") }; 1947 1948 1955 private static Field[] getCrossReferenceOrImportExportedKeysFields = new Field[]{ 1956 new Field("PKTABLE_CAT", "PKTABLE_CAT", 9, Types.VARCHAR, "VARCHAR", 1957 "String"), 1958 new Field("PKTABLE_SCHEM", "PKTABLE_SCHEM", 10, Types.VARCHAR, "VARCHAR", 1959 "String"), 1960 new Field("PKTABLE_NAME", "PKTABLE_NAME", 10, Types.VARCHAR, "VARCHAR", 1961 "String"), 1962 new Field("PKCOLUMN_NAME", "PKCOLUMN_NAME", 10, Types.VARCHAR, "VARCHAR", 1963 "String"), 1964 new Field("FKTABLE_CAT", "FKTABLE_CAT", 9, Types.VARCHAR, "VARCHAR", 1965 "String"), 1966 new Field("FKTABLE_SCHEM", "FKTABLE_SCHEM", 10, Types.VARCHAR, "VARCHAR", 1967 "String"), 1968 new Field("FKTABLE_NAME", "FKTABLE_NAME", 10, Types.VARCHAR, "VARCHAR", 1969 "String"), 1970 new Field("FKCOLUMN_NAME", "FKCOLUMN_NAME", 10, Types.VARCHAR, "VARCHAR", 1971 "String"), 1972 new Field("KEY_SEQ", "KEY_SEQ", 10, Types.SMALLINT, "SMALLINT", "Short"), 1973 new Field("UPDATE_RULE", "UPDATE_RULE", 10, Types.SMALLINT, "SMALLINT", 1974 "Short"), 1975 new Field("DELETE_RULE", "DELETE_RULE", 10, Types.SMALLINT, "SMALLINT", 1976 "Short"), 1977 new Field("FK_NAME", "FK_NAME", 10, Types.VARCHAR, "VARCHAR", "String"), 1978 new Field("PK_NAME", "PK_NAME", 10, Types.VARCHAR, "VARCHAR", "String"), 1979 new Field("DEFERRABILITY", "DEFERRABILITY", 10, Types.SMALLINT, 1980 "SMALLINT", "Short") }; 1981 1982 1986 private static Field[] getIndexInfoFields = new Field[]{ 1987 new Field("TABLE_CAT", "TABLE_CAT", 9, Types.VARCHAR, "VARCHAR", "String"), 1988 new Field("TABLE_SCHEM", "TABLE_SCHEM", 10, Types.VARCHAR, "VARCHAR", 1989 "String"), 1990 new Field("TABLE_NAME", "TABLE_NAME", 10, Types.VARCHAR, "VARCHAR", 1991 "String"), 1992 new Field("NON_UNIQUE", "NON_UNIQUE", 10, Types.INTEGER, "INTEGER", 1993 "Integer"), 1994 new Field("INDEX_QUALIFIER", "INDEX_QUALIFIER", 10, Types.VARCHAR, 1995 "VARCHAR", "String"), 1996 new Field("INDEX_NAME", "INDEX_NAME", 10, Types.VARCHAR, "VARCHAR", 1997 "String"), 1998 new Field("TYPE", "TYPE", 10, Types.SMALLINT, "SMALLINT", "Short"), 1999 new Field("ORDINAL_POSITION", "ORDINAL_POSITION", 10, Types.SMALLINT, 2000 "SMALLINT", "Short"), 2001 new Field("COLUMN_NAME", "COLUMN_NAME", 10, Types.VARCHAR, "VARCHAR", 2002 "String"), 2003 new Field("ASC_OR_DESC", "ASC_OR_DESC", 10, Types.VARCHAR, "VARCHAR", 2004 "String"), 2005 new Field("CARDINALITY", "CARDINALITY", 10, Types.INTEGER, "INTEGER", 2006 "Integer"), 2007 new Field("PAGES", "PAGES", 10, Types.INTEGER, "INTEGER", "Integer"), 2008 new Field("FILTER_CONDITION", "FILTER_CONDITION", 10, Types.VARCHAR, 2009 "VARCHAR", "String") }; 2010 2011 2015 private static Field[] getPrimaryKeysFields = new Field[]{ 2016 new Field("TABLE_CAT", "TABLE_CAT", 9, Types.VARCHAR, "VARCHAR", "String"), 2017 new Field("TABLE_SCHEM", "TABLE_SCHEM", 10, Types.VARCHAR, "VARCHAR", 2018 "String"), 2019 new Field("TABLE_NAME", "TABLE_NAME", 10, Types.VARCHAR, "VARCHAR", 2020 "String"), 2021 new Field("COLUMN_NAME", "COLUMN_NAME", 10, Types.VARCHAR, "VARCHAR", 2022 "String"), 2023 new Field("KEY_SEQ", "KEY_SEQ", 10, Types.SMALLINT, "SMALLINT", "Short"), 2024 new Field("PK_NAME", "PK_NAME", 10, Types.VARCHAR, "VARCHAR", "String")}; 2025 2029 private static Field[] getProcedureColumnsFields = new Field[]{ 2030 new Field("PROCEDURE_CAT", "PROCEDURE_CAT", 9, Types.VARCHAR, "VARCHAR", 2031 "String"), 2032 new Field("PROCEDURE_SCHEM", "PROCEDURE_SCHEM", 10, Types.VARCHAR, 2033 "VARCHAR", "String"), 2034 new Field("PROCEDURE_NAME", "PROCEDURE_NAME", 10, Types.VARCHAR, 2035 "VARCHAR", "String"), 2036 new Field("COLUMN_NAME", "COLUMN_NAME", 10, Types.VARCHAR, "VARCHAR", 2037 "String"), 2038 new Field("COLUMN_TYPE", "COLUMN_TYPE", 10, Types.SMALLINT, "SMALLINT", 2039 "Short"), 2040 new Field("DATA_TYPE", "DATA_TYPE", 10, Types.SMALLINT, "SMALLINT", 2041 "Short"), 2042 new Field("TYPE_NAME", "TYPE_NAME", 10, Types.VARCHAR, "VARCHAR", 2043 "String"), 2044 new Field("PRECISION", "PRECISION", 10, Types.FLOAT, "FLOAT", "Float"), 2045 new Field("LENGTH", "LENGTH", 10, Types.INTEGER, "INTEGER", "Integer"), 2046 new Field("SCALE", "SCALE", 10, Types.SMALLINT, "SMALLINT", "Short"), 2047 new Field("RADIX", "RADIX", 10, Types.SMALLINT, "SMALLINT", "Short"), 2048 new Field("NULLABLE", "NULLABLE", 10, Types.SMALLINT, "SMALLINT", "Short"), 2049 new Field("REMARKS", "REMARKS", 10, Types.VARCHAR, "VARCHAR", "String")}; 2050 2051 2055 private static Field[] getProceduresFields = new Field[]{ 2056 new Field("PROCEDURE_CAT", "PROCEDURE_CAT", 9, Types.VARCHAR, "VARCHAR", 2057 "String"), 2058 new Field("PROCEDURE_SCHEM", "PROCEDURE_SCHEM", 10, Types.VARCHAR, 2059 "VARCHAR", "String"), 2060 new Field("PROCEDURE_NAME", "PROCEDURE_NAME", 10, Types.VARCHAR, 2061 "VARCHAR", "String"), 2062 new Field("", "", 0, Types.VARCHAR, "VARCHAR", "String"), 2063 new Field("", "", 0, Types.VARCHAR, "VARCHAR", "String"), 2064 new Field("", "", 0, Types.VARCHAR, "VARCHAR", "String"), 2065 new Field("REMARKS", "REMARKS", 10, Types.VARCHAR, "VARCHAR", "String"), 2066 new Field("PROCEDURE_TYPE", "PROCEDURE_TYPE", 10, Types.SMALLINT, 2067 "SMALLINT", "Short") }; 2068 2069 2072 private static Field[] getSchemasFields = new Field[]{ 2073 new Field("TABLE_SCHEM", "TABLE_SCHEM", 9, Types.VARCHAR, "VARCHAR", 2074 "String"), 2075 new Field("TABLE_CATALOG", "TABLE_CATALOG", 9, Types.VARCHAR, "VARCHAR", 2076 "String") }; 2077 2078 2082 private static Field[] getSuperTablesFields = new Field[]{ 2083 new Field("TABLE_CAT", "TABLE_CAT", 9, Types.VARCHAR, "VARCHAR", "String"), 2084 new Field("TABLE_SCHEM", "TABLE_SCHEM", 10, Types.VARCHAR, "VARCHAR", 2085 "String"), 2086 new Field("TABLE_NAME", "TABLE_NAME", 10, Types.VARCHAR, "VARCHAR", 2087 "String"), 2088 new Field("SUPERTABLE_NAME", "SUPERTABLE_NAME", 10, Types.VARCHAR, 2089 "VARCHAR", "String") }; 2090 2091 2095 private static Field[] getSuperTypesFields = new Field[]{ 2096 new Field("TYPE_CAT", "TYPE_CAT", 9, Types.VARCHAR, "VARCHAR", "String"), 2097 new Field("TYPE_SCHEM", "TYPE_SCHEM", 10, Types.VARCHAR, "VARCHAR", 2098 "String"), 2099 new Field("TYPE_NAME", "TYPE_NAME", 10, Types.VARCHAR, "VARCHAR", 2100 "String"), 2101 new Field("SUPERTYPE_CAT", "SUPERTYPE_CAT", 10, Types.VARCHAR, "VARCHAR", 2102 "String"), 2103 new Field("SUPERTYPE_SCHEM", "SUPERTYPE_SCHEM", 10, Types.VARCHAR, 2104 "VARCHAR", "String") }; 2105 2106 2110 private static Field[] getTablePrivilegesFields = new Field[]{ 2111 new Field("TABLE_CAT", "TABLE_CAT", 9, Types.VARCHAR, "VARCHAR", "String"), 2112 new Field("TABLE_SCHEM", "TABLE_SCHEM", 10, Types.VARCHAR, "VARCHAR", 2113 "String"), 2114 new Field("TABLE_NAME", "TABLE_NAME", 10, Types.VARCHAR, "VARCHAR", 2115 "String"), 2116 new Field("GRANTOR", "GRANTOR", 10, Types.VARCHAR, "VARCHAR", "String"), 2117 new Field("GRANTEE", "GRANTEE", 10, Types.VARCHAR, "VARCHAR", "String"), 2118 new Field("PRIVILEGE", "PRIVILEGE", 10, Types.VARCHAR, "VARCHAR", 2119 "String"), 2120 new Field("IS_GRANTABLE", "IS_GRANTABLE", 10, Types.VARCHAR, "VARCHAR", 2121 "String"), }; 2122 2123 2126 private static Field[] getTablesFields = new Field[]{ 2127 new Field("TABLE_CAT", "TABLE_CAT", 9, Types.VARCHAR, "VARCHAR", "String"), 2128 new Field("TABLE_SCHEM", "TABLE_SCHEM", 10, Types.VARCHAR, "VARCHAR", 2129 "String"), 2130 new Field("TABLE_NAME", "TABLE_NAME", 10, Types.VARCHAR, "VARCHAR", 2131 "String"), 2132 new Field("TABLE_TYPE", "TABLE_TYPE", 10, Types.VARCHAR, "VARCHAR", 2133 "String"), 2134 new Field("REMARKS", "REMARKS", 10, Types.VARCHAR, "VARCHAR", "String"), 2135 new Field("TYPE_CAT", "TYPE_CAT", 10, Types.VARCHAR, "VARCHAR", "String"), 2136 new Field("TYPE_SCHEM", "TYPE_SCHEM", 10, Types.VARCHAR, "VARCHAR", 2137 "String"), 2138 new Field("TYPE_NAME", "TYPE_NAME", 10, Types.VARCHAR, "VARCHAR", 2139 "String"), 2140 new Field("SELF_REFERENCING_COL_NAME", "SELF_REFERENCING_COL_NAME", 25, 2141 Types.VARCHAR, "VARCHAR", "String"), 2142 new Field("REF_GENERATION", "REF_GENERATION", 15, Types.VARCHAR, 2143 "VARCHAR", "String") }; 2144 2145 2148 private static Field[] getTableTypesFields = new Field[]{new Field( 2149 "TABLE_TYPE", 2150 "TABLE_TYPE", 2151 9, 2152 Types.VARCHAR, 2153 "VARCHAR", 2154 "String")}; 2155 2156 2159 private static Field[] getTypeInfoFields = new Field[]{ 2160 new Field("TYPE_NAME", "TYPE_NAME", 10, Types.VARCHAR, "VARCHAR", 2161 "String"), 2162 new Field("DATA_TYPE", "DATA_TYPE", 10, Types.SMALLINT, "SMALLINT", 2163 "Short"), 2164 new Field("PRECISION", "PRECISION", 10, Types.INTEGER, "INTEGER", 2165 "Integer"), 2166 new Field("LITERAL_PREFIX", "LITERAL_PREFIX", 10, Types.VARCHAR, 2167 "VARCHAR", "String"), 2168 new Field("LITERAL_SUFFIX", "LITERAL_SUFFIX", 10, Types.VARCHAR, 2169 "VARCHAR", "String"), 2170 new Field("CREATE_PARAMS", "CREATE_PARAMS", 10, Types.VARCHAR, "VARCHAR", 2171 "String"), 2172 new Field("NULLABLE", "NULLABLE", 10, Types.INTEGER, "INTEGER", "Integer"), 2173 new Field("CASE_SENSITIVE", "CASE_SENSITIVE", 10, Types.INTEGER, 2174 "INTEGER", "Integer"), 2175 new Field("SEARCHABLE", "SEARCHABLE", 10, Types.SMALLINT, "SMALLINT", 2176 "Short"), 2177 new Field("UNSIGNED_ATTRIBUTE", "UNSIGNED_ATTRIBUTE", 10, Types.INTEGER, 2178 "INTEGER", "Integer"), 2179 new Field("FIXED_PREC_SCALE", "FIXED_PREC_SCALE", 10, Types.INTEGER, 2180 "INTEGER", "Integer"), 2181 new Field("AUTO_INCREMENT", "AUTO_INCREMENT", 10, Types.INTEGER, 2182 "INTEGER", "Integer"), 2183 new Field("LOCAL_TYPE_NAME", "LOCAL_TYPE_NAME", 10, Types.VARCHAR, 2184 "VARCHAR", "String"), 2185 new Field("MINIMUM_SCALE", "MINIMUM_SCALE", 10, Types.SMALLINT, 2186 "SMALLINT", "Short"), 2187 new Field("MAXIMUM_SCALE", "MAXIMUM_SCALE", 10, Types.SMALLINT, 2188 "SMALLINT", "Short"), 2189 new Field("SQL_DATA_TYPE", "SQL_DATA_TYPE", 10, Types.INTEGER, "INTEGER", 2190 "Integer"), 2191 new Field("SQL_DATETIME_SUB", "SQL_DATETIME_SUB", 10, Types.INTEGER, 2192 "INTEGER", "Integer"), 2193 new Field("NUM_PREC_RADIX", "NUM_PREC_RADIX", 10, Types.INTEGER, 2194 "INTEGER", "Integer") }; 2195 2196 2200 private static Field[] getUDTsFields = new Field[]{ 2201 new Field("TYPE_CAT", "TYPE_CAT", 9, Types.VARCHAR, "VARCHAR", "String"), 2202 new Field("TYPE_SCHEM", "TYPE_SCHEM", 10, Types.VARCHAR, "VARCHAR", 2203 "String"), 2204 new Field("TYPE_NAME", "TYPE_NAME", 10, Types.VARCHAR, "VARCHAR", 2205 "String"), 2206 new Field("CLASS_NAME", "CLASS_NAME", 10, Types.VARCHAR, "VARCHAR", 2207 "String"), 2208 new Field("DATA_TYPE", "DATA_TYPE", 10, Types.SMALLINT, "SMALLINT", 2209 "Short"), 2210 new Field("REMARKS", "REMARKS", 10, Types.VARCHAR, "VARCHAR", "String"), 2211 new Field("BASE_TYPE", "BASE_TYPE", 10, Types.SMALLINT, "SMALLINT", 2212 "Short") }; 2213 2214} | Popular Tags |