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.SQLException;
import java.sql.Time; import java.sql.Time;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.sql.Types;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@ -666,12 +667,12 @@ public abstract class AbstractResult
public Object getObject(Object obj, int metaType, Object arg) public Object getObject(Object obj, int metaType, Object arg)
throws SQLException { 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) public Object getObject(Column col, Object arg, Joins joins)
throws SQLException { throws SQLException {
return getObjectInternal(translate(col, joins), col.getJavaType(), return getObjectInternal(col, col.getJavaType(),
arg, joins); arg, joins);
} }
@ -736,15 +737,17 @@ public abstract class AbstractResult
public String getString(Object obj) public String getString(Object obj)
throws SQLException { 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) public String getString(Column col, Joins joins)
throws SQLException { 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 { throws SQLException {
Object val = checkNull(getObjectInternal(obj, JavaTypes.STRING, Object val = checkNull(getObjectInternal(obj, JavaTypes.STRING,
null, joins)); null, joins));
@ -810,7 +813,8 @@ public abstract class AbstractResult
/** /**
* Translate the user-given id or column. This method is called before * 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. * original value by default.
*/ */
protected Object translate(Object obj, Joins joins) protected Object translate(Object obj, Joins joins)

View File

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

View File

@ -1,78 +1,78 @@
/* /*
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the * to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at * with the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, * Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an * software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.openjpa.jdbc.meta.strats; package org.apache.openjpa.jdbc.meta.strats;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
/** /**
* Defines all the abstract methods from AbstractLobTest to tests the * Defines all the abstract methods from AbstractLobTest to tests the
* the LOB support with an InputStream. * the LOB support with an InputStream.
* *
* @author Ignacio Andreu * @author Ignacio Andreu
* @since 1.1.0 * @since 1.1.0
*/ */
public class InputStreamLobTest extends AbstractLobTest { public class TestInputStreamLob extends AbstractLobTest {
protected LobEntity newLobEntity(String s, int id) { protected LobEntity newLobEntity(String s, int id) {
InputStreamLobEntity isle = new InputStreamLobEntity(); InputStreamLobEntity isle = new InputStreamLobEntity();
isle.setId(id); isle.setId(id);
if (s != null) { if (s != null) {
isle.setStream(new ByteArrayInputStream(s.getBytes())); isle.setStream(new ByteArrayInputStream(s.getBytes()));
} else { } else {
isle.setStream(null); isle.setStream(null);
} }
return isle; return isle;
} }
protected LobEntity newLobEntityForLoadContent(String s, int id) { protected LobEntity newLobEntityForLoadContent(String s, int id) {
InputStreamLobEntity isle = new InputStreamLobEntity(); InputStreamLobEntity isle = new InputStreamLobEntity();
isle.setId(id); isle.setId(id);
isle.setStream(new InputStreamWrapper(s)); isle.setStream(new InputStreamWrapper(s));
return isle; return isle;
} }
protected Class getLobEntityClass() { protected Class getLobEntityClass() {
return InputStreamLobEntity.class; return InputStreamLobEntity.class;
} }
protected String getSelectQuery() { protected String getSelectQuery() {
return "SELECT o FROM InputStreamLobEntity o"; return "SELECT o FROM InputStreamLobEntity o";
} }
protected String getStreamContentAsString(Object o) throws IOException { protected String getStreamContentAsString(Object o) throws IOException {
InputStream is = (InputStream) o; InputStream is = (InputStream) o;
String content = ""; String content = "";
byte[] bs = new byte[4]; byte[] bs = new byte[4];
int read = -1; int read = -1;
do { do {
read = is.read(bs); read = is.read(bs);
if (read == -1) { if (read == -1) {
return content; return content;
} }
content = content + (new String(bs)).substring(0, read); content = content + (new String(bs)).substring(0, read);
} while (true); } while (true);
} }
protected void changeStream(LobEntity le, String s) { protected void changeStream(LobEntity le, String s) {
le.setStream(new ByteArrayInputStream(s.getBytes())); le.setStream(new ByteArrayInputStream(s.getBytes()));
} }
} }

View File

@ -1,78 +1,78 @@
/* /*
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the * to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at * with the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, * Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an * software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.openjpa.jdbc.meta.strats; package org.apache.openjpa.jdbc.meta.strats;
import java.io.CharArrayReader; import java.io.CharArrayReader;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
/** /**
* Defines all the abstract methods from AbstractLobTest to tests the * Defines all the abstract methods from AbstractLobTest to tests the
* the LOB support with a Reader. * the LOB support with a Reader.
* *
* @author Ignacio Andreu * @author Ignacio Andreu
* @since 1.1.0 * @since 1.1.0
*/ */
public class ReaderLobTest extends AbstractLobTest { public class TestReaderLob extends AbstractLobTest {
protected LobEntity newLobEntity(String s, int id) { protected LobEntity newLobEntity(String s, int id) {
ReaderLobEntity rle = new ReaderLobEntity(); ReaderLobEntity rle = new ReaderLobEntity();
rle.setId(id); rle.setId(id);
if (s != null) { if (s != null) {
rle.setStream(new CharArrayReader(s.toCharArray())); rle.setStream(new CharArrayReader(s.toCharArray()));
} else { } else {
rle.setStream(null); rle.setStream(null);
} }
return rle; return rle;
} }
protected LobEntity newLobEntityForLoadContent(String s, int id) { protected LobEntity newLobEntityForLoadContent(String s, int id) {
ReaderLobEntity rle = new ReaderLobEntity(); ReaderLobEntity rle = new ReaderLobEntity();
rle.setId(id); rle.setId(id);
rle.setStream(new ReaderWrapper(s)); rle.setStream(new ReaderWrapper(s));
return rle; return rle;
} }
protected Class getLobEntityClass() { protected Class getLobEntityClass() {
return ReaderLobEntity.class; return ReaderLobEntity.class;
} }
protected String getSelectQuery() { protected String getSelectQuery() {
return "SELECT o FROM ReaderLobEntity o"; return "SELECT o FROM ReaderLobEntity o";
} }
protected String getStreamContentAsString(Object o) throws IOException { protected String getStreamContentAsString(Object o) throws IOException {
Reader r = (Reader) o; Reader r = (Reader) o;
String content = ""; String content = "";
char[] cs = new char[4]; char[] cs = new char[4];
int read = -1; int read = -1;
do { do {
read = r.read(cs); read = r.read(cs);
if (read == -1) { if (read == -1) {
return content; return content;
} }
content = content + (new String(cs)).substring(0, read); content = content + (new String(cs)).substring(0, read);
} while (true); } while (true);
} }
protected void changeStream(LobEntity le, String s) { protected void changeStream(LobEntity le, String s) {
le.setStream(new CharArrayReader(s.toCharArray())); le.setStream(new CharArrayReader(s.toCharArray()));
} }
} }