OpenJPA-525: Applied Amy's patch OPENJPA-525-3-branch1.1.x.patch . Also merged revision 79066 at trunk that renamed misnamed test classes.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/1.1.x@807362 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David Ezzio 2009-08-24 20:18:38 +00:00
parent 539660ebaa
commit dbf69ac79d
4 changed files with 174 additions and 169 deletions

View File

@ -30,6 +30,7 @@ import java.sql.Ref;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
@ -666,12 +667,12 @@ public abstract class AbstractResult
public Object getObject(Object obj, int metaType, Object arg)
throws SQLException {
return getObjectInternal(translate(obj, null), metaType, arg, null);
return getObjectInternal(obj, metaType, arg, null);
}
public Object getObject(Column col, Object arg, Joins joins)
throws SQLException {
return getObjectInternal(translate(col, joins), col.getJavaType(),
return getObjectInternal(col, col.getJavaType(),
arg, joins);
}
@ -736,15 +737,17 @@ public abstract class AbstractResult
public String getString(Object obj)
throws SQLException {
return getStringInternal(translate(obj, null), null);
return getStringInternal(translate(obj, null), null,
obj instanceof Column && ((Column) obj).getType() == Types.CLOB);
}
public String getString(Column col, Joins joins)
throws SQLException {
return getStringInternal(translate(col, joins), joins);
return getStringInternal(translate(col, joins), joins,
col.getType() == Types.CLOB);
}
protected String getStringInternal(Object obj, Joins joins)
protected String getStringInternal(Object obj, Joins joins, boolean isClobString)
throws SQLException {
Object val = checkNull(getObjectInternal(obj, JavaTypes.STRING,
null, joins));
@ -810,7 +813,8 @@ public abstract class AbstractResult
/**
* Translate the user-given id or column. This method is called before
* delegating to any <code>get*Internal</code> methods. Return the
* delegating to any <code>get*Internal</code> methods with the exception of
* <code>getObjectInternal</code>. Return the
* original value by default.
*/
protected Object translate(Object obj, Joins joins)

View File

@ -357,6 +357,9 @@ public class ResultSetResult
if (metaTypeCode == -1 && obj instanceof Column)
metaTypeCode = ((Column) obj).getJavaType();
boolean isClob = (obj instanceof Column) ? ((Column) obj).getType() == Types.CLOB : false;
obj = translate(obj, joins);
Object val = null;
switch (metaTypeCode) {
case JavaTypes.BOOLEAN:
@ -393,7 +396,7 @@ public class ResultSetResult
val = new Short(getShortInternal(obj, joins));
break;
case JavaTypes.STRING:
return getStringInternal(obj, joins);
return getStringInternal(obj, joins, isClob);
case JavaTypes.OBJECT:
return _dict
.getBlobObject(_rs, ((Number) obj).intValue(), _store);
@ -462,10 +465,11 @@ public class ResultSetResult
return _dict.getShort(_rs, ((Number) obj).intValue());
}
protected String getStringInternal(Object obj, Joins joins)
protected String getStringInternal(Object obj, Joins joins, boolean isClobString)
throws SQLException {
if (obj instanceof Column && ((Column) obj).getType() == Types.CLOB)
return _dict.getClobString(_rs, findObject(obj, joins));
if (isClobString) {
return _dict.getClobString(_rs, ((Number) obj).intValue());
}
return _dict.getString(_rs, ((Number) obj).intValue());
}
@ -489,9 +493,6 @@ public class ResultSetResult
throws SQLException {
if (obj instanceof Number)
return obj;
// getStringInternal will take care the translation
if (obj instanceof Column && ((Column) obj).getType() == Types.CLOB)
return obj;
return Numbers.valueOf(findObject(obj, joins));
}

View File

@ -1,78 +1,78 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.openjpa.jdbc.meta.strats;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* Defines all the abstract methods from AbstractLobTest to tests the
* the LOB support with an InputStream.
*
* @author Ignacio Andreu
* @since 1.1.0
*/
public class InputStreamLobTest extends AbstractLobTest {
protected LobEntity newLobEntity(String s, int id) {
InputStreamLobEntity isle = new InputStreamLobEntity();
isle.setId(id);
if (s != null) {
isle.setStream(new ByteArrayInputStream(s.getBytes()));
} else {
isle.setStream(null);
}
return isle;
}
protected LobEntity newLobEntityForLoadContent(String s, int id) {
InputStreamLobEntity isle = new InputStreamLobEntity();
isle.setId(id);
isle.setStream(new InputStreamWrapper(s));
return isle;
}
protected Class getLobEntityClass() {
return InputStreamLobEntity.class;
}
protected String getSelectQuery() {
return "SELECT o FROM InputStreamLobEntity o";
}
protected String getStreamContentAsString(Object o) throws IOException {
InputStream is = (InputStream) o;
String content = "";
byte[] bs = new byte[4];
int read = -1;
do {
read = is.read(bs);
if (read == -1) {
return content;
}
content = content + (new String(bs)).substring(0, read);
} while (true);
}
protected void changeStream(LobEntity le, String s) {
le.setStream(new ByteArrayInputStream(s.getBytes()));
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.openjpa.jdbc.meta.strats;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* Defines all the abstract methods from AbstractLobTest to tests the
* the LOB support with an InputStream.
*
* @author Ignacio Andreu
* @since 1.1.0
*/
public class TestInputStreamLob extends AbstractLobTest {
protected LobEntity newLobEntity(String s, int id) {
InputStreamLobEntity isle = new InputStreamLobEntity();
isle.setId(id);
if (s != null) {
isle.setStream(new ByteArrayInputStream(s.getBytes()));
} else {
isle.setStream(null);
}
return isle;
}
protected LobEntity newLobEntityForLoadContent(String s, int id) {
InputStreamLobEntity isle = new InputStreamLobEntity();
isle.setId(id);
isle.setStream(new InputStreamWrapper(s));
return isle;
}
protected Class getLobEntityClass() {
return InputStreamLobEntity.class;
}
protected String getSelectQuery() {
return "SELECT o FROM InputStreamLobEntity o";
}
protected String getStreamContentAsString(Object o) throws IOException {
InputStream is = (InputStream) o;
String content = "";
byte[] bs = new byte[4];
int read = -1;
do {
read = is.read(bs);
if (read == -1) {
return content;
}
content = content + (new String(bs)).substring(0, read);
} while (true);
}
protected void changeStream(LobEntity le, String s) {
le.setStream(new ByteArrayInputStream(s.getBytes()));
}
}

View File

@ -1,78 +1,78 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.openjpa.jdbc.meta.strats;
import java.io.CharArrayReader;
import java.io.IOException;
import java.io.Reader;
/**
* Defines all the abstract methods from AbstractLobTest to tests the
* the LOB support with a Reader.
*
* @author Ignacio Andreu
* @since 1.1.0
*/
public class ReaderLobTest extends AbstractLobTest {
protected LobEntity newLobEntity(String s, int id) {
ReaderLobEntity rle = new ReaderLobEntity();
rle.setId(id);
if (s != null) {
rle.setStream(new CharArrayReader(s.toCharArray()));
} else {
rle.setStream(null);
}
return rle;
}
protected LobEntity newLobEntityForLoadContent(String s, int id) {
ReaderLobEntity rle = new ReaderLobEntity();
rle.setId(id);
rle.setStream(new ReaderWrapper(s));
return rle;
}
protected Class getLobEntityClass() {
return ReaderLobEntity.class;
}
protected String getSelectQuery() {
return "SELECT o FROM ReaderLobEntity o";
}
protected String getStreamContentAsString(Object o) throws IOException {
Reader r = (Reader) o;
String content = "";
char[] cs = new char[4];
int read = -1;
do {
read = r.read(cs);
if (read == -1) {
return content;
}
content = content + (new String(cs)).substring(0, read);
} while (true);
}
protected void changeStream(LobEntity le, String s) {
le.setStream(new CharArrayReader(s.toCharArray()));
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.openjpa.jdbc.meta.strats;
import java.io.CharArrayReader;
import java.io.IOException;
import java.io.Reader;
/**
* Defines all the abstract methods from AbstractLobTest to tests the
* the LOB support with a Reader.
*
* @author Ignacio Andreu
* @since 1.1.0
*/
public class TestReaderLob extends AbstractLobTest {
protected LobEntity newLobEntity(String s, int id) {
ReaderLobEntity rle = new ReaderLobEntity();
rle.setId(id);
if (s != null) {
rle.setStream(new CharArrayReader(s.toCharArray()));
} else {
rle.setStream(null);
}
return rle;
}
protected LobEntity newLobEntityForLoadContent(String s, int id) {
ReaderLobEntity rle = new ReaderLobEntity();
rle.setId(id);
rle.setStream(new ReaderWrapper(s));
return rle;
}
protected Class getLobEntityClass() {
return ReaderLobEntity.class;
}
protected String getSelectQuery() {
return "SELECT o FROM ReaderLobEntity o";
}
protected String getStreamContentAsString(Object o) throws IOException {
Reader r = (Reader) o;
String content = "";
char[] cs = new char[4];
int read = -1;
do {
read = r.read(cs);
if (read == -1) {
return content;
}
content = content + (new String(cs)).substring(0, read);
} while (true);
}
protected void changeStream(LobEntity le, String s) {
le.setStream(new CharArrayReader(s.toCharArray()));
}
}