Search in sources :

Example 6 with ArrayStore

use of org.datanucleus.store.types.scostore.ArrayStore in project datanucleus-rdbms by datanucleus.

the class ArrayMapping method preDelete.

/**
 * Method to be called before any delete of the owner class element, if the field in the owner is dependent
 * @param ownerOP ObjectProvider of the owner
 */
public void preDelete(ObjectProvider ownerOP) {
    if (containerIsStoredInSingleColumn()) {
        // Do nothing when stored in a single column since we are handled in the main request
        return;
    }
    // makes sure field is loaded
    ownerOP.isLoaded(getAbsoluteFieldNumber());
    Object value = ownerOP.provideField(getAbsoluteFieldNumber());
    if (value == null) {
        return;
    }
    // Clear the array via its backing store
    ArrayStore backingStore = (ArrayStore) storeMgr.getBackingStoreForField(ownerOP.getExecutionContext().getClassLoaderResolver(), mmd, null);
    backingStore.clear(ownerOP);
}
Also used : ArrayStore(org.datanucleus.store.types.scostore.ArrayStore)

Example 7 with ArrayStore

use of org.datanucleus.store.types.scostore.ArrayStore in project datanucleus-rdbms by datanucleus.

the class ArrayMapping method postFetch.

/**
 * Method to be called after any fetch of the owner class element.
 * @param sm StateManager of the owner
 */
public void postFetch(DNStateManager sm) {
    if (containerIsStoredInSingleColumn()) {
        // Do nothing when stored in a single column since we are handled in the main request
        return;
    }
    List elements = ((ArrayStore) storeMgr.getBackingStoreForField(sm.getExecutionContext().getClassLoaderResolver(), mmd, null)).getArray(sm);
    if (elements != null) {
        boolean primitiveArray = mmd.getType().getComponentType().isPrimitive();
        Object array = Array.newInstance(mmd.getType().getComponentType(), elements.size());
        for (int i = 0; i < elements.size(); i++) {
            Object element = elements.get(i);
            if (primitiveArray) {
                // Handle the conversion back to the primitive
                if (element instanceof Boolean) {
                    Array.setBoolean(array, i, ((Boolean) element).booleanValue());
                } else if (element instanceof Byte) {
                    Array.setByte(array, i, ((Byte) element).byteValue());
                } else if (element instanceof Character) {
                    Array.setChar(array, i, ((Character) element).charValue());
                } else if (element instanceof Double) {
                    Array.setDouble(array, i, ((Double) element).doubleValue());
                } else if (element instanceof Float) {
                    Array.setFloat(array, i, ((Float) element).floatValue());
                } else if (element instanceof Integer) {
                    Array.setInt(array, i, ((Integer) element).intValue());
                } else if (element instanceof Long) {
                    Array.setLong(array, i, ((Long) element).longValue());
                } else if (element instanceof Short) {
                    Array.setShort(array, i, ((Short) element).shortValue());
                }
            } else {
                Array.set(array, i, element);
            }
        }
        if (elements.size() == 0) {
            sm.replaceFieldMakeDirty(getAbsoluteFieldNumber(), null);
        } else {
            sm.replaceFieldMakeDirty(getAbsoluteFieldNumber(), array);
        }
    } else {
        sm.replaceFieldMakeDirty(getAbsoluteFieldNumber(), null);
    }
}
Also used : ArrayStore(org.datanucleus.store.types.scostore.ArrayStore) List(java.util.List)

Example 8 with ArrayStore

use of org.datanucleus.store.types.scostore.ArrayStore in project datanucleus-rdbms by datanucleus.

the class ArrayMapping method preDelete.

/**
 * Method to be called before any delete of the owner class element, if the field in the owner is dependent
 * @param ownerSM StateManager of the owner
 */
public void preDelete(DNStateManager ownerSM) {
    if (containerIsStoredInSingleColumn()) {
        // Do nothing when stored in a single column since we are handled in the main request
        return;
    }
    // makes sure field is loaded
    ownerSM.isLoaded(getAbsoluteFieldNumber());
    Object value = ownerSM.provideField(getAbsoluteFieldNumber());
    if (value == null) {
        return;
    }
    // Clear the array via its backing store
    ArrayStore backingStore = (ArrayStore) storeMgr.getBackingStoreForField(ownerSM.getExecutionContext().getClassLoaderResolver(), mmd, null);
    backingStore.clear(ownerSM);
}
Also used : ArrayStore(org.datanucleus.store.types.scostore.ArrayStore)

Aggregations

ArrayStore (org.datanucleus.store.types.scostore.ArrayStore)8 ExecutionContext (org.datanucleus.ExecutionContext)4 List (java.util.List)2 ReachableObjectNotCascadedException (org.datanucleus.exceptions.ReachableObjectNotCascadedException)2 DNStateManager (org.datanucleus.state.DNStateManager)2 ObjectProvider (org.datanucleus.state.ObjectProvider)2 SCO (org.datanucleus.store.types.SCO)2 BackedSCO (org.datanucleus.store.types.wrappers.backed.BackedSCO)2