Package org.jpox.store.mapped

Examples of org.jpox.store.mapped.IdentifierFactory


     * Return the BooleanExpression for a query filter in the form "collection.isEmpty()".
     * @return The BooleanExpression for a query filter in the form "collection.isEmpty()".
     */
    public BooleanExpression isEmptyMethod()
    {
        IdentifierFactory idFactory = qs.getStoreManager().getIdentifierFactory();
        String existsTableId = idFactory.newIdentifier(te.getAlias(), fieldName).getIdentifier();
        DatastoreIdentifier existsTableAlias = idFactory.newIdentifier(IdentifierFactory.TABLE, existsTableId);
        QueryExpression qexpr = getBackingStoreQueryable().getExistsSubquery(qs, mapping, te, existsTableAlias);

        return new ExistsExpression(qs, qexpr, false);
    }
View Full Code Here


     */
    public NumericExpression sizeMethod()
    {
        if (arrayStore != null)
        {
            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));
        }
        else
        {
View Full Code Here

    public BooleanExpression containsMethod(ScalarExpression expr)
    {
        // ct... = "collection table"
        // et... = "element table"

        IdentifierFactory idFactory = qs.getStoreManager().getIdentifierFactory();
        if (expr instanceof NullLiteral)
        {
            // JPOX doesn't currently support storing nulls in Collections so just return "1 = 0"
            // TODO Add support for storing nulls in collections and querying for this situation
            return new BooleanLiteral(qs, mapping, false).eq(new BooleanLiteral(qs, mapping, true));
        }
        else if( exprs != null )
        {
            BooleanExpression bExpr = null;
            for( int i=0; i<exprs.length; i++)
            {
                if( bExpr == null )
                {
                    bExpr = exprs[i].eq(expr);
                }
                else
                {
                    bExpr = bExpr.ior(exprs[i].eq(expr));
                }
            }
            bExpr.encloseWithInParentheses();
            return bExpr;
        }
        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(qs.getClassLoaderResolver().classForName(arrayStore.getElementType()));
            }
            //ctJavaName += + '.' + var.getVariableName();
            //String etJavaName = qs.getDefaultTableExpression().getRangeVariable().getJavaName() + '.' + var.getVariableName();

            String etIdentifier = "UNBOUND" + '.' + var.getVariableName();
            String ctIdentifier = idFactory.newIdentifier(idFactory.newIdentifier(te.getAlias(), fieldName), var.getVariableName()).getIdentifier();

            DatastoreIdentifier ctRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, ctIdentifier);
            DatastoreIdentifier etRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, etIdentifier);
            QueryExpression qexpr = getBackingStoreQueryable().getExistsSubquery(qs, mapping, te, ctRangeVar);
            var.bindTo(getBackingStoreQueryable().joinElementsTo(qexpr,
                qs,
                mapping,
                te,
                ctRangeVar,
                var.getVariableType(),
                expr,
                expr.te == null ? etRangeVar : expr.te.getAlias()));

            return new ExistsExpression(qs, qexpr, true);

        }
        else if (expr instanceof Literal)
        {
            String ctIdentifier = idFactory.newIdentifier(te.getAlias(), fieldName).getIdentifier();
            DatastoreIdentifier ctRangeVar = qs.getStoreManager().getIdentifierFactory().newIdentifier(IdentifierFactory.TABLE, ctIdentifier);
            DatastoreIdentifier etRangeVar;            
            if (expr.te == null) // literals
            {
                int n = 0;

                do
                {
                    String etIdentifier = ctIdentifier + '.' + (++n);
                    etRangeVar = qs.getStoreManager().getIdentifierFactory().newIdentifier(IdentifierFactory.TABLE, etIdentifier);
                } while (qs.getTableExpression(etRangeVar) != null);
            }
            else
            {
                etRangeVar = expr.te.getAlias();
            }

            ClassLoaderResolver clr=qs.getClassLoaderResolver();
            QueryExpression qexpr = getBackingStoreQueryable().getExistsSubquery(qs, mapping, te, ctRangeVar);
            ScalarExpression expr1 = getBackingStoreQueryable().joinElementsTo(qexpr,
                qs,
                   mapping,
                   te,
                ctRangeVar,
                clr.classForName(expr.getMapping().getType()),
                expr,
                expr.te == null ? etRangeVar : expr.te.getAlias());
            qexpr.andCondition(expr.eq(expr1));
            return new ExistsExpression(qs, qexpr, true);
        }       
        else
        {
            String ctIdentifier = idFactory.newIdentifier(te.getAlias(), fieldName).getIdentifier();
            DatastoreIdentifier ctRangeVar = qs.getStoreManager().getIdentifierFactory().newIdentifier(IdentifierFactory.TABLE, ctIdentifier);
            DatastoreIdentifier etRangeVar;            
            if (expr.te == null) // literals
            {
                int n = 0;
View Full Code Here

             *
             * So even though the caller may have been looking for column FOO
             * relative to rangevar THIS he may actually get back something like
             * THIS_1.FOO.
             */
            IdentifierFactory idFactory = qs.getStoreManager().getIdentifierFactory();
            alias = idFactory.newIdentifier(mainAlias, String.valueOf(aliasesByTable.size()));
            aliasesByTable.put(table, alias);

            /* mt... = "main table" */
            /* st... = "secondary table" */
            DatastoreClass mt = (DatastoreClass)mainTable;
View Full Code Here

        ObjectExpression objectCast;
        LogicSetExpression te = qs.getTableExpression(this.qs.getStoreManager().getDatastoreClass(castType.getName(), qs.getClassLoaderResolver()).getIdentifier());
        DatastoreClass dc = this.qs.getStoreManager().getDatastoreClass(castType.getName(), qs.getClassLoaderResolver());
        if (te == null)
        {
            IdentifierFactory idFactory = qs.getStoreManager().getIdentifierFactory();
            String jtIdentifier = this.te.getAlias().getIdentifier();
            if (castType != null && !castType.getName().equals(mapping.getType()))
            {
                String castTypeName = castType.getName();
                jtIdentifier = idFactory.newIdentifier(this.te.getAlias(), castTypeName.substring(castTypeName.lastIndexOf('.') + 1)).getIdentifier();
            }

            DatastoreIdentifier jtRangeVar = idFactory.newIdentifier(IdentifierFactory.TABLE, jtIdentifier);
            LogicSetExpression jtTblExpr = qs.getTableExpression(jtRangeVar);

            if (jtTblExpr == null)
            {
                jtTblExpr = qs.newTableExpression(dc, jtRangeVar);
View Full Code Here

                // 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);
View Full Code Here

                colmds[0] = colmd;
            }
        }

        // Generate the column identifier
        IdentifierFactory idFactory = datastoreContainer.getStoreManager().getIdentifierFactory();
        DatastoreIdentifier identifier = null;
        if (colmd.getName() == null)
        {
            // No name specified, so generate the identifier from the field name
            if (roleForField == JavaTypeMapping.MAPPING_FIELD)
            {
                identifier = idFactory.newIdentifier(IdentifierFactory.COLUMN, fmd.getName());
                int i=0;
                while (datastoreContainer.hasDatastoreField(identifier))
                {
                    identifier = idFactory.newIdentifier(IdentifierFactory.COLUMN, fmd.getName() + "_" + i);
                    i++;
                }
            }
            else if (roleForField == JavaTypeMapping.MAPPING_COLLECTION_ELEMENT)
            {
                // Join table collection element
                identifier = ((RDBMSIdentifierFactory)idFactory).newJoinTableFieldIdentifier(fmd, null, null, true, FieldRole.ROLE_COLLECTION_ELEMENT);
            }
            else if (roleForField == JavaTypeMapping.MAPPING_ARRAY_ELEMENT)
            {
                // Join table array element
                identifier = ((RDBMSIdentifierFactory)idFactory).newJoinTableFieldIdentifier(fmd, null, null, true, FieldRole.ROLE_ARRAY_ELEMENT);
            }
            else if (roleForField == JavaTypeMapping.MAPPING_MAP_KEY)
            {
                // Join table map key
                identifier = ((RDBMSIdentifierFactory)idFactory).newJoinTableFieldIdentifier(fmd, null, null, true, FieldRole.ROLE_MAP_KEY);
            }
            else if (roleForField == JavaTypeMapping.MAPPING_MAP_VALUE)
            {
                // Join table map value
                identifier = ((RDBMSIdentifierFactory)idFactory).newJoinTableFieldIdentifier(fmd, null, null, true, FieldRole.ROLE_MAP_VALUE);
            }

            colmd.setName(identifier.getIdentifier());
        }
        else
        {
            // User has specified a name, so try to keep this unmodified
            identifier = idFactory.newDatastoreFieldIdentifier(colmds[datastoreFieldIndex].getName(),
                datastoreContainer.getStoreManager().getOMFContext().getTypeManager().isDefaultEmbeddedType(fmd.getType()),
                FieldRole.ROLE_CUSTOM);
        }

        // Create the column
View Full Code Here

            // If column specified add one (use any column name specified on field element)
            colmd = new ColumnMetaData(fmd, fmd.getColumn());
            fmd.addColumn(colmd);
        }

        IdentifierFactory idFactory = datastoreContainer.getStoreManager().getIdentifierFactory();
        if (colmd.getName() == null)
        {
            // No name specified, so generate the identifier from the field name
            DatastoreIdentifier identifier = idFactory.newIdentifier(IdentifierFactory.COLUMN, fmd.getName());
            int i=0;
            while (datastoreContainer.hasDatastoreField(identifier))
            {
                identifier = idFactory.newIdentifier(IdentifierFactory.COLUMN, fmd.getName() + "_" + i);
                i++;
            }

            colmd.setName(identifier.getIdentifier());
            col = (Column) datastoreContainer.addDatastoreField(javaType, identifier, mapping, colmd);
        }
        else
        {
            // User has specified a name, so try to keep this unmodified
            col = (Column) datastoreContainer.addDatastoreField(javaType,
                idFactory.newDatastoreFieldIdentifier(colmd.getName(),
                    datastoreContainer.getStoreManager().getOMFContext().getTypeManager().isDefaultEmbeddedType(fmd.getType()),
                    FieldRole.ROLE_CUSTOM),
                mapping, colmd);
        }
View Full Code Here

                                               JavaTypeMapping mapping,
                                               ColumnMetaData colmd,
                                               DatastoreField reference,
                                               ClassLoaderResolver clr)
    {
        IdentifierFactory idFactory = datastoreContainer.getStoreManager().getIdentifierFactory();
        DatastoreIdentifier identifier = null;
        if (colmd.getName() == null)
        {
            // No name specified, so generate the identifier from the field name
            AbstractMemberMetaData[] relatedMmds = fmd.getRelatedMemberMetaData(clr);
            identifier = ((RDBMSIdentifierFactory)idFactory).newForeignKeyFieldIdentifier(
                relatedMmds != null ? relatedMmds[0] : null,
                fmd, reference.getIdentifier(),
                datastoreContainer.getStoreManager().getOMFContext().getTypeManager().isDefaultEmbeddedType(fmd.getType()),
                FieldRole.ROLE_OWNER);
            colmd.setName(identifier.getIdentifier());
        }
        else
        {
            // User has specified a name, so try to keep this unmodified
            identifier = idFactory.newDatastoreFieldIdentifier(colmd.getName(), false, FieldRole.ROLE_CUSTOM);
        }
        Column col = (Column)datastoreContainer.addDatastoreField(fmd.getType().getName(), identifier, mapping, colmd);

        // Copy the characteristics of the reference column to this one
        reference.copyConfigurationTo(col);
View Full Code Here

     **/
    public void initialize(ClassLoaderResolver clr)
    {
        assertIsUninitialized();

        IdentifierFactory idFactory = storeMgr.getIdentifierFactory();

        // "SEQUENCE_NAME" column
        sequenceNameMapping = dba.getMapping(String.class, storeMgr);
        Column colSequenceName=(Column) addDatastoreField(String.class.getName(),
            idFactory.newDatastoreFieldIdentifier(sequenceNameColumnName), sequenceNameMapping, null);
        colSequenceName.setAsPrimaryKey();
        colSequenceName.getColumnMetaData().setLength(Integer.valueOf("255"));
        colSequenceName.getColumnMetaData().setJdbcType("VARCHAR");
    getStoreManager().getMappingManager().createDatastoreMapping(sequenceNameMapping, storeMgr, colSequenceName,
            String.class.getName());

        // "NEXT_VAL" column
        nextValMapping = dba.getMapping(Long.class, storeMgr);
        DatastoreField colNextVal=addDatastoreField(Long.class.getName(),
            idFactory.newDatastoreFieldIdentifier(nextValColumnName), nextValMapping, null);
    getStoreManager().getMappingManager().createDatastoreMapping(nextValMapping, storeMgr, colNextVal, Long.class.getName());

        // Set up JDBC statements for supported operations
        insertStmt = "INSERT INTO " + identifier.getFullyQualifiedName(false) + " (" + colSequenceName.getIdentifier() + "," + colNextVal.getIdentifier() +
            ") VALUES (?,?)";
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.