Hello Kathey.
Kathey Marsden (JIRA) wrote:
In the email:
http://mail-archives.apache.org/mod_mbox/db-derby-dev/200601.mbox/[EMAIL
PROTECTED]
Bryan asked
What sort of faults are we likely to hit? Are things
like "corrupt page in database" the most likely?
I don't know what is most likely, but I did think of one test case likely to
cause an IOException.
If the reader is in TRANSACTION_READ_UNCOMMITTED isolation mode and then
another connection updated the LOB, the reader should get an IOException. on
the next read.
Reading your comment above, I wrote test code attached to this mail, and
tried executing it with my latest patch, which is not submitted yet.
Then I found no Exception happens at all.
Are there any misunderstanding you in my test code ?
Or is this unlucky success ?
Best regards.
--
/*
Tomohito Nakayama
[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED]
Naka
http://www5.ocn.ne.jp/~tomohito/TopPage.html
*/
/*
Derby - Class org.apache.derbyTesting.functionTests.tests.lang.DirtyReadOfLob
Copyright 1999, 2005 The Apache Software Foundation or its licensors, as
applicable.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.apache.derbyTesting.functionTests.tests.lang;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.io.IOException;
import java.sql.SQLException;
import org.apache.derby.tools.ij;
public class DirtyReadOfLob {
public static void main(String[] args){
try{
ij.getPropertyArg(args);
createTestTable();
Connection conn1 = ij.startJBMS();
Connection conn2 = ij.startJBMS();
testDirtyReadOfLob( conn1,
conn2 );
conn1.close();
conn2.close();
}catch(Throwable t){
t.printStackTrace();
}
}
private static void createTestTable()
throws SQLException,
IllegalAccessException,
ClassNotFoundException,
InstantiationException
{
Connection conn = ij.startJBMS();
Statement createTableSt = conn.createStatement();
createTableSt.execute("create table TEST_TABLE( TEST_COL blob( 512 ))");
createTableSt.close();
PreparedStatement insertLobSt =
conn.prepareStatement("insert into TEST_TABLE( TEST_COL )
values(?)");
insertLobSt.setBinaryStream(1,createOriginalDataInputStream(),512);
insertLobSt.executeUpdate();
insertLobSt.close();
conn.commit();
conn.close();
}
private static void testDirtyReadOfLob(Connection conn1,
Connection conn2)
throws SQLException,
IOException
{
conn1.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
conn2.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
conn1.setAutoCommit(false);
conn2.setAutoCommit(false);
PreparedStatement st = conn1.prepareStatement("select TEST_COL from
TEST_TABLE");
ResultSet rs = st.executeQuery();
rs.next();
InputStream is = rs.getBinaryStream(1);
read256Bytes(is);
updateLobValue(conn2);
conn2.commit();
read256Bytes(is);
is.close();
rs.close();
st.close();
conn1.commit();
}
private static ByteArrayInputStream createOriginalDataInputStream(){
byte[] originalValue = new byte[ 512 ];
for(int i = 0; i < originalValue.length; i ++){
originalValue[i] = (byte) (i % 256);
}
return new ByteArrayInputStream(originalValue);
}
private static ByteArrayInputStream createUpdatedDataInputStream(){
byte[] updatedValue = new byte[ 512 ];
for(int i = 0; i < updatedValue.length; i ++){
updatedValue[i] = (byte) ( (updatedValue.length - i) % 256 );
}
return new ByteArrayInputStream(updatedValue);
}
private static void read256Bytes(InputStream is) throws IOException{
for(int i = 0;
i < 256;
i ++){
System.out.print(is.read());
System.out.print(',');
}
System.out.println();
}
private static void updateLobValue(Connection conn) throws SQLException{
PreparedStatement updateSt = conn.prepareStatement("update TEST_TABLE
set TEST_COL = ?");
updateSt.setBinaryStream(1,createUpdatedDataInputStream(),512);
updateSt.executeUpdate();
updateSt.close();
}
}