Package org.datanucleus.store.mapped.expression

Examples of org.datanucleus.store.mapped.expression.ScalarExpression


                 * LEFT OUTER JOIN ELEM_TBL ELEM1 ON ELEM1.ID = THIS.ELEM_ID
                 * WHERE THIS.ELEM_ID IS NULL
                 */
                QueryExpression nullStmt = getQueryForElement(candidateFullClassName,
                    storeMgr.getDatastoreClass(candidateFullClassName, clr), true, candidateAlias);
                ScalarExpression elemIdExpr = sourceMapping.newScalarExpression(nullStmt, nullStmt.getMainTableExpression());
                nullStmt.andCondition(new NullLiteral(nullStmt).eq(elemIdExpr));
                stmt.union(nullStmt);
            }

            return stmt;
View Full Code Here


            // Add join from the join table to the root element table
            DatastoreIdentifier targetTableIdentifier = null;
            DatastoreIdentifier rootElementTblId = idFactory.newIdentifier(IdentifierType.TABLE, "ELEMENT");
            LogicSetExpression rootElementTblExpr = stmt.newTableExpression(candidateTable, rootElementTblId);
            ScalarExpression sourceExpr = sourceMapping.newScalarExpression(stmt, stmt.getMainTableExpression());
            ScalarExpression rootElementExpr =
                candidateTable.getIDMapping().newScalarExpression(stmt, rootElementTblExpr);
            if (allowNull)
            {
                stmt.leftOuterJoin(sourceExpr, rootElementExpr, rootElementTblExpr, true);
            }
            else
            {
                stmt.innerJoin(sourceExpr, rootElementExpr, rootElementTblExpr, true);
            }
            targetTableIdentifier = rootElementTblId;

            if (targetElementTable != candidateTable)
            {
                // Add join from the root element table to the target element table
                DatastoreIdentifier tgtElementTblId = idFactory.newIdentifier(IdentifierType.TABLE, "ELMNTSUB");
                LogicSetExpression tgtElementTblExpr = stmt.newTableExpression(targetElementTable, tgtElementTblId);
                ScalarExpression targetExpr =
                    targetElementTable.getIDMapping().newScalarExpression(stmt, tgtElementTblExpr);
                if (allowNull)
                {
                    stmt.leftOuterJoin(rootElementExpr, targetExpr, tgtElementTblExpr, true);
                }
                else
                {
                    stmt.innerJoin(rootElementExpr, targetExpr, tgtElementTblExpr, true);
                }
                targetTableIdentifier = tgtElementTblId;
            }

            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

    {
        // TODO Make this identifier specifiable as input to the iterator statement
        DatastoreIdentifier targetTableIdentifier =
            stmt.getStoreManager().getIdentifierFactory().newIdentifier(IdentifierType.TABLE, "ELEMENT");
        LogicSetExpression teTargetElement = stmt.newTableExpression(elementTargetTable, targetTableIdentifier);
        ScalarExpression sourceExpr = sourceMapping.newScalarExpression(stmt, stmt.getMainTableExpression());
        ScalarExpression targetExpr =
            elementTargetTable.getIDMapping().newScalarExpression(stmt, teTargetElement);
        if (leftOuterJoin)
        {
            stmt.leftOuterJoin(sourceExpr, targetExpr, teTargetElement, true);
        }
View Full Code Here

    {
        // TODO Make this identifier specifiable as input to the iterator statement
        DatastoreIdentifier sourceTableIdentifier =
            stmt.getStoreManager().getIdentifierFactory().newIdentifier(IdentifierType.TABLE, "VALUE");
        LogicSetExpression teSourceElement = stmt.newTableExpression(sourceTable, sourceTableIdentifier);
        ScalarExpression sourceExpr = sourceMapping.newScalarExpression(stmt, teSourceElement);
        ScalarExpression targetExpr =
            elementTargetTable.getIDMapping().newScalarExpression(stmt, stmt.getMainTableExpression());
        if (leftOuterJoin)
        {
            stmt.leftOuterJoin(sourceExpr, targetExpr, teSourceElement, true);
        }
View Full Code Here

                    // Create the container table if not yet present in the statement
                    stmt.newTableExpression(containerTable, containerRangeVar);
                }

                // Reverse collection contains query so join back to the owner
                ScalarExpression ownerExpr = ownerMapping.newScalarExpression(stmt, ownerTe);
                ScalarExpression ownerSetExpr = this.ownerMapping.newScalarExpression(stmt,
                    stmt.getTableExpression(containerRangeVar));
                stmt.andCondition(ownerExpr.eq(ownerSetExpr), true);
            }
            else
            {
                if (elementExpr.getLogicSetExpression().getMainTable() == filteredElementTable)
                {
                    // Element expression is of the container table
                    // Simple example is "SELECT FROM MyType WHERE field1.contains(this)"
                    // so candidate is MyType, element type is MyType and the element we are checking
                    // is MyType.
                    if (stmt.getTableExpression(containerRangeVar) == null)
                    {
                        // Why???????????????
                        containerRangeVar = elementTableAlias;
                    }
                    if (stmt.getTableExpression(containerRangeVar) == null)
                    {
                        // Create the container table if not yet present in the statement
                        stmt.newTableExpression(containerTable, containerRangeVar);
                    }
                    ScalarExpression ownerExpr = ownerMapping.newScalarExpression(stmt, ownerTe);
                    ScalarExpression ownerSetExpr = this.ownerMapping.newScalarExpression(stmt,
                        stmt.getTableExpression(containerRangeVar));
                    stmt.andCondition(ownerExpr.eq(ownerSetExpr), true);
                }
                else
                {
                    // Element is of a different table
                    // Simple example is "SELECT FROM MyType WHERE field1.contains(field2)"
                    // so candidate is MyType, element type is MyElement, and the element we are checking
                    // is MyType.field2. This creates an INNER JOIN MYTYPES.ID -> MYELEMENT.FK
                    if (stmt.getTableExpression(containerRangeVar) == null)
                    {
                        // Create the container table if not yet present in the statement
                        stmt.newTableExpression(containerTable, containerRangeVar);
                    }

                    // Add a join from the owner table to the container table
                    ScalarExpression ownerExpr = ownerMapping.newScalarExpression(stmt, ownerTe);
                    ScalarExpression ownerSetExpr = this.ownerMapping.newScalarExpression(stmt,
                        stmt.getTableExpression(containerRangeVar));
                    stmt.innerJoin(ownerExpr, ownerSetExpr, stmt.getTableExpression(containerRangeVar), true, true);
                }
            }
        }
View Full Code Here

            QueryExpression targetQS;
            DatastoreClass cbtTargetSubElementType = storeMgr.getDatastoreClass(targetSubElementType, clr);
            DatastoreIdentifier tiTargetSubElementType;
            LogicSetExpression teTargetSubElementType;
            ScalarExpression targetSubElementTypeExpr;

            DatastoreClass[] targetSubElementTypes = null;
            if (cbtTargetSubElementType == null)
            {
                AbstractClassMetaData targetSubCmd =
                    storeMgr.getOMFContext().getMetaDataManager().getMetaDataForClass(targetSubElementType, stmt.getClassLoaderResolver());
                AbstractClassMetaData[] targetSubCmds = storeMgr.getClassesManagingTableForClass(targetSubCmd, clr);
                targetSubElementTypes = new DatastoreClass[targetSubCmds.length];
                for (int i=0;i<targetSubCmds.length;i++)
                {
                    targetSubElementTypes[i] = storeMgr.getDatastoreClass(targetSubCmds[i].getFullClassName(), clr);
                }
            }
            else
            {
                targetSubElementTypes = new DatastoreClass[1];
                targetSubElementTypes[0] = cbtTargetSubElementType;
            }

            for (int i=0;i<targetSubElementTypes.length;i++)
            {
                // Add leftOuterJoin to sub-target elements if they are not in the same table as the target
                if (!targetSubElementTypes[i].toString().equals(storeMgr.getDatastoreClass(targetElementType, clr).toString()))
                {
                    tiTargetSubElementType =
                        storeMgr.getIdentifierFactory().newIdentifier(IdentifierType.TABLE,
                            "SUBELEMENT" + (subSequenceIdentifier++));

                    // create a new statement
                    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

    // ---------------------------- JDOQL Query Methods --------------------------------------

    public ScalarExpression newLiteral(QueryExpression qs, Object value)
    {
        ScalarExpression expr = new ObjectLiteral(qs, this, value,getType());
        return expr;       
    }
View Full Code Here

TOP

Related Classes of org.datanucleus.store.mapped.expression.ScalarExpression

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.