⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spillhash.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            {
                System.out.println( "Invalid value in first join column.");
                errorCount++;
                continue;
            }
            if( col1Val > 0)
            {
                if( joinRowFound.get( col1Val - 1))
                {
                    System.out.println( "Multiple rows for value " + col1Val);
                    errorCount++;
                }
                joinRowFound.set( col1Val - 1);
                String col2Val = trim( rs.getString(2));
                String col3Val = trim( rs.getString(3));
                if( !( ca2Val( col1Val).equals( col2Val) && cb2Val( col1Val).equals( col3Val)))
                {
                    System.out.println( "Incorrect value in column 2 or 3 of join.");
                    errorCount++;
                }
            }
            else // col1Val <= 0, there are duplicates in the source tables
            {
                int dupKeyIdx = -col1Val;
                int col2Idx = findDupVal( rs, 2, 'A', dupKeyIdx, dupVals);
                int col3Idx = findDupVal( rs, 3, 'B', dupKeyIdx, dupVals);
                if( col2Idx < 0 || col3Idx < 0)
                    continue;

                int idx = col2Idx + dupCount[dupKeyIdx]*col3Idx;
                if( dupsFound[dupKeyIdx].get( idx))
                {
                    System.out.println( "Repeat of row with key value 0");
                    errorCount++;
                }
                dupsFound[dupKeyIdx].set( idx);
            }
        };
        if( count != expectedRowCount)
        {
            System.out.println( "Incorrect number of rows in join.");
            errorCount++;
        }
        rs.close();
    } // end of runJoin

    private static int findDupVal( ResultSet rs, int col, char prefix, int keyIdx, String[][][] dupVals)
        throws SQLException
    {
        String colVal = rs.getString(col);
        if( colVal != null && colVal.length() > 1 || colVal.charAt(0) == prefix)
        {
            colVal = trim( colVal.substring( 1));
            int dupIdx = 0;
            for( int i = 0; i < dupVals.length; i++)
            {
                if( keyIdx < dupVals[i].length)
                {
                    for( int j = 0; j < dupVals[i][keyIdx].length; j++, dupIdx++)
                    {
                        if( colVal.equals( dupVals[i][keyIdx][j]))
                            return dupIdx;
                    }
                }
            }
        }
        System.out.println( "Incorrect value in column " + col + " of join with duplicate keys.");
        errorCount++;
        return -1;
    } // end of findDupVal
        
    private static String trim( String str)
    {
        if( str == null)
            return str;
        return str.trim();
    }
    
    private static void runDistinct( Connection conn, int maxColValue, String[][][] dupVals)
        throws SQLException
    {
        System.out.println( "Running distinct");
        ResultSet rs = distinctStmt.executeQuery();
        checkAllCa1( rs, false, false, maxColValue, dupVals, "DISTINCT");
    }

    private static void checkAllCa1( ResultSet rs,
                                     boolean expectDups,
                                     boolean holdOverCommit,
                                     int maxColValue,
                                     String[][][] dupVals,
                                     String label)
        throws SQLException
    {
        int dupKeyCount = 0;
        for( int i = 0; i < dupVals.length; i++)
        {
            if( dupVals[i].length > dupKeyCount)
                dupKeyCount = dupVals[i].length;
        }
        int[] expectedDupCount = new int[dupKeyCount];
        int[] dupFoundCount = new int[dupKeyCount];
        for( int i = 0; i < dupKeyCount; i++)
        {
            
            dupFoundCount[i] = 0;
            if( !expectDups)
                expectedDupCount[i] = 1;
            else
            {
                expectedDupCount[i] = 0;
                for( int j = 0; j < dupVals.length; j++)
                {
                    if( i < dupVals[j].length)
                        expectedDupCount[i] += dupVals[j][i].length;
                }
            }
        }
        BitSet found = new BitSet( maxColValue);
        int count = 0;
        boolean nullFound = false;
        try
        {
            for( count = 0; rs.next();)
            {
                int col1Val = rs.getInt(1);
                if( rs.wasNull())
                {
                    if( nullFound)
                    {
                        System.out.println( "Too many nulls returned by " + label);
                        errorCount++;
                        continue;
                    }
                    nullFound = true;
                    continue;
                }
                if( col1Val <= -dupKeyCount || col1Val > maxColValue)
                {
                    System.out.println( "Invalid value returned by " + label);
                    errorCount++;
                    continue;
                }
                if( col1Val <= 0)
                {
                    dupFoundCount[ -col1Val]++;
                    if( !expectDups)
                    {
                        if( dupFoundCount[ -col1Val] > 1)
                        {
                            System.out.println( label + " returned a duplicate.");
                            errorCount++;
                            continue;
                        }
                    }
                    else if( dupFoundCount[ -col1Val] > expectedDupCount[ -col1Val])
                    {
                        System.out.println( label + " returned too many duplicates.");
                        errorCount++;
                        continue;
                    }
                }
                else
                {
                    if( found.get( col1Val))
                    {
                        System.out.println( label + " returned a duplicate.");
                        errorCount++;
                        continue;
                    }
                    found.set( col1Val);
                    count++;
                }
                if( holdOverCommit)
                {
                    rs.getStatement().getConnection().commit();
                    holdOverCommit = false;
                }
            }
            if( count != maxColValue)
            {
                System.out.println( "Incorrect number of rows in " + label);
                errorCount++;
            }
            for( int i = 0; i < dupFoundCount.length; i++)
            {
                if( dupFoundCount[i] != expectedDupCount[i])
                {
                    System.out.println( "A duplicate key row is missing in " + label);
                    errorCount++;
                    break;
                }
            }
        }
        finally
        {
            rs.close();
        }
    } // End of checkAllCa1

    private static void runCursor( Connection conn, int maxColValue, String[][][] dupVals)
        throws SQLException
    {
        System.out.println( "Running scroll insensitive cursor");
        DatabaseMetaData dmd = conn.getMetaData();
        boolean holdOverCommit = dmd.supportsOpenCursorsAcrossCommit();
        Statement stmt;
        if( holdOverCommit)
            stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                        ResultSet.CONCUR_READ_ONLY,
                                        ResultSet.HOLD_CURSORS_OVER_COMMIT);
        else
            stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                        ResultSet.CONCUR_READ_ONLY);
        ResultSet rs = stmt.executeQuery( "SELECT ca1 FROM ta");
        checkAllCa1( rs, true, holdOverCommit, maxColValue, dupVals, "scroll insensitive cursor");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -