Package org.apache.openjpa.kernel

Examples of org.apache.openjpa.kernel.StoreContext


            case JavaTypes.PC:
            case JavaTypes.PC_UNTYPED:
                // for relations to other persistent objects, we store the related
                // object's oid -- convert it back into a persistent instance
                StoreContext ctx = sm.getContext();
                Object pc = ctx.find(val, fetch, null, null, 0);
                if (pc != null)
                    return pc;
                OrphanedKeyAction action = ctx.getConfiguration().
                    getOrphanedKeyActionInstance();
                return action.orphan(val, sm, vmd);
            default:
                return val;
        }
View Full Code Here


        }

        // null inverse columns for deletes and update them with our oid for
        // inserts
        ClassMapping rel = field.getElementMapping().getTypeMapping();
        StoreContext ctx = store.getContext();
        if (field.getMappedBy() == null) {
            Collection rem = ct.getRemoved();
            for (Iterator itr = rem.iterator(); itr.hasNext();)
                updateInverse(ctx, itr.next(), rel, rm, null, 0);
        }
View Full Code Here

        if (!sm.getLoaded().get(field.getIndex()))
            return;

        // update fk on each field value row
        ClassMapping rel = field.getElementMapping().getTypeMapping();
        StoreContext ctx = store.getContext();
        Collection objs = toCollection(sm.fetchObject(field.getIndex()));
        if (objs != null && !objs.isEmpty())
            for (Iterator itr = objs.iterator(); itr.hasNext();)
                updateInverse (ctx, itr.next(), rel, rm, sm, 0);
    }
View Full Code Here

        //### call will always return false, meaning we always have to assume
        //### we selected the embedded object fields and load the object
        //### immediately; this will be inefficient when the embedded object
        //### was not selected after all

        StoreContext ctx = store.getContext();
        OpenJPAStateManager em = ctx.embed(null, null, sm, field);
        sm.storeObject(field.getIndex(), em.getManagedInstance());

        FieldMapping[] fields = field.getEmbeddedMapping().getFieldMappings();
        Object eres, processed;
        boolean loaded = false;
View Full Code Here

        Element root = doc.createElement(ELEMENT_INSTANCE);
        parent.appendChild(root);
        root.setAttribute(ATTR_ID, ior(sm));
        Element child = null;
        BitSet loaded = sm.getLoaded();
        StoreContext ctx = (StoreContext)sm.getGenericContext();
        List<Attribute<?, ?>> attrs = MetamodelHelper.getAttributesInOrder(sm.getMetaData(), model);
        for (int i = 0; i < attrs.size(); child = null, i++) {
            Members.Member<?, ?> attr = (Members.Member<?, ?>) attrs.get(i);
            FieldMetaData fmd = attr.fmd;
            if (!loaded.get(fmd.getIndex()))
                continue;
            String tag = MetamodelHelper.getTagByAttributeType(attr);
            Object value = sm.fetch(fmd.getIndex());
            switch (fmd.getDeclaredTypeCode()) {
                case JavaTypes.BOOLEAN:
                case JavaTypes.BYTE:
                case JavaTypes.CHAR:
                case JavaTypes.DOUBLE:
                case JavaTypes.FLOAT:
                case JavaTypes.INT:
                case JavaTypes.LONG:
                case JavaTypes.SHORT:

                case JavaTypes.BOOLEAN_OBJ:
                case JavaTypes.BYTE_OBJ:
                case JavaTypes.CHAR_OBJ:
                case JavaTypes.DOUBLE_OBJ:
                case JavaTypes.FLOAT_OBJ:
                case JavaTypes.INT_OBJ:
                case JavaTypes.LONG_OBJ:
                case JavaTypes.SHORT_OBJ:

                case JavaTypes.BIGDECIMAL:
                case JavaTypes.BIGINTEGER:
                case JavaTypes.DATE:
                case JavaTypes.NUMBER:
                case JavaTypes.CALENDAR:
                case JavaTypes.LOCALE:
                case JavaTypes.STRING:
                case JavaTypes.ENUM:
                child = doc.createElement(tag);
                child.setAttribute(ATTR_NAME, fmd.getName());
                if (value == null) {
                    encodeNull(child);
                } else {
                    encodeBasic(child, value, fmd.getDeclaredType());
                }
                break;
               
                case JavaTypes.OID:
                    child = doc.createElement(ELEMENT_REF);
                    child.setAttribute(ATTR_NAME, fmd.getName());
                    if (value == null) {
                        encodeNull(child);
                    } else {
                        encodeBasic(child, value, fmd.getDeclaredType());
                    }
                    break;
                   
                case JavaTypes.PC:
                    child = doc.createElement(tag);
                    child.setAttribute(ATTR_NAME, fmd.getName());
                    child.setAttribute(ATTR_TYPE, typeOf(fmd));
                    OpenJPAStateManager other = ctx.getStateManager(value);
                    encodeManagedInstance(other, child, true, model);
                    break;
                   
                case JavaTypes.ARRAY:
                    Object[] values = (Object[])value;
                    value = Arrays.asList(values);
                // no break;
                case JavaTypes.COLLECTION:
                    child = doc.createElement(tag);
                    child.setAttribute(ATTR_NAME, fmd.getName());
                    child.setAttribute(ATTR_TYPE, typeOf(fmd));
                    child.setAttribute(ATTR_MEMBER_TYPE, typeOf(fmd.getElement().getDeclaredType()));
                    if (value == null) {
                        encodeNull(child);
                        break;
                    }
                    Collection<?> members = (Collection<?>)value;
                    boolean basic = fmd.getElement().getTypeMetaData() == null;
                    for (Object o : members) {
                        Element member = doc.createElement(ELEMENT_MEMBER);
                        child.appendChild(member);
                        if (o == null) {
                            encodeNull(member);
                        } else {
                            if (basic) {
                                encodeBasic(member, o, o.getClass());
                            } else {
                                encodeManagedInstance(ctx.getStateManager(o), member, true, model);
                            }
                        }
                    }
                    break;
                case JavaTypes.MAP:
                    child = doc.createElement(tag);
                    child.setAttribute(ATTR_NAME, fmd.getName());
                    child.setAttribute(ATTR_TYPE, typeOf(fmd));
                    child.setAttribute(ATTR_KEY_TYPE, typeOf(fmd.getElement().getDeclaredType()));
                    child.setAttribute(ATTR_VALUE_TYPE, typeOf(fmd.getValue().getDeclaredType()));
                    if (value == null) {
                        encodeNull(child);
                        break;
                    }
                    Set<Map.Entry<?,?>> entries = ((Map)value).entrySet();
                    boolean basicKey   = fmd.getElement().getTypeMetaData() == null;
                    boolean basicValue = fmd.getValue().getTypeMetaData() == null;
                    for (Map.Entry<?,?> e : entries) {
                        Element entry = doc.createElement(ELEMENT_ENTRY);
                        Element entryKey = doc.createElement(ELEMENT_ENTRY_KEY);
                        Element entryValue = doc.createElement(ELEMENT_ENTRY_VALUE);
                        entry.appendChild(entryKey);
                        entry.appendChild(entryValue);
                        child.appendChild(entry);
                        if (e.getKey() == null) {
                            encodeNull(entryKey);
                        } else {
                            if (basicKey) {
                                encodeBasic(entryKey, e.getKey(), e.getKey().getClass());
                            } else {
                                encodeManagedInstance(ctx.getStateManager(e.getKey()), entryKey, true, model);
                            }
                        }
                        if (e.getValue() == null) {
                            encodeNull(entryValue);
                        } else {
                            if (basicValue) {
                                encodeBasic(entryValue, e.getValue(), e.getValue().getClass());
                            } else {
                                encodeManagedInstance(ctx.getStateManager(e.getValue()), entryValue, true, model);
                            }
                        }
                    }
                    break;
                   
View Full Code Here

        //### note: without a null indicator column, the above indicatesNull()
        //### call will always return false, meaning we always have to assume
        //### we selected the embedded object fields and load the object
        //### immediately; this will be inefficient when the embedded object
        //### was not selected after all
        StoreContext ctx = store.getContext();
        OpenJPAStateManager em = ctx.embed(null, null, sm, field);
        sm.storeObject(field.getIndex(), em.getManagedInstance());
        boolean needsLoad = loadFields(em, store, fetch, res);

        // After loading everything from result, load the rest of the
        // configured fields if anything is missing.
View Full Code Here

        throws SQLException {
        Boolean isNull = indicatesNull(res);
        if (isNull == null)
            return null;

        StoreContext ctx = store.getContext();
        // load primary key of owner entity
        Object owner = field.getDefiningMapping().getObjectId(store, res,
            null, true, joins);
        OpenJPAStateManager em = ctx.embed(null, null, null, field);
        // set owner id
        ((StateManagerImpl) em).setOwner(owner);
        boolean needsLoad = loadFields(em, store, fetch, res);

        // After loading everything from result, load the rest of the
View Full Code Here

        if (ref) {
            return root;
        }
       
        BitSet loaded = sm.getLoaded();
        StoreContext ctx = (StoreContext)sm.getGenericContext();
        List<Attribute<?, ?>> attrs = MetamodelHelper.getAttributesInOrder(sm.getMetaData(), model);
           
        for (int i = 0; i < attrs.size(); i++) {
            FieldMetaData fmd = ((Members.Member<?, ?>) attrs.get(i)).fmd;
            if (!loaded.get(fmd.getIndex()))
                continue;
            Object value = sm.fetch(fmd.getIndex());
            switch (fmd.getDeclaredTypeCode()) {
                case JavaTypes.BOOLEAN:
                case JavaTypes.BYTE:
                case JavaTypes.CHAR:
                case JavaTypes.DOUBLE:
                case JavaTypes.FLOAT:
                case JavaTypes.INT:
                case JavaTypes.LONG:
                case JavaTypes.SHORT:

                case JavaTypes.BOOLEAN_OBJ:
                case JavaTypes.BYTE_OBJ:
                case JavaTypes.CHAR_OBJ:
                case JavaTypes.DOUBLE_OBJ:
                case JavaTypes.FLOAT_OBJ:
                case JavaTypes.INT_OBJ:
                case JavaTypes.LONG_OBJ:
                case JavaTypes.SHORT_OBJ:

                case JavaTypes.BIGDECIMAL:
                case JavaTypes.BIGINTEGER:
                case JavaTypes.DATE:
                case JavaTypes.NUMBER:
                case JavaTypes.CALENDAR:
                case JavaTypes.LOCALE:
                case JavaTypes.STRING:
                case JavaTypes.ENUM:
                         root.set(fmd.getName(),value);
                break;
               
                case JavaTypes.PC:
                    if (value == null) {
                        root.set(fmd.getName(), null);
                    } else {
                        root.set(fmd.getName(),encodeManagedInstance(ctx.getStateManager(value), visited,
                            indent+1, false, model));
                    }
                    break;
                   
                case JavaTypes.ARRAY:
                    Object[] values = (Object[])value;
                    value = Arrays.asList(values);
                // no break;
                case JavaTypes.COLLECTION:
                    if (value == null) {
                        root.set(fmd.getName(), null);
                        break;
                    }
                    Collection<?> members = (Collection<?>)value;
                    JSONObject.Array array = new JSONObject.Array();
                    root.set(fmd.getName(), array);
                    if (members.isEmpty()) {
                        break;
                    }
                    boolean basic = fmd.getElement().getTypeMetaData() == null;
                    for (Object o : members) {
                        if (o == null) {
                            array.add(null);
                        } else {
                            if (basic) {
                                array.add(o);
                            } else {
                                array.add(encodeManagedInstance(ctx.getStateManager(o), visited, indent+1, true,
                                    model));
                            }
                        }
                    }
                    break;
                case JavaTypes.MAP:
                    if (value == null) {
                        root.set(fmd.getName(), null);
                        break;
                    }
                    Set<Map.Entry> entries = ((Map)value).entrySet();
                    JSONObject.KVMap map = new JSONObject.KVMap();
                    root.set(fmd.getName(), map);
                    if (entries.isEmpty()) {
                        break;
                    }
                   
                    boolean basicKey   = fmd.getElement().getTypeMetaData() == null;
                    boolean basicValue = fmd.getValue().getTypeMetaData() == null;
                    for (Map.Entry<?,?> e : entries) {
                        Object k = e.getKey();
                        Object v = e.getValue();
                        if (!basicKey) {
                            k = encodeManagedInstance(ctx.getStateManager(k), visited, indent+1, true, model);
                        }
                        if (!basicValue) {
                            v = encodeManagedInstance(ctx.getStateManager(e.getValue()), visited,
                                indent+1, false, model);
                        }
                        map.put(k,v);
                    }
                    break;
View Full Code Here

            QueryKey key =
                QueryKey.newInstance(cq.getContext(), _ex.isPacking(q), params, _candidate, _subs, range.start,
                    range.end, parsed);

            // Create a new FetchConfiguration that will be used to ensure that any JOIN FETCHed fields are loaded
            StoreContext store = q.getContext().getStoreContext();
            FetchConfiguration cacheFc = store.pushFetchConfiguration();
            for (QueryExpressions qe : _ex.getQueryExpressions()) {
                for (String fetchFields : qe.fetchPaths) {
                    cacheFc.addField(fetchFields);
                }
                for (String fetchFields : qe.fetchInnerPaths) {
                    cacheFc.addField(fetchFields);
                }
            }
            try {
                List<Object> cached = cq.checkCache(key, cacheFc);
                if (cached != null) {
                    return new ListResultObjectProvider(cached);
                }
            } finally {
                store.popFetchConfiguration();
            }

            ResultObjectProvider rop = _ex.executeQuery(cq.getDelegate(), params, range);
            if (_fc.getQueryCacheEnabled())
                return cq.wrapResult(rop, key);
View Full Code Here

     * Access JDBC configuration information. May return null if not a
     * JDBC back-end (possible to get a JDBCFetchConfiguration on non-JDBC
     * back end in remote client).
     */
    private JDBCConfiguration getJDBCConfiguration() {
        StoreContext ctx = getContext();
        if (ctx == null)
            return null;
        OpenJPAConfiguration conf = ctx.getConfiguration();
        if (!(conf instanceof JDBCConfiguration))
            return null;
        return (JDBCConfiguration) conf;
    }
View Full Code Here

TOP

Related Classes of org.apache.openjpa.kernel.StoreContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.