Package org.datanucleus.store.rdbms

Examples of org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder


        if (!(expr instanceof TemporalExpression))
        {
            throw new NucleusException(LOCALISER.msg("060001", "getHour()", expr));
        }

        RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
        JavaTypeMapping mapping = storeMgr.getMappingManager().getMapping(String.class);
        SQLExpression hh = exprFactory.newLiteral(stmt, mapping, "hour");

        ArrayList funcArgs = new ArrayList();
        funcArgs.add(hh);
        funcArgs.add(expr);
View Full Code Here


        }

        // Choose the statement based on whether optimistic or not
        String stmt = null;
        ExecutionContext ec = sm.getExecutionContext();
        RDBMSStoreManager storeMgr = (RDBMSStoreManager)ec.getStoreManager();
        boolean optimisticChecks = (versionMetaData != null && ec.getTransaction().getOptimistic() && versionChecks);
        if (optimisticChecks)
        {
            stmt = deleteStmtOptimistic;
        }
        else
        {
            stmt = deleteStmt;
        }

        // Process the delete of this object
        try
        {
            ManagedConnection mconn = storeMgr.getConnection(ec);
            SQLController sqlControl = storeMgr.getSQLController();

            try
            {
                // Perform the delete
                boolean batch = true;
                if (optimisticChecks || !ec.getTransaction().isActive())
                {
                    // Turn OFF batching if doing optimistic checks (since we need the result of the delete)
                    // or if using nontransactional writes (since we want it sending to the datastore now)
                    batch = false;
                }
                PreparedStatement ps = sqlControl.getStatementForUpdate(mconn, stmt, batch);
                try
                {
                    // provide primary key field(s)
                    if (cmd.getIdentityType() == IdentityType.DATASTORE)
                    {
                        StatementMappingIndex mapIdx = mappingStatementIndex.getDatastoreId();
                        for (int i=0;i<mapIdx.getNumberOfParameterOccurrences();i++)
                        {
                            table.getDatastoreObjectIdMapping().setObject(ec, ps,
                                mapIdx.getParameterPositionsForOccurrence(i), sm.getInternalObjectId());
                        }
                    }
                    else if (cmd.getIdentityType() == IdentityType.APPLICATION)
                    {
                        StatementClassMapping mappingDefinition = new StatementClassMapping();
                        StatementMappingIndex[] idxs = mappingStatementIndex.getPrimaryKeys();
                        for (int i=0;i<idxs.length;i++)
                        {
                            if (idxs[i] != null)
                            {
                                mappingDefinition.addMappingForMember(i, idxs[i]);
                            }
                        }
                        sm.provideFields(pkFieldNumbers,
                            storeMgr.getFieldManagerForStatementGeneration(sm, ps, mappingDefinition, true));
                    }

                    if (optimisticChecks)
                    {
                        // WHERE clause - current version discriminator
View Full Code Here

        if (NucleusLogger.PERSISTENCE.isDebugEnabled())
        {
            NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("052217", sm.toPrintableID(), fmd.getFullFieldName()));
        }

        RDBMSStoreManager storeMgr = (RDBMSStoreManager)sm.getExecutionContext().getStoreManager();
        ExecutionContext ec = sm.getExecutionContext();
        ClassLoaderResolver clr = ec.getClassLoaderResolver();
        AbstractMemberMetaData[] relatedMmds = fmd.getRelatedMemberMetaData(clr);

        // Check if we should null here, or leave to the datastore FK handler
        boolean checkFK = true;
        if (ec.getNucleusContext().getPersistenceConfiguration().getStringProperty("datanucleus.deletionPolicy").equals("JDO2"))
        {
            // JDO2 doesn't currently (2.0 spec) take note of foreign-key
            checkFK = false;
        }
        if (checkFK)
        {
            for (int i=0;i<relatedMmds.length;i++)
            {
                ForeignKeyMetaData relFkmd = relatedMmds[i].getForeignKeyMetaData();
                if (relFkmd != null && relFkmd.getDeleteAction() != null)
                {
                    // Field has a FK with a delete-action so leave to the datastore to process the delete
                    return;
                }
            }
        }

        // TODO Cater for more than 1 related field
        String fullClassName = ((AbstractClassMetaData)relatedMmds[0].getParent()).getFullClassName();

        //TODO I'm not sure that we need to loop all implementations. will we have the fk set to all tables, if many?
        String[] classes;
        if (((AbstractClassMetaData)relatedMmds[0].getParent()) instanceof InterfaceMetaData)
        {
            classes = storeMgr.getNucleusContext().getMetaDataManager().getClassesImplementingInterface(fullClassName, clr);
        }
        else
        {
            classes = new String[] {fullClassName};
        }
        Set datastoreClasses = new HashSet();
        for (int i=0; i<classes.length; i++)
        {
            // just remove duplicates
            datastoreClasses.add(storeMgr.getDatastoreClass(classes[i], clr));
        }

        Iterator it = datastoreClasses.iterator();
        while (it.hasNext())
        {
            DatastoreClass refTable = (DatastoreClass)it.next();
            JavaTypeMapping refMapping = refTable.getMemberMapping(fmd.getMappedBy());
            if (refMapping.isNullable()) // Only clear the references that can be cleared
            {
                // Create a statement to clear the link from the previous related object
                StringBuffer clearLinkStmt = new StringBuffer("UPDATE " + refTable.toString() + " SET ");
                for (int j=0;j<refMapping.getNumberOfDatastoreMappings();j++)
                {
                    if (j > 0)
                    {
                        clearLinkStmt.append(",");
                    }
                    clearLinkStmt.append(refMapping.getDatastoreMapping(j).getDatastoreField().getIdentifier());
                    clearLinkStmt.append("=NULL");
                }
                clearLinkStmt.append(" WHERE ");
                for (int j=0;j<refMapping.getNumberOfDatastoreMappings();j++)
                {
                    if (j > 0)
                    {
                        clearLinkStmt.append(" AND ");
                    }
                    clearLinkStmt.append(refMapping.getDatastoreMapping(j).getDatastoreField().getIdentifier());
                    clearLinkStmt.append("=?");
                }

                try
                {
                    ManagedConnection mconn = storeMgr.getConnection(ec);
                    SQLController sqlControl = storeMgr.getSQLController();
                    try
                    {
                        // Null out the relationship to the object being deleted.
                        PreparedStatement ps = null;
                        try
View Full Code Here

     * @param expr The expression
     * @return The numeric expression for this SQL expression
     */
    public static NumericExpression getNumericExpression(SQLExpression expr)
    {
        RDBMSStoreManager storeMgr = expr.getSQLStatement().getRDBMSManager();
        SQLExpressionFactory factory = storeMgr.getSQLExpressionFactory();
        DatabaseAdapter dba = expr.getSQLStatement().getDatabaseAdapter();
        if (expr instanceof CharacterLiteral)
        {
            char c = ((Character)((CharacterLiteral)expr).getValue()).charValue();
            BigInteger value = new BigInteger("" + (int)c);
            return (NumericExpression)factory.newLiteral(expr.getSQLStatement(),
                storeMgr.getMappingManager().getMapping(value.getClass()), value);
        }
        else if (expr instanceof SQLLiteral)
        {
            BigInteger value = new BigInteger((String)((SQLLiteral)expr).getValue());
            return (NumericExpression)factory.newLiteral(expr.getSQLStatement(),
                storeMgr.getMappingManager().getMapping(value.getClass()), value);
        }

        ArrayList args = new ArrayList();
        args.add(expr);
        return new NumericExpression(expr.getSQLStatement(), expr.getJavaTypeMapping(),
View Full Code Here

     * @param stmt The SQL statement
     * @return The literal
     */
    public static SQLExpression getLiteralForOne(SQLStatement stmt)
    {
        RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
        JavaTypeMapping mapping = storeMgr.getMappingManager().getMapping(BigInteger.class);
        return storeMgr.getSQLExpressionFactory().newLiteral(stmt, mapping, BigInteger.ONE);
    }
View Full Code Here

     * @param expr The expression
     * @return The StringExpression
     */
    public static StringExpression getStringExpression(SQLExpression expr)
    {
        RDBMSStoreManager storeMgr = expr.getSQLStatement().getRDBMSManager();
        JavaTypeMapping m = storeMgr.getSQLExpressionFactory().getMappingForType(String.class, false);
        if (expr instanceof SQLLiteral)
        {
            return new StringLiteral(expr.getSQLStatement(), m, ((SQLLiteral)expr).getValue().toString(), null);           
        }
        else
View Full Code Here

     */
    public static BooleanExpression getEqualityExpressionForObjectExpressions(ObjectExpression expr1,
            ObjectExpression expr2, boolean equals)
    {
        SQLStatement stmt = expr1.stmt;
        RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
        SQLExpressionFactory exprFactory = storeMgr.getSQLExpressionFactory();
        ClassLoaderResolver clr = stmt.getClassLoaderResolver();
        ApiAdapter api = storeMgr.getApiAdapter();
        if (expr1 instanceof ObjectLiteral && expr2 instanceof ObjectLiteral)
        {
            // ObjectLiterall == ObjectLiteral
            ObjectLiteral lit1 = (ObjectLiteral)expr1;
            ObjectLiteral lit2 = (ObjectLiteral)expr2;
            return new BooleanLiteral(stmt, expr1.mapping,
                equals ? lit1.getValue().equals(lit2.getValue()) : !lit1.getValue().equals(lit2.getValue()));
        }
        else if (expr1 instanceof ObjectLiteral || expr2 instanceof ObjectLiteral)
        {
            // ObjectExpression == ObjectLiteral, ObjectLiteral == ObjectExpression
            BooleanExpression bExpr = null;
            boolean secondIsLiteral = (expr2 instanceof ObjectLiteral);
            Object value = (!secondIsLiteral ? ((ObjectLiteral)expr1).getValue() : ((ObjectLiteral)expr2).getValue());
            if (value instanceof OID)
            {
                // Object is an OID
                JavaTypeMapping m = storeMgr.getSQLExpressionFactory().getMappingForType(
                    ((OID)value).getKeyValue().getClass(), false);
                SQLExpression oidLit = exprFactory.newLiteral(stmt, m, ((OID)value).getKeyValue());
                if (equals)
                {
                    return (secondIsLiteral ? expr1.subExprs.getExpression(0).eq(oidLit) : expr2.subExprs.getExpression(0).eq(oidLit));
                }
                else
                {
                    return (secondIsLiteral ? expr1.subExprs.getExpression(0).ne(oidLit) : expr2.subExprs.getExpression(0).ne(oidLit));
                }
            }
            else if (api.isSingleFieldIdentity(value))
            {
                // Object is SingleFieldIdentity
                JavaTypeMapping m = storeMgr.getSQLExpressionFactory().getMappingForType(
                    api.getTargetClassForSingleFieldIdentity(value), false);
                SQLExpression oidLit = exprFactory.newLiteral(stmt, m,
                    api.getTargetKeyForSingleFieldIdentity(value));
                if (equals)
                {
                    return (secondIsLiteral ? expr1.subExprs.getExpression(0).eq(oidLit) : expr2.subExprs.getExpression(0).eq(oidLit));
                }
                else
                {
                    return (secondIsLiteral ? expr1.subExprs.getExpression(0).ne(oidLit) : expr2.subExprs.getExpression(0).ne(oidLit));
                }
            }
            else
            {
                AbstractClassMetaData cmd =
                    storeMgr.getNucleusContext().getMetaDataManager().getMetaDataForClass(value.getClass(), clr);
                if (cmd != null)
                {
                    // Value is a persistable object
                    if (cmd.getIdentityType() == IdentityType.APPLICATION)
                    {
                        // Application identity
                        if (api.getIdForObject(value) != null)
                        {
                            // Persistent PC object (FCO)
                            // Cater for composite PKs and parts of PK being PC mappings, and recursion
                            ObjectExpression expr = (secondIsLiteral ? expr1 : expr2);
                            JavaTypeMapping[] pkMappingsApp = new JavaTypeMapping[expr.subExprs.size()];
                            Object[] pkFieldValues = new Object[expr.subExprs.size()];
                            int position = 0;
                            ExecutionContext ec = api.getExecutionContext(value);
                            JavaTypeMapping thisMapping = expr.mapping;
                            if (expr.mapping instanceof ReferenceMapping)
                            {
                                // "InterfaceField == value", so pick an implementation mapping that is castable
                                thisMapping = null;
                                ReferenceMapping refMapping = (ReferenceMapping)expr.mapping;
                                JavaTypeMapping[] implMappings = refMapping.getJavaTypeMapping();
                                for (int i=0;i<implMappings.length;i++)
                                {
                                    Class implType = clr.classForName(implMappings[i].getType());
                                    if (implType.isAssignableFrom(value.getClass()))
                                    {
                                        thisMapping = implMappings[i];
                                        break;
                                    }
                                }
                            }
                            if (thisMapping == null)
                            {
                                // Just return a (1=0) since no implementation castable
                                return exprFactory.newLiteral(stmt, expr1.mapping, false).eq(exprFactory.newLiteral(stmt, expr1.mapping, true));
                            }

                            for (int i=0;i<cmd.getNoOfPrimaryKeyMembers();i++)
                            {
                                AbstractMemberMetaData mmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(cmd.getPKMemberPositions()[i]);
                                Object fieldValue = ExpressionUtils.getValueForMemberOfObject(ec, mmd, value);
                                JavaTypeMapping mapping = ((PersistableMapping)thisMapping).getJavaTypeMapping()[i];
                                if (mapping instanceof PersistableMapping)
                                {
                                    position = ExpressionUtils.populatePrimaryKeyMappingsValuesForPCMapping(pkMappingsApp,
                                        pkFieldValues, position, (PersistableMapping)mapping,
                                        cmd, mmd, fieldValue, storeMgr, clr);
                                }
                                else
                                {
                                    pkMappingsApp[position] = mapping;
                                    pkFieldValues[position] = fieldValue;
                                    position++;
                                }
                            }

                            for (int i=0; i<expr.subExprs.size(); i++)
                            {
                                SQLExpression source = expr.subExprs.getExpression(i);
                                SQLExpression target =
                                    exprFactory.newLiteral(stmt, pkMappingsApp[i], pkFieldValues[i]);
                                BooleanExpression subExpr = (secondIsLiteral ? source.eq(target) : target.eq(source));
                                if (bExpr == null)
                                {
                                    bExpr = subExpr;
                                }
                                else
                                {
                                    bExpr = bExpr.and(subExpr);
                                }
                            }
                        }
                        else
                        {
                            // PC object with no id (embedded, or transient maybe)
                            if (secondIsLiteral)
                            {
                                for (int i=0; i<expr1.subExprs.size(); i++)
                                {
                                    // Query should return nothing (so just do "(1 = 0)")
                                    NucleusLogger.QUERY.warn(LOCALISER.msg("037003", value));
                                    bExpr = exprFactory.newLiteral(stmt, expr1.mapping, false).eq(exprFactory.newLiteral(stmt, expr1.mapping, true));
                                    // It is arguable that we should compare the id with null (as below)
                                    /*bExpr = expr.eq(new NullLiteral(qs));*/
                                }
                            }
                            else
                            {
                                for (int i=0; i<expr2.subExprs.size(); i++)
                                {
                                    // Query should return nothing (so just do "(1 = 0)")
                                    NucleusLogger.QUERY.warn(LOCALISER.msg("037003", value));
                                    bExpr = exprFactory.newLiteral(stmt, expr2.mapping, false).eq(exprFactory.newLiteral(stmt, expr2.mapping, true));
                                    // It is arguable that we should compare the id with null (as below)
                                    /*bExpr = expr.eq(new NullLiteral(qs));*/
                                }
                            }
                        }
                        // TODO Allow for !equals
                        return bExpr;
                    }
                    else if (cmd.getIdentityType() == IdentityType.DATASTORE)
                    {
                        // Datastore identity
                        SQLExpression source = (secondIsLiteral ? expr1.subExprs.getExpression(0) : expr2.subExprs.getExpression(0));
                        JavaTypeMapping mapping = (secondIsLiteral ? expr1.mapping : expr2.mapping);
                        OID objectId = (OID)api.getIdForObject(value);
                        if (objectId == null)
                        {
                            // PC object with no id (embedded, or transient maybe)
                            // Query should return nothing (so just do "(1 = 0)")
                            NucleusLogger.QUERY.warn(LOCALISER.msg("037003", value));
                            // TODO Allow for !equals
                            return exprFactory.newLiteral(stmt, mapping, false).eq(exprFactory.newLiteral(stmt, mapping, true));
                            // It is arguable that we should compare the id with null (as below)
                            /*bExpr = expr.eq(new NullLiteral(qs));*/
                        }
                        else
                        {
                            JavaTypeMapping m = storeMgr.getSQLExpressionFactory().getMappingForType(
                                objectId.getKeyValue().getClass(), false);
                            SQLExpression oidExpr = exprFactory.newLiteral(stmt, m, objectId.getKeyValue());
                            if (equals)
                            {
                                return source.eq(oidExpr);
                            }
                            else
                            {
                                return source.ne(oidExpr);
                            }
                        }
                    }
                }
                else
                {
                    // No metadata, so we either have an application identity, or any object
                    String pcClassName = storeMgr.getClassNameForObjectID(value, clr, null);
                    if (pcClassName != null)
                    {
                        // Object is an application identity
                        cmd = storeMgr.getNucleusContext().getMetaDataManager().getMetaDataForClass(pcClassName, clr);
                        return (secondIsLiteral ?
                            ExpressionUtils.getAppIdEqualityExpression(value, expr1, storeMgr, clr, cmd, null, null) :
                            ExpressionUtils.getAppIdEqualityExpression(value, expr2, storeMgr, clr, cmd, null, null));
                        // TODO Allow for !equals
                    }
View Full Code Here

            NucleusLogger.QUERY.debug(">> Map.containsEntry binding unbound variable " + valVarName +
                " using INNER JOIN");
            // TODO What if the variable is declared as a subtype, handle this see CollectionContainsMethod
        }

        RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
        MetaDataManager mmgr = storeMgr.getMetaDataManager();
        AbstractMemberMetaData mmd = mapExpr.getJavaTypeMapping().getMemberMetaData();
        AbstractClassMetaData keyCmd = mmd.getMap().getKeyClassMetaData(clr, mmgr);
        AbstractClassMetaData valCmd = mmd.getMap().getValueClassMetaData(clr, mmgr);
        if (mmd.getMap().getMapType() == MapType.MAP_TYPE_JOIN)
        {
            // Map formed in join table - add join to join table, then to key/value tables (if present)
            MapTable mapTbl = (MapTable)storeMgr.getDatastoreContainerObject(mmd);
            SQLTable joinSqlTbl = stmt.innerJoin(mapExpr.getSQLTable(), mapExpr.getSQLTable().getTable().getIdMapping(),
                mapTbl, null, mapTbl.getOwnerMapping(), null, null);
            if (valCmd != null)
            {
                DatastoreClass valTbl = storeMgr.getDatastoreClass(valCmd.getFullClassName(), clr);
                SQLTable valSqlTbl = stmt.innerJoin(joinSqlTbl, mapTbl.getValueMapping(),
                    valTbl, null, valTbl.getIdMapping(), null, null);

                SQLExpression valIdExpr = exprFactory.newExpression(stmt, valSqlTbl, valTbl.getIdMapping());
                if (valIsUnbound)
                {
                    // Bind the variable in the QueryGenerator
                    stmt.getQueryGenerator().bindVariable(valVarName, valCmd, valIdExpr.getSQLTable(),
                        valIdExpr.getJavaTypeMapping());
                }
                else
                {
                    // Add restrict to value
                    stmt.whereAnd(valIdExpr.eq(valExpr), true);
                }
            }
            else
            {
                SQLExpression valIdExpr = exprFactory.newExpression(stmt, joinSqlTbl, mapTbl.getValueMapping());
                if (valIsUnbound)
                {
                    // Bind the variable in the QueryGenerator
                    stmt.getQueryGenerator().bindVariable(valVarName, valCmd, valIdExpr.getSQLTable(),
                        valIdExpr.getJavaTypeMapping());
                }
                else
                {
                    // Add restrict to value
                    stmt.whereAnd(valIdExpr.eq(valExpr), true);
                }
            }

            if (keyCmd != null)
            {
                DatastoreClass keyTbl = storeMgr.getDatastoreClass(keyCmd.getFullClassName(), clr);
                SQLTable keySqlTbl = stmt.innerJoin(joinSqlTbl, mapTbl.getKeyMapping(),
                    keyTbl, null, keyTbl.getIdMapping(), null, null);

                SQLExpression keyIdExpr = exprFactory.newExpression(stmt, keySqlTbl, keyTbl.getIdMapping());
                if (keyIsUnbound)
                {
                    // Bind the variable in the QueryGenerator
                    stmt.getQueryGenerator().bindVariable(keyVarName, keyCmd, keyIdExpr.getSQLTable(),
                        keyIdExpr.getJavaTypeMapping());
                }
                else
                {
                    // Add restrict to key
                    stmt.whereAnd(keyIdExpr.eq(keyExpr), true);
                }
            }
            else
            {
                SQLExpression keyIdExpr = exprFactory.newExpression(stmt, joinSqlTbl, mapTbl.getKeyMapping());
                if (keyIsUnbound)
                {
                    // Bind the variable in the QueryGenerator
                    stmt.getQueryGenerator().bindVariable(keyVarName, keyCmd, keyIdExpr.getSQLTable(),
                        keyIdExpr.getJavaTypeMapping());
                }
                else
                {
                    // Add restrict to key
                    stmt.whereAnd(keyIdExpr.eq(keyExpr), true);
                }
            }
        }
        else if (mmd.getMap().getMapType() == MapType.MAP_TYPE_KEY_IN_VALUE)
        {
            // Map formed in value table - add join to value table, then to key table (if present)
            DatastoreClass valTbl = storeMgr.getDatastoreClass(valCmd.getFullClassName(), clr);
            JavaTypeMapping ownerMapping = null;
            if (mmd.getMappedBy() != null)
            {
                ownerMapping = valTbl.getMemberMapping(valCmd.getMetaDataForMember(mmd.getMappedBy()));
            }
            else
            {
                ownerMapping = valTbl.getExternalMapping(mmd, MappingConsumer.MAPPING_TYPE_EXTERNAL_FK);
            }
            SQLTable valSqlTbl = stmt.innerJoin(mapExpr.getSQLTable(), mapExpr.getSQLTable().getTable().getIdMapping(),
                valTbl, null, ownerMapping, null, null);

            SQLExpression valIdExpr = exprFactory.newExpression(stmt, valSqlTbl, valTbl.getIdMapping());
            if (valIsUnbound)
            {
                // Bind the variable in the QueryGenerator
                stmt.getQueryGenerator().bindVariable(valVarName, valCmd, valIdExpr.getSQLTable(),
                    valIdExpr.getJavaTypeMapping());
            }
            else
            {
                // Add restrict to value
                stmt.whereAnd(valIdExpr.eq(valExpr), true);
            }

            if (keyCmd != null)
            {
                // Add inner join to key table
                AbstractMemberMetaData valKeyMmd =
                    valCmd.getMetaDataForMember(mmd.getKeyMetaData().getMappedBy());
                DatastoreClass keyTbl = storeMgr.getDatastoreClass(keyCmd.getFullClassName(), clr);
                SQLTable keySqlTbl = stmt.innerJoin(valSqlTbl, valTbl.getMemberMapping(valKeyMmd),
                    keyTbl, null, keyTbl.getIdMapping(), null, null);

                SQLExpression keyIdExpr = exprFactory.newExpression(stmt, keySqlTbl, keyTbl.getIdMapping());
                if (keyIsUnbound)
                {
                    // Bind the variable in the QueryGenerator
                    stmt.getQueryGenerator().bindVariable(keyVarName, keyCmd, keyIdExpr.getSQLTable(),
                        keyIdExpr.getJavaTypeMapping());
                }
                else
                {
                    // Add restriction to key
                    stmt.whereAnd(keyIdExpr.eq(keyExpr), true);
                }
            }
            else
            {
                AbstractMemberMetaData valKeyMmd =
                    valCmd.getMetaDataForMember(mmd.getKeyMetaData().getMappedBy());
                SQLExpression keyIdExpr = exprFactory.newExpression(stmt, valSqlTbl,
                    valTbl.getMemberMapping(valKeyMmd));
                if (keyIsUnbound)
                {
                    // Bind the variable in the QueryGenerator
                    stmt.getQueryGenerator().bindVariable(keyVarName, keyCmd, keyIdExpr.getSQLTable(),
                        keyIdExpr.getJavaTypeMapping());
                }
                else
                {
                    // Add restriction to key
                    stmt.whereAnd(keyIdExpr.eq(keyExpr), true);
                }
            }
        }
        else if (mmd.getMap().getMapType() == MapType.MAP_TYPE_VALUE_IN_KEY)
        {
            // Map formed in key table - add join to key table then to value table (if present)
            DatastoreClass keyTbl = storeMgr.getDatastoreClass(keyCmd.getFullClassName(), clr);
            AbstractMemberMetaData keyValMmd =
                keyCmd.getMetaDataForMember(mmd.getValueMetaData().getMappedBy());
            JavaTypeMapping ownerMapping = null;
            if (mmd.getMappedBy() != null)
            {
                ownerMapping = keyTbl.getMemberMapping(keyCmd.getMetaDataForMember(mmd.getMappedBy()));
            }
            else
            {
                ownerMapping = keyTbl.getExternalMapping(mmd, MappingConsumer.MAPPING_TYPE_EXTERNAL_FK);
            }
            SQLTable keySqlTbl = stmt.innerJoin(mapExpr.getSQLTable(), mapExpr.getSQLTable().getTable().getIdMapping(),
                keyTbl, null, ownerMapping, null, null);

            SQLExpression keyIdExpr = exprFactory.newExpression(stmt, keySqlTbl, keyTbl.getIdMapping());
            if (keyIsUnbound)
            {
                // Bind the variable in the QueryGenerator
                stmt.getQueryGenerator().bindVariable(keyVarName, keyCmd, keyIdExpr.getSQLTable(),
                    keyIdExpr.getJavaTypeMapping());
            }
            else
            {
                // Add restrict to key
                stmt.whereAnd(keyIdExpr.eq(keyExpr), true);
            }

            if (valCmd != null)
            {
                // Add inner join to value table
                DatastoreClass valTbl = storeMgr.getDatastoreClass(valCmd.getFullClassName(), clr);
                SQLTable valSqlTbl = stmt.innerJoin(keySqlTbl, keyTbl.getMemberMapping(keyValMmd),
                    valTbl, null, valTbl.getIdMapping(), null, null);

                SQLExpression valIdExpr = exprFactory.newExpression(stmt, valSqlTbl, valTbl.getIdMapping());
                if (valIsUnbound)
View Full Code Here

        if (!(expr instanceof TemporalExpression))
        {
            throw new NucleusException(LOCALISER.msg("060001", "getDay", expr));
        }

        RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
        JavaTypeMapping mapping = storeMgr.getMappingManager().getMapping(String.class);
        SQLExpression dd = exprFactory.newLiteral(stmt, mapping, "DD");

        ArrayList funcArgs = new ArrayList();
        funcArgs.add(expr);
        funcArgs.add(dd);
View Full Code Here

        if (!(expr instanceof TemporalExpression))
        {
            throw new NucleusException(LOCALISER.msg("060001", "getHour", expr));
        }

        RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
        JavaTypeMapping mapping = storeMgr.getMappingManager().getMapping(String.class);
        SQLExpression hh = exprFactory.newLiteral(stmt, mapping, "HH24");

        ArrayList funcArgs = new ArrayList();
        funcArgs.add(expr);
        funcArgs.add(hh);
View Full Code Here

TOP

Related Classes of org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder

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.