📄 metadata_test.java
字号:
null, null, new boolean [] {false, false})); System.out.println("getIndexInfo():"); dumpRS(GET_INDEX_INFO, getMetaDataRS(met, GET_INDEX_INFO, new String [] {"", "SYS", "SYSTABLES"}, null, null, new boolean [] {true, false})); rs = s.executeQuery("SELECT * FROM SYS.SYSTABLES"); System.out.println("getColumns('SYSTABLES'):"); dumpRS(GET_COLUMNS, getMetaDataRS(met, GET_COLUMNS, new String [] {"", "SYS", "SYSTABLES", null}, null, null, null)); try { if (!rs.next()) { System.out.println("FAIL -- user result set closed by"+ " intervening getColumns request"); } } catch (SQLException se) { if (this instanceof metadata) { System.out.println("FAIL -- user result set closed by"+ " intervening getColumns request"); } else { System.out.println("OK -- user result set closed by"+ " intervening OBDC getColumns request; this was" + " expected because of the way the test works."); } } rs.close(); // // Test referential actions on delete // System.out.println("---------------------------------------"); //create tables to test that we get the delete and update // referential action correct System.out.println("Referential action values"); System.out.println("RESTRICT = "+ DatabaseMetaData.importedKeyRestrict); System.out.println("NO ACTION = "+ DatabaseMetaData.importedKeyNoAction); System.out.println("CASCADE = "+ DatabaseMetaData.importedKeyCascade); System.out.println("SETNULL = "+ DatabaseMetaData.importedKeySetNull); System.out.println("SETDEFAULT = "+ DatabaseMetaData.importedKeySetDefault); s.execute("create table refaction1(a int not null primary key)"); s.execute("create table refactnone(a int references refaction1(a))"); s.execute("create table refactrestrict(a int references refaction1(a) on delete restrict)"); s.execute("create table refactnoaction(a int references refaction1(a) on delete no action)"); s.execute("create table refactcascade(a int references refaction1(a) on delete cascade)"); s.execute("create table refactsetnull(a int references refaction1(a) on delete set null)"); System.out.println("getCrossReference('','APP','REFACTION1','','APP','REFACTIONNONE' ):"); s.execute("create table refactupdrestrict(a int references refaction1(a) on update restrict)"); s.execute("create table refactupdnoaction(a int references refaction1(a) on update no action)"); dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met, GET_CROSS_REFERENCE, new String [] {"", "APP", "REFACTION1", "", "APP", "REFACTNONE"}, null, null, null)); System.out.println("\ngetCrossReference('','APP','REFACTION1','','APP','REFACTRESTRICT' ):"); dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met, GET_CROSS_REFERENCE, new String [] {"", "APP", "REFACTION1", "", "APP", "REFACTRESTRICT"}, null, null, null)); System.out.println("\ngetCrossReference('','APP','REFACTION1','','APP','REFACTNOACTION' ):"); dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met, GET_CROSS_REFERENCE, new String [] {"", "APP", "REFACTION1", "", "APP", "REFACTNOACTION"}, null, null, null)); System.out.println("\ngetCrossReference('','APP','REFACTION1','','APP','REFACTCASCADE' ):"); dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met, GET_CROSS_REFERENCE, new String [] {"", "APP", "REFACTION1", "", "APP", "REFACTCASCADE"}, null, null, null)); System.out.println("\ngetCrossReference('','APP','REFACTION1','','APP','REFACTSETNULL' ):"); dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met, GET_CROSS_REFERENCE, new String [] {"", "APP", "REFACTION1", "", "APP", "REFACTSETNULL"}, null, null, null)); System.out.println("\ngetCrossReference('','APP','REFACTION1','','APP','REFACTUPDRESTRICT' ):"); dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met, GET_CROSS_REFERENCE, new String [] {"", "APP", "REFACTION1", "", "APP", "REFACTUPDRESTRICT"}, null, null, null)); System.out.println("\ngetCrossReference('','APP','REFACTION1','','APP','REFACTUPDNOACTION' ):"); dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met, GET_CROSS_REFERENCE, new String [] {"", "APP", "REFACTION1", "", "APP", "REFACTUPDNOACTION"}, null, null, null)); ResultSet refrs = getMetaDataRS(met, GET_IMPORTED_KEYS, new String [] {"", "APP", "REFACTNONE"}, null, null, null); if (refrs.next()) { //check update rule if (refrs.getShort(11) != DatabaseMetaData.importedKeyNoAction) System.out.println("\ngetImportedKeys - none update Failed - action = " + refrs.getShort(11) + " required value = " + DatabaseMetaData.importedKeyNoAction); else System.out.println("\ngetImportedKeys - none update Passed"); //check delete rule if (refrs.getShort(11) != DatabaseMetaData.importedKeyNoAction) System.out.println("\ngetImportedKeys - none delete Failed - action = " + refrs.getShort(11) + " required value = " + DatabaseMetaData.importedKeyNoAction); else System.out.println("\ngetImportedKeys - none delete Passed"); } else System.out.println("\ngetImportedKeys - none Failed no rows"); refrs.close(); refrs = getMetaDataRS(met, GET_IMPORTED_KEYS, new String [] {"", "APP", "REFACTRESTRICT"}, null, null, null); if (refrs.next()) { if (refrs.getShort(11) != DatabaseMetaData.importedKeyRestrict) System.out.println("\ngetImportedKeys - delete Restrict Failed - action = " + refrs.getShort(11) + " required value = " + DatabaseMetaData.importedKeyRestrict); else System.out.println("\ngetImportedKeys - delete Restrict Passed"); } else System.out.println("\ngetImportedKeys - delete Restrict Failed no rows"); refrs.close(); refrs = getMetaDataRS(met, GET_IMPORTED_KEYS, new String [] {"", "APP", "REFACTNOACTION"}, null, null, null); if (refrs.next()) { if (refrs.getShort(11) != DatabaseMetaData.importedKeyNoAction) System.out.println("\ngetImportedKeys - delete NO ACTION Failed - action = " + refrs.getShort(11) + " required value = " + DatabaseMetaData.importedKeyNoAction); else System.out.println("\ngetImportedKeys - delete NO ACTION Passed"); } else System.out.println("\ngetImportedKeys - delete NO ACTION Failed no rows"); refrs.close(); refrs = getMetaDataRS(met, GET_IMPORTED_KEYS, new String [] {"", "APP", "REFACTCASCADE"}, null, null, null); if (refrs.next()) { if (refrs.getShort(11) != DatabaseMetaData.importedKeyCascade) System.out.println("\ngetImportedKeys - delete CASCADE Failed - action = " + refrs.getShort(11) + " required value = " + DatabaseMetaData.importedKeyCascade); else System.out.println("\ngetImportedKeys - delete CASCADE Passed"); } else System.out.println("\ngetImportedKeys - delete CASCADE Failed no rows"); refrs.close(); refrs = getMetaDataRS(met, GET_IMPORTED_KEYS, new String [] {"", "APP", "REFACTSETNULL"}, null, null, null); if (refrs.next()) { if (refrs.getShort(11) != DatabaseMetaData.importedKeySetNull) System.out.println("\ngetImportedKeys - delete SET NULL Failed - action = " + refrs.getShort(11) + " required value = " + DatabaseMetaData.importedKeySetNull); else System.out.println("\ngetImportedKeys - delete SET NULL Passed"); } else System.out.println("\ngetImportedKeys - SET NULL Failed no rows"); refrs.close(); refrs = getMetaDataRS(met, GET_IMPORTED_KEYS, new String [] {"", "APP", "REFACTRESTRICT"}, null, null, null); if (refrs.next()) { // test update rule if (refrs.getShort(11) != DatabaseMetaData.importedKeyRestrict) System.out.println("\ngetImportedKeys - update Restrict Failed - action = " + refrs.getShort(11) + " required value = " + DatabaseMetaData.importedKeyRestrict); else System.out.println("\ngetImportedKeys - update Restrict Passed"); } else System.out.println("\ngetImportedKeys - update Restrict Failed no rows"); refrs.close(); refrs = getMetaDataRS(met, GET_IMPORTED_KEYS, new String [] {"", "APP", "REFACTNOACTION"}, null, null, null); if (refrs.next()) { if (refrs.getShort(11) != DatabaseMetaData.importedKeyNoAction) System.out.println("\ngetImportedKeys - update NO ACTION Failed - action = " + refrs.getShort(11) + " required value = " + DatabaseMetaData.importedKeyNoAction); else System.out.println("\ngetImportedKeys - update NO ACTION Passed"); } else System.out.println("\ngetImportedKeys - update NO ACTION Failed no rows"); refrs.close(); System.out.println("\ngetExportedKeys('',null,null,'','APP','REFACTION1' ):"); dumpRS(GET_EXPORTED_KEYS, getMetaDataRS(met, GET_EXPORTED_KEYS, new String [] {"", "APP", "REFACTION1"}, null, null, null)); System.out.println("---------------------------------------"); // drop referential action test tables s.execute("drop table refactnone"); s.execute("drop table refactupdrestrict"); s.execute("drop table refactupdnoaction"); s.execute("drop table refactrestrict"); s.execute("drop table refactnoaction"); s.execute("drop table refactcascade"); s.execute("drop table refactsetnull"); s.execute("drop table refaction1"); // test beetle 5195 s.execute("create table t1 (c1 int not null, c2 int, c3 int default null, c4 char(10) not null, c5 char(10) default null, c6 char(10) default 'NULL', c7 int default 88)"); String schema = "APP"; String tableName = "T1"; DatabaseMetaData dmd = con.getMetaData(); System.out.println("getColumns for '" + tableName + "'"); rs = getMetaDataRS(dmd, GET_COLUMNS, new String [] {null, schema, tableName, null}, null, null, null); try { while (rs.next()) { String col = rs.getString(4); String type = rs.getString(6); String defval = rs.getString(13); if (defval == null) System.out.println(" Next line is real null."); System.out.println("defval for col " + col + " type " + type + " DEFAULT '" + defval + "' wasnull " + rs.wasNull()); } } finally { if (rs != null) rs.close(); } s.execute("drop table t1"); // test DERBY-655, DERBY-1343 // If a table has duplicate backing index, then it will share the // physical conglomerate with the existing index, but the duplicate // indexes should have their own unique logical congomerates // associated with them. That way, it will be possible to // distinguish the 2 indexes in SYSCONGLOMERATES from each other. s.execute("CREATE TABLE Derby655t1(c11_ID BIGINT NOT NULL)"); s.execute("CREATE TABLE Derby655t2 (c21_ID BIGINT NOT NULL primary key)"); s.execute("ALTER TABLE Derby655t1 ADD CONSTRAINT F_12 Foreign Key (c11_ID) REFERENCES Derby655t2 (c21_ID) ON DELETE CASCADE ON UPDATE NO ACTION"); s.execute("CREATE TABLE Derby655t3(c31_ID BIGINT NOT NULL primary key)"); s.execute("ALTER TABLE Derby655t2 ADD CONSTRAINT F_443 Foreign Key (c21_ID) REFERENCES Derby655t3(c31_ID) ON DELETE CASCADE ON UPDATE NO ACTION"); dmd = con.getMetaData(); System.out.println("\ngetImportedKeys('',null,null,'','APP','Derby655t1' ):"); dumpRS(met.getImportedKeys("", "APP", "DERBY655T1")); s.execute("drop table Derby655t1"); s.execute("drop table Derby655t2"); s.execute("drop table Derby655t3"); // tiny test moved over from no longer used metadata2.sql // This checks for a bug where you get incorrect behavior on a nested connection. // if you do not get an error, the bug does not occur. s.execute("create procedure isReadO() "+ "language java external name " + "'org.apache.derbyTesting.functionTests.tests.jdbcapi.metadata.isro'" + " parameter style java"); s.execute("call isReadO()"); s.close(); if (con.getAutoCommit() == false) con.commit(); con.close(); } catch (SQLException e) { dumpSQLExceptions(e); } catch (Throwable e) { System.out.println("FAIL -- unexpected exception:"); e.printStackTrace(System.out); } System.out.println("Test metadata finished"); } static protected void dumpSQLExceptions (SQLException se) { System.out.println("FAIL -- unexpected exception"); while (se != null) { System.out.print("SQLSTATE("+se.getSQLState()+"):"); se.printStackTrace(System.out); se = se.getNextException(); } } /** * This method is responsible for executing a metadata query and returning * the result set. We do it like this so that the metadata.java and * odbc_metadata.java classes can implement this method in their * own ways (which is needed because we have to extra work to * get the ODBC versions of the metadata). */ abstract protected ResultSet getMetaDataRS(DatabaseMetaData dmd, int procId, String [] sArgs, String [] argArray, int [] iArgs, boolean [] bArgs) throws SQLException; /** * Dump the values in the received result set to output. */ protected void dumpRS(ResultSet rs) throws SQLException { dumpRS(IGNORE_PROC_ID, rs); } /** * Dump the values in the received result set to output. */ abstract protected void dumpRS(int procId, ResultSet s) throws SQLException; /** * Create a connect based on the test arguments passed in. */ protected Connection createConnection(String[] args) throws Exception { Connection con; // use the ij utility to read the property file and // make the initial connection. ij.getPropertyArg(args); con = ij.startJBMS(); //con.setAutoCommit(true); // make sure it is true con.setAutoCommit(false); return con; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -