Package org.jpox.store.mapped

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


            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

        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

                                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

            // 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

     * @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

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

        if (parameters != null && parameters.size() > 0)
        {
            if (parameters.containsKey(position))
            {
                // Implicit parameter already found, so reuse the value
                Object paramValue = parameters.get(position);
                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

    public static void createColumnsForFieldUsingSubclassTable(JavaTypeMapping mapping,
            DatastoreContainerObject table,
            AbstractMemberMetaData fmd,
            ClassLoaderResolver clr)
    {
        MappedStoreManager storeMgr = table.getStoreManager();
        AbstractClassMetaData refCmd = storeMgr.getOMFContext().getMetaDataManager().getMetaDataForClass(fmd.getType(), clr);
        if (refCmd.getInheritanceMetaData().getStrategyValue() != InheritanceStrategy.SUBCLASS_TABLE)
        {
            throw new JPOXUserException(LOCALISER.msg("020185", fmd.getFullFieldName()));
        }
        AbstractClassMetaData[] subclassCmds = storeMgr.getClassesManagingTableForClass(refCmd, clr);

        boolean pk = false;
        if (subclassCmds.length > 1)
        {
            pk = false;
        }
        boolean nullable = true;
        if (subclassCmds.length > 1)
        {
            nullable = true;
        }

        int colPos = 0;
        for (int i=0; i<subclassCmds.length; i++)
        {
            Class type = clr.classForName(subclassCmds[i].getFullClassName());
            DatastoreClass dc = storeMgr.getDatastoreClass(subclassCmds[i].getFullClassName(), clr);
            JavaTypeMapping m = dc.getIDMapping();

            // obtain the column names for this type
            // TODO Fix this. The <column> elements have no way of being ordered to match the subclasses
            ColumnMetaData[] columnMetaDataForType = null;
View Full Code Here

            else if (fieldRole == FieldRole.ROLE_MAP_VALUE)
            {
                fieldTypeName = fmd.getMap().getValueType();
            }
        }
        MappedStoreManager storeMgr = table.getStoreManager();
        boolean isPersistentInterfaceField = storeMgr.getOMFContext().getMetaDataManager().isPersistentInterface(fieldTypeName);

        // Set the PK and nullability of column(s) for the implementations (based on the number of impls etc)
        boolean pk = isPrimaryKey;
        boolean nullable = isNullable;
        if (implTypes.length > 1)
        {
            pk = false; // Cannot be part of PK if more than 1 implementation
        }
        if (implTypes.length > 1 && !pk)
        {
            nullable = true; // Must be nullable if more than 1 impl (since only 1 impl can have value at a time)
        }

        int colPos = 0;
        Class[] implTypeClasses = new Class[implTypes.length];
        for (int i=0; i<implTypes.length; i++)
        {
            String implName = implTypes[i];

            Class type = clr.classForName(implName);
            if (type == null)
            {
                throw new JPOXUserException(LOCALISER.msg("020189",
                    fmd.getTypeName(), implName));
            }
            else if (type.isInterface())
            {
                throw new JPOXUserException(LOCALISER.msg("020190",
                    fmd.getFullFieldName(), fmd.getTypeName(), implName));
            }
            implTypeClasses[i] = type;

            // Check if this implementation needs columns (or if its inheritance tree is already catered for in previous impls)
            boolean columnsNeeded = true;
            for (int j=0;j<i;j++)
            {
                if (type.isAssignableFrom(implTypeClasses[j]) || implTypeClasses[j].isAssignableFrom(type))
                {
                    // This implementation is part of the same inheritance tree as another implementation already processed
                    // so we already have its FK present
                    columnsNeeded = false;
                    break;
                }
            }

            if (isPersistentInterfaceField &&
                !storeMgr.getOMFContext().getMetaDataManager().isPersistentInterfaceImplementation(fieldTypeName, implName))
            {
                // We have a "persistent-interface" field yet this is not a JPOX-generated implementation so ignore it
                // It is arguable if we should allow the real implementations of this interface here, but the JDO2 TCK doesn't
                // make that assumption so we don't either
                columnsNeeded = false;
            }

            if (columnsNeeded)
            {
                // Get the mapping for this implementation
                JavaTypeMapping m;
                if (storeMgr.getOMFContext().getTypeManager().isSupportedType(type.getName()))
                {
                    m = storeMgr.getDatastoreAdapter().getMapping(type, storeMgr, serialised, embedded,
                        fmd.getFullFieldName());
                }
                else
                {
                    try
                    {
                        DatastoreClass dc = storeMgr.getDatastoreClass(type.getName(), clr);
                        m = dc.getIDMapping();
                    }
                    catch (NoTableManagedException ex)
                    {
                        // TODO Localise this message
View Full Code Here

     * </p>
     * @param classExpr The class expression to process
     */
    protected void processClassExpression(ClassExpression classExpr)
    {
        MappedStoreManager srm = (MappedStoreManager)query.getStoreManager();
        ClassLoaderResolver clr = query.getObjectManager().getClassLoaderResolver();
        JoinExpression[] joinExprs = classExpr.getJoins();
        if (classExpr.getCls() != candidateClass && classExpr.getCls() != null)
        {
            // Not candidate class so must be cross join (JPA spec 4.4.5)
            DatastoreIdentifier rightTblId =
                srm.getIdentifierFactory().newIdentifier(IdentifierFactory.TABLE, classExpr.getAlias());
            DatastoreClass rightTable = srm.getDatastoreClass(classExpr.getCls().getName(), clr);
            LogicSetExpression rightTblExpr = qs.newTableExpression(rightTable, rightTblId);
            AliasJoinInformation rightAliasInfo = new AliasJoinInformation(classExpr.getAlias().toUpperCase(),
                classExpr.getCls(), rightTblExpr, false);
            aliases.put(rightAliasInfo.alias, rightAliasInfo);
            qs.crossJoin(rightTblExpr, true);
View Full Code Here

TOP

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

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.