Package org.jpox.store.mapped

Examples of org.jpox.store.mapped.IdentifierFactory


    {
        initialize(dba, delegate.getType());
        this.delegate = delegate;

        DiscriminatorMetaData dismd = datastoreContainer.getDiscriminatorMetaData();
        IdentifierFactory idFactory = datastoreContainer.getStoreManager().getIdentifierFactory();
        DatastoreIdentifier id = null;
        if (dismd.getColumnMetaData() == null)
        {
            // No column name so generate a default
            id = idFactory.newDiscriminatorFieldIdentifier();
            ColumnMetaData colmd = new ColumnMetaData(dismd, id.getIdentifier());
            dismd.setColumnMetaData(colmd);
        }
        else
        {
            // Column name defined
            ColumnMetaData colmd = dismd.getColumnMetaData();
            id = idFactory.newDatastoreFieldIdentifier(colmd.getName());
        }

        DatastoreField column = datastoreContainer.addDatastoreField(getType(), id, this, dismd.getColumnMetaData());
        datastoreContainer.getStoreManager().getMappingManager().createDatastoreMapping(delegate, datastoreContainer.getStoreManager(),
            column, getType());
View Full Code Here


        // Currently we only use a single column mapping for versioning.
        // The MetaData supports multiple columns and so we could extend this in the future
        // to use all MetaData information.
        ColumnMetaData[] versionColumnMetaData = versionMetaData.getColumnMetaData();
        ColumnMetaData colmd;
        IdentifierFactory idFactory = datastoreContainer.getStoreManager().getIdentifierFactory();
        DatastoreIdentifier id = null;
        if (versionColumnMetaData.length == 0)
        {
            // No column name so generate a default
            id = idFactory.newVersionFieldIdentifier();
            colmd = new ColumnMetaData(versionMetaData, id.getIdentifier());
            datastoreContainer.getVersionMetaData().addColumn(colmd);
        }
        else
        {
            // Column name defined
            colmd = versionColumnMetaData[0];
            id = idFactory.newDatastoreFieldIdentifier(colmd.getName());
        }
        DatastoreField column = datastoreContainer.addDatastoreField(getType(), id, this, colmd);
        datastoreContainer.getStoreManager().getMappingManager().createDatastoreMapping(delegate, datastoreContainer.getStoreManager(),
            column, getType());
    }
View Full Code Here

     * Executed when the size() method is found in a query filter.
     * @return  The NumericExpression resulting from the size() method.
     */
    public NumericExpression sizeMethod()
    {
        IdentifierFactory idFactory = qs.getStoreManager().getIdentifierFactory();
        String ctIdentifier = idFactory.newIdentifier(te.getAlias(), fieldName).getIdentifier();
        DatastoreIdentifier ctRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, ctIdentifier);

        return new ContainerSizeExpression(qs, getBackingStoreQueryable().getSizeSubquery(qs, mapping, te, ctRangeVar));
    }
View Full Code Here

    public BooleanExpression containsKeyMethod(ScalarExpression expr)
    {
        // mt... = "map table"
        // vt... = "value table"

        IdentifierFactory idFactory = qs.getStoreManager().getIdentifierFactory();
        if (expr instanceof UnboundVariable)
        {
            UnboundVariable var = (UnboundVariable)expr;
            if (var.getVariableType() == null)
            {
                // Set the variable type to be the element type for this collection
                var.setVariableType(qs.getClassLoaderResolver().classForName(mapStore.getKeyType()));
            }
            String vtIdentifier = "UNBOUND" + '.' + var.getVariableName();
            String mtIdentifier = idFactory.newIdentifier(idFactory.newIdentifier(te.getAlias(), fieldName), var.getVariableName()).getIdentifier();

            DatastoreIdentifier mtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, mtIdentifier);
            DatastoreIdentifier vtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, vtIdentifier);

            QueryExpression qexpr = getBackingStoreQueryable().getExistsSubquery(qs, mapping, te, mtRangeVar);
            var.bindTo(getBackingStoreQueryable().joinKeysTo(qexpr,
                                           qs,
                                           mapping,
                                           te,
                                           mtRangeVar,
                                           var.getVariableType(),
                                           expr,
                                           vtRangeVar));
            return new ExistsExpression(qs, qexpr, true);           
        }
        else if (expr instanceof Literal)
        {
            String mtIdentifier = idFactory.newIdentifier(te.getAlias(), fieldName).getIdentifier();
            DatastoreIdentifier mtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, mtIdentifier);
            DatastoreIdentifier vtRangeVar;
            int n = 0;

            do
            {
                String vtIdentifier = mtIdentifier + '.' + (++n);
                vtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, vtIdentifier);
            } while (qs.getTableExpression(vtRangeVar) != null);

            ClassLoaderResolver clr = qs.getClassLoaderResolver();
            QueryExpression qexpr = getBackingStoreQueryable().getExistsSubquery(qs, mapping, te, mtRangeVar);
            ScalarExpression joinKeysExpr = getBackingStoreQueryable().joinKeysTo(qexpr,
                                           qs,
                                           mapping,
                                           te,
                                           mtRangeVar,
                                           clr.classForName(expr.getMapping().getType()),
                                           expr,
                                           vtRangeVar);
            qexpr.andCondition(expr.eq(joinKeysExpr));
            return new ExistsExpression(qs, qexpr, true);
        }       
        else
        {
            String mtIdentifier = idFactory.newIdentifier(te.getAlias(), fieldName).getIdentifier();
            DatastoreIdentifier mtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, mtIdentifier);
            DatastoreIdentifier vtRangeVar;

            if (expr.te == null) // literals
            {
                int n = 0;

                do
                {
                    String vtIdentifier = mtIdentifier + '.' + (++n);
                    vtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, vtIdentifier);
                } while (qs.getTableExpression(vtRangeVar) != null);
            }
            else
            {
                vtRangeVar = expr.te.getAlias();
View Full Code Here

                                                 ScalarExpression valueExpr)
    {
        // mt... = "map table"
        // kt... = "key table"
        // vt... = "value table"
        IdentifierFactory idFactory = qs.getStoreManager().getIdentifierFactory();
        String mtIdentifier = idFactory.newIdentifier(te.getAlias(), fieldName).getIdentifier();
        DatastoreIdentifier mtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, mtIdentifier);

        // obtains a variable name for key
        Class keyType;
        DatastoreIdentifier ktRangeVar;
        UnboundVariable keyVar = null;
        ClassLoaderResolver clr=qs.getClassLoaderResolver();
        int nKey = 0;
        if (keyExpr instanceof UnboundVariable)
        {
            keyVar = (UnboundVariable)keyExpr;
            String ktJavaName = "UNBOUND" + '.' + keyVar.getVariableName();
            keyType = keyVar.getVariableType();
            ktRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, ktJavaName);
        }
        else
        {
            keyType = clr.classForName(mapStore.getKeyType());
            do
            {
                String ktIdentifier = mtIdentifier + '.' + (++nKey);
                ktRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, ktIdentifier);
            } while (qs.getTableExpression(ktRangeVar) != null);
        }

        // obtains a variable name for value
        Class valueType;
        DatastoreIdentifier vtRangeVar;
        UnboundVariable valueVar = null;
        int nValue = 0;
        if (valueExpr instanceof UnboundVariable)
        {
            valueVar = (UnboundVariable)valueExpr;
            String vtJavaName = "UNBOUND" + '.' + valueVar.getVariableName();
            valueType = valueVar.getVariableType();
            vtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, vtJavaName);
        }
        else
        {
            valueType = clr.classForName(mapStore.getValueType());
            do
            {
                String vtIdentifier = mtIdentifier + '.' + (++nValue);
                vtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, vtIdentifier);
            } while (qs.getTableExpression(vtRangeVar) != null);
        }

        QueryExpression qexpr = getBackingStoreQueryable().getExistsSubquery(qs, mapping, te, mtRangeVar);
        ScalarExpression[] qclKeyValues =
View Full Code Here

    public BooleanExpression containsValueMethod(ScalarExpression expr)
    {
        // mt... = "map table"
        // vt... = "value table"

        IdentifierFactory idFactory = qs.getStoreManager().getIdentifierFactory();
        if (expr instanceof UnboundVariable)
        {
            UnboundVariable var = (UnboundVariable)expr;
            if (var.getVariableType() == null)
            {
                // Set the variable type to be the element type for this collection
                var.setVariableType(qs.getClassLoaderResolver().classForName(mapStore.getValueType()));
            }
            String vtIdentifier = "UNBOUND" + '.' + var.getVariableName();
            String mtIdentifier = idFactory.newIdentifier(idFactory.newIdentifier(te.getAlias(), fieldName), var.getVariableName()).getIdentifier();

            DatastoreIdentifier mtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, mtIdentifier);
            DatastoreIdentifier vtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, vtIdentifier);

            QueryExpression qexpr = getBackingStoreQueryable().getExistsSubquery(qs, mapping, te, mtRangeVar);
            var.bindTo(getBackingStoreQueryable().joinValuesTo(qexpr,
                                           qs,
                                           mapping,
                                           te,
                                           mtRangeVar,
                                           var.getVariableType(),
                                           expr,
                                           vtRangeVar));
            return new ExistsExpression(qs, qexpr, true);           
        }
        else if (expr instanceof Literal)
        {
            String mtIdentifier = idFactory.newIdentifier(te.getAlias(), fieldName).getIdentifier();
            DatastoreIdentifier mtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, mtIdentifier);
            DatastoreIdentifier vtRangeVar;
            int n = 0;

            do
            {
                String vtIdentifier = mtIdentifier + '.' + (++n);
                vtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, vtIdentifier);
            } while (qs.getTableExpression(vtRangeVar) != null);

            ClassLoaderResolver clr = qs.getClassLoaderResolver();
            QueryExpression qexpr = getBackingStoreQueryable().getExistsSubquery(qs, mapping, te, mtRangeVar);
            ScalarExpression joinValuesExpr = getBackingStoreQueryable().joinValuesTo(qexpr,
                                           qs,
                                           mapping,
                                           te,
                                           mtRangeVar,
                                           clr.classForName(expr.getMapping().getType()),
                                           expr,
                                           vtRangeVar);
            qexpr.andCondition(expr.eq(joinValuesExpr));
            return new ExistsExpression(qs, qexpr, true);
        }       
        else
        {
            String mtIdentifier = idFactory.newIdentifier(te.getAlias(), fieldName).getIdentifier();
            DatastoreIdentifier mtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, mtIdentifier);
            DatastoreIdentifier vtRangeVar;

            if (expr.te == null) // literals
            {
                int n = 0;

                do
                {
                    String vtIdentifier = mtIdentifier + '.' + (++n);
                    vtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, vtIdentifier);
                } while (qs.getTableExpression(vtRangeVar) != null);
            }
            else
            {
                vtRangeVar = expr.te.getAlias();
View Full Code Here

     *          "map.isEmpty()".
     **/
    public BooleanExpression isEmptyMethod()
    {
        // mt... = "map table"
        IdentifierFactory idFactory = qs.getStoreManager().getIdentifierFactory();
        String mtIdentifier = idFactory.newIdentifier(te.getAlias(), fieldName).getIdentifier();
        DatastoreIdentifier mtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, mtIdentifier);

        return new ExistsExpression(qs, getBackingStoreQueryable().getExistsSubquery(qs, mapping, te, mtRangeVar), false);
    }
View Full Code Here

     **/
    public ScalarExpression getMethod(ScalarExpression expr)
    {
        // mt... = "map table"
        // vt... = "value table"
        IdentifierFactory idFactory = qs.getStoreManager().getIdentifierFactory();
        String mtIdentifier = idFactory.newIdentifier(te.getAlias(), fieldName).getIdentifier();

        DatastoreIdentifier mtRangeVar;
        DatastoreIdentifier ktRangeVar;
        DatastoreIdentifier vtRangeVar;
        int n = 0;
        if (expr instanceof UnboundVariable)
        {
            UnboundVariable var = (UnboundVariable)expr;
            if (var.getVariableType() == null)
            {
                // Set the variable type to be the element type for this collection
                var.setVariableType(qs.getClassLoaderResolver().classForName(mapStore.getKeyType()));
            }
            String ktIdentifier = "UNBOUND" + '.' + var.getVariableName();
            String vtIdentifier = "UNBOUNDVALUE" + '.' + var.getVariableName();

            mtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, mtIdentifier);
            ktRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, ktIdentifier);
            vtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, vtIdentifier);
        }
        else
        {
            mtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, mtIdentifier);

            do
            {
                String ktJavaName = mtIdentifier + '.' + (++n);
                ktRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, ktJavaName);
            } while (qs.getTableExpression(ktRangeVar) != null);

            n = 0;

            do
            {
                String vtIdentifier = mtIdentifier + '.' + (++n);
                vtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, vtIdentifier);
            } while (qs.getTableExpression(vtRangeVar) != null || vtRangeVar.equals(ktRangeVar));
        }
           
        /* QueryExpression qexpr = */ getBackingStoreQueryable().getExistsSubquery(qs, mapping, te, mtRangeVar);
        ClassLoaderResolver clr=qs.getClassLoaderResolver();
View Full Code Here

     * Executed when the size() method is found in a query filter.
     * @return  The NumericExpression resulting from the size() method.
     */
    public NumericExpression sizeMethod()
    {
        IdentifierFactory idFactory = qs.getStoreManager().getIdentifierFactory();
        String ctIdentifier = idFactory.newIdentifier(te.getAlias(), fieldName).getIdentifier();
        DatastoreIdentifier ctRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, ctIdentifier);

        return new ContainerSizeExpression(qs, getBackingStoreQueryable().getSizeSubquery(qs, mapping, te, ctRangeVar));
    }
View Full Code Here

     * @param expr The ScalarExpression passed as a parameter to contains().
     * @return The BooleanExpression resulting from the contains() method.
     */
    public BooleanExpression containsMethod(ScalarExpression expr)
    {
        IdentifierFactory idFactory = qs.getStoreManager().getIdentifierFactory();
        ClassLoaderResolver clr = qs.getClassLoaderResolver();
        if (expr instanceof NullLiteral)
        {
            // JPOX doesn't currently support querying for nulls in Collections so just return "1 = 0"
            // TODO Add support for querying for nulls in collections
            return new BooleanLiteral(qs, mapping, false).eq(new BooleanLiteral(qs, mapping, true));
        }
        else if (expr instanceof UnboundVariable)
        {
            UnboundVariable var = (UnboundVariable)expr;
            if (var.getVariableType() == null)
            {
                // Set the variable type to be the element type for this collection
                // implicit variable type. We now set the type to the collection type
                var.setVariableType(clr.classForName(collStore.getElementType()));
            }

            // Get the exists query of the collection table
            String existsTableId = idFactory.newIdentifier(
                idFactory.newIdentifier(te.getAlias(), fieldName), var.getVariableName()).getIdentifier();
            DatastoreIdentifier existsTableAlias = idFactory.newIdentifier(IdentifierFactory.TABLE, existsTableId);
            QueryExpression qexpr = getBackingStoreQueryable().getExistsSubquery(qs, mapping, te, existsTableAlias);

            // Join from the collection table to the element table
            DatastoreIdentifier elementTableAlias = null;
            if (expr.te == null)
            {
                String elementTableId = "UNBOUND" + '.' + var.getVariableName();
                elementTableAlias = idFactory.newIdentifier(IdentifierFactory.TABLE, elementTableId);
            }
            else
            {
                elementTableAlias = expr.te.getAlias();
            }
            ScalarExpression joinExpr = getBackingStoreQueryable().joinElementsTo(qexpr, qs, mapping, te,
                existsTableAlias, var.getVariableType(), expr, elementTableAlias, true);

            var.bindTo(joinExpr);

            //START see JDOQLContainerTest.testContainsResultVariable
            LogicSetExpression elementTblExpr = qs.getTableExpression(elementTableAlias);
            if (qs.hasCrossJoin(elementTblExpr))
            {
                // Perhaps some description about what this is supposed to be doing and WHY ????
                qexpr.andCondition(joinExpr.eq(expr.mapping.newScalarExpression(qs, elementTblExpr)));
            }
            //END see JDOQLContainerTest.

            return new ExistsExpression(qs, qexpr, true);
        }
        else
        {
            // "contains(Literal)", "contains(Expression)"
            String existsTableId = idFactory.newIdentifier(te.getAlias(), fieldName).getIdentifier();
            DatastoreIdentifier existsTableAlias = idFactory.newIdentifier(IdentifierFactory.TABLE, existsTableId);

            DatastoreIdentifier elementTableAlias;
            if (expr.te == null) // literals
            {
                int n = 0;
                do
                {
                    String elementTableId = existsTableId + '.' + (++n);
                    elementTableAlias = idFactory.newIdentifier(IdentifierFactory.TABLE, elementTableId);
                } while (qs.getTableExpression(elementTableAlias) != null);
            }
            else // expressions
            {
                elementTableAlias = expr.te.getAlias();
View Full Code Here

TOP

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

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.