Package org.jpox.store.mapped.expression

Examples of org.jpox.store.mapped.expression.QueryExpression


        }
        else
        {
            // Key = PC(embedded) or Value = PC(embedded)
            // Generate the statement dynamically since we should select the FetchPlan fields only
            QueryExpression expr = dba.newQueryStatement(setTable, clr);
            ScalarExpression ownerExpr = ownerMapping.newScalarExpression(expr, expr.getMainTableExpression());
            ScalarExpression ownerVal = ownerMapping.newLiteral(expr, sm.getObject());
            expr.andCondition(ownerExpr.eq(ownerVal), true);

            rof = newResultObjectFactory(sm, expr, true);

            stmt = expr.toStatementText(false).toString();
        }

        try
        {
            ObjectManager om = sm.getObjectManager();
View Full Code Here


     * @return Iterator for the set.
     **/
    public Iterator iterator(StateManager ownerSM)
    {
        // Create the basic statement (without any selected columns)
        QueryExpression stmt = getIteratorStatement(ownerSM);
        if (stmt == null)
        {
            throw new JPOXException(LOCALISER.msg("056005")).setFatal();
        }

View Full Code Here

        {
            return null;
        }

        final ClassLoaderResolver clr = ownerSM.getObjectManager().getClassLoaderResolver();
        QueryExpression stmt = null;
        for (int i=0;i<elementInfo.length;i++)
        {
            final int elementNo = i;
            Class elementCls = clr.classForName(elementType);
            QueryExpression subStmt = new UnionIteratorStatement(
                clr, elementCls, true, this.storeMgr,
                elementCls, elementMapping, elementInfo[elementNo].getDatastoreClass(), false,
                null, true, false).getQueryStatement(null);
            if (stmt == null)
            {
View Full Code Here

     **/   
    protected QueryExpression getIteratorStatement(StateManager ownerSM)
    {
        final ClassLoaderResolver clr = ownerSM.getObjectManager().getClassLoaderResolver();
        final Class elementCls = clr.classForName(elementType);
        QueryExpression stmt = null;
        if (emd != null &&
            emd.getDiscriminatorStrategy() != null &&
            emd.getDiscriminatorStrategy() != DiscriminatorStrategy.NONE &&
            containerTable instanceof DatastoreClass)
        {
            // Inverse Map where Value is PC and uses discriminator
            if (storeMgr.getOMFContext().getTypeManager().isReferenceType(clr.classForName(elementType)))
            {
                // Take the metadata for the first implementation of the reference type
                String[] clsNames = storeMgr.getOMFContext().getMetaDataManager().getClassesImplementingInterface(elementType, clr);
                Class[] cls = new Class[clsNames.length];
                for (int j=0; j<clsNames.length; j++)
                {
                    cls[j] = clr.classForName(clsNames[j]);
                }
                stmt = new DiscriminatorIteratorStatement(clr,
                    cls, true, this.storeMgr, true).getQueryStatement(null);
            }
            else
            {
                stmt = new DiscriminatorIteratorStatement(clr, new Class[] {elementCls},
                    true, this.storeMgr, true).getQueryStatement(null);
            }

            iterateUsingDiscriminator = true;

            // Add inner join to the container table
            DatastoreClass sourceTable = storeMgr.getDatastoreClass(elementType, clr);
            ScalarExpression sourceExpr = sourceTable.getIDMapping().newScalarExpression(stmt, stmt.getMainTableExpression());
            LogicSetExpression teTargetElement = stmt.newTableExpression(containerTable, valueIdentifier);
            ScalarExpression targetExpr = elementMapping.newScalarExpression(stmt, teTargetElement);
            stmt.innerJoin(sourceExpr, targetExpr, teTargetElement, true);
        }
        else
        {
            stmt = new UnionIteratorStatement(clr, elementCls, true, this.storeMgr,
                elementCls, elementMapping, containerTable, false, null,
                true, false).getQueryStatement(null);
        }

        // Apply condition on owner field to filter by owner
        ScalarExpression ownerExpr = ownerMapping.newScalarExpression(stmt, stmt.getMainTableExpression());
        ScalarExpression ownerVal = ownerMapping.newLiteral(stmt, ownerSM.getObject());
        stmt.andCondition(ownerExpr.eq(ownerVal), true);

        return stmt;
    }
View Full Code Here

     * @return The Iterator
     **/
    public Iterator iterator(StateManager ownerSM)
    {
        // Create the basic statement (without any selected columns)
        QueryExpression stmt = getIteratorStatement(ownerSM);
        if (stmt == null)
        {
            throw new JPOXException(LOCALISER.msg("056005")).setFatal();
        }

View Full Code Here

    public QueryExpression getExistsSubquery(QueryExpression qs,
                                             JavaTypeMapping mapping,
                                             LogicSetExpression ownerTe,
                                             DatastoreIdentifier arrayTableAlias)
    {
        QueryExpression stmt = dba.newQueryStatement(containerTable, arrayTableAlias, qs.getClassLoaderResolver());
        stmt.setParent(qs);

        // Join for the owner
        ScalarExpression ownerExpr = mapping.newScalarExpression(stmt, ownerTe);
        ScalarExpression ownerInCollectionExpr = ownerMapping.newScalarExpression(stmt, stmt.getTableExpression(arrayTableAlias));
        stmt.andCondition(ownerExpr.eq(ownerInCollectionExpr));

        stmt.select(arrayTableAlias, elementMapping);

        return stmt;
    }
View Full Code Here

    public QueryExpression getSizeSubquery(QueryExpression qs,
                                           JavaTypeMapping mapping,
                                           LogicSetExpression ownerTe,
                                           DatastoreIdentifier arrayTableAlias)
    {
        QueryExpression stmt = dba.newQueryStatement(containerTable, arrayTableAlias, qs.getClassLoaderResolver());
        stmt.setParent(qs);

        // Join for the owner
        ScalarExpression ownerExpr = mapping.newScalarExpression(stmt, ownerTe);
        ScalarExpression ownerInCollectionExpr = ownerMapping.newScalarExpression(stmt, stmt.getTableExpression(arrayTableAlias));
        stmt.andCondition(ownerExpr.eq(ownerInCollectionExpr));

        // Select COUNT(*)
        JavaTypeMapping m = dba.getMapping(String.class, storeMgr);
        StringLiteral lit = (StringLiteral)m.newLiteral(stmt, "COUNT(*)");
        lit.generateStatementWithoutQuotes();
        stmt.selectScalarExpression(lit);

        return stmt;
    }   
View Full Code Here

        // Compile the subquery to get our statement
        JDOQLQueryCompiler subCompiler = new JDOQLQueryCompiler((AbstractJDOQLQuery)subqueryDef.getQuery(),
            imports, subqueryDef.getParameterMap());
        subCompiler.processAsSubquery(qs, subqueryDef.getCandidateExpression(), subqueryDef.getParameterMap());
        QueryExpression subqueryExpr = (QueryExpression)subCompiler.compile(QueryCompiler.COMPILE_EXECUTION);

        // Make sure the result clause is added - this should be refactored into the Compiler from newROF()
        subCompiler.getCandidates().newResultObjectFactory(subqueryExpr, false, subCompiler.getResultClass(), true);

        ScalarExpression expr = new SubqueryExpression(qs, subqueryExpr);
View Full Code Here

     * @param ownerSM the owner StateManager
     * @return The iterator Query Statement.
     */
    protected QueryExpression getIteratorStatement(StateManager ownerSM)
    {
        QueryExpression stmt = null;
        final ClassLoaderResolver clr = ownerSM.getObjectManager().getClassLoaderResolver();
        if (elementsAreEmbedded || elementsAreSerialised)
        {
            // Element = embedded, serialised
            // Just select the join table since we're going to return the embedded/serialised columns from it
            stmt = dba.newQueryStatement(containerTable, clr);
            stmt = dba.newQueryStatement(containerTable, clr);
            stmt.select(elementMapping);
        }
        else if (elementMapping instanceof ReferenceMapping)
        {
            // Element = Reference type (interface/Object)
            // Just select the join table since we're going to return the implementation id columns only
            stmt = dba.newQueryStatement(containerTable, clr);
        }
        else if (elementInfo != null)
        {
            // Element = PC
            // Join to the element table(s)
            for (int i=0;i<elementInfo.length;i++)
            {
                // TODO This will only work if all element types have a discriminator
                final int elementNo = i;
                final Class elementCls = clr.classForName(elementInfo[elementNo].getClassName());
                QueryExpression elementStmt = null;
                if (elementInfo[elementNo].getDiscriminatorStrategy() != null &&
                    elementInfo[elementNo].getDiscriminatorStrategy() != DiscriminatorStrategy.NONE)
                {
                    // The element uses a discriminator so just use that in the SELECT
                    if (storeMgr.getOMFContext().getTypeManager().isReferenceType(clr.classForName(ownerMemberMetaData.getCollection().getElementType())))
View Full Code Here

        }

        ClassLoaderResolver clr = sm.getObjectManager().getClassLoaderResolver();
        DatastoreIdentifier setTableAlias = storeMgr.getIdentifierFactory().newIdentifier(IdentifierFactory.TABLE, setName);

        QueryExpression stmt = dba.newQueryStatement(containerTable, setTableAlias, clr);

        // Join to the owner
        ScalarExpression ownerExpr = ownerMapping.newScalarExpression(stmt, stmt.getTableExpression(setTableAlias));
        ScalarExpression ownerVal = ownerMapping.newLiteral(stmt, sm.getObject());
        stmt.andCondition(ownerExpr.eq(ownerVal), true);

        if (!clr.isAssignableFrom(elementType, candidateClass))
        {
            throw new IncompatibleQueryElementTypeException(elementType, candidateClass);
        }

        /*
         * Try to join to the element table and select the element ID.
         *
         * If the element class does not have a mapping to a table (e.g. -
         * the Set has the element defined as Object or some other super
         * class or interface that is not PersistenceCapable, but has
         * PersistenceCapable implementations), just select the element
         * ID from the join table.  The actual element table will be joined
         * in later if it is casted to in the Query.
         * Because the ClassNotPersistenceCapableException is not thrown anymore
         * with types that are natively supported by TypeManager, we check for
         * it here.
         */
        if (storeMgr.getOMFContext().getTypeManager().isSupportedType(candidateClass))
        {
            // Non-PC(embedded) - select the join table element
            stmt.select(setTableAlias, elementMapping);
        }
        else
        {
            // PC
            DatastoreClass candidateTable = storeMgr.getDatastoreClass(candidateClass, clr);

            // Add the element table to the query, called "SET_ELEMENTS"
            DatastoreIdentifier elementTblAlias = storeMgr.getIdentifierFactory().newIdentifier(
                IdentifierFactory.TABLE, "SET_ELEMENTS");
            LogicSetExpression elementTblExpr = stmt.newTableExpression(candidateTable, elementTblAlias);

            // Inner Join from the ID of the element to the element mapping of the join table
            JavaTypeMapping elementTableID = candidateTable.getIDMapping();
            ScalarExpression elmSetExpr = elementMapping.newScalarExpression(stmt,
                stmt.getTableExpression(setTableAlias));
            ScalarExpression elmExpr = elementTableID.newScalarExpression(stmt, elementTblExpr);
            stmt.innerJoin(elmExpr, elmSetExpr, elementTblExpr, true, true);

            // Select the ID of the element table
            stmt.selectScalarExpression(elementTableID.newScalarExpression(stmt, elementTblExpr));
        }

        return stmt;
    }
View Full Code Here

TOP

Related Classes of org.jpox.store.mapped.expression.QueryExpression

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.