Examples of JavaTypeMapping


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

    {
        if (mainTable instanceof DatastoreClass)
        {
            // Field of class in its primary/secondary table
            DatastoreClass ct = (DatastoreClass) mainTable;
            JavaTypeMapping m = null;
            if (fieldName.equals(qs.getCandidateAlias()))
            {
                // Candidate table so return id mapping
                m = ct.getIDMapping();
                return m.newScalarExpression(qs, this);
            }
            else
            {
                if (fieldName.indexOf(".") > 0)
                {
                    String baseField = fieldName.substring(0, fieldName.indexOf("."));
                    try
                    {
                        m = ct.getFieldMapping(baseField);
                    }
                    catch (NoSuchPersistentFieldException npfe)
                    {
                        // Check if this field is a previously utilised embedded field
                        if (embeddedFieldMappings != null)
                        {
                            m = (JavaTypeMapping)embeddedFieldMappings.get(baseField);
                        }
                        if (m == null)
                        {
                            // Field is not valid for this class, and we have no known embedded mapping for it so its a user error
                            throw npfe;
                        }
                    }
                    if (m == null)
                    {
                        throw new JPOXUserException(LOCALISER.msg("037001", fieldName, ct.toString()));
                    }
                   
                    if (m instanceof EmbeddedPCMapping)
                    {
                        // Embedded PC field
                        String subField = fieldName.substring(fieldName.indexOf(".") + 1);
                        m = getMappingForEmbeddedField((EmbeddedPCMapping)m, subField);
                        if (m == null)
                        {
                            throw new JPOXUserException(LOCALISER.msg("037002", fieldName, subField, baseField));
                        }
                        // Save this embedded mapping in case the user has nested subobjects within it
                        // TODO This doesnt allow for embedded "subfields" having the same name as other embedded subfields
                        // Currently we just keep on saving these against the subfield name, but maybe we only to keep the
                        // most recent since the field will be processed straight away if it's part of a JDOQL query
                        if (embeddedFieldMappings == null)
                        {
                            embeddedFieldMappings = new HashMap();
                        }
                        embeddedFieldMappings.put(subField, m);
                    }
                   
                    ScalarExpression expr = m.newScalarExpression(qs, this);
                    if (expr instanceof ObjectExpression)
                    {
                        ((ObjectExpression)expr).setFieldDefinition(m.getFieldMetaData().getName(), m.getFieldMetaData().getTypeName());
                    }
                    return expr;
                }
                else
                {
                    // Field of main table
                    m = ct.getFieldMapping(fieldName);
                    if (m == null)
                    {
                        throw new JPOXUserException(LOCALISER.msg("037001", fieldName, ct.toString()));
                    }

                    ScalarExpression expr = m.newScalarExpression(qs, this);
                    if (expr instanceof ObjectExpression)
                    {
                        ((ObjectExpression)expr).setFieldDefinition(fieldName, m.getType());
                    }
                    return expr;
                }
            }
        }
        else if (mainTable instanceof DatastoreCollection ||
                 mainTable instanceof DatastoreMap)
        {
            // User has an embedded element/key/value and has a constraint on it
            String fld = fieldName;
            if (fieldName.indexOf(".") > 0)
            {
                // TODO Process the base field - typically is "null". When is it not "null" ?
                String subField = fieldName.substring(fieldName.indexOf(".")+1);
                fld = subField;
            }

            if (mainTable instanceof DatastoreElementContainer)
            {
                // collection/array - element mapping
                DatastoreElementContainer join = (DatastoreElementContainer)mainTable;
                JavaTypeMapping m = join.getElementMapping();
                if (m instanceof EmbeddedElementPCMapping)
                {
                    JavaTypeMapping fieldMapping = ((EmbeddedMapping)m).getJavaTypeMapping(fld);
                    if (fieldMapping != null)
                    {
                        return fieldMapping.newScalarExpression(qs, this);
                    }
                    else
                    {
                        throw new JPOXUserException("'" + fieldName + "' was not found as a field stored in the join table " + mainTable);
                    }
                }
            }
            else if (mainTable instanceof DatastoreMap)
            {
                // Check for a key field first
                DatastoreMap join = (DatastoreMap)mainTable;
                JavaTypeMapping m = join.getKeyMapping();
                if (m instanceof EmbeddedKeyPCMapping)
                {
                    JavaTypeMapping fieldMapping = ((EmbeddedMapping)m).getJavaTypeMapping(fld);
                    if (fieldMapping != null)
                    {
                        return fieldMapping.newScalarExpression(qs, this);
                    }
                }

                // Check for a value field next
                m = join.getValueMapping();
                if (m instanceof EmbeddedValuePCMapping)
                {
                    JavaTypeMapping fieldMapping = ((EmbeddedMapping)m).getJavaTypeMapping(fld);
                    if (fieldMapping != null)
                    {
                        return fieldMapping.newScalarExpression(qs, this);
                    }
                }
            }

            throw new JPOXUserException("'" + fieldName + "' was not found as an embedded element/key/value field stored in the join table " + mainTable);
View Full Code Here

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

            return m.getJavaTypeMapping(fieldName);
        }

        String field = fieldName.substring(0, fieldName.indexOf("."));
        String subField = fieldName.substring(fieldName.indexOf(".")+1);
        JavaTypeMapping mapping = m.getJavaTypeMapping(field);
        if (mapping instanceof EmbeddedPCMapping && subField != null)
        {
            return getMappingForEmbeddedField((EmbeddedPCMapping)mapping, subField);
        }
        return mapping;
View Full Code Here

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

            if (value == null)
            {
                return new NullLiteral(qs);
            }

            JavaTypeMapping m = null;
            ApiAdapter api = qs.getStoreManager().getApiAdapter();
            if (api.isPersistable(cls))
            {
                // PC class, so maybe has its own table
                try
                {
                    // PC class, so maybe has its own table
                    DatastoreClass clsTable = qs.getStoreManager().getDatastoreClass(cls.getName(), qs.getClassLoaderResolver());
                    m = clsTable.getFieldMapping(fieldName);
                }
                catch (Exception e)
                {
                    // PC class has no table or no such field so just get a default mapping for type
                    m = qs.getStoreManager().getDatastoreAdapter().getMapping(value.getClass(),
                        qs.getStoreManager(), qs.getClassLoaderResolver());
                }
            }
            else
            {
                // Just get a default mapping for type
                m = qs.getStoreManager().getDatastoreAdapter().getMapping(value.getClass(),
                    qs.getStoreManager(), qs.getClassLoaderResolver());
            }
            return m.newLiteral(qs, value);
        }
        catch (IllegalAccessException iae)
        {
            // Will not happen since we already checked for it
        }
View Full Code Here

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

    public ScalarExpression cast(Class castType)
    {
        JavaTypeMapping[] javaTypeMappings = ((ReferenceMapping)mapping).getJavaTypeMapping();
        for (int i = 0; i < javaTypeMappings.length; ++i)
        {
            JavaTypeMapping m = javaTypeMappings[i];
            if (castType.getName().equals(m.getType()))
            {         
                return m.newScalarExpression(qs,te);
            }
        }
        return super.cast(castType);
    }
View Full Code Here

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

        {
            // Expression of form "ReferenceExpression == ReferenceExpression"
            // TODO Should really split into an expression for each part and line up the JavaTypeMappings
            for (int i = 0; i < javaTypeMappings.length; ++i)
            {
                JavaTypeMapping m = javaTypeMappings[i];

                if (bexpr == null)
                {
                    bexpr = m.newScalarExpression(qs, te).eq(expr);
                    bexpr.encloseWithInParentheses();
                }
                else
                {
                    bexpr = bexpr.ior(m.newScalarExpression(qs, te).eq(expr).encloseWithInParentheses());
                    bexpr.encloseWithInParentheses();
                }
            }
        }
        else if (expr.mapping instanceof NullMapping)
        {
            // Expression of form "ReferenceExpression == null"
            for (int i = 0; i < javaTypeMappings.length; ++i)
            {
                JavaTypeMapping m = javaTypeMappings[i];
                if (bexpr == null)
                {
                    bexpr = m.newScalarExpression(qs, te).eq(expr);
                }
                else
                {
                    bexpr = bexpr.and(m.newScalarExpression(qs, te).eq(expr));
                }
            }
        }
        else
        {
            // Expression of form "ReferenceExpression == PC"
            for (int i = 0; i < javaTypeMappings.length; ++i)
            {
                JavaTypeMapping m = javaTypeMappings[i];
                JavaTypeMapping exprMapping = expr.mapping;
                if (m.getNumberOfDatastoreFields() == exprMapping.getNumberOfDatastoreFields())
                {
                    // TODO Should apply the above check on noteq() too but in reverse
                    // If expression implementation and this implementation have same number of PK fields allow the compare
                    // TODO Should really also compare the types of the mappings
                    if (bexpr == null)
View Full Code Here

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

        {
            // Expression of form "ReferenceExpression != null"
            // So find a mapping that is not null amongst the possible impls
            for (int i = 0; i < javaTypeMappings.length; ++i)
            {
                JavaTypeMapping m = javaTypeMappings[i];
                if (bexpr == null)
                {
                    bexpr = m.newScalarExpression(qs, te).noteq(expr);
                }
                else
                {
                    bexpr = bexpr.ior(m.newScalarExpression(qs, te).noteq(expr));
                }
            }
        }
        else
        {
            for (int i = 0; i < javaTypeMappings.length; ++i)
            {
                JavaTypeMapping m = javaTypeMappings[i];
                if (bexpr == null)
                {
                    bexpr = m.newScalarExpression(qs,te).noteq(expr);
                }
                else
                {
                    bexpr = bexpr.and(m.newScalarExpression(qs,te).noteq(expr));
                }
            }
        }
    bexpr.encloseWithInParentheses();
        return bexpr;
View Full Code Here

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

            return new ContainerSizeExpression(qs, getBackingStoreQueryable().getSizeSubquery(qs, mapping, te, ctRangeVar));
        }
        else
        {
            JavaTypeMapping mapping = qs.getStoreManager().getDatastoreAdapter().getMapping(Integer.class, qs.getStoreManager(), qs.getClassLoaderResolver());
            return new IntegerLiteral(qs,mapping,new Integer(exprs.length));
        }
    }   
View Full Code Here

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

            for (Iterator it=value.iterator(); it.hasNext();)
            {
                Object current = it.next();
                if (current != null)
                {
                    JavaTypeMapping m = dba.getMapping(current.getClass(), qs.getStoreManager(), qs.getClassLoaderResolver());
                    ScalarExpression expr = m.newLiteral(qs,current);

                    // Append the SQLExpression (should be a literal) for the
                    // current element.
                    st.append(hadPrev ? "," : "");
                    st.append(expr);
View Full Code Here

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

            for (Iterator it=values.iterator(); it.hasNext();)
            {
                Object current = it.next();
                if (null != current)
                {
                    JavaTypeMapping m = dba.getMapping(current.getClass(), qs.getStoreManager(), qs.getClassLoaderResolver());
                    ScalarExpression expr = m.newLiteral(qs, current);

                    // Append the SQLExpression (should be a literal) for the
                    // current element.
                    st.append(hadPrev ? "," : "");
                    st.append(expr);
View Full Code Here

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

            jtExpr = qs.newTableExpression(cbt, jtRangeVar);
            //qs.addAlias(jtExpr, true);
        }

        // bind unbound variable
        JavaTypeMapping mb = cbt.getIDMapping();
        ScalarExpression exprBindTo = mb.newScalarExpression(qs, jtExpr);

        // Save the mapping in case we are selecting this in the result clause later
        mapping = mb;

        exprToBind = exprBindTo;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.