Package org.jpox.store.mapped

Examples of org.jpox.store.mapped.DatastoreClass


     */
    public ScalarExpression cast(Class castType)
    {
        ObjectExpression objectCast;
        LogicSetExpression te = qs.getTableExpression(this.qs.getStoreManager().getDatastoreClass(castType.getName(), qs.getClassLoaderResolver()).getIdentifier());
        DatastoreClass dc = this.qs.getStoreManager().getDatastoreClass(castType.getName(), qs.getClassLoaderResolver());
        if (te == null)
        {
            IdentifierFactory idFactory = qs.getStoreManager().getIdentifierFactory();
            String jtIdentifier = this.te.getAlias().getIdentifier();
            if (castType != null && !castType.getName().equals(mapping.getType()))
            {
                String castTypeName = castType.getName();
                jtIdentifier = idFactory.newIdentifier(this.te.getAlias(), castTypeName.substring(castTypeName.lastIndexOf('.') + 1)).getIdentifier();
            }

            DatastoreIdentifier jtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, jtIdentifier);
            LogicSetExpression jtTblExpr = qs.getTableExpression(jtRangeVar);

            if (jtTblExpr == null)
            {
                jtTblExpr = qs.newTableExpression(dc, jtRangeVar);
            }
            te = jtTblExpr;
            qs.leftOuterJoin(this, dc.getIDMapping().newScalarExpression(qs,jtTblExpr), jtTblExpr, true, true);
        }
        objectCast = new ObjectExpression(qs,dc.getIDMapping(),te);
        objectCast.conditionExpr = this.conditionExpr;
        return objectCast;
    }
View Full Code Here


                // No discriminator so maybe union, or just a SELECT
                // Need to join to the instanceof class (where appropriate)
                // TODO RDBMS-71 Only join on the UNION select that it is applicable to
                if (table instanceof DatastoreClass)
                {
                    DatastoreClass ct = (DatastoreClass)table;
                    if (ct.managesClass(instanceofClass.getName()))
                    {
                        // This type is managed in this table so must be an instance
                        return new BooleanLiteral(qs, mapping, true).eq(new BooleanLiteral(qs, mapping, true));
                    }
                    else
                    {
                        // The instanceof type is not managed here
                        DatastoreClass instanceofTable = qs.getStoreManager().getDatastoreClass(
                            instanceofClass.getName(), clr);
                        String fieldIdentifier = te.getAlias().getIdentifier();
                        if (fieldName == null)
                        {
                            // Using THIS, so our real table will have an identifier of "THIS_INST"
                            fieldIdentifier += ".INST";
                        }
                        else
                        {
                            // Using field, so our real table will have an identifier of "THIS_{fieldName}"
                            fieldIdentifier += '.' + fieldName;
                        }
                        DatastoreIdentifier fieldRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, fieldIdentifier);
                        LogicSetExpression fieldTblExpr = qs.newTableExpression(instanceofTable, fieldRangeVar);
                        ScalarExpression fieldExpr = table.getIDMapping().newScalarExpression(qs, te);
                        if (fieldName == null)
                        {
                            expr = instanceofTable.getIDMapping().newScalarExpression(qs, fieldTblExpr);
                        }
                        else
                        {
                            expr = mapping.newScalarExpression(qs, fieldTblExpr);
                        }
View Full Code Here

            return false;
        }

        if (latestInsertedDatastoreClass != null)
        {
            DatastoreClass datastoreCls = latestInsertedDatastoreClass;
            while (datastoreCls != null)
            {
                if (datastoreCls.managesClass(className))
                {
                    return true; // This datastore class manages the specified class so it is inserted
                }
                datastoreCls = datastoreCls.getSuperDatastoreClass();
            }
        }

        return false;
    }
View Full Code Here

    {
        JavaTypeMapping[] subMappings = pcMapping.getJavaTypeMapping();
        if (subMappings.length == 0)
        {
            // Embedded PC has no PK so must be embedded-only so use mapping from owner table
            DatastoreClass table = storeMgr.getDatastoreClass(cmd.getFullClassName(), clr);
            JavaTypeMapping ownerMapping = table.getFieldMapping(mmd);
            EmbeddedMapping embMapping = (EmbeddedMapping)ownerMapping;
            for (int k=0;k<embMapping.getNumberOfJavaTypeMappings();k++)
            {
                JavaTypeMapping subMapping = embMapping.getJavaTypeMapping(k);
                pkMappings[position] = subMapping;
View Full Code Here

    public ScalarExpression newFieldExpression(String fieldName)
    {
        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)
                    {
View Full Code Here

            {
                // 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(),
View Full Code Here

    {
        JavaTypeMapping m;
        try
        {
            // TODO This doesnt take into account serialised/embedded
            DatastoreClass datastoreClass = storeMgr.getDatastoreClass(c.getName(), clr);
            m = datastoreClass.getIDMapping();
        }
        catch (NoTableManagedException ex)
        {
            // Note that this doesnt allow for whether a field is serialised or embedded so they get the default mapping only
            Class mc = getMappingClass(c, serialised, embedded, null, storeMgr.getOMFContext().getTypeManager(),
View Full Code Here

            alias = idFactory.newIdentifier(mainAlias, String.valueOf(aliasesByTable.size()));
            aliasesByTable.put(table, alias);

            /* mt... = "main table" */
            /* st... = "secondary table" */
            DatastoreClass mt = (DatastoreClass)mainTable;
            DatastoreClass st = (DatastoreClass)table;
            boolean useInnerJoin = true;
            if (st instanceof SecondaryDatastoreClass)
            {
                // Support join with any secondary table via outer join
                JoinMetaData joinmd = ((SecondaryDatastoreClass)st).getJoinMetaData();
                if (joinmd != null && joinmd.isOuter())
                {
                    useInnerJoin = false;
                }
            }

            LogicSetExpression stTblExpr = qs.newTableExpression(st, alias);

            ScalarExpression mtExpr = mt.getIDMapping().newScalarExpression(qs,this);
            ScalarExpression stExpr = st.getIDMapping().newScalarExpression(qs,stTblExpr);

            if (useInnerJoin)
            {
                qs.innerJoin(mtExpr, stExpr, stTblExpr, true, true);
            }
View Full Code Here

            return null;
        }

        String jtJavaName = "UNBOUND" + '.' + this.getVariableName();

        DatastoreClass cbt = qs.getStoreManager().getDatastoreClass(type.getName(), qs.getClassLoaderResolver());
        DatastoreIdentifier jtRangeVar = qs.getStoreManager().getIdentifierFactory().newIdentifier(IdentifierFactory.TABLE, jtJavaName);
        LogicSetExpression jtExpr = qs.getTableExpression(jtRangeVar);
        if (jtExpr == null)
        {
            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;
View Full Code Here

                    sb.append("SELECT * FROM ");
                }
                sb.append(mainTable.toString());
                while (i.hasNext())
                {
                    DatastoreClass supertable = (DatastoreClass)i.next();

          sb.append(" INNER JOIN ").append(supertable.toString());
          sb.append(" ON ");
          for (int j=0; j<((DatastoreClass) mainTable).getIDMapping().getNumberOfDatastoreFields(); j++)
          {
            DatastoreIdentifier mainTableIDColumnName = ((DatastoreClass)mainTable).getIDMapping().getDataStoreMapping(j).getDatastoreField().getIdentifier();
            if (j > 0)
            {
              sb.append(" AND ");
            }
            sb.append(mainTable.toString()).append('.').append(mainTableIDColumnName);
            sb.append(" = ");
            sb.append(supertable.toString()).append('.').append(supertable.getIDMapping().getDataStoreMapping(j).getDatastoreField().getIdentifier());
          }
                }

                sb.append(") ").append(mainAlias);
            }
View Full Code Here

TOP

Related Classes of org.jpox.store.mapped.DatastoreClass

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.