Package org.apache.openjpa.jdbc.meta

Examples of org.apache.openjpa.jdbc.meta.FieldMapping


        JDBCFetchConfiguration fetch, Result res)
        throws SQLException {
        ClassMapping cls = field.getIndependentTypeMappings()[0];

        // for inverseEager field
        FieldMapping mappedByFieldMapping = field.getMappedByMapping();
        PersistenceCapable mappedByValue = null;

        if (mappedByFieldMapping != null) {
            ValueMapping val = mappedByFieldMapping.getValueMapping();
            ClassMetaData decMeta = val.getTypeMetaData();
            // eager loading a child from its toOne parent and
            // the parent has @OneToOne(mappedBy="parent") child relation.
            // By saving the mapped-by info in 'res' is to
            // avoid unneeded SQL pushdown that would otherwise gets
View Full Code Here


            // and the object id instance if the type as determined
            // from the indicator is a subclass of expected type
            sm.initialize(type, state);

            if (info != null && info.result != null) {
                FieldMapping mappedByFieldMapping = info.result.
                    getMappedByFieldMapping();
                Object mappedByObject = info.result.getMappedByValue();
                if (mappedByFieldMapping != null && mappedByObject != null)
                    if (mappedByObject instanceof OpenJPAId &&
                        mapping.getExtraFieldDataIndex(mappedByFieldMapping.
                        getIndex()) != -1)
                        // The inverse relation can not be set since
                        // we are eagerly loading this sm for
                        // a sm owner that is still in the process of
                        // initializing itself.
                        // Remember owner oid by setIntermediate().
                        // The inverse relation is set later by
                        // setInverseRelation() when the sm owner is fully
                        // initialized.
                        sm.setIntermediate(mappedByFieldMapping.getIndex(),
                            mappedByObject);
                    else
                        setMappedBy(sm, mappedByFieldMapping, mappedByObject);
            }
            // load the selected mappings into the given state manager
View Full Code Here

        return _ctx.find(oid, fetch, exclude, info, 0);
    }

    private BitSet excludeInverseRelation(ClassMapping mapping,
        ConnectionInfo info, BitSet exclude) {
        FieldMapping inverse = info.result.getMappedByFieldMapping();
        if (inverse != null) {
            FieldMapping[] fms = mapping.getDefinedFieldMappings();
            if (exclude == null)
                exclude = new BitSet(fms.length);
            for (int i = 0; i < fms.length; i++) {
View Full Code Here

     * Load the given state manager with data from the result set. Only
     * mappings originally selected will be loaded.
     */
    private void load(ClassMapping mapping, OpenJPAStateManager sm,
        JDBCFetchConfiguration fetch, Result res) throws SQLException {
        FieldMapping eagerToMany = load(mapping, sm, fetch, res, null);
        if (eagerToMany != null)
            eagerToMany.loadEagerJoin(sm, this, fetch.traverseJDBC(eagerToMany),
                res);
        if (_active && _lm != null && res.isLocking())
            _lm.loadedForUpdate(sm);
    }
View Full Code Here

        // create all our eager selects so that those fields are reserved
        // and cannot be reused during the actual eager select process,
        // preventing infinite recursion
        eager = Math.min(eager, fetch.getEagerFetchMode());
        FieldMapping eagerToMany = createEagerSelects(sel, mapping, sm, fields,
            fetch, eager);

        // select all base class mappings; do this after batching so that
        // the joins needed by these selects don't get in the WHERE clause
        // of the batched selects
        int seld = selectBaseMappings(sel, mapping, mapping, sm, fields,
            fetch, eager, eagerToMany, ident, joinedSupers);

        // select eager to-many relations last because during load they
        // advance the result set and could exhaust it, so no other mappings
        // can load afterwords
        if (eagerToMany != null)
            eagerToMany.selectEagerJoin(sel, sm, this,
                fetch.traverseJDBC(eagerToMany), eager);

        // optionally select subclass mappings
        if (subs == Select.SUBS_JOINABLE || subs == Select.SUBS_ANY_JOINABLE)
            selectSubclassMappings(sel, mapping, sm, fetch);
View Full Code Here

        OpenJPAStateManager sm, BitSet fields, JDBCFetchConfiguration fetch,
        int eager) {
        if (mapping == null || eager == JDBCFetchConfiguration.EAGER_NONE)
            return null;

        FieldMapping eagerToMany = createEagerSelects(sel,
            mapping.getJoinablePCSuperclassMapping(), sm, fields, fetch, eager);

        FieldMapping[] fms = mapping.getDefinedFieldMappings();
        boolean inEagerJoin = sel.hasEagerJoin(false);
        int sels;
View Full Code Here

        boolean augmentUpdates = true;

        for (Iterator i = updateParams.entrySet().iterator(); i.hasNext();) {
            Map.Entry next = (Map.Entry) i.next();
            Path path = (Path) next.getKey();
            FieldMapping fmd = (FieldMapping) path.last();

            if (fmd.isVersion())
                augmentUpdates = false;

            Val val = (Val) next.getValue();
            if (val == null)
              val = new Null();
            Column col = fmd.getColumns()[0];
            if (allowAlias) {
              sql.append(sel.getColumnAlias(col));
            } else {
              sql.append(col.getName())
            }           
            sql.append(" = ");

            ExpState state = val.initialize(sel, ctx, 0);
            // JDBC Paths are always PCPaths; PCPath implements Val
            ExpState pathState = ((Val) path).initialize(sel, ctx, 0);
            calculateValue(val, sel, ctx, state, path, pathState);

            // append the value with a null for the Select; i
            // indicates that the
            int length = val.length(sel, ctx, state);
            for (int j = 0; j < length; j++)
                val.appendTo((allowAlias) ? sel : null, ctx, state, sql, j);

            if (i.hasNext())
                sql.append(", ");
        }

        if (augmentUpdates) {
            Path path = (Path) updateParams.keySet().iterator().next();
            FieldMapping fm = (FieldMapping) path.last();
            ClassMapping meta = fm.getDeclaringMapping();
            Map updates = meta.getVersion().getBulkUpdateValues();
            for (Iterator iter = updates.entrySet().iterator();
                iter.hasNext(); ) {
                Map.Entry e = (Map.Entry) iter.next();
                Column col = (Column) e.getKey();
View Full Code Here

        assertEquals("Y_COL", fm.getColumns()[1].getName());
        assertNotNull(fm.getValueIndex());
    }

    public void testValueCollection() {
        FieldMapping fm = _mapping.getFieldMapping("stringCollection");
        assertEquals("STRINGS_COLL", fm.getTable().getName());
        assertEquals(1, fm.getJoinForeignKey().getColumns().length);
        assertEquals("OWNER", fm.getJoinForeignKey().getColumns()[0].
            getName());
        assertEquals(1, fm.getElementMapping().getColumns().length);
        assertEquals("STR_ELEM", fm.getElementMapping().getColumns()[0].
            getName());
        assertEquals(127, fm.getElementMapping().getColumns()[0].getSize());
        assertNotNull(fm.getElementMapping().getValueIndex());
        assertNull(fm.getJoinIndex());
    }
View Full Code Here

        assertNotNull(fm.getElementMapping().getValueIndex());
        assertNull(fm.getJoinIndex());
    }

    public void testJoinCollection() {
        FieldMapping fm = _mapping.getFieldMapping("joinCollection");
        assertEquals("JOIN_COLL", fm.getTable().getName());
        assertEquals(1, fm.getJoinForeignKey().getColumns().length);
        assertEquals("OWNER", fm.getJoinForeignKey().getColumns()[0].
            getName());
        assertEquals(1, fm.getElementMapping().getColumns().length);
        assertEquals("JOIN_ELEM", fm.getElementMapping().getColumns()[0].
            getName());
        assertForeignKey(fm.getJoinForeignKey());
        assertForeignKey(fm.getElementMapping().getForeignKey());
    }
View Full Code Here

        if (_dict.supportsForeignKeys)
            assertEquals(ForeignKey.ACTION_RESTRICT, fk.getDeleteAction());
    }

    public void testValueMap() {
        FieldMapping fm = _mapping.getFieldMapping("stringMap");
        assertEquals("STRINGS_MAP", fm.getTable().getName());
        assertEquals(1, fm.getJoinForeignKey().getColumns().length);
        assertEquals("OWNER", fm.getJoinForeignKey().getColumns()[0].
            getName());
        assertEquals(1, fm.getKeyMapping().getColumns().length);
        assertEquals("STR_KEY", fm.getKeyMapping().getColumns()[0].
            getName());
        assertEquals(127, fm.getKeyMapping().getColumns()[0].getSize());
        assertEquals(1, fm.getElementMapping().getColumns().length);
        assertEquals("STR_VAL", fm.getElementMapping().getColumns()[0].
            getName());
        assertEquals(127, fm.getElementMapping().getColumns()[0].getSize());
        assertNull(fm.getJoinIndex());
        assertNotNull(fm.getKeyMapping().getValueIndex());
        assertNotNull(fm.getElementMapping().getValueIndex());
    }
View Full Code Here

TOP

Related Classes of org.apache.openjpa.jdbc.meta.FieldMapping

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.