Package org.jpox.store.mapped.expression

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


     * @return the match expression.
     */
    public BooleanExpression matchesMethod(StringExpression text, StringExpression pattern)
    {
        JavaTypeMapping m = getMapping(BigInteger.class, text);
        ScalarExpression integerLiteral = m.newLiteral(text.getQueryExpression(), BigInteger.ONE);

        List args = new ArrayList();
        args.add(text);
        args.add(pattern);

View Full Code Here


                clr.classForName(valueType), valueMapping, mapTable, false, null,
                true, false).getQueryStatement(null);
        }

        // Apply condition on join-table 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);

        // TODO this is a database hack. :-)
        // if the keyMapping contains a BLOB column (or any other column not supported by the database
        // as primary key), uses like instead of the operator OP_EQ (=)
        // in future do not check if the keyMapping is of ObjectMapping, but use the database
        // adapter to check the data types not supported as primary key
        // if object mapping (BLOB) use like
        // TODO Cater for embedded key
        if (keyMapping instanceof SerialisedMapping)
        {
            // Apply condition on join-table owner field to filter by owner
            ScalarExpression keyExpr = keyMapping.newScalarExpression(stmt,stmt.getMainTableExpression());
            ScalarExpression keyVal = keyMapping.newLiteral(stmt, key).add(dba.getMapping(String.class, storeMgr).newLiteral(stmt,"%"));
            stmt.andCondition(new BooleanExpression(keyExpr,ScalarExpression.OP_LIKE,keyVal), true);            
        }
        else
        {
            // Apply condition on join-table owner field to filter by owner
            ScalarExpression keyExpr = keyMapping.newScalarExpression(stmt,stmt.getMainTableExpression());
            ScalarExpression keyVal = keyMapping.newLiteral(stmt, key);
            stmt.andCondition(keyExpr.eq(keyVal), true);
        }
        return stmt;
    }
View Full Code Here

        ClassLoaderResolver clr = sm.getObjectManager().getClassLoaderResolver();
        DatastoreIdentifier mapTableAlias = storeMgr.getIdentifierFactory().newIdentifier(IdentifierFactory.TABLE, "map");
        QueryExpression stmt = dba.newQueryStatement(mapTable, mapTableAlias, clr);

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

        if (storeMgr.getOMFContext().getTypeManager().isSupportedType(candidateClass))
        {
            // Non-PC(embedded) - select the join table value
            stmt.select(mapTableAlias, valueMapping);
        }
        else
        {
            // PC - Join the value table on the value ID column
            DatastoreClass candidateTable = storeMgr.getDatastoreClass(candidateClass, clr);

            // Add the element table to the query
            // TODO Why use the default table alias ?, and why the default table expression below?
            // This uses the assumption that if this is a subquery then we find the right outer query candidate!
            stmt.newTableExpression(candidateTable, stmt.getMainTableAlias());

            // Inner Join from the ID of the value to the value mapping of the join table
            JavaTypeMapping valueTableID = candidateTable.getIDMapping();
            ScalarExpression valueMapExpr = valueMapping.newScalarExpression(stmt,
                stmt.getTableExpression(mapTableAlias));
            ScalarExpression valueExpr = valueTableID.newScalarExpression(stmt,
                stmt.getMainTableExpression());
            stmt.innerJoin(valueExpr, valueMapExpr, stmt.getMainTableExpression(), true, true);

            // Select the ID of the value table
            stmt.select(valueTableID);
View Full Code Here

            throw new IncompatibleQueryElementTypeException(keyType, filteredKeyType == null ? null : filteredKeyType.getName());
        }

        // Join the map table on the owner ID column (apply to any unions)
        LogicSetExpression mapTblExpr = stmt.newTableExpression(mapTable, mapTableAlias);
        ScalarExpression ownerMapExpr = this.ownerMapping.newScalarExpression(stmt,stmt.getTableExpression(mapTableAlias));
        ScalarExpression ownerExpr = ownerMapping.newScalarExpression(stmt, ownerTe);
        if( !parentStmt.hasCrossJoin(mapTblExpr) )
        {
            stmt.crossJoin(mapTblExpr, true);
        }
        stmt.andCondition(ownerExpr.eq(ownerMapExpr),true);
       
        if (storeMgr.getOMFContext().getTypeManager().isSupportedType(filteredKeyType.getName()))
        {
            // Key = Non-PC(embedded)
            return keyMapping.newScalarExpression(stmt,stmt.getTableExpression(mapTableAlias));
        }
        else if (keysAreEmbedded || keysAreSerialised)
        {
            // Key = PC(embedded), PC(serialised)
            return keyMapping.newScalarExpression(stmt,stmt.getTableExpression(mapTableAlias));
        }
        else
        {
            // Key = PC
            // Join the key table on the key ID column
            DatastoreClass keyTable = storeMgr.getDatastoreClass(filteredKeyType.getName(), stmt.getClassLoaderResolver());
            JavaTypeMapping keyTableID = keyTable.getIDMapping();

            LogicSetExpression keyTblExpr = stmt.getTableExpression(keyTableAlias);
            if (keyTblExpr==null)
            {
                keyTblExpr = stmt.newTableExpression(keyTable,keyTableAlias);
            }
            ScalarExpression keyMapExpr = keyMapping.newScalarExpression(stmt,stmt.getTableExpression(mapTableAlias));
            if (!parentStmt.hasCrossJoin(keyTblExpr))
            {
                stmt.crossJoin(keyTblExpr, true);
            }
            if( keyExpr == null )
            {
                keyExpr = keyTableID.newScalarExpression(stmt, stmt.getTableExpression(keyTableAlias));
            }
            if( keyExpr.getLogicSetExpression()!= null && !keyTable.equals(keyExpr.getLogicSetExpression().getMainTable()) )
            {
                //keyExpr might express a FK in another to the KEY table
                stmt.andCondition(keyMapExpr.eq(keyExpr),true);
                return this.keyMapping.newScalarExpression(stmt,stmt.getTableExpression(mapTableAlias));
            }
            else
            {
                //keyExpr might be a PK of the KEY table
                ScalarExpression kExpr = keyTableID.newScalarExpression(stmt, stmt.getTableExpression(keyTableAlias));
                stmt.andCondition(keyMapExpr.eq(kExpr),true);
                return kExpr;
            }
        }
    }
View Full Code Here

            throw new IncompatibleQueryElementTypeException(valueType, filteredValueType==null ? null : filteredValueType.getName());
        }

        // Join the map table on the owner ID column
        LogicSetExpression mapTblExpr = stmt.newTableExpression(mapTable, mapTableAlias);
        ScalarExpression ownerExpr = ownerMapping.newScalarExpression(stmt,ownerTe);
        ScalarExpression ownerMapExpr = this.ownerMapping.newScalarExpression(stmt, stmt.getTableExpression(mapTableAlias));
        if( !parentStmt.hasCrossJoin(mapTblExpr) )
        {
            stmt.crossJoin(mapTblExpr, true);
        }
        stmt.andCondition(ownerExpr.eq(ownerMapExpr),true);
       
        if (storeMgr.getOMFContext().getTypeManager().isSupportedType(filteredValueType.getName()))
        {
            // Value = Non-PC(embedded)
            return valueMapping.newScalarExpression(stmt,stmt.getTableExpression(mapTableAlias));
        }
        else if (valuesAreEmbedded || valuesAreSerialised)
        {
            // Value = PC(embedded), PC(serialised)
            return valueMapping.newScalarExpression(stmt,stmt.getTableExpression(mapTableAlias));
        }
        else
        {
            // Value = PC
            // Join the value table on the value ID column
            DatastoreClass valueTable=storeMgr.getDatastoreClass(filteredValueType.getName(), stmt.getClassLoaderResolver());
            JavaTypeMapping valueTableID = valueTable.getIDMapping();
            LogicSetExpression valueTblExpr = stmt.getTableExpression(valueTableAlias);
            if (valueTblExpr == null)
            {
                valueTblExpr = stmt.newTableExpression(valueTable,valueTableAlias);
            }
            ScalarExpression valueMapExpr = valueMapping.newScalarExpression(stmt,stmt.getTableExpression(mapTableAlias));
            if (!parentStmt.hasCrossJoin(valueTblExpr))
            {
                stmt.crossJoin(valueTblExpr, true);
            }
            if (valExpr == null)
            {
                valExpr = valueTableID.newScalarExpression(stmt, stmt.getTableExpression(valueTableAlias));
            }
            if (valExpr.getLogicSetExpression() != null &&
                !valueTable.equals(valExpr.getLogicSetExpression().getMainTable()))
            {
                //valExpr might express a FK in another to the VALUE table
                stmt.andCondition(valueMapExpr.eq(valExpr),true);
                return this.valueMapping.newScalarExpression(stmt,stmt.getTableExpression(mapTableAlias));
            }
            else
            {
                //valExpr might be a PK of the VALUE table
                ScalarExpression valueExpr = valueTableID.newScalarExpression(stmt, stmt.getTableExpression(valueTableAlias));
                stmt.andCondition(valueMapExpr.eq(valueExpr),true);
                return valueExpr;
            }
        }
    }
View Full Code Here

     * @param from The from position
     * @return The text of the SQL expression.
     */
    public NumericExpression indexOfMethod(ScalarExpression source, ScalarExpression str, NumericExpression from)
    {
        ScalarExpression integerLiteral = getMapping(BigInteger.class, source).newLiteral(source.getQueryExpression(), BigInteger.ONE);

        ArrayList args = new ArrayList();
        args.add(source);
        args.add(str);
        if (from != null)
View Full Code Here

    public NumericExpression getDayMethod(SqlTemporalExpression date)
    {
        ArrayList args = new ArrayList();

        JavaTypeMapping m = getMapping(String.class, date);
        ScalarExpression submethodLiteral = m.newLiteral(date.getQueryExpression(), "day");
        args.add(submethodLiteral);

        args.add(date);

        return new NumericExpression("date_part", args);
View Full Code Here

    public NumericExpression getMonthMethod(SqlTemporalExpression date)
    {
        ArrayList args = new ArrayList();

        JavaTypeMapping m = getMapping(String.class, date);
        ScalarExpression submethodLiteral = m.newLiteral(date.getQueryExpression(), "month");
        args.add(submethodLiteral);

        args.add(date);

        // Delete one from the SQL "month" (origin=1) to be compatible with Java month (origin=0)
        JavaTypeMapping m2 = getMapping(BigInteger.class, date);
        ScalarExpression integerLiteral = m2.newLiteral(date.getQueryExpression(), BigInteger.ONE);
        NumericExpression expr = new NumericExpression(new NumericExpression("date_part", args), ScalarExpression.OP_SUB, integerLiteral);
        expr.encloseWithInParentheses();
        return expr;
    }
View Full Code Here

    public NumericExpression getYearMethod(SqlTemporalExpression date)
    {
        ArrayList args = new ArrayList();

        JavaTypeMapping m = getMapping(String.class, date);
        ScalarExpression submethodLiteral = m.newLiteral(date.getQueryExpression(), "year");
        args.add(submethodLiteral);

        args.add(date);

        return new NumericExpression("date_part", args);
View Full Code Here

    public NumericExpression getHourMethod(SqlTemporalExpression time)
    {
        ArrayList args = new ArrayList();

        JavaTypeMapping m = getMapping(String.class, time);
        ScalarExpression submethodLiteral = m.newLiteral(time.getQueryExpression(), "hour");
        args.add(submethodLiteral);

        args.add(time);

        return new NumericExpression("date_part", args);
View Full Code Here

TOP

Related Classes of org.jpox.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.