Author: mtylenda
Date: Sun May 30 19:27:58 2010
New Revision: 949560
URL: http://svn.apache.org/viewvc?rev=949560&view=rev
Log:
OPENJPA-1248: LOB streaming fixes for MySQL, Oracle, PostgreSQL and SQL Server.
Modified:
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/LobFieldStrategy.java
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java
openjpa/branches/1.3.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties
openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/AbstractLobTest.java
openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/TestInputStreamLob.java
Modified:
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/LobFieldStrategy.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/LobFieldStrategy.java?rev=949560&r1=949559&r2=949560&view=diff
==============================================================================
---
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/LobFieldStrategy.java
(original)
+++
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/LobFieldStrategy.java
Sun May 30 19:27:58 2010
@@ -135,7 +135,7 @@ public class LobFieldStrategy extends Ab
(row, field.getColumns()[0], store, ob, sel);
} else {
store.getDBDictionary().insertClobForStreamingLoad
- (row, field.getColumns()[0], sel);
+ (row, field.getColumns()[0], ob);
}
}
}
Modified:
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java?rev=949560&r1=949559&r2=949560&view=diff
==============================================================================
---
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
(original)
+++
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
Sun May 30 19:27:58 2010
@@ -39,6 +39,7 @@ import java.util.List;
import java.util.Map;
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
import org.apache.openjpa.jdbc.schema.Column;
@@ -1141,18 +1142,14 @@ public class OracleDictionary
buf.append("')");
}
- public void insertBlobForStreamingLoad(Row row, Column col, Object ob)
- throws SQLException {
- if (ob == null)
- col.setType(Types.OTHER);
- row.setNull(col);
- }
-
public void insertClobForStreamingLoad(Row row, Column col, Object ob)
throws SQLException {
- if (ob == null)
+ if (ob == null) {
col.setType(Types.OTHER);
- row.setNull(col);
+ row.setNull(col);
+ } else {
+ row.setClob(col, getEmptyClob());
+ }
}
public int getBatchUpdateCount(PreparedStatement ps) throws SQLException {
@@ -1165,4 +1162,15 @@ public class OracleDictionary
}
return updateSuccessCnt;
}
+
+ @Override
+ public void insertBlobForStreamingLoad(Row row, Column col,
+ JDBCStore store, Object ob, Select sel) throws SQLException {
+ if (ob == null) {
+ col.setType(Types.OTHER);
+ row.setNull(col);
+ } else {
+ row.setBlob(col, getEmptyBlob());
+ }
+ }
}
Modified:
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java?rev=949560&r1=949559&r2=949560&view=diff
==============================================================================
---
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
(original)
+++
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
Sun May 30 19:27:58 2010
@@ -23,13 +23,13 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.security.AccessController;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import java.sql.Timestamp;
import java.sql.Types;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -45,6 +45,7 @@ import org.apache.openjpa.jdbc.schema.Ta
import org.apache.openjpa.kernel.Filters;
import org.apache.openjpa.lib.jdbc.DelegatingConnection;
import org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement;
+import org.apache.openjpa.lib.util.J2DoPrivHelper;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.meta.JavaTypes;
import org.apache.openjpa.util.InternalException;
@@ -54,7 +55,7 @@ import org.postgresql.largeobject.LargeO
import org.postgresql.largeobject.LargeObjectManager;
/**
- * Dictionary for Postgres.
+ * Dictionary for PostgreSQL.
*/
public class PostgresDictionary
extends DBDictionary {
@@ -62,6 +63,9 @@ public class PostgresDictionary
private static final Localizer _loc = Localizer.forPackage
(PostgresDictionary.class);
+ private Method dbcpGetDelegate;
+ private Method connectionUnwrap;
+
/**
* SQL statement to load all sequence schema,name pairs from all schemas.
*/
@@ -363,8 +367,7 @@ public class PostgresDictionary
DelegatingConnection conn = (DelegatingConnection)store
.getConnection();
conn.setAutoCommit(false);
- LargeObjectManager lom = ((PGConnection)conn.getInnermostDelegate())
- .getLargeObjectAPI();
+ LargeObjectManager lom = getLargeObjectManager(conn);
if (rs.getInt(column) != -1) {
LargeObject lo = lom.open(rs.getInt(column));
return lo.getInputStream();
@@ -390,10 +393,9 @@ public class PostgresDictionary
.getConnection();
try {
conn.setAutoCommit(false);
- PGConnection pgconn = (PGConnection)
conn.getInnermostDelegate();
- LargeObjectManager lom = pgconn.getLargeObjectAPI();
- // The create method is valid in versions previous 8.3
- // in 8.3 this methos is deprecated, use createLO
+ LargeObjectManager lom = getLargeObjectManager(conn);
+ // The create method is valid in versions previous to 8.3
+ // in 8.3 this method is deprecated, use createLO
int oid = lom.create();
LargeObject lo = lom.open(oid, LargeObjectManager.WRITE);
OutputStream os = lo.getOutputStream();
@@ -427,13 +429,12 @@ public class PostgresDictionary
int oid = res.getInt(1);
if (oid != -1) {
conn.setAutoCommit(false);
- PGConnection pgconn = (PGConnection)conn
- .getInnermostDelegate();
- LargeObjectManager lom = pgconn.getLargeObjectAPI();
+ LargeObjectManager lom = getLargeObjectManager(conn);
if (ob != null) {
LargeObject lo = lom.open(oid, LargeObjectManager.WRITE);
OutputStream os = lo.getOutputStream();
- copy((InputStream)ob, os);
+ long size = copy((InputStream) ob, os);
+ lo.truncate((int) size);
lo.close();
} else {
lom.delete(oid);
@@ -442,9 +443,7 @@ public class PostgresDictionary
} else {
if (ob != null) {
conn.setAutoCommit(false);
- PGConnection pgconn = (PGConnection)conn
- .getInnermostDelegate();
- LargeObjectManager lom = pgconn.getLargeObjectAPI();
+ LargeObjectManager lom = getLargeObjectManager(conn);
oid = lom.create();
LargeObject lo = lom.open(oid, LargeObjectManager.WRITE);
OutputStream os = lo.getOutputStream();
@@ -488,9 +487,7 @@ public class PostgresDictionary
int oid = res.getInt(1);
if (oid != -1) {
conn.setAutoCommit(false);
- PGConnection pgconn = (PGConnection)conn
- .getInnermostDelegate();
- LargeObjectManager lom = pgconn.getLargeObjectAPI();
+ LargeObjectManager lom = getLargeObjectManager(conn);
lom.delete(oid);
}
} finally {
@@ -502,7 +499,7 @@ public class PostgresDictionary
try { conn.close (); } catch (SQLException e) {}
}
}
-
+
/**
* Determine whether XML column is supported.
*/
@@ -605,6 +602,75 @@ public class PostgresDictionary
}
/**
+ * Get the native PostgreSQL Large Object Manager used for LOB handling.
+ */
+ protected LargeObjectManager getLargeObjectManager(DelegatingConnection
conn) throws SQLException {
+ return getPGConnection(conn).getLargeObjectAPI();
+ }
+
+ /**
+ * Get the native PostgreSQL connection from the given connection.
+ * Various attempts of unwrapping are being performed.
+ */
+ protected PGConnection getPGConnection(DelegatingConnection conn) {
+ Connection innerConn = conn.getInnermostDelegate();
+ if (innerConn instanceof PGConnection) {
+ return (PGConnection) innerConn;
+ }
+ if
(innerConn.getClass().getName().startsWith("org.apache.commons.dbcp")) {
+ return (PGConnection) getDbcpDelegate(innerConn);
+ }
+ return (PGConnection) unwrapConnection(conn, PGConnection.class);
+ }
+
+ /**
+ * Get the delegated connection from the given DBCP connection.
+ *
+ * @param conn must be a DBCP connection
+ * @return connection the DBCP connection delegates to
+ */
+ protected Connection getDbcpDelegate(Connection conn) {
+ Connection delegate = null;
+ try {
+ if (dbcpGetDelegate == null) {
+ Class<?> dbcpConnectionClass =
+
Class.forName("org.apache.commons.dbcp.DelegatingConnection", true,
AccessController
+
.doPrivileged(J2DoPrivHelper.getContextClassLoaderAction()));
+
+ dbcpGetDelegate =
dbcpConnectionClass.getMethod("getInnermostDelegate");
+ }
+ delegate = (Connection) dbcpGetDelegate.invoke(conn);
+ } catch (Exception e) {
+ throw new InternalException(_loc.get("dbcp-unwrap-failed"), e);
+ }
+ if (delegate == null) {
+ throw new InternalException(_loc.get("dbcp-unwrap-failed"));
+ }
+ return delegate;
+ }
+
+ /**
+ * Get (unwrap) the delegated connection from the given connection.
+ * Use reflection to attempt to unwrap a connection.
+ * Note: This is a JDBC 4 operation, so it requires a Java 6 environment
+ * with a JDBC 4 driver or data source to have any chance of success.
+ *
+ * @param conn a delegating connection
+ * @param connectionClass the expected type of delegated connection
+ * @return connection the given connection delegates to
+ */
+ private Connection unwrapConnection(Connection conn, Class<?>
connectionClass) {
+ try {
+ if (connectionUnwrap == null) {
+ connectionUnwrap = Connection.class.getMethod("unwrap",
Class.class);
+ }
+ return (Connection) connectionUnwrap.invoke(conn, connectionClass);
+ } catch (Exception e) {
+ throw new InternalException(_loc.get("connection-unwrap-failed"),
e);
+ }
+ }
+
+ /**
* Connection wrapper to work around the postgres empty result set bug.
*/
private static class PostgresConnection
@@ -658,7 +724,7 @@ public class PostgresDictionary
ResultSet rs = getResultSet(wrap);
// ResultSet should be empty: if not, then maybe an
- // actual error occured
+ // actual error occurred
if (rs == null)
throw se;
Modified:
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java?rev=949560&r1=949559&r2=949560&view=diff
==============================================================================
---
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java
(original)
+++
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java
Sun May 30 19:27:58 2010
@@ -18,11 +18,17 @@
*/
package org.apache.openjpa.jdbc.sql;
+import java.io.InputStream;
+import java.io.Reader;
+import java.sql.Blob;
+import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
import org.apache.openjpa.kernel.Filters;
import org.apache.openjpa.jdbc.schema.Column;
@@ -30,7 +36,7 @@ import org.apache.openjpa.lib.util.Local
import org.apache.openjpa.meta.JavaTypes;
/**
- * Dictionary for MS SQLServer.
+ * Dictionary for Microsoft SQL Server.
*/
public class SQLServerDictionary
extends AbstractSQLServerDictionary {
@@ -270,4 +276,36 @@ public class SQLServerDictionary
public String getSchemaCase() {
return schemaCase;
}
+
+ /**
+ * Obtain an {...@link InputStream} by using {...@link
ResultSet#getBlob(int)} and
+ * {...@link Blob#getBinaryStream()}.
+ * Unfortunately this will load entire BLOB into memory.
+ * The alternative {...@link ResultSet#getBinaryStream(int)} provides true
streaming but
+ * the stream can be consumed only as long as {...@link ResultSet} is open.
+ */
+ @Override
+ public InputStream getLOBStream(JDBCStore store, ResultSet rs, int column)
throws SQLException {
+ Blob blob = rs.getBlob(column);
+ if (blob == null) {
+ return null;
+ }
+ return blob.getBinaryStream();
+ }
+
+ /**
+ * Obtain a {...@link Reader} by using {...@link ResultSet#getClob(int)}
and
+ * {...@link Clob#getCharacterStream()}.
+ * Unfortunately this will load entire CLOB into memory.
+ * The alternative {...@link ResultSet#getCharacterStream(int)} provides
true streaming but
+ * the stream can be consumed only as long as {...@link ResultSet} is open.
+ */
+ @Override
+ public Reader getCharacterStream(ResultSet rs, int column) throws
SQLException {
+ Clob clob = rs.getClob(column);
+ if (clob == null) {
+ return null;
+ }
+ return clob.getCharacterStream();
+ }
}
Modified:
openjpa/branches/1.3.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties?rev=949560&r1=949559&r2=949560&view=diff
==============================================================================
---
openjpa/branches/1.3.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties
(original)
+++
openjpa/branches/1.3.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties
Sun May 30 19:27:58 2010
@@ -192,3 +192,9 @@ error-setting-query-timeout: A SQLExcept
continue processing. If this is a benign error you may disable it entirely
\
by setting the supportsQueryTimeout attribute on the DBDictionary to
false.\
The exception thrown was {1}.
+dbcp-unwrap-failed: Unable to get underlying connection from DBCP pooled \
+ connection. Make sure the DBCP property
AccessToUnderlyingConnectionAllowed \
+ is enabled.
+connection-unwrap-failed: Unable to get underlying connection from pooled \
+ connection. Java version 6 and a version 4 capable JDBC driver \
+ or data source are minimum requirements to perform this operation.
Modified:
openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/AbstractLobTest.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/AbstractLobTest.java?rev=949560&r1=949559&r2=949560&view=diff
==============================================================================
---
openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/AbstractLobTest.java
(original)
+++
openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/AbstractLobTest.java
Sun May 30 19:27:58 2010
@@ -20,17 +20,20 @@
package org.apache.openjpa.jdbc.meta.strats;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
+import org.apache.commons.lang.StringUtils;
import org.apache.openjpa.conf.OpenJPAConfiguration;
import org.apache.openjpa.datacache.DataCachePCData;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.jdbc.sql.DBDictionary;
import org.apache.openjpa.jdbc.sql.MySQLDictionary;
import org.apache.openjpa.jdbc.sql.OracleDictionary;
-import org.apache.openjpa.jdbc.sql.PostgresDictionary;
import org.apache.openjpa.jdbc.sql.SQLServerDictionary;
import org.apache.openjpa.meta.ClassMetaData;
import org.apache.openjpa.persistence.JPAFacadeHelper;
@@ -38,7 +41,7 @@ import org.apache.openjpa.persistence.Op
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
/**
- * This abstract class defines all the tests for LOBS.
+ * This abstract class defines all the tests for LOB streaming.
*
* @author Ignacio Andreu
* @since 1.1.0
@@ -46,22 +49,26 @@ import org.apache.openjpa.persistence.te
public abstract class AbstractLobTest extends SingleEMFTestCase {
+ protected static boolean firstTestExecuted;
+
+ protected List<Class<? extends DBDictionary>> supportedDatabases =
+ new ArrayList<Class<? extends DBDictionary>>
+ (Arrays.asList(MySQLDictionary.class, OracleDictionary.class,
SQLServerDictionary.class));
+
public void setUp() throws Exception {
- super.setUp(getLobEntityClass(), CLEAR_TABLES,
+ // Test CREATE TABLE but only once to save time.
+ Object clearOrDropTables = (firstTestExecuted) ? CLEAR_TABLES :
DROP_TABLES;
+ firstTestExecuted = true;
+ super.setUp(getLobEntityClass(), clearOrDropTables,
"openjpa.DataCache", "true",
- "openjpa.RemoteCommitProvider", "sjvm");
+ "openjpa.RemoteCommitProvider", "sjvm",
+ "openjpa.ConnectionRetainMode", "transaction");
}
public boolean isDatabaseSupported() {
DBDictionary dict = ((JDBCConfiguration) emf.getConfiguration())
.getDBDictionaryInstance();
- if (dict instanceof MySQLDictionary ||
- dict instanceof SQLServerDictionary ||
- dict instanceof OracleDictionary ||
- dict instanceof PostgresDictionary) {
- return true;
- }
- return false;
+ return supportedDatabases.contains(dict.getClass());
}
public void insert(LobEntity le) {
@@ -74,12 +81,12 @@ public abstract class AbstractLobTest ex
public void testInsert() {
if (!isDatabaseSupported()) return;
- insert(newLobEntity("oOOOOOo", 1));
+ insert(newLobEntity(createLobData(), 1));
}
public void testInsertAndSelect() throws IOException {
if (!isDatabaseSupported()) return;
- String s = "oooOOOooo";
+ String s = createLobData();
insert(newLobEntity(s, 1));
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
@@ -105,11 +112,11 @@ public abstract class AbstractLobTest ex
public void testUpdate() throws IOException {
if (!isDatabaseSupported()) return;
- insert(newLobEntity("oOOOOOo", 1));
+ insert(newLobEntity(createLobData(), 1));
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
LobEntity entity = (LobEntity) em.find(getLobEntityClass(), 1);
- String string = "iIIIIIi";
+ String string = createLobData2();
changeStream(entity, string);
em.getTransaction().commit();
em.close();
@@ -123,7 +130,7 @@ public abstract class AbstractLobTest ex
public void testUpdateWithNull() {
if (!isDatabaseSupported()) return;
- insert(newLobEntity("oOOOOOo", 1));
+ insert(newLobEntity(createLobData(), 1));
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
LobEntity entity = (LobEntity) em.find(getLobEntityClass(), 1);
@@ -144,7 +151,7 @@ public abstract class AbstractLobTest ex
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
LobEntity entity = (LobEntity) em.find(getLobEntityClass(), 1);
- String string = "iIIIIIi";
+ String string = createLobData2();
changeStream(entity, string);
em.getTransaction().commit();
em.close();
@@ -158,7 +165,7 @@ public abstract class AbstractLobTest ex
public void testDelete() {
if (!isDatabaseSupported()) return;
- insert(newLobEntity("oOOOOOo", 1));
+ insert(newLobEntity(createLobData(), 1));
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
LobEntity entity = (LobEntity) em.find(getLobEntityClass(), 1);
@@ -177,22 +184,22 @@ public abstract class AbstractLobTest ex
if (!isDatabaseSupported()) return;
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
- LobEntity le = newLobEntity("oOOOOOo", 1);
+ LobEntity le = newLobEntity(createLobData(), 1);
em.persist(le);
em.flush();
- changeStream(le, "iIIIIIi");
+ changeStream(le, createLobData2());
em.getTransaction().commit();
em.close();
}
public void testLifeCycleLoadFlushModifyFlush() {
if (!isDatabaseSupported()) return;
- insert(newLobEntity("oOOOOOo", 1));
+ insert(newLobEntity(createLobData(), 1));
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
LobEntity entity = (LobEntity) em.find(getLobEntityClass(), 1);
em.flush();
- changeStream(entity, "iIIIIIi");
+ changeStream(entity, createLobData2());
em.flush();
em.getTransaction().commit();
em.close();
@@ -201,11 +208,11 @@ public abstract class AbstractLobTest ex
public void testReadingMultipleTimesWithASingleConnection()
throws IOException {
if (!isDatabaseSupported()) return;
- insert(newLobEntity("oOOOOOo", 1));
+ insert(newLobEntity(createLobData(), 1));
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
LobEntity le = (LobEntity) em.find(getLobEntityClass(), 1);
- String string = "iIIIIIi";
+ String string = createLobData2();
changeStream(le, string);
em.getTransaction().commit();
em.close();
@@ -213,7 +220,7 @@ public abstract class AbstractLobTest ex
em.getTransaction().begin();
le = (LobEntity) em.find(getLobEntityClass(), 1);
assertNotNull(le.getStream());
- LobEntity entity = newLobEntity("oOOOOOo", 2);
+ LobEntity entity = newLobEntity(createLobData(), 2);
em.persist(entity);
assertEquals(string, getStreamContentAsString(le.getStream()));
em.getTransaction().commit();
@@ -225,7 +232,7 @@ public abstract class AbstractLobTest ex
OpenJPAEntityManager em = emf.createEntityManager();
em.getTransaction().begin();
- LobEntity le = newLobEntity("oOOOOOo", 1);
+ LobEntity le = newLobEntity(createLobData(), 1);
em.persist(le);
em.getTransaction().commit();
OpenJPAConfiguration conf = emf.getConfiguration();
@@ -243,16 +250,17 @@ public abstract class AbstractLobTest ex
if (!isDatabaseSupported()) return;
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
- LobEntity le = newLobEntity("oOOOOOo", 1);
+ LobEntity le = newLobEntity(createLobData(), 1);
em.persist(le);
- changeStream(le, "iIIIIIi");
+ String string = createLobData2();
+ changeStream(le, string);
em.flush();
em.getTransaction().commit();
em.close();
em = emf.createEntityManager();
em.getTransaction().begin();
LobEntity entity = (LobEntity) em.find(getLobEntityClass(), 1);
- assertEquals("iIIIIIi", getStreamContentAsString(entity.getStream()));
+ assertEquals(string, getStreamContentAsString(entity.getStream()));
em.getTransaction().commit();
em.close();
}
@@ -261,16 +269,25 @@ public abstract class AbstractLobTest ex
if (!isDatabaseSupported()) return;
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
- LobEntity le = newLobEntity("oOOOOOo", 1);
+ LobEntity le = newLobEntity(createLobData(), 1);
em.persist(le);
em.flush();
- changeStream(le, "iIIIIIi");
+ String string = createLobData2();
+ changeStream(le, string);
LobEntity entity = (LobEntity) em.find(getLobEntityClass(), 1);
- assertEquals("iIIIIIi", getStreamContentAsString(entity.getStream()));
+ assertEquals(string, getStreamContentAsString(entity.getStream()));
em.getTransaction().commit();
em.close();
}
+ protected String createLobData() {
+ return StringUtils.repeat("ooOOOOoo, ", 3000);
+ }
+
+ protected String createLobData2() {
+ return StringUtils.repeat("iiIIIIii, ", 1000);
+ }
+
protected abstract Class getLobEntityClass();
protected abstract String getStreamContentAsString(Object o)
Modified:
openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/TestInputStreamLob.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/TestInputStreamLob.java?rev=949560&r1=949559&r2=949560&view=diff
==============================================================================
---
openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/TestInputStreamLob.java
(original)
+++
openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/TestInputStreamLob.java
Sun May 30 19:27:58 2010
@@ -22,8 +22,10 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import org.apache.openjpa.jdbc.sql.PostgresDictionary;
+
/**
- * Defines all the abstract methods from AbstractLobTest to tests the
+ * Defines all the abstract methods from AbstractLobTest to test
* the LOB support with an InputStream.
*
* @author Ignacio Andreu
@@ -32,6 +34,12 @@ import java.io.InputStream;
public class TestInputStreamLob extends AbstractLobTest {
+ @Override
+ public void setUp() throws Exception {
+ supportedDatabases.add(PostgresDictionary.class);
+ super.setUp();
+ }
+
protected LobEntity newLobEntity(String s, int id) {
InputStreamLobEntity isle = new InputStreamLobEntity();
isle.setId(id);
@@ -61,7 +69,7 @@ public class TestInputStreamLob extends
protected String getStreamContentAsString(Object o) throws IOException {
InputStream is = (InputStream) o;
String content = "";
- byte[] bs = new byte[4];
+ byte[] bs = new byte[1024];
int read = -1;
do {
read = is.read(bs);