Package org.jpox.store.mapped.mapping

Examples of org.jpox.store.mapped.mapping.JavaTypeMapping


        return statementExpressionIndex[fieldNumber].getMapping().getString(om, rs, statementExpressionIndex[fieldNumber].getExpressionIndex());
    }

    public Object fetchObjectField(int fieldNumber)
    {
        JavaTypeMapping mapping = statementExpressionIndex[fieldNumber].getMapping();
        Object value;
        if (mapping instanceof EmbeddedPCMapping ||
            mapping instanceof SerialisedPCMapping ||
            mapping instanceof SerialisedReferenceMapping)
        {
            value = mapping.getObject(om, rs, statementExpressionIndex[fieldNumber].getExpressionIndex(), sm, fieldNumber);
        }
        else
        {
            value = mapping.getObject(om, rs, statementExpressionIndex[fieldNumber].getExpressionIndex());
        }

        // Return the field value (as a wrapper if wrappable)
        return sm.wrapSCOField(fieldNumber, value, false, false, false);
    }
View Full Code Here


        else
        {
            return null;
        }

        JavaTypeMapping m = qs.getStoreManager().getDatastoreAdapter().getMapping(litType,
            qs.getStoreManager(), qs.getClassLoaderResolver());
        return m.newLiteral(qs, litValue);
    }
View Full Code Here

            throw new JPOXUserException(LOCALISER.msg("052400",statementExpressionIndex[fieldNumber].getMapping().getFieldMetaData().getFullFieldName()));
        }

        try
        {
            JavaTypeMapping mapping = statementExpressionIndex[fieldNumber].getMapping();
            if (mapping instanceof EmbeddedPCMapping ||
                mapping instanceof SerialisedPCMapping ||
                mapping instanceof SerialisedReferenceMapping ||
                mapping instanceof PersistenceCapableMapping ||
                mapping instanceof InterfaceMapping)
            {
                // Pass in the owner StateManager/field for any mappings that need to perform management of the relation
                mapping.setObject(om, ps, statementExpressionIndex[fieldNumber].getParameterIndex(), value, sm, fieldNumber);
            }
            else
            {
                mapping.setObject(om, ps, statementExpressionIndex[fieldNumber].getParameterIndex(), value);
            }

            // Make sure the field is wrapped where appropriate
          sm.wrapSCOField(fieldNumber, value, false, true, true);
        }
View Full Code Here

                {
                    elementTable = storeMgr.getDatastoreClass(elementType, clr);
                }
                if (elementTable != null)
                {
                    JavaTypeMapping externalFKMapping = elementTable.getExternalMapping(ownerMemberMetaData,
                        MappingConsumer.MAPPING_TYPE_EXTERNAL_FK);
                    if (externalFKMapping != null)
                    {
                        // The element has an external FK mapping so set the value it needs to use in the INSERT
                        esm.setExternalFieldValueForMapping(externalFKMapping, sm.getObject());
View Full Code Here

                }
            }
        }

        // Return the expression of the PK of the elements table for the element to be bound to
        JavaTypeMapping elementTableID = filteredElementTable.getIDMapping();
        return elementTableID.newScalarExpression(stmt, stmt.getTableExpression(containerRangeVar));
    }
View Full Code Here

    private QueryExpression getQueryForElement(String targetElementType, DatastoreClass targetElementTable,
            boolean allowNull, DatastoreIdentifier candidateId)
    {
        QueryExpression stmt;

        JavaTypeMapping discriminatorMapping = null;
        DiscriminatorMetaData discriminatorMetaData = null;
        LogicSetExpression discriminatorTableExpr = null;
        if (sourceTable instanceof SCOTable)
        {
            // * Selecting the join table of a JoinTable (normal) relationship, and joining to the element table
            stmt = dba.newQueryStatement(sourceTable, candidateId, clr);

            // Add inner joins to all classes above up to elementType and across to the join table
            DatastoreIdentifier targetTableIdentifier = joinSourceToTargetElement(stmt, targetElementTable, allowNull);

            discriminatorMapping = targetElementTable.getDiscriminatorMapping(false);
            discriminatorMetaData = targetElementTable.getDiscriminatorMetaData();
            discriminatorTableExpr = stmt.getTableExpression(targetTableIdentifier);

            // Add left outer joins to exclude any target element subclasses
            if (joinToExcludeTargetSubclasses)
            {
                joinToExcludeTargetWhenSubElementsExists(stmt, sourceMapping, targetElementType);
            }
        }
        else
        {
            // * Selecting FCO objects directly (Extents etc)
            // * Selecting the element table of a ForeignKey (inverse) relationship
            stmt = dba.newQueryStatement(candidateTable, candidateId, clr);

            discriminatorMapping = sourceTable.getDiscriminatorMapping(false);
            discriminatorMetaData = sourceTable.getDiscriminatorMetaData();
            discriminatorTableExpr = stmt.getMainTableExpression();

            // in case of the elementType is a subClass of the element for the candidateTable
            // if the root (candidate) element type is not the same as the current target element type
            // joins the root to the current element
            if ((!targetElementTable.toString().equals(sourceTable.toString()) &&
                 !candidateTable.getType().equals(targetElementType)) ||
                 sourceJoin)
            {
                // Add inner joins to all classes above up to elementType and across to the join table
                if (sourceJoin)
                {
                    joinTargetToSourceElement(stmt, targetElementTable, false);
                }
                else
                {
                    joinSourceToTargetElement(stmt, targetElementTable, false);
                }
            }
            if (joinToExcludeTargetSubclasses)
            {
                joinToExcludeTargetWhenSubElementsExists(stmt, candidateTable.getIDMapping(), targetElementType);
            }
        }

        if (discriminatorMapping != null && discriminatorMetaData.getStrategy() != DiscriminatorStrategy.NONE)
        {
            // Restrict to valid discriminator values where we have a discriminator specified on this table
            String discriminatorValue = targetElementType;
            if (discriminatorMetaData.getStrategy() == DiscriminatorStrategy.VALUE_MAP)
            {
                // Get the MetaData for the target class since that holds the "value"
                AbstractClassMetaData targetCmd = storeMgr.getOMFContext().getMetaDataManager().getMetaDataForClass(targetElementType, clr);
                discriminatorValue = targetCmd.getInheritanceMetaData().getDiscriminatorMetaData().getValue();
            }
            ScalarExpression discrExpr = discriminatorMapping.newScalarExpression(stmt, discriminatorTableExpr);
            ScalarExpression discrVal = discriminatorMapping.newLiteral(stmt, discriminatorValue);
            stmt.andCondition(discrExpr.eq(discrVal));
        }

        if (withMetadata == null || withMetadata.booleanValue())
        {
View Full Code Here

                    targetQS = dba.newQueryStatement(targetSubElementTypes[i], tiTargetSubElementType, stmt.getClassLoaderResolver());

                    // table expression from the table identifier
                    teTargetSubElementType = targetQS.newTableExpression(targetSubElementTypes[i], tiTargetSubElementType);

                    JavaTypeMapping targetMapping = targetSubElementTypes[i].getIDMapping();
                    ScalarExpression targetElementExpr =
                        targetElementMapping.newScalarExpression(stmt, stmt.getMainTableExpression());
                    targetSubElementTypeExpr = targetMapping.newScalarExpression(stmt, teTargetSubElementType);
                    stmt.leftOuterJoin(targetElementExpr,targetSubElementTypeExpr, teTargetSubElementType, true);
                    ScalarExpression seTargetSubElementType = targetMapping.newScalarExpression(targetQS, teTargetSubElementType);
                    stmt.andCondition(new NullLiteral(stmt).eq(seTargetSubElementType));
                }
            }
        }
    }
View Full Code Here

        }

        EmbeddedElementPCMapping embeddedMapping = (EmbeddedElementPCMapping)elementMapping;
        for (int i=0;i<embeddedMapping.getNumberOfJavaTypeMappings();i++)
        {
            JavaTypeMapping m = embeddedMapping.getJavaTypeMapping(i);
            if (m != null)
            {
                for (int j=0;j<m.getNumberOfDatastoreFields();j++)
                {
                    stmt.append(" AND ");
                    stmt.append(m.getDataStoreMapping(j).getDatastoreField().getIdentifier().toString());
                    stmt.append(" = ");
                    stmt.append(((RDBMSMapping)m.getDataStoreMapping(j)).getUpdateInputParameter());
                }
            }
        }
        return stmt.toString();
    }
View Full Code Here

            if (fieldName == null)
            {
                // We have no mapping for this field so presumably is the owner field or a PK field
                return false;
            }
            JavaTypeMapping fieldMapping = ((EmbeddedElementPCMapping)elementMapping).getJavaTypeMapping(fieldName);
            if (fieldMapping == null)
            {
                // We have no mapping for this field so presumably is the owner field or a PK field
                return false;
            }

            String stmt = getUpdateEmbeddedElementStmt(fieldMapping);
            try
            {
                ObjectManager om = sm.getObjectManager();
                ManagedConnection mconn = storeMgr.getConnection(om);
                SQLController sqlControl = storeMgr.getSQLController();

                try
                {
                    PreparedStatement ps = sqlControl.getStatementForUpdate(mconn, stmt, false);
                    try
                    {
                        int jdbcPosition = 1;
                        fieldMapping.setObject(om, ps, Mappings.getParametersIndex(jdbcPosition, fieldMapping), value);
                        jdbcPosition += fieldMapping.getNumberOfDatastoreFields();
                        jdbcPosition = populateOwnerInStatement(sm, om, ps, jdbcPosition);
                        jdbcPosition = populateEmbeddedElementFieldsInStatement(sm, element, ps, jdbcPosition, (JoinTable)containerTable);

                        sqlControl.executeStatementUpdate(mconn, stmt, ps, true);
                        modified = true;
View Full Code Here

                // Add WHERE for the element and each subclass type so we restrict to valid element types
                HashSet subclasses = storeMgr.getSubClassesForClass(elementInfo[0].getClassName(), true, clr);
                for (int i=0;i<subclasses.size()+1;i++)
                {
                    JavaTypeMapping discrimMapping = elementInfo[0].getDiscriminatorMapping();
                    for (int j=0;j<discrimMapping.getNumberOfDatastoreFields();j++)
                    {
                        if (joinedDiscrim)
                        {
                            stmt.append(joinedElementAlias);
                        }
                        else
                        {
                            stmt.append(containerAlias);
                        }
                        stmt.append(".").append(discrimMapping.getDataStoreMapping(j).getDatastoreField().getIdentifier().toString());
                        stmt.append(" = ");
                        stmt.append(((RDBMSMapping)discrimMapping.getDataStoreMapping(j)).getUpdateInputParameter());

                        if (j != discrimMapping.getNumberOfDatastoreFields()-1 || i != subclasses.size())
                        {
                            stmt.append(" OR ");
                        }
                    }
                }
View Full Code Here

TOP

Related Classes of org.jpox.store.mapped.mapping.JavaTypeMapping

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.