use of org.datanucleus.store.rdbms.mapping.column.ColumnMappingPostSet in project datanucleus-rdbms by datanucleus.
the class OracleSerialisedPCMapping method performSetPostProcessing.
/**
* Retrieve the empty BLOB created by the insert statement and write out the current BLOB field value to the Oracle BLOB object
* @param ownerSM the current StateManager
*/
public void performSetPostProcessing(DNStateManager ownerSM) {
Object value = ownerSM.provideField(mmd.getAbsoluteFieldNumber());
DNStateManager sm = null;
if (value != null) {
ExecutionContext ec = ownerSM.getExecutionContext();
sm = ec.findStateManager(value);
if (sm == null || sm.getExecutionContext().getApiAdapter().getExecutionContext(value) == null) {
// Assign a StateManager to the serialised object since none present
sm = ec.getNucleusContext().getStateManagerFactory().newForEmbedded(ec, value, false, ownerSM, mmd.getAbsoluteFieldNumber(), PersistableObjectType.EMBEDDED_PC);
}
}
if (sm != null) {
sm.setStoringPC();
}
// Generate the contents for the BLOB
byte[] bytes = new byte[0];
if (value != null) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(value);
bytes = baos.toByteArray();
} catch (IOException e1) {
// Do Nothing
}
}
// Update the BLOB
if (columnMappings[0] instanceof ColumnMappingPostSet) {
((ColumnMappingPostSet) columnMappings[0]).setPostProcessing(ownerSM, bytes);
}
if (sm != null) {
sm.unsetStoringPC();
}
}
use of org.datanucleus.store.rdbms.mapping.column.ColumnMappingPostSet in project datanucleus-rdbms by datanucleus.
the class OracleCollectionMapping method performSetPostProcessing.
public void performSetPostProcessing(DNStateManager sm) {
if (containerIsStoredInSingleColumn()) {
if (columnMappings[0] instanceof ColumnMappingPostSet) {
// Create the value to put in the BLOB
Collection value = (Collection) sm.provideField(mmd.getAbsoluteFieldNumber());
byte[] bytes = new byte[0];
if (value != null) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(value);
bytes = baos.toByteArray();
} catch (IOException e1) {
// Do Nothing
}
}
// Update the BLOB
((ColumnMappingPostSet) columnMappings[0]).setPostProcessing(sm, bytes);
}
}
}
use of org.datanucleus.store.rdbms.mapping.column.ColumnMappingPostSet in project datanucleus-rdbms by datanucleus.
the class OracleSerialisedObjectMapping method performSetPostProcessing.
/**
* Retrieve the empty BLOB created by the insert statement and write out the current BLOB field value to the Oracle BLOB object
* @param sm the current StateManager
*/
public void performSetPostProcessing(DNStateManager sm) {
// Generate the contents for the BLOB
byte[] bytes = new byte[0];
Object value = sm.provideField(mmd.getAbsoluteFieldNumber());
if (value != null) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(value);
bytes = baos.toByteArray();
} catch (IOException e1) {
// Do Nothing
}
}
if (columnMappings[0] instanceof ColumnMappingPostSet) {
// Update the BLOB
((ColumnMappingPostSet) columnMappings[0]).setPostProcessing(sm, bytes);
}
}
use of org.datanucleus.store.rdbms.mapping.column.ColumnMappingPostSet in project datanucleus-rdbms by datanucleus.
the class OracleBitSetMapping method performSetPostProcessing.
/**
* Retrieve the empty BLOB created by the insert statement and write out the current BLOB field value to the Oracle BLOB object
* @param sm the current StateManager
*/
public void performSetPostProcessing(DNStateManager sm) {
Object value = sm.provideField(mmd.getAbsoluteFieldNumber());
if (value == null) {
return;
}
// Generate the contents for the BLOB
byte[] bytes = new byte[0];
try {
if (mmd.isSerialized()) {
// Serialised field so just perform basic Java serialisation for retrieval
if (!(value instanceof Serializable)) {
throw new NucleusDataStoreException(Localiser.msg("055005", value.getClass().getName()));
}
BlobImpl b = new BlobImpl(value);
bytes = b.getBytes(0, (int) b.length());
} else if (value instanceof java.util.BitSet) {
bytes = ArrayConversionHelper.getByteArrayFromBooleanArray(ArrayConversionHelper.getBooleanArrayFromBitSet((java.util.BitSet) value));
} else {
// Fall back to just perform Java serialisation for storage
if (!(value instanceof Serializable)) {
throw new NucleusDataStoreException(Localiser.msg("055005", value.getClass().getName()));
}
BlobImpl b = new BlobImpl(value);
bytes = b.getBytes(0, (int) b.length());
}
} catch (SQLException e) {
throw new NucleusDataStoreException(Localiser.msg("055001", "Object", "" + value, mmd, e.getMessage()), e);
} catch (IOException e1) {
// Do nothing
}
if (columnMappings[0] instanceof ColumnMappingPostSet) {
((ColumnMappingPostSet) columnMappings[0]).setPostProcessing(sm, bytes);
}
}
use of org.datanucleus.store.rdbms.mapping.column.ColumnMappingPostSet in project datanucleus-rdbms by datanucleus.
the class OracleMapMapping method performSetPostProcessing.
public void performSetPostProcessing(DNStateManager sm) {
if (containerIsStoredInSingleColumn()) {
if (columnMappings[0] instanceof ColumnMappingPostSet) {
// Create the value to put in the BLOB
java.util.Map value = (java.util.Map) sm.provideField(mmd.getAbsoluteFieldNumber());
byte[] bytes = new byte[0];
if (value != null) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(value);
bytes = baos.toByteArray();
} catch (IOException e1) {
// Do Nothing
}
}
// Update the BLOB
((ColumnMappingPostSet) columnMappings[0]).setPostProcessing(sm, bytes);
}
}
}
Aggregations