Search in sources :

Example 1 with BlobImpl

use of org.datanucleus.store.rdbms.mapping.datastore.BlobImpl in project datanucleus-rdbms by datanucleus.

the class OracleArrayMapping method postInsert.

/**
 * Method to be called after the insert of the owner class element.
 * @param ownerOP ObjectProvider of the owner
 */
public void postInsert(ObjectProvider ownerOP) {
    if (containerIsStoredInSingleColumn()) {
        Object value = ownerOP.provideField(mmd.getAbsoluteFieldNumber());
        if (value == null) {
            return;
        }
        ExecutionContext ec = ownerOP.getExecutionContext();
        if (mmd.getArray().elementIsPersistent()) {
            // Make sure all persistable elements have ObjectProviders
            Object[] arrElements = (Object[]) value;
            for (Object elem : arrElements) {
                if (elem != null) {
                    ObjectProvider elemOP = ec.findObjectProvider(elem);
                    if (elemOP == null || ec.getApiAdapter().getExecutionContext(elem) == null) {
                        elemOP = ec.getNucleusContext().getObjectProviderFactory().newForEmbedded(ec, elem, false, ownerOP, mmd.getAbsoluteFieldNumber());
                    }
                }
            }
        }
        // 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 boolean[]) {
                bytes = TypeConversionHelper.getByteArrayFromBooleanArray(value);
            } else if (value instanceof char[]) {
                bytes = TypeConversionHelper.getByteArrayFromCharArray(value);
            } else if (value instanceof double[]) {
                bytes = TypeConversionHelper.getByteArrayFromDoubleArray(value);
            } else if (value instanceof float[]) {
                bytes = TypeConversionHelper.getByteArrayFromFloatArray(value);
            } else if (value instanceof int[]) {
                bytes = TypeConversionHelper.getByteArrayFromIntArray(value);
            } else if (value instanceof long[]) {
                bytes = TypeConversionHelper.getByteArrayFromLongArray(value);
            } else if (value instanceof short[]) {
                bytes = TypeConversionHelper.getByteArrayFromShortArray(value);
            } else if (value instanceof Boolean[]) {
                bytes = TypeConversionHelper.getByteArrayFromBooleanObjectArray(value);
            } else if (value instanceof Byte[]) {
                bytes = TypeConversionHelper.getByteArrayFromByteObjectArray(value);
            } else if (value instanceof Character[]) {
                bytes = TypeConversionHelper.getByteArrayFromCharObjectArray(value);
            } else if (value instanceof Double[]) {
                bytes = TypeConversionHelper.getByteArrayFromDoubleObjectArray(value);
            } else if (value instanceof Float[]) {
                bytes = TypeConversionHelper.getByteArrayFromFloatObjectArray(value);
            } else if (value instanceof Integer[]) {
                bytes = TypeConversionHelper.getByteArrayFromIntObjectArray(value);
            } else if (value instanceof Long[]) {
                bytes = TypeConversionHelper.getByteArrayFromLongObjectArray(value);
            } else if (value instanceof Short[]) {
                bytes = TypeConversionHelper.getByteArrayFromShortObjectArray(value);
            } else if (value instanceof BigDecimal[]) {
                bytes = TypeConversionHelper.getByteArrayFromBigDecimalArray(value);
            } else if (value instanceof BigInteger[]) {
                bytes = TypeConversionHelper.getByteArrayFromBigIntegerArray(value);
            } else if (value instanceof byte[]) {
                bytes = (byte[]) value;
            } else if (value instanceof java.util.BitSet) {
                bytes = TypeConversionHelper.getByteArrayFromBooleanArray(TypeConversionHelper.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
        }
        // Update the BLOB
        OracleBlobRDBMSMapping.updateBlobColumn(ownerOP, getTable(), getDatastoreMapping(0), bytes);
    } else {
        super.postInsert(ownerOP);
    }
}
Also used : Serializable(java.io.Serializable) SQLException(java.sql.SQLException) NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) BlobImpl(org.datanucleus.store.rdbms.mapping.datastore.BlobImpl) IOException(java.io.IOException) BigInteger(java.math.BigInteger) ExecutionContext(org.datanucleus.ExecutionContext) BigInteger(java.math.BigInteger) ObjectProvider(org.datanucleus.state.ObjectProvider)

Example 2 with BlobImpl

use of org.datanucleus.store.rdbms.mapping.datastore.BlobImpl in project datanucleus-rdbms by datanucleus.

the class OracleBitSetMapping method insertPostProcessing.

/**
 * Method to handle post-processing of the insert of the BLOB/CLOB for Oracle.
 * @param op ObjectProvider of the owner
 */
public void insertPostProcessing(ObjectProvider op) {
    Object value = op.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 = TypeConversionHelper.getByteArrayFromBooleanArray(TypeConversionHelper.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
    }
    // Update the BLOB
    OracleBlobRDBMSMapping.updateBlobColumn(op, getTable(), getDatastoreMapping(0), bytes);
}
Also used : NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) Serializable(java.io.Serializable) SQLException(java.sql.SQLException) IOException(java.io.IOException) BlobImpl(org.datanucleus.store.rdbms.mapping.datastore.BlobImpl)

Aggregations

IOException (java.io.IOException)2 Serializable (java.io.Serializable)2 SQLException (java.sql.SQLException)2 NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)2 BlobImpl (org.datanucleus.store.rdbms.mapping.datastore.BlobImpl)2 BigInteger (java.math.BigInteger)1 ExecutionContext (org.datanucleus.ExecutionContext)1 ObjectProvider (org.datanucleus.state.ObjectProvider)1