Examples of LoopingAlphabetReader


Examples of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader

    public void testPositionWithString_CJK()
            throws IOException, SQLException {
        final long prefix = 11L;
        final long postfix = 90L;
        char[] tmpChar = new char[1];
        LoopingAlphabetReader tokenSrc =
            new LoopingAlphabetReader(1L, CharAlphabet.cjkSubset());
        tokenSrc.read(tmpChar);
        String token = String.copyValueOf(tmpChar);
        insertDataWithToken(token, prefix, postfix, SET_CHARACTER_STREAM);
        //insertDataWithToken(token, prefix, 2*1024-7, SET_CHARACTER_STREAM);
        executeTestPositionWithStringToken(token, prefix);
    }
View Full Code Here

Examples of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader

                                     long pre, long post, int mode)
            throws IOException, SQLException {
        long total = 0;
        switch (mode) {
            case SET_STRING: {
                Reader charIn = new LoopingAlphabetReader(pre);
                total += transferData(charIn, TRANSFER_BUFFER_SIZE);
                this.clob.setString(pre +1, token);
                total += token.length();
                charIn = new LoopingAlphabetReader(post);
                total += transferData(charIn, TRANSFER_BUFFER_SIZE);
                break;
            } case SET_ASCII_STREAM: {
                OutputStream asciiOut = this.clob.setAsciiStream(1L);
                InputStream asciiIn = new LoopingAlphabetStream(pre);
                total += transferData(asciiIn, asciiOut, TRANSFER_BUFFER_SIZE);
                byte[] tokenBytes = token.getBytes("ISO-8859-1");
                asciiOut.write(tokenBytes, 0, tokenBytes.length);
                total += tokenBytes.length;
                asciiIn = new LoopingAlphabetStream(post);
                total += transferData(asciiIn, asciiOut, TRANSFER_BUFFER_SIZE);
                break;
            } case SET_CHARACTER_STREAM: {
                Writer charOut = this.clob.setCharacterStream(1L);
                Reader charIn = new LoopingAlphabetReader(pre);
                total += transferData(charIn, charOut, TRANSFER_BUFFER_SIZE);
                charOut.write(token);
                total += token.length();
                charIn = new LoopingAlphabetReader(post);
                total += transferData(charIn, charOut, TRANSFER_BUFFER_SIZE);
                break;
            } default:
                throw new IllegalArgumentException(
                    "Unknown insertion mode: " + mode);
View Full Code Here

Examples of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader

       
        ps.setString(1, clobSize +"");

        // - set the value of the input parameter to the input stream
        ps.setCharacterStream(2,
                new LoopingAlphabetReader(clobSize, a1), clobSize);
        ps.execute();
        closeStatement(ps);
        commit();

        // Now executing update to fire trigger
        s.executeUpdate("update LOB1 set str1 = str1 || ' '");
      
       
        s.executeUpdate("drop table lob1");
        s.executeUpdate("drop table t_lob1_log");

        // now referencing the lob column
        trig = " create trigger t_lob1 after update of c_lob on lob1 ";
        trig = trig + " REFERENCING OLD AS old NEW AS new FOR EACH ROW MODE DB2SQL ";
        trig = trig + " insert into t_lob1_log(oldvalue, newvalue) values (old.c_lob, new.c_lob)";

        s.executeUpdate("create table LOB1 (str1 Varchar(80), c_lob CLOB(50M))");
        s.executeUpdate("create table t_lob1_log(oldvalue CLOB(50M), newvalue  CLOB(50M), chng_time timestamp default current_timestamp)");
        s.executeUpdate(trig);
        commit();     

        ps = prepareStatement("INSERT INTO LOB1 VALUES (?, ?)");
       
        ps.setString(1, clobSize +"");

        // - set the value of the input parameter to the input stream
        ps.setCharacterStream(2,
                new LoopingAlphabetReader(clobSize, a1), clobSize);
        ps.execute();
        closeStatement(ps);
        commit();

        // Now executing update to fire trigger
        ps = prepareStatement("update LOB1 set c_lob = ?");
        ps.setCharacterStream(1,
                new LoopingAlphabetReader(clobSize, a2), clobSize);
        ps.execute();
        closeStatement(ps);
        commit();       

        s.executeUpdate("drop table lob1");
        s.executeUpdate("drop table t_lob1_log");
       
        //      now referencing the lob column twice
        trig = " create trigger t_lob1 after update of c_lob on lob1 ";
        trig = trig + " REFERENCING OLD AS old NEW AS new FOR EACH ROW MODE DB2SQL ";
        trig = trig + " insert into t_lob1_log(oldvalue, newvalue, oldvalue_again, newvalue_again) values (old.c_lob, new.c_lob, old.c_lob, new.c_lob)";

        s.executeUpdate("create table LOB1 (str1 Varchar(80), c_lob CLOB(50M))");
        s.executeUpdate("create table t_lob1_log(oldvalue CLOB(50M), newvalue  CLOB(50M), oldvalue_again CLOB(50M), newvalue_again CLOB(50M), chng_time timestamp default current_timestamp)");
        s.executeUpdate(trig);
        commit();     

        ps = prepareStatement("INSERT INTO LOB1 VALUES (?, ?)");
       
        ps.setString(1, clobSize +"");

        // - set the value of the input parameter to the input stream
        ps.setCharacterStream(2,
                new LoopingAlphabetReader(clobSize, a1), clobSize);
        ps.execute();
        closeStatement(ps);
        commit();

        // Now executing update to fire trigger
        ps = prepareStatement("update LOB1 set c_lob = ?");
        ps.setCharacterStream(1,
                new LoopingAlphabetReader(clobSize, a2), clobSize);
        ps.execute();
        closeStatement(ps);
        commit();
       
        // check log table.
        ResultSet rs = s.executeQuery("SELECT * from t_lob1_log");
        rs.next();
              
        assertEquals(new LoopingAlphabetReader(clobSize, a1),
                     rs.getCharacterStream(1));

        assertEquals(new LoopingAlphabetReader(clobSize, a2),
                     rs.getCharacterStream(2));

        assertEquals(new LoopingAlphabetReader(clobSize, a1),
                     rs.getCharacterStream(3));

        assertEquals(new LoopingAlphabetReader(clobSize, a2),
                     rs.getCharacterStream(4));

        rs.close();
       
        s.executeUpdate("drop table lob1");
View Full Code Here

Examples of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader

        ps.setString(1, clobSize +"");


        // - set the value of the input parameter to the input stream
        ps.setCharacterStream(2,
                new LoopingAlphabetReader(clobSize, a1), clobSize);
        ps.execute();
        conn.commit();


        PreparedStatement ps2 = prepareStatement("update LOB1 set c_lob = ? where str1 = '" + clobSize + "'");
        ps2.setCharacterStream(1,
                new LoopingAlphabetReader(clobSize, a2), clobSize);
        ps2.executeUpdate();
        conn.commit();
        //   --- reading the clob make sure it was updated
        ResultSet rs = s.executeQuery("SELECT * FROM LOB1 where str1 = '" + clobSize + "'");
        rs.next();
       
        assertEquals(new LoopingAlphabetReader(clobSize, a2),
                     rs.getCharacterStream(2));
        rs.close();
        s.executeUpdate("drop table lob1");
        s.executeUpdate("drop table t_lob1_log");
       
View Full Code Here

Examples of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader

                "select dClob, length from largeClobs where id = 4");
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            Clob clob = rs.getClob(1);
            int remaining = rs.getInt(2);
            Reader myReader = new LoopingAlphabetReader(remaining);
            if (modifyClob) {
                // Modify the Clob to create a temporary copy in memory or on
                // disk (depends on the Clob size).
                long modifyStart = System.currentTimeMillis();
                clob.setString(++remaining, "X");
                println("Clob modification duration: " +
                        (System.currentTimeMillis() - modifyStart) + " ms");
            }
            long pos = 1;
            while (remaining > 0) {
                String str = clob.getSubString(
                        pos, Math.min(MAX_BSIZE, remaining));
                myReader.skip(Math.min(MAX_BSIZE, remaining) -1);
                pos += str.length();
                remaining -= str.length();
                // Avoid failure on the last char when Clob is modified.
                if (!modifyClob || remaining != 0) {
                    assertEquals(myReader.read(), str.charAt(str.length() -1));
                }
            }
        }
        rs.close();
    }
View Full Code Here

Examples of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader

                "select dClob, length from largeClobs where id = 5");
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            Clob clob = rs.getClob(1);
            int remaining = rs.getInt(2);
            Reader myReader = new LoopingAlphabetReader(remaining);
            if (modifyClob) {
                // Modify the Clob to create a temporary copy in memory or on
                // disk (depends on the Clob size).
                long modifyStart = System.currentTimeMillis();
                clob.setString(++remaining, "X");
                println("Clob modification duration: " +
                        (System.currentTimeMillis() - modifyStart) + " ms");
            }
            Reader clobReader = clob.getCharacterStream();
            char[] buf = new char[MAX_BSIZE];
            while (remaining > 0) {
                int read = clobReader.read(buf, 0, Math.min(MAX_BSIZE, remaining));
                myReader.skip(read -1);
                remaining -= read;
                assertEquals(myReader.read(), buf[read -1]);
            }
        }
        rs.close();
       
    }
View Full Code Here

Examples of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader

            // Insert some large Clobs.
            final int size = largeClobSizeMB*1024*1024; // 15 MB default
            for (int clobCounter = 1; clobCounter < 11; clobCounter++) {
                largeClobInsert.setInt(1, clobCounter);
                largeClobInsert.setCharacterStream(
                        2, new LoopingAlphabetReader(size), size);
                largeClobInsert.setInt(3, size);
                largeClobInsert.executeUpdate();
                println("Inserted large Clob #" + (clobCounter -1));
            }
            con.commit();
View Full Code Here

Examples of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader

      int blobLength = Rn.nextInt(102400 - 0 + 1) + 0;//to create a stream of random length between 0 and 100K
      streamIn = new LoopingAlphabetStream(blobLength);
      ps.setBinaryStream(3, streamIn, blobLength);
      //"t_clob
      int clobLength = Rn.nextInt(102400 - 0 + 1) + 0;//to create a stream of random length between 0 and 100K
      streamReader = new LoopingAlphabetReader(clobLength, CharAlphabet
          .modernLatinLowercase());
      ps.setCharacterStream(4, streamReader, clobLength);
      //"t_ndate"
      dt.setTime(Math.abs(Rn.nextLong() / 150000));
      ps.setDate(5, dt);
View Full Code Here

Examples of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader

      ps2.setBinaryStream(1, streamIn, blobLength);

      break;
    case TCLOB:
      int clobLength = Rn.nextInt(102400 - 0 + 1) + 0;//to create a stream of random length between 0 and 100K
      streamReader = new LoopingAlphabetReader(clobLength, CharAlphabet
          .modernLatinLowercase());
      ps2.setCharacterStream(1, streamReader, clobLength);
      break;
    }
    int rows = 0;
View Full Code Here

Examples of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader

     * \u0000 at positions after the size of the internal buffer.
     */
    public void testGetSubString_BiggerThanInternalBuffer()
            throws IOException, SQLException {
        int stringLength = 1*1024*1024; // 1 M characters
        transferData(new LoopingAlphabetReader(stringLength),
                     this.clob.setCharacterStream(1L),
                     TRANSFER_BUFFER_SIZE);
        String obtained = this.clob.getSubString(1, stringLength);
        assertEquals("Incorrect string length",
            stringLength, obtained.length());
        // Obtain the string we inserted for comparison.
        CharArrayWriter charWriter = new CharArrayWriter();
        transferData(new LoopingAlphabetReader(stringLength), charWriter,
                                               TRANSFER_BUFFER_SIZE);
        assertEquals("String do not match",
            charWriter.toString(), obtained);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.