Examples of DatastoreContainerObject


Examples of org.datanucleus.store.mapped.DatastoreContainerObject

                if (coll == null || coll.isEmpty())
                {
                    return;
                }

                DatastoreContainerObject joinTbl = ((RDBMSStoreManager)ec.getStoreManager()).getDatastoreContainerObject(mmd);
                CollectionTable collTbl = (CollectionTable)joinTbl;
                JavaTypeMapping elemMapping = collTbl.getElementMapping();
                if (elemMapping instanceof InterfaceMapping)
                {
                    InterfaceMapping intfMapping = (InterfaceMapping)elemMapping;
View Full Code Here

Examples of org.datanucleus.store.mapped.DatastoreContainerObject

            String elementType = ownerMmd.getArray().getElementType();
            RDBMSStoreManager storeMgr = stmt.getRDBMSManager();

            // TODO Allow for interface elements, etc
            JavaTypeMapping ownerMapping = null;
            DatastoreContainerObject arrayTbl = null;
            if (ownerMmd.getMappedBy() != null)
            {
                // Bidirectional
                AbstractMemberMetaData elementMmd = ownerMmd.getRelatedMemberMetaData(clr)[0];
                if (ownerMmd.getJoinMetaData() != null || elementMmd.getJoinMetaData() != null)
                {
                    // JoinTable
                    arrayTbl = storeMgr.getDatastoreContainerObject(ownerMmd);
                    ownerMapping = ((JoinTable)arrayTbl).getOwnerMapping();
                }
                else
                {
                    // ForeignKey
                    arrayTbl = storeMgr.getDatastoreClass(elementType, clr);
                    ownerMapping = arrayTbl.getMemberMapping(elementMmd);
                }
            }
            else
            {
                // Unidirectional
View Full Code Here

Examples of org.datanucleus.store.mapped.DatastoreContainerObject

        ExecutionContext ec = sm.getExecutionContext();
        ArrayList results = new ArrayList();
        if (resultSet != null)
        {
            DatastoreContainerObject containerTable = als.getContainerTable();
            boolean elementsAreSerialised = als.isElementsAreSerialised();
            boolean elementsAreEmbedded = als.isElementsAreEmbedded();
            JavaTypeMapping elementMapping = als.getElementMapping();
            while (next(resultSet))
            {
View Full Code Here

Examples of org.datanucleus.store.mapped.DatastoreContainerObject

            AbstractMemberMetaData ownerMmd = expr.getJavaTypeMapping().getMemberMetaData();
            RDBMSStoreManager storeMgr = stmt.getRDBMSManager();

            // TODO Allow for interface keys/values, etc
            JavaTypeMapping ownerMapping = null;
            DatastoreContainerObject mapTbl = null;
            if (ownerMmd.getMap().getMapType() == MapType.MAP_TYPE_JOIN)
            {
                // JoinTable
                mapTbl = storeMgr.getDatastoreContainerObject(ownerMmd);
                ownerMapping = ((JoinTable)mapTbl).getOwnerMapping();
            }
            else if (ownerMmd.getMap().getMapType() == MapType.MAP_TYPE_KEY_IN_VALUE)
            {
                // ForeignKey from value table to key
                AbstractClassMetaData valueCmd =
                    storeMgr.getNucleusContext().getMetaDataManager().getMetaDataForClass(ownerMmd.getMap().getValueType(), clr);
                mapTbl = storeMgr.getDatastoreClass(ownerMmd.getMap().getValueType(), clr);
                if (ownerMmd.getMappedBy() != null)
                {
                    ownerMapping = mapTbl.getMemberMapping(valueCmd.getMetaDataForMember(ownerMmd.getMappedBy()));
                }
                else
                {
                    ownerMapping = ((DatastoreClass)mapTbl).getExternalMapping(ownerMmd, MappingConsumer.MAPPING_TYPE_EXTERNAL_FK);
                }
            }
            else if (ownerMmd.getMap().getMapType() == MapType.MAP_TYPE_VALUE_IN_KEY)
            {
                // ForeignKey from key table to value
                AbstractClassMetaData keyCmd =
                    storeMgr.getNucleusContext().getMetaDataManager().getMetaDataForClass(ownerMmd.getMap().getKeyType(), clr);
                mapTbl = storeMgr.getDatastoreClass(ownerMmd.getMap().getKeyType(), clr);
                if (ownerMmd.getMappedBy() != null)
                {
                    ownerMapping = mapTbl.getMemberMapping(keyCmd.getMetaDataForMember(ownerMmd.getMappedBy()));
                }
                else
                {
                    ownerMapping = ((DatastoreClass)mapTbl).getExternalMapping(ownerMmd, MappingConsumer.MAPPING_TYPE_EXTERNAL_FK);
                }
View Full Code Here

Examples of org.datanucleus.store.mapped.DatastoreContainerObject

            String elementType = mmd.getCollection().getElementType();
            RDBMSStoreManager storeMgr = stmt.getRDBMSManager();

            // TODO Allow for interface elements, etc
            JavaTypeMapping ownerMapping = null;
            DatastoreContainerObject collectionTbl = null;
            if (mmd.getMappedBy() != null)
            {
                // Bidirectional
                AbstractMemberMetaData elementMmd = mmd.getRelatedMemberMetaData(clr)[0];
                if (mmd.getJoinMetaData() != null || elementMmd.getJoinMetaData() != null)
                {
                    // JoinTable
                    collectionTbl = storeMgr.getDatastoreContainerObject(mmd);
                    ownerMapping = ((JoinTable)collectionTbl).getOwnerMapping();
                }
                else
                {
                    // ForeignKey
                    collectionTbl = storeMgr.getDatastoreClass(elementType, clr);
                    ownerMapping = collectionTbl.getMemberMapping(elementMmd);
                }
            }
            else
            {
                // Unidirectional
View Full Code Here

Examples of org.datanucleus.store.mapped.DatastoreContainerObject

                    " does not represent an indexed list!");
            }

            JavaTypeMapping orderMapping = null;
            SQLTable orderTable = null;
            DatastoreContainerObject joinTbl = stmt.getRDBMSManager().getDatastoreContainerObject(mmd);
            if (joinTbl != null)
            {
                // 1-N via join table
                CollectionTable collTable = (CollectionTable)joinTbl;
                orderTable = stmt.getTable(collTable, collSqlExpr.getSQLTable().getGroupName());
View Full Code Here

Examples of org.jpox.store.mapped.DatastoreContainerObject

     * @param innerJoin whether to inner join
     * @return The field expression representing the required field of this object
     */
    public ScalarExpression accessField(String subfieldName, boolean innerJoin)
    {
        DatastoreContainerObject table;
        ClassLoaderResolver clr = qs.getClassLoaderResolver();
        try
        {
            if (mapping instanceof EmbeddedMapping)
            {
                // Any embedded fields can go straight to the main table if embedded there
                table = mapping.getDatastoreContainer();
                if (te.getMainTable().equals(table))
                {
                    // Provide the full field name so we can allow for nested embeddings
                    return te.newFieldExpression(fieldName + "." + subfieldName);
                }
            }
            else if (mapping instanceof PersistenceCapableMapping || mapping instanceof ReferenceMapping)
            {
                AbstractClassMetaData otherCmd = qs.getStoreManager().getOMFContext().getMetaDataManager().getMetaDataForClass(
                    mapping.getType(), clr);
                if (otherCmd.getInheritanceMetaData().getStrategyValue() == InheritanceStrategy.SUBCLASS_TABLE)
                {
                    // Field is a PC class that uses "subclass-table" inheritance strategy (and so has multiple possible tables to join to)
                    AbstractClassMetaData[] cmds = qs.getStoreManager().getClassesManagingTableForClass(otherCmd, clr);
                    if (cmds != null)
                    {
                        // Join to the first table
                        // TODO Allow for all possible tables. Can we do an OR of the tables ? How ?
                        if (cmds.length > 1)
                        {
                            JPOXLogger.QUERY.warn(LOCALISER.msg("037006",
                                mapping.getFieldMetaData().getFullFieldName(), cmds[0].getFullClassName()));
                        }
                        table = qs.getStoreManager().getDatastoreClass(cmds[0].getFullClassName(), clr);
                    }
                    else
                    {
                        // No subclasses with tables to join to, so throw a user error
                        throw new JPOXUserException(LOCALISER.msg("037005",
                            mapping.getFieldMetaData().getFullFieldName()));
                    }
                }
                else
                {
                    // Class of the field will have its own table
                    table = qs.getStoreManager().getDatastoreClass(mapping.getType(), clr);
                    ApiAdapter api = qs.getStoreManager().getApiAdapter();

                    if (fieldName != null && subfieldName != null)
                    {
                        AbstractMemberMetaData subfieldMetaData = otherCmd.getMetaDataForMember(subfieldName);
                        if (subfieldMetaData != null && subfieldMetaData.isPrimaryKey() &&
                            !api.isPersistable(subfieldMetaData.getType()))
                        {
                            // Selecting a non-PC field in the other class that is part of its PK mapping (so we have a column here for it)
                            // Avoids the extra join to the other table
                            JavaTypeMapping[] subMappings = ((PersistenceCapableMapping)mapping).getJavaTypeMapping();
                            if (subMappings.length == 1)
                            {
                                // TODO Cater for a field of a composite PK being selected
                                return subMappings[0].newScalarExpression(qs, te);
                            }
                        }
                    }
                }
            }
            else
            {
                table = qs.getStoreManager().getDatastoreClass(mapping.getType(), clr);
            }
        }
        catch (ClassNotPersistenceCapableException cnpce)
        {
            return te.newFieldExpression(subfieldName);
        }

        if (fieldType != null && !fieldType.equals(mapping.getType()))
        {
            // The field relation is to a table that allows multiple types to be stored (and has a discriminator)
            // and the type we want is not the base type, so we need to restrict the values of the discriminator.
            DiscriminatorMetaData dismd = table.getDiscriminatorMetaData();
            DiscriminatorMapping discriminatorMapping = (DiscriminatorMapping)table.getDiscriminatorMapping(false);
            if (dismd != null && dismd.getStrategy() != DiscriminatorStrategy.NONE)
            {
                // Start with the required class
                BooleanExpression discrExpr = booleanConditionForClassInDiscriminator(qs, fieldType, dismd, discriminatorMapping, te);

                // Add "or" condition for any of its possible subclasses (if any)
                Iterator subclassIter = qs.getStoreManager().getSubClassesForClass(fieldType, true, clr).iterator();
                while (subclassIter.hasNext())
                {
                    String subCandidateType = (String)subclassIter.next();
                    discrExpr.ior(booleanConditionForClassInDiscriminator(qs, subCandidateType, dismd, discriminatorMapping, te));
                }

                discrExpr.encloseWithInParentheses();

                // Add the discriminator restrictions as an "and" condition to the Query Statement
                qs.andCondition(discrExpr);
            }
        }

        if (te.getMainTable().equals(table) && usingRelatedTable && fieldName==null)
        {
            //TODO fieldname==null, QUESTION is it "<candidateAlias>" namespace? debug and see
            // We are already in the same table (left outer join in the constructor) and it isn't a self reference so just return
            // the field expression. This can happen when we have a 1-1 bidir single FK and to generate the ObjectExpression we
            // had to join across to the related field
            return te.newFieldExpression(subfieldName);
        }

        // jt... = "joined table"
        String jtIdentifier = te.getAlias().getIdentifier();
        if (fieldName != null)
        {
            jtIdentifier += '.' + fieldName;
        }
        if (!subfieldName.equals("this")) // TODO Use qs.getCandidateAlias()
        {
            jtIdentifier += '.' + subfieldName;
        }

        if (castType != null && !castType.getName().equals(mapping.getType()))
        {
            String castTypeName = castType.getName();
            jtIdentifier += '.' + castTypeName.substring(castTypeName.lastIndexOf('.') + 1);
        }

        DatastoreIdentifier jtRangeVar = qs.getStoreManager().getIdentifierFactory().newIdentifier(IdentifierFactory.TABLE, jtIdentifier);
        LogicSetExpression jtTblExpr = qs.getTableExpression(jtRangeVar);
        if (jtTblExpr == null)
        {
            // We can't join further (this subfield is not an object with a table expression)
            if (te.getAlias().getIdentifier().equalsIgnoreCase("this") && // TODO Use qs.getCandidateAlias()
                table == qs.getMainTableExpression().getMainTable() &&
                fieldName == null)
            {
                // Query contains "this.field" so just provide the associated field expression for that field
                return qs.getMainTableExpression().newFieldExpression(subfieldName);
            }

            jtTblExpr = qs.newTableExpression(table, jtRangeVar);

            ScalarExpression jtExpr = table.getIDMapping().newScalarExpression(qs, jtTblExpr);
            ScalarExpression expr = mapping.newScalarExpression(qs, te);
            if (mapping.isNullable())
            {
                if (innerJoin)
                {
View Full Code Here

Examples of org.jpox.store.mapped.DatastoreContainerObject

            {
                // Field type and instanceof type are totally incompatible, so just return false
                return new BooleanLiteral(qs, mapping, true).eq(new BooleanLiteral(qs, mapping, false));
            }

            DatastoreContainerObject table;
            try
            {
                if (mapping instanceof EmbeddedMapping)
                {
                    // Field is embedded in this table
                    // TODO Enable instanceof on non-PC fields (currently just return "true")
                    return new BooleanLiteral(qs, mapping, true).eq(new BooleanLiteral(qs, mapping, true));
                }
                else if (mapping instanceof PersistenceCapableMapping || mapping instanceof ReferenceMapping)
                {
                    // Field has its own table, so join to it
                    AbstractClassMetaData fieldCmd = qs.getStoreManager().getOMFContext().getMetaDataManager().getMetaDataForClass(
                        mapping.getType(), clr);
                    if (fieldCmd.getInheritanceMetaData().getStrategyValue() == InheritanceStrategy.SUBCLASS_TABLE)
                    {
                        // Field is a PC class that uses "subclass-table" inheritance strategy (and so has multiple possible tables to join to)
                        AbstractClassMetaData[] cmds = qs.getStoreManager().getClassesManagingTableForClass(fieldCmd, clr);
                        if (cmds != null)
                        {
                            // Join to the first table
                            // TODO Allow for all possible tables. Can we do an OR of the tables ? How ?
                            if (cmds.length > 1)
                            {
                                JPOXLogger.QUERY.warn(LOCALISER.msg("037006",
                                    mapping.getFieldMetaData().getFullFieldName(), cmds[0].getFullClassName()));
                            }
                            table = qs.getStoreManager().getDatastoreClass(cmds[0].getFullClassName(), clr);
                        }
                        else
                        {
                            // No subclasses with tables to join to, so throw a user error
                            throw new JPOXUserException(LOCALISER.msg("037005",
                                mapping.getFieldMetaData().getFullFieldName()));
                        }
                    }
                    else
                    {
                        // Class of the field will have its own table
                        table = qs.getStoreManager().getDatastoreClass(mapping.getType(), clr);
                    }
                }
                else
                {
                    table = qs.getStoreManager().getDatastoreClass(mapping.getType(), clr);
                }
            }
            catch (ClassNotPersistenceCapableException cnpce)
            {
                // Field is not PersistenceCapable
                // TODO Enable instanceof on non-PC fields (currently just return "true")
                return new BooleanLiteral(qs, mapping, true).eq(new BooleanLiteral(qs, mapping, true));
            }

            // Check if the table of the field has a discriminator
            IdentifierFactory idFactory = qs.getStoreManager().getIdentifierFactory();
            DiscriminatorMetaData dismd = table.getDiscriminatorMetaData();
            DiscriminatorMapping discriminatorMapping = (DiscriminatorMapping)table.getDiscriminatorMapping(false);
            if (discriminatorMapping != null)
            {
                // Has a discriminator so do a join to the table of the field and apply a constraint on its discriminator
                LogicSetExpression fieldTblExpr = null;
                if (fieldName == null)
                {
                    // Using THIS so use default table expression
                    fieldTblExpr = qs.getMainTableExpression();
                }
                else
                {
                    // Using field, so our real table will have an identifier of "THIS_{fieldName}" via INNER JOIN
                    String fieldIdentifier = te.getAlias().getIdentifier();
                    fieldIdentifier += '.' + fieldName;
                    DatastoreIdentifier fieldRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, fieldIdentifier);
                    fieldTblExpr = qs.getTableExpression(fieldRangeVar);
                    if (fieldTblExpr == null)
                    {
                        fieldTblExpr = qs.newTableExpression(table, fieldRangeVar);
                    }
                    ScalarExpression fieldExpr = table.getIDMapping().newScalarExpression(qs, fieldTblExpr);
                    expr = mapping.newScalarExpression(qs, te);
                    qs.innerJoin(fieldExpr, expr, fieldTblExpr, true, true);
                }

                // Return a constraint on the discriminator for this table to get the right instances
                // This allows all discriminator values for the instanceof class and all of its subclasses
                // DISCRIM = 'baseVal' OR DISCRIM = 'sub1Val' OR DISCRIM = 'sub2Val' ... etc
                BooleanExpression discrExpr =
                    booleanConditionForClassInDiscriminator(qs, instanceofClass.getName(), dismd,
                        discriminatorMapping, fieldTblExpr);
                Iterator subclassIter = qs.getStoreManager().getSubClassesForClass(instanceofClass.getName(),
                    true, clr).iterator();
                while (subclassIter.hasNext())
                {
                    String subCandidateType = (String)subclassIter.next();
                    discrExpr.ior(booleanConditionForClassInDiscriminator(qs, subCandidateType, dismd,
                        discriminatorMapping, fieldTblExpr));
                }
                discrExpr.encloseWithInParentheses();

                return discrExpr;
            }
            else
            {
                // No discriminator so maybe union, or just a SELECT
                // Need to join to the instanceof class (where appropriate)
                // TODO RDBMS-71 Only join on the UNION select that it is applicable to
                if (table instanceof DatastoreClass)
                {
                    DatastoreClass ct = (DatastoreClass)table;
                    if (ct.managesClass(instanceofClass.getName()))
                    {
                        // This type is managed in this table so must be an instance
                        return new BooleanLiteral(qs, mapping, true).eq(new BooleanLiteral(qs, mapping, true));
                    }
                    else
                    {
                        // The instanceof type is not managed here
                        DatastoreClass instanceofTable = qs.getStoreManager().getDatastoreClass(
                            instanceofClass.getName(), clr);
                        String fieldIdentifier = te.getAlias().getIdentifier();
                        if (fieldName == null)
                        {
                            // Using THIS, so our real table will have an identifier of "THIS_INST"
                            fieldIdentifier += ".INST";
                        }
                        else
                        {
                            // Using field, so our real table will have an identifier of "THIS_{fieldName}"
                            fieldIdentifier += '.' + fieldName;
                        }
                        DatastoreIdentifier fieldRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, fieldIdentifier);
                        LogicSetExpression fieldTblExpr = qs.newTableExpression(instanceofTable, fieldRangeVar);
                        ScalarExpression fieldExpr = table.getIDMapping().newScalarExpression(qs, te);
                        if (fieldName == null)
                        {
                            expr = instanceofTable.getIDMapping().newScalarExpression(qs, fieldTblExpr);
                        }
                        else
View Full Code Here

Examples of org.jpox.store.mapped.DatastoreContainerObject

            if (fmd.getJoinMetaData() != null || relatedMmds[0].getJoinMetaData() != null)
            {
                // 1-N bidirectional join table relation.
                // Do a LEFT OUTER JOIN to the join table to pick up the value.
                MappedStoreManager storeMgr = qs.getStoreManager();
                DatastoreContainerObject joinTable = storeMgr.getDatastoreContainerObject(relatedMmds[0]);
                JavaTypeMapping referenceMapping = null;
                JavaTypeMapping selectMapping = null;

                DatastoreElementContainer collTable = (DatastoreElementContainer)joinTable;
                referenceMapping = collTable.getElementMapping();
View Full Code Here

Examples of org.jpox.store.mapped.DatastoreContainerObject

    public String referenceColumn(DatastoreField col)
    {
        assertNotFrozen();

        DatastoreContainerObject table = col.getDatastoreContainerObject();
        DatastoreIdentifier alias = (DatastoreIdentifier)aliasesByTable.get(table);

        if (alias == null)
        {
            if (!(mainTable instanceof DatastoreClass) || !(table instanceof DatastoreClass))
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.