Examples of MappedStoreManager


Examples of org.jpox.store.mapped.MappedStoreManager

            Class cls = (subqueryCandidateExprRootAliasInfo != null ?
                    subqueryCandidateExprRootAliasInfo.cls : parentExpr.getCandidateClass());
            ClassLoaderResolver clr = query.getObjectManager().getClassLoaderResolver();
            MetaDataManager mmgr = query.getObjectManager().getMetaDataManager();
            MappedStoreManager storeMgr = (MappedStoreManager)query.getStoreManager();
            AbstractClassMetaData leftCmd = mmgr.getMetaDataForClass(cls, clr);
            LogicSetExpression leftTblExpr = (subqueryCandidateExprRootAliasInfo != null ?
                    subqueryCandidateExprRootAliasInfo.tableExpression : parentExpr.getMainTableExpression());
            String leftAlias = (subqueryCandidateExprRootAliasInfo != null ?
                    subqueryCandidateExprRootAliasInfo.alias : parentExpr.getCandidateAlias());
            DatastoreClass leftTable = (DatastoreClass)leftTblExpr.getMainTable();
            for (int i=1;i<tokens.length;i++)
            {
                // Process the join from the previous token to this token
                AbstractMemberMetaData leftMmd = leftCmd.getMetaDataForMember(tokens[i]);
                AbstractClassMetaData rightCmd = null;
                int relationType = leftMmd.getRelationType(clr);
                AbstractMemberMetaData rightMmd = null;
                if (relationType == Relation.ONE_TO_ONE_BI || relationType == Relation.ONE_TO_MANY_BI ||
                    relationType == Relation.MANY_TO_MANY_BI || relationType == Relation.MANY_TO_ONE_BI)
                {
                    rightMmd = leftMmd.getRelatedMemberMetaData(clr)[0]; // Take first possible
                }

                // Find class of right hand side
                if (i == tokens.length-1)
                {
                    cls = candidateClass;
                }
                else
                {
                    if (relationType == Relation.ONE_TO_ONE_BI ||
                        relationType == Relation.ONE_TO_ONE_UNI ||
                        relationType == Relation.MANY_TO_ONE_BI)
                    {
                        cls = leftMmd.getType();
                        rightCmd = mmgr.getMetaDataForClass(cls, clr);
                    }
                    else if (relationType == Relation.ONE_TO_MANY_BI ||
                        relationType == Relation.ONE_TO_MANY_UNI ||
                        relationType == Relation.MANY_TO_MANY_BI)
                    {
                        if (leftMmd.hasCollection())
                        {
                            cls = clr.classForName(leftMmd.getCollection().getElementType());
                            rightCmd = mmgr.getMetaDataForClass(cls, clr);
                        }
                        else if (leftMmd.hasMap())
                        {
                            cls = clr.classForName(leftMmd.getMap().getValueType());
                            rightCmd = mmgr.getMetaDataForClass(cls, clr);
                        }
                    }
                    else
                    {
                        throw new JPOXUserException("Subquery has been specified with a candidate-expression that" +
                            " includes \"" + tokens[i] + "\" that isnt a relation field!!");
                    }
                }

                LogicSetExpression rightTblExpr;
                String rightAlias;
                DatastoreIdentifier rightTblAlias;
                DatastoreClass rightTable;
                if (i == tokens.length-1)
                {
                    // Candidate
                    rightTblExpr = qs.getMainTableExpression();
                    rightTblAlias = qs.getMainTableAlias();
                    rightTable = (DatastoreClass)rightTblExpr.getMainTable();
                    rightAlias = candidateAlias;
                }
                else
                {
                    // Not outer candidate, nor inner candidate so add table. Alias is "T{num}"
                    // TODO Parameterise this naming of intermediate tables
                    rightTable = storeMgr.getDatastoreClass(cls.getName(), clr);
                    rightAlias = "T" + i;
                    rightTblAlias = storeMgr.getIdentifierFactory().newIdentifier(
                        IdentifierFactory.TABLE, rightAlias);
                    rightTblExpr = qs.newTableExpression(rightTable, rightTblAlias);
                }

                if (relationType == Relation.ONE_TO_ONE_UNI ||
                    (relationType == Relation.ONE_TO_ONE_BI && leftMmd.getMappedBy() == null) ||
                    (relationType == Relation.MANY_TO_ONE_BI &&
                     (leftMmd.getJoinMetaData() == null && rightMmd.getJoinMetaData() == null)))
                {
                    // 1-1/N-1 with FK here
                    ScalarExpression leftExpr = leftTblExpr.newFieldExpression(tokens[i]);
                    ScalarExpression rightExpr = rightTable.getIDMapping().newScalarExpression(qs, rightTblExpr);
                    if (i == 1)
                    {
                        // And condition to outer candidate
                        qs.andCondition(leftExpr.eq(rightExpr), true);
                    }
                    else
                    {
                        // Inner join to table
                        qs.innerJoin(rightExpr, leftExpr, leftTblExpr, true, true);
                    }
                }
                else if (relationType == Relation.ONE_TO_ONE_BI && leftMmd.getMappedBy() != null)
                {
                    // 1-1 with FK on other side
                    ScalarExpression leftExpr = leftTable.getIDMapping().newScalarExpression(qs, leftTblExpr);
                    ScalarExpression rightExpr = rightTblExpr.newFieldExpression(rightMmd.getName());
                    if (i == 1)
                    {
                        // And condition to outer candidate
                        qs.andCondition(leftExpr.eq(rightExpr), true);
                    }
                    else
                    {
                        // Inner join to table
                        qs.innerJoin(rightExpr, leftExpr, leftTblExpr, true, true);
                    }
                }
                else if ((relationType == Relation.ONE_TO_MANY_UNI && leftMmd.getJoinMetaData() == null) ||
                    (relationType == Relation.ONE_TO_MANY_BI &&
                     (leftMmd.getJoinMetaData() == null && rightMmd.getJoinMetaData() == null)))
                {
                    // 1-N FK with FK on other side
                    ScalarExpression leftExpr = leftTable.getIDMapping().newScalarExpression(qs, leftTblExpr);
                    ScalarExpression rightExpr = rightTblExpr.newFieldExpression(rightMmd.getName());
                    if (i == 1)
                    {
                        // And condition to outer candidate
                        qs.andCondition(leftExpr.eq(rightExpr), true);
                    }
                    else
                    {
                        // Inner join to table
                        qs.innerJoin(rightExpr, leftExpr, leftTblExpr, true, true);
                    }
                }
                else if (relationType == Relation.ONE_TO_MANY_UNI && leftMmd.getJoinMetaData() != null)
                {
                    // 1-N uni JoinTable
                    ScalarExpression leftExpr = leftTable.getIDMapping().newScalarExpression(qs, leftTblExpr);
                    ScalarExpression rightExpr = rightTable.getIDMapping().newScalarExpression(qs, rightTblExpr);
                    ScalarExpression leftCentreExpr = null;
                    ScalarExpression rightCentreExpr = null;
                    LogicSetExpression joinTblExpr = null;
                    if (leftMmd.hasCollection())
                    {
                        CollectionTable joinTbl = (CollectionTable)storeMgr.getDatastoreContainerObject(leftMmd);
                        DatastoreIdentifier joinTblAlias = storeMgr.getIdentifierFactory().newIdentifier(
                            IdentifierFactory.TABLE, leftAlias + "." + rightAlias);
                        joinTblExpr = qs.newTableExpression(joinTbl, joinTblAlias);
                        leftCentreExpr = joinTbl.getOwnerMapping().newScalarExpression(qs, joinTblExpr);
                        rightCentreExpr = joinTbl.getElementMapping().newScalarExpression(qs, joinTblExpr);
                    }
                    else if (leftMmd.hasMap())
                    {
                        MapTable joinTbl = (MapTable)storeMgr.getDatastoreContainerObject(leftMmd);
                        DatastoreIdentifier joinTblAlias = storeMgr.getIdentifierFactory().newIdentifier(
                            IdentifierFactory.TABLE, leftAlias + "." + rightAlias);
                        joinTblExpr = qs.newTableExpression(joinTbl, joinTblAlias);
                        leftCentreExpr = joinTbl.getOwnerMapping().newScalarExpression(qs, joinTblExpr);
                        rightCentreExpr = joinTbl.getValueMapping().newScalarExpression(qs, joinTblExpr);
                    }

                    if (i == 1)
                    {
                        // And condition to outer candidate
                        qs.andCondition(leftExpr.eq(leftCentreExpr), true);
                    }
                    else
                    {
                        // Inner join to table
                        qs.innerJoin(leftCentreExpr, leftExpr, leftTblExpr, true, true);
                    }
                    qs.innerJoin(rightExpr, rightCentreExpr, joinTblExpr, true, true);
                }
                else if ((relationType == Relation.ONE_TO_MANY_BI &&
                    (leftMmd.getJoinMetaData() != null || rightMmd.getJoinMetaData() != null)) ||
                    (relationType == Relation.MANY_TO_ONE_BI &&
                     (leftMmd.getJoinMetaData() != null || rightMmd.getJoinMetaData() != null)) ||
                     relationType == Relation.MANY_TO_MANY_BI)
                {
                    // 1-N/N-1 bi JoinTable
                    ScalarExpression leftExpr = leftTable.getIDMapping().newScalarExpression(qs, leftTblExpr);
                    ScalarExpression rightExpr = rightTable.getIDMapping().newScalarExpression(qs, rightTblExpr);
                    ScalarExpression leftCentreExpr = null;
                    ScalarExpression rightCentreExpr = null;
                    LogicSetExpression joinTblExpr = null;
                    if (leftMmd.hasCollection() || rightMmd.hasCollection())
                    {
                        CollectionTable joinTbl = (CollectionTable)storeMgr.getDatastoreContainerObject(leftMmd);
                        DatastoreIdentifier joinTblAlias = storeMgr.getIdentifierFactory().newIdentifier(
                            IdentifierFactory.TABLE, leftAlias + "." + rightAlias);
                        joinTblExpr = qs.newTableExpression(joinTbl, joinTblAlias);
                        leftCentreExpr = joinTbl.getOwnerMapping().newScalarExpression(qs, joinTblExpr);
                        rightCentreExpr = joinTbl.getElementMapping().newScalarExpression(qs, joinTblExpr);
                    }
                    else if (leftMmd.hasMap() || rightMmd.hasMap())
                    {
                        MapTable joinTbl = (MapTable)storeMgr.getDatastoreContainerObject(leftMmd);
                        DatastoreIdentifier joinTblAlias = storeMgr.getIdentifierFactory().newIdentifier(
                            IdentifierFactory.TABLE, leftAlias + "." + rightAlias);
                        joinTblExpr = qs.newTableExpression(joinTbl, joinTblAlias);
                        leftCentreExpr = joinTbl.getOwnerMapping().newScalarExpression(qs, joinTblExpr);
                        rightCentreExpr = joinTbl.getValueMapping().newScalarExpression(qs, joinTblExpr);
                    }
View Full Code Here

Examples of org.jpox.store.mapped.MappedStoreManager

     * TODO Allow this to work in different catalog/schema
     * @return statement
     */
    private String getStatement()
    {
        MappedStoreManager srm = (MappedStoreManager)storeMgr;
        StringBuffer stmt = new StringBuffer();
        stmt.append("SELECT max(");
        stmt.append(srm.getIdentifierFactory().getIdentifierInAdapterCase((String)properties.get("column-name")));
        stmt.append(") FROM ");
        stmt.append(srm.getIdentifierFactory().getIdentifierInAdapterCase((String)properties.get("table-name")))
        return stmt.toString();
    }
View Full Code Here

Examples of org.jpox.store.mapped.MappedStoreManager

     */
    protected void prepareStatementForExecution(PreparedStatement ps)
    throws SQLException
    {
        OMFContext omfCtx = om.getOMFContext();
        MappedStoreManager storeMgr = (MappedStoreManager)omfCtx.getStoreManager();
        PersistenceConfiguration conf = omfCtx.getPersistenceConfiguration();

        // Apply any user-specified timeout
        int timeout = conf.getIntProperty("org.jpox.query.timeout");
        Object timeoutExt = query.getExtension("org.jpox.query.timeout");
        if (timeoutExt != null)
        {
            // Accept timeout as an Integer or String
            if (timeoutExt instanceof Integer)
            {
                timeout = ((Integer)timeoutExt).intValue();
            }
            else if (timeoutExt instanceof String)
            {
                timeout = TypeConversionHelper.intFromString((String)timeoutExt, 0);
            }
        }
        if (timeout > 0)
        {
            ps.setQueryTimeout(timeout);
        }

        // Apply any fetch size
        int fetchSize = 0;
        if (query.getFetchPlan().getFetchSize() > 0)
        {
            // FetchPlan has a size set so use that
            fetchSize = query.getFetchPlan().getFetchSize();
        }
        if (storeMgr.getDatastoreAdapter().supportsQueryFetchSize(fetchSize))
        {
            ps.setFetchSize(fetchSize);
        }

        // Apply any fetch direction
View Full Code Here

Examples of org.jpox.store.mapped.MappedStoreManager

     * @param useFetchPlan Whether to retrieve the fetch plan fields or DFG
     * @return The Result Object factory
     */
    public ResultObjectFactory newResultObjectFactory(StateManager sm, QueryExpression stmt, boolean ignoreCache, boolean useFetchPlan)
    {
        MappedStoreManager storeMgr = (MappedStoreManager)sm.getObjectManager().getStoreManager();
        ClassLoaderResolver clr = sm.getObjectManager().getClassLoaderResolver();
        if (valuesAreEmbedded || valuesAreSerialised)
        {
            // Value = Embedded, Serialised
            // valueTable is null here so why return this ?
            return new PersistentIDROF(this.valueTable, null, vmd, null, null, null, ignoreCache, false,
                stmt.hasMetaDataExpression(), null, clr.classForName(valueType));
        }
        else
        {
            // Value = PC

            // Select any datastore/version columns
            int[] datastoreIndex = null;
            int[] versionIndex = null;
            if (stmt.getTableExpression(elmIdentifier) != null)
            {
                if (valueTable.getIdentityType() == IdentityType.DATASTORE)
                {
                    datastoreIndex = stmt.select(elmIdentifier, valueTable.getDataStoreObjectIdMapping(),true);
                }
                if (valueTable.getVersionMapping(true) != null)
                {
                    versionIndex = stmt.select(elmIdentifier, valueTable.getVersionMapping(true), true);
                }
            }
            else
            {
                if (valueTable.getIdentityType() == IdentityType.DATASTORE)
                {
                    datastoreIndex = stmt.select(stmt.getMainTableAlias(),
                        valueTable.getDataStoreObjectIdMapping(),true);
                }
                if (valueTable.getVersionMapping(true) != null)
                {
                    versionIndex = stmt.select(stmt.getMainTableAlias(),
                        valueTable.getVersionMapping(true), true);
                }
            }

            StatementExpressionIndex[] statementExpressionIndex = null;
            int[] prefetchFieldNumbers = null;
            if (useFetchPlan)
            {
                // Select the FetchPlan fields
                FetchPlan fp = sm.getObjectManager().getFetchPlan();
                fp.manageFetchPlanForClass(vmd);
                FetchPlanForClass fpc = fp.getFetchPlanForClass(vmd);
                int fieldNumbers[] = fpc.getFieldsInActualFetchPlan();
                int fn[] = new int[fieldNumbers.length];
                int prefetchFieldCount = 0;
                int fieldCount = vmd.getNoOfInheritedManagedMembers() + vmd.getNoOfManagedMembers();
               
                statementExpressionIndex = new StatementExpressionIndex[fieldCount];
                for (int i=0; i<fieldNumbers.length; ++i)
                {
                    JavaTypeMapping m = valueTable.getFieldMapping(vmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumbers[i]));
                    if (m != null)
                    {
                        if (m.includeInFetchStatement() && !(m instanceof AbstractContainerMapping))
                        {
                            statementExpressionIndex[fieldNumbers[i]] = new StatementExpressionIndex();
                            statementExpressionIndex[fieldNumbers[i]].setMapping(m);
                            fn[prefetchFieldCount++] = fieldNumbers[i];
                        }
                    }
                }
               
                prefetchFieldNumbers = new int[prefetchFieldCount];
                System.arraycopy(fn, 0, prefetchFieldNumbers, 0, prefetchFieldCount);
            }
            else
            {
                AbstractClassMetaData cmd = vmd;
                if (cmd.getIdentityType() == IdentityType.APPLICATION)
                {
                    prefetchFieldNumbers = new int[cmd.getPKMemberPositions().length];
                    int fieldCount = cmd.getNoOfInheritedManagedMembers() + cmd.getNoOfManagedMembers();
                    statementExpressionIndex = new StatementExpressionIndex[fieldCount];
                    for (int i = 0; i < prefetchFieldNumbers.length; ++i)
                    {
                        prefetchFieldNumbers[i] = cmd.getPKMemberPositions()[i];
                        JavaTypeMapping m = valueTable.getFieldMapping(cmd.getMetaDataForManagedMemberAtAbsolutePosition(prefetchFieldNumbers[i]));
                        if (m != null) // field is not stored in the table, e.g List, Set, etc or is transactional
                        {
                            if (m.includeInFetchStatement() && !(m instanceof AbstractContainerMapping))
                            {
                                statementExpressionIndex[prefetchFieldNumbers[i]] = new StatementExpressionIndex();
                                statementExpressionIndex[prefetchFieldNumbers[i]].setMapping(m);
                            }
                        }
                    }
                }
            }

            if (stmt.getTableExpression(elmIdentifier) != null)
            {
                Mappings.selectMapping(stmt, elmIdentifier, statementExpressionIndex);
            }
            else
            {
                Mappings.selectMapping(stmt, statementExpressionIndex);
            }

            return new PersistentIDROF(storeMgr.getDatastoreClass(getValueType(), clr),
                prefetchFieldNumbers, vmd, statementExpressionIndex, datastoreIndex, versionIndex,
                ignoreCache, iterateUsingDiscriminator, stmt.hasMetaDataExpression(), null, clr.classForName(valueType));
        }
    }
View Full Code Here

Examples of org.jpox.store.mapped.MappedStoreManager

            }
        }

        // A). Process persistent types
        PersistentTypeMapping[] persistentTypes = queryResultMetaData.getPersistentTypeMappings();
        MappedStoreManager storeMgr = (MappedStoreManager)om.getStoreManager();
        if (persistentTypes != null)
        {
            int startColumnIndex = 0;
            for (int i=0;i<persistentTypes.length;i++)
            {
                int[] fieldNumbers;   
                StatementExpressionIndex[] statementExpressionIndex;
                Set columnsInThisType = new HashSet();
                AbstractMemberMetaData[] fmds = new AbstractMemberMetaData[columnNames.length];
                Map fieldColumns = new HashMap();
                DatastoreClass dc = storeMgr.getDatastoreClass(persistentTypes[i].getClassName(),om.getClassLoaderResolver());
                AbstractClassMetaData acmd = om.getMetaDataManager().getMetaDataForClass(persistentTypes[i].getClassName(), om.getClassLoaderResolver());
                Object id = null;
                for (int j=startColumnIndex;j<columnNames.length;j++)
                {
                    if( columnsInThisType.contains(columnNames[j]) )
View Full Code Here

Examples of org.jpox.store.mapped.MappedStoreManager

            fieldColumnNames = new ArrayList(); // Empty
            candidateCmd = null;
        }
        else
        {
            MappedStoreManager storeMgr = (MappedStoreManager)om.getStoreManager();
            DatastoreAdapter dba = storeMgr.getDatastoreAdapter();
            candidateCmd = om.getMetaDataManager().getMetaDataForClass(candidateClass,om.getClassLoaderResolver());
            if (candidateCmd == null)
            {
                throw new ClassNotPersistenceCapableException(candidateClass.getName());
            }
            if (candidateCmd.getPersistenceCapableSuperclass() != null)
            {
                throw new PersistentSuperclassNotAllowedException(candidateClass.getName());
            }
            if (candidateCmd.isRequiresExtent())
            {
                throw new JPOXUserException(LOCALISER_RDBMS.msg("060000",
                    candidateClass.getName()));
            }
            if (candidateCmd.getIdentityType() != IdentityType.NONDURABLE)
            {
                throw new JPOXUserException(LOCALISER_RDBMS.msg("060001",
                    candidateClass.getName()));
            }

            int fieldCount = candidateCmd.getNoOfManagedMembers();
            int[] fn = new int[fieldCount];
            statementExpressionIndex = new StatementExpressionIndex[fieldCount];
            fieldColumnNames = new ArrayList(fieldCount);
            int n = 0;

            for (int fieldNumber = 0; fieldNumber < fieldCount; ++fieldNumber)
            {
                statementExpressionIndex[fieldNumber] = new StatementExpressionIndex();
                AbstractMemberMetaData fmd = candidateCmd.getMetaDataForManagedMemberAtPosition(fieldNumber);
                String fieldName = fmd.getName();
                Class fieldType = fmd.getType();

                if (fmd.getPersistenceModifier() == FieldPersistenceModifier.PERSISTENT)
                {
                    JavaTypeMapping m = dba.getMapping(fieldType, storeMgr, om.getClassLoaderResolver());
                    if (m.includeInFetchStatement())
                    {
                        statementExpressionIndex[fieldNumber].setMapping(m);
                        fn[n++] = fieldNumber;

                        String columnName = null;
                        if (fmd.getColumnMetaData() != null && fmd.getColumnMetaData().length > 0)
                        {
                            columnName = fmd.getColumnMetaData()[0].getName();
                        }
                        else
                        {
                            columnName = storeMgr.getIdentifierFactory().newDatastoreFieldIdentifier(fieldName,
                                om.getOMFContext().getTypeManager().isDefaultEmbeddedType(fieldType),
                                FieldRole.ROLE_NONE).getIdentifier();
                        }
                        fieldColumnNames.add(columnName);
                    }
View Full Code Here

Examples of org.jpox.store.mapped.MappedStoreManager

        if (candidateClass != null && query.getType() == Query.SELECT)
        {
            // Perform any sanity checking of input for SELECT queries
            ObjectManager om = query.getObjectManager();
            MappedStoreManager storeMgr = (MappedStoreManager)om.getStoreManager();
            ClassLoaderResolver clr = om.getClassLoaderResolver();
            AbstractClassMetaData cmd = om.getMetaDataManager().getMetaDataForClass(candidateClass, clr);
            if (cmd == null)
            {
                throw new ClassNotPersistenceCapableException(candidateClass.getName());
            }
            if (cmd.getPersistenceCapableSuperclass() != null)
            {
               // throw new PersistentSuperclassNotAllowedException(candidateClass.getName());
            }

            if (query.getResultClass() == null)
            {
                // Check the presence of the required columns (id, version, discriminator) in the candidate class
                String selections = compiledSQL.trim().substring(7); // Skip "SELECT "
                int fromStart = selections.indexOf("FROM");
                if (fromStart == -1)
                {
                    fromStart = selections.indexOf("from");
                }
                selections = selections.substring(0, fromStart).trim();
                String[] selectedColumns = StringUtils.split(selections, ",");

                if (selectedColumns == null || selectedColumns.length == 0)
                {
                    throw new JPOXUserException(LOCALISER_RDBMS.msg("059003", compiledSQL));
                }
                if (selectedColumns.length == 1 && selectedColumns[0].trim().equals("*"))
                {
                    // SQL Query using * so just return since all possible columns will be selected
                    return compiledSQL;
                }

                // Generate id column field information for later checking the id is present
                DatastoreClass table = storeMgr.getDatastoreClass(candidateClass.getName(), clr);
                PersistenceCapableMapping idMapping = (PersistenceCapableMapping)table.getIDMapping();
                String[] idColNames = new String[idMapping.getNumberOfDatastoreFields()];
                boolean[] idColMissing = new boolean[idMapping.getNumberOfDatastoreFields()];
                for (int i=0;i<idMapping.getNumberOfDatastoreFields();i++)
                {
                    DatastoreMapping m = idMapping.getDataStoreMapping(i);
                    idColNames[i] = m.getDatastoreField().getIdentifier().toString();
                    idColMissing[i] = true;
                }

                // Generate discriminator/version information for later checking they are present
                String discriminatorColName = table.getDiscriminatorMapping(false) != null ?
                        table.getDiscriminatorMapping(false).getDataStoreMapping(0).getDatastoreField().getIdentifier().toString() : null;
                String versionColName = table.getVersionMapping(false) != null ?
                        table.getVersionMapping(false).getDataStoreMapping(0).getDatastoreField().getIdentifier().toString() : null;
                boolean discrimMissing = (discriminatorColName != null);
                boolean versionMissing = true;
                if (versionColName == null)
                {
                    versionMissing = false;
                }

                // Go through the selected fields and check the existence of id, version, discriminator cols
                DatastoreAdapter dba = storeMgr.getDatastoreAdapter();
                final AbstractClassMetaData candidateCmd = om.getMetaDataManager().getMetaDataForClass(candidateClass, clr);
                for (int i = 0; i < selectedColumns.length; i++)
                {
                    String colName = selectedColumns[i].trim();
                    if (colName.indexOf(" AS ") > 0)
View Full Code Here

Examples of org.jpox.store.mapped.MappedStoreManager

                                if (!p.parseChar(')'))
                                {
                                    throw new QueryCompilerSyntaxException("')' expected", p.getIndex(), p.getInput());
                                }
                            }
                            MappedStoreManager srm =
                                (MappedStoreManager)(qs != null ? qs.getStoreManager() : query.getObjectManager().getStoreManager());
                            //TODO make these functions pluggable
                            if (methodId.equalsIgnoreCase("ABS"))
                            {
                                return new MathExpression(qs).absMethod(((ScalarExpression) args.get(0)));
                            }
                            else if (methodId.equalsIgnoreCase("SQRT"))
                            {
                                return new MathExpression(qs).sqrtMethod(((ScalarExpression) args.get(0)));
                            }
                            else if (methodId.equalsIgnoreCase("CONCAT"))
                            {
                                return ((ScalarExpression) args.get(0)).add((ScalarExpression) args.get(1));
                            }
                            else if (methodId.equalsIgnoreCase("MOD"))
                            {
                                return ((ScalarExpression) args.get(0)).mod((ScalarExpression) args.get(1));
                            }
                            else if (methodId.equalsIgnoreCase("LENGTH"))
                            {
                                return ((ScalarExpression) args.get(0)).callMethod(methodId.toLowerCase(),
                                    Collections.EMPTY_LIST);
                            }
                            else if (methodId.equalsIgnoreCase("SUBSTRING"))
                            {
                                List argscall = new ArrayList();
                                JavaTypeMapping mapping = srm.getDatastoreAdapter().getMapping(String.class, srm);
                                IntegerLiteral one = new IntegerLiteral(qs, mapping, BigInteger.ONE, false);
                                argscall.add(((ScalarExpression) args.get(1)).sub(one));
                                if (args.size() > 2)
                                {
                                    argscall.add(((ScalarExpression) args.get(2)).add(one));
                                }
                                return ((ScalarExpression) args.get(0)).callMethod(methodId.toLowerCase(), argscall);
                            }
                            else if (methodId.equalsIgnoreCase("LOWER"))
                            {
                                return ((ScalarExpression) args.get(0)).callMethod("toLowerCase",
                                    Collections.EMPTY_LIST);
                            }
                            else if (methodId.equalsIgnoreCase("UPPER"))
                            {
                                return ((ScalarExpression) args.get(0)).callMethod("toUpperCase",
                                    Collections.EMPTY_LIST);
                            }
                            else if (methodId.equalsIgnoreCase("SIZE"))
                            {
                                return ((ScalarExpression) args.get(0)).callMethod(methodId.toLowerCase(),
                                    Collections.EMPTY_LIST);
                            }
                            else if (methodId.equalsIgnoreCase("LOCATE"))
                            {
                                List argscall = new ArrayList();
                                argscall.add(args.get(0));
                                JavaTypeMapping mapping = srm.getDatastoreAdapter().getMapping(String.class, srm);
                                IntegerLiteral one = new IntegerLiteral(qs, mapping, BigInteger.ONE,false);
                                if (args.size() > 2)
                                {
                                    argscall.add(((ScalarExpression)args.get(2)).sub(one));
                                }
View Full Code Here

Examples of org.jpox.store.mapped.MappedStoreManager

            // Identifier is not allowed to be a JPQL keyword
            throw new QueryCompilerSyntaxException(LOCALISER.msg("021052", language, id),
                p.getIndex(), p.getInput());
        }

        MappedStoreManager srm = (MappedStoreManager)query.getObjectManager().getStoreManager();
        ClassLoaderResolver clr = query.getObjectManager().getClassLoaderResolver();
        ScalarExpression expr;

        if (id.equalsIgnoreCase("CURRENT_DATE"))
        {
            return new TemporalExpression(qs).currentDateMethod();
        }
        else if (id.equalsIgnoreCase("CURRENT_TIME"))
        {
            return new TemporalExpression(qs).currentTimeMethod();
        }
        else if (id.equalsIgnoreCase("CURRENT_TIMESTAMP"))
        {
            return new TemporalExpression(qs).currentTimestampMethod();
        }
        else if (id.equalsIgnoreCase("true"))
        {
            JavaTypeMapping m = srm.getDatastoreAdapter().getMapping(Boolean.class, srm, clr);
            return m.newLiteral(qs, Boolean.TRUE);
        }
        else if (id.equalsIgnoreCase("false"))
        {
            JavaTypeMapping m = srm.getDatastoreAdapter().getMapping(Boolean.class, srm, clr);
            return m.newLiteral(qs, Boolean.FALSE);
        }
        else if (id.startsWith(":"))
        {
            // Named parameters (":param1")
            return compileNamedImplicitParameter(id);
        }
        else if (id.startsWith("?"))
        {
            // Numbered parameters ("?1")
            return compileNumberedImplicitParameter(id);
        }
        else if (id.equalsIgnoreCase("NEW"))
        {
            // Found syntax for "new MyObject(param1, param2)" - result expression (JPA1 $4.8.2]
            return compileNewObject();
        }
        else if (query.hasSubqueryForVariable(id))
        {
            // Variable represented as a subquery (process before explicit variables below)
            return compileSubqueryVariable(id);
        }
        else if (variableNames.contains(id))
        {
            // Identifier is an explicit variable
            return compileExplicitVariable(id);
        }
        else
        {
            try
            {
                // Check if the identifier is a field of the candidate class
                expr = qs.getMainTableExpression().newFieldExpression(id);

                // What is this doing ? If "id" is a field then it comes to this, so how can it be an alias too ?
                if (!id.equalsIgnoreCase(candidateAlias)) // JPQL identifiers are case insensitive
                {
                    // Make a check on whether the field exists in the candidate class (TableExpression only checks the same table).
                    if (candidateCmd == null)
                    {
                        candidateCmd = query.getObjectManager().getMetaDataManager().getMetaDataForClass(
                            candidateClass, clr);
                    }
                    if (candidateCmd.getMetaDataForMember(id) == null)
                    {
                        // The field doesnt exist in the candidate class, so no point proceeding
                        throw new JPOXUserException(LOCALISER.msg("021049", id));
                    }
                }

                fieldExpressions.add(expr); // Add to the field expressions list
            }
            catch (NoSuchPersistentFieldException nspfe)
            {
                // Not a field of the candidate class, so check if an alias (case insensitive)
                AliasJoinInformation aliasInfo = (AliasJoinInformation)aliases.get(id.toUpperCase());
                if (aliasInfo == null && parentCompiler != null)
                {
                    // This is a subquery, so try the parent query
                    aliasInfo = (AliasJoinInformation)parentCompiler.aliases.get(id.toUpperCase());
                }
                if (aliasInfo != null)
                {
                    DatastoreClass table = srm.getDatastoreClass(aliasInfo.cls.getName(), clr);
                    if (aliasInfo.tableExpression == null)
                    {
                        if (aliasInfo.alias.equalsIgnoreCase(candidateAlias))
                        {
                            aliasInfo.tableExpression = qs.getMainTableExpression();
                        }
                        else
                        {
                            DatastoreIdentifier tableId =
                                srm.getIdentifierFactory().newIdentifier(IdentifierFactory.TABLE, aliasInfo.alias);
                            aliasInfo.tableExpression = qs.newTableExpression(table, tableId);
                        }
                    }
                    return table.getIDMapping().newScalarExpression(qs, aliasInfo.tableExpression);
                }
View Full Code Here

Examples of org.jpox.store.mapped.MappedStoreManager

     * @param id Identifier of the named parameter, starts with ":"
     * @return Expression representing the named param
     */
    protected ScalarExpression compileNamedImplicitParameter(String id)
    {
        MappedStoreManager srm = (MappedStoreManager)query.getObjectManager().getStoreManager();
        ClassLoaderResolver clr = query.getObjectManager().getClassLoaderResolver();
        id = id.substring(1); // Omit the ":"
        if (processedParameters == null)
        {
            processedParameters = new HashSet();
        }
        processedParameters.add(id); // Register as processed for this query

        if (parameters != null && parameters.size() > 0)
        {
            if (parameters.containsKey(id))
            {
                // Implicit parameter defined, so use the value
                Object paramValue = parameters.get(id);
                if (paramValue != null)
                {
                    JavaTypeMapping m = srm.getDatastoreAdapter().getMapping(paramValue.getClass(), srm, clr);
                    ScalarExpression paramExpr = m.newLiteral(qs, paramValue);
                    paramExpr.setParameterName(id);
                    paramExpr.checkForTypeAssignability();
                    return paramExpr;
                }
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.