mirror of https://github.com/apache/openjpa.git
OPENJPA-130. Merge from ../branches/1.1.x. svn merge -c 653008 ../branches/1.1.x
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@666905 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f17afddbd6
commit
97a94847f6
|
@ -80,18 +80,12 @@ public class LobFieldStrategy extends AbstractFieldStrategy {
|
|||
(field.getIndex()), store);
|
||||
Row row = field.getRow(sm, store, rm, Row.ACTION_INSERT);
|
||||
if (field.getColumnIO().isInsertable(0, ob == null)) {
|
||||
if (ob != null) {
|
||||
if (isBlob()) {
|
||||
store.getDBDictionary().insertBlobForStreamingLoad
|
||||
(row, field.getColumns()[0]);
|
||||
} else {
|
||||
store.getDBDictionary().insertClobForStreamingLoad
|
||||
(row, field.getColumns()[0]);
|
||||
}
|
||||
if (isBlob()) {
|
||||
store.getDBDictionary().insertBlobForStreamingLoad
|
||||
(row, field.getColumns()[0], ob);
|
||||
} else {
|
||||
Column col = field.getColumns()[0];
|
||||
col.setType(Types.OTHER);
|
||||
row.setNull(col);
|
||||
store.getDBDictionary().insertClobForStreamingLoad
|
||||
(row, field.getColumns()[0], ob);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -113,11 +107,31 @@ public class LobFieldStrategy extends AbstractFieldStrategy {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean isCustomUpdate(OpenJPAStateManager sm, JDBCStore store) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void update(OpenJPAStateManager sm, JDBCStore store, RowManager rm)
|
||||
throws SQLException {
|
||||
Object ob = toDataStoreValue(sm.fetchObjectField
|
||||
(field.getIndex()), store);
|
||||
(field.getIndex()), store);
|
||||
if (field.getColumnIO().isUpdatable(0, ob == null)) {
|
||||
Row row = field.getRow(sm, store, rm, Row.ACTION_UPDATE);
|
||||
if (isBlob()) {
|
||||
store.getDBDictionary().insertBlobForStreamingLoad
|
||||
(row, field.getColumns()[0], ob);
|
||||
} else {
|
||||
store.getDBDictionary().insertClobForStreamingLoad
|
||||
(row, field.getColumns()[0], ob);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void customUpdate(OpenJPAStateManager sm, JDBCStore store)
|
||||
throws SQLException {
|
||||
Object ob = toDataStoreValue(sm.fetchObjectField
|
||||
(field.getIndex()), store);
|
||||
if (field.getColumnIO().isUpdatable(0, ob == null)) {
|
||||
if (ob != null) {
|
||||
Select sel = createSelect(sm, store);
|
||||
|
@ -128,11 +142,6 @@ public class LobFieldStrategy extends AbstractFieldStrategy {
|
|||
store.getDBDictionary().updateClob
|
||||
(sel, store, (Reader)ob);
|
||||
}
|
||||
} else {
|
||||
Row row = field.getRow(sm, store, rm, Row.ACTION_UPDATE);
|
||||
Column col = field.getColumns()[0];
|
||||
col.setType(Types.OTHER);
|
||||
row.setNull(col);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -191,4 +200,5 @@ public class LobFieldStrategy extends AbstractFieldStrategy {
|
|||
sel.setLob(true);
|
||||
return sel;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -127,8 +127,8 @@ public class DBDictionary
|
|||
public static final String CONS_NAME_MID = "mid";
|
||||
public static final String CONS_NAME_AFTER = "after";
|
||||
|
||||
public int blobBufferSize = 50;
|
||||
public int clobBufferSize = 50;
|
||||
public int blobBufferSize = 50000;
|
||||
public int clobBufferSize = 50000;
|
||||
|
||||
protected static final int RANGE_POST_SELECT = 0;
|
||||
protected static final int RANGE_PRE_DISTINCT = 1;
|
||||
|
@ -4189,16 +4189,24 @@ public class DBDictionary
|
|||
return column.toString();
|
||||
}
|
||||
|
||||
public void insertBlobForStreamingLoad(Row row, Column col)
|
||||
public void insertBlobForStreamingLoad(Row row, Column col, Object ob)
|
||||
throws SQLException {
|
||||
row.setBinaryStream(col,
|
||||
new ByteArrayInputStream(new byte[0]), 0);
|
||||
if (ob != null) {
|
||||
row.setBinaryStream(col,
|
||||
new ByteArrayInputStream(new byte[0]), 0);
|
||||
} else {
|
||||
row.setNull(col);
|
||||
}
|
||||
}
|
||||
|
||||
public void insertClobForStreamingLoad(Row row, Column col)
|
||||
public void insertClobForStreamingLoad(Row row, Column col, Object ob)
|
||||
throws SQLException {
|
||||
if (ob != null) {
|
||||
row.setCharacterStream(col,
|
||||
new CharArrayReader(new char[0]), 0);
|
||||
} else {
|
||||
row.setNull(col);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateBlob(Select sel, JDBCStore store, InputStream is)
|
||||
|
|
|
@ -1096,13 +1096,17 @@ public class OracleDictionary
|
|||
buf.append("')");
|
||||
}
|
||||
|
||||
public void insertBlobForStreamingLoad(Row row, Column col)
|
||||
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)
|
||||
public void insertClobForStreamingLoad(Row row, Column col, Object ob)
|
||||
throws SQLException {
|
||||
if (ob == null)
|
||||
col.setType(Types.OTHER);
|
||||
row.setNull(col);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.apache.openjpa.jdbc.meta.strats;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
|
||||
|
@ -117,6 +118,41 @@ public abstract class AbstractLobTest extends SingleEMFTestCase {
|
|||
em.close();
|
||||
}
|
||||
|
||||
public void testUpdateWithNull() {
|
||||
if (!isDatabaseSupported()) return;
|
||||
insert(newLobEntity("oOOOOOo", 1));
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
LobEntity entity = (LobEntity) em.find(getLobEntityClass(), 1);
|
||||
entity.setStream(null);
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
entity = (LobEntity) em.find(getLobEntityClass(), 1);
|
||||
assertNull(entity.getStream());
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testUpdateANullObjectWithoutNull() throws IOException {
|
||||
if (!isDatabaseSupported()) return;
|
||||
insert(newLobEntity(null, 1));
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
LobEntity entity = (LobEntity) em.find(getLobEntityClass(), 1);
|
||||
String string = "iIIIIIi";
|
||||
changeStream(entity, string);
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
entity = (LobEntity) em.find(getLobEntityClass(), 1);
|
||||
assertEquals(string, getStreamContentAsString(entity.getStream()));
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testDelete() {
|
||||
if (!isDatabaseSupported()) return;
|
||||
insert(newLobEntity("oOOOOOo", 1));
|
||||
|
|
|
@ -35,10 +35,10 @@ import org.apache.openjpa.persistence.Persistent;
|
|||
public class ReaderLobEntity implements LobEntity {
|
||||
|
||||
@Id
|
||||
int id;
|
||||
private int id;
|
||||
|
||||
@Persistent
|
||||
Reader stream;
|
||||
private Reader stream;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
|
|
Loading…
Reference in New Issue