Package org.sql.generation.api.grammar.factories

Examples of org.sql.generation.api.grammar.factories.LiteralFactory


        {
            QueryFactory q = vendor.getQueryFactory();
            TableReferenceFactory t = vendor.getTableReferenceFactory();
            BooleanFactory b = vendor.getBooleanFactory();
            ColumnsFactory c = vendor.getColumnsFactory();
            LiteralFactory l = vendor.getLiteralFactory();

            // @formatter:off
            return q.simpleQueryBuilder()
                .select( SQLs.ENTITY_PK_COLUMN_NAME, SQLs.ENTITY_OPTIMISTIC_LOCK_COLUMN_NAME, SQLs.ENTITY_STATE_COLUMN_NAME )
                .from( t.tableName( this.schemaName, SQLs.TABLE_NAME ) )
                .where( b.eq( c.colName( SQLs.ENTITY_IDENTITY_COLUMN_NAME ), l.param() ) )
                .createExpression();
            // @formatter:on
        }
View Full Code Here


        protected SQLStatement createInsertEntityStatement( SQLVendor vendor )
        {
            ModificationFactory m = vendor.getModificationFactory();
            TableReferenceFactory t = vendor.getTableReferenceFactory();
            LiteralFactory l = vendor.getLiteralFactory();

            // @formatter:off
            return m.insert()
                .setTableName( t.tableName( this.schemaName, SQLs.TABLE_NAME ) )
                .setColumnSource( m.columnSourceByValues()
                    .addColumnNames(
                        SQLs.ENTITY_OPTIMISTIC_LOCK_COLUMN_NAME,
                        SQLs.ENTITY_IDENTITY_COLUMN_NAME,
                        SQLs.ENTITY_STATE_COLUMN_NAME,
                        SQLs.ENTITY_LAST_MODIFIED_COLUMN_NAME
                        )
                    .addValues(
                        l.n( 0 ),
                        l.param(),
                        l.param(),
                        l.param()
                        )
                    .createExpression()
                    )
                 .createExpression();
            // @formatter:on
View Full Code Here

        protected SQLStatement createUpdateEntityStatement( SQLVendor vendor )
        {
            ModificationFactory m = vendor.getModificationFactory();
            TableReferenceFactory t = vendor.getTableReferenceFactory();
            LiteralFactory l = vendor.getLiteralFactory();
            BooleanFactory b = vendor.getBooleanFactory();
            ColumnsFactory c = vendor.getColumnsFactory();

            // @formatter:off
            UpdateBySearchBuilder builder = m.updateBySearch()
                .setTargetTable( m.createTargetTable( t.tableName( this.schemaName, SQLs.TABLE_NAME ) ) )
                .addSetClauses(
                    m.setClause( SQLs.ENTITY_OPTIMISTIC_LOCK_COLUMN_NAME, m.updateSourceByExp( l.param() ) ),
                    m.setClause( SQLs.ENTITY_STATE_COLUMN_NAME, m.updateSourceByExp( l.param() ) ),
                    m.setClause( SQLs.ENTITY_LAST_MODIFIED_COLUMN_NAME, m.updateSourceByExp( l.param() ) )
                    );
            builder
                .getWhereBuilder()
                    .reset( b.eq( c.colName( SQLs.ENTITY_PK_COLUMN_NAME ), l.param() ) )
                    .and( b.eq( c.colName( SQLs.ENTITY_OPTIMISTIC_LOCK_COLUMN_NAME ), l.param() ) );
            return builder.createExpression();
            // @formatter:on
        }
View Full Code Here

        protected SQLStatement createRemoveEntityStatement( SQLVendor vendor )
        {
            ModificationFactory m = vendor.getModificationFactory();
            TableReferenceFactory t = vendor.getTableReferenceFactory();
            LiteralFactory l = vendor.getLiteralFactory();
            BooleanFactory b = vendor.getBooleanFactory();
            ColumnsFactory c = vendor.getColumnsFactory();

            // @formatter:off
            DeleteBySearchBuilder builder = m.deleteBySearch()
                .setTargetTable( m.createTargetTable( t.tableName( this.schemaName, SQLs.TABLE_NAME ) ) );
            builder.getWhere()
                .reset( b.eq( c.colName( SQLs.ENTITY_PK_COLUMN_NAME ), l.param() ) );
            return builder.createExpression();
            // @formatter:on
        }
View Full Code Here

    {
        SQLVendor vendor = this.descriptor.metaInfo( SQLVendor.class );

        QueryFactory q = vendor.getQueryFactory();
        TableReferenceFactory t = vendor.getTableReferenceFactory();
        LiteralFactory l = vendor.getLiteralFactory();
        ColumnsFactory c = vendor.getColumnsFactory();

        ColumnReference mainColumn = c.colName( TABLE_NAME_PREFIX + "0", DBNames.ENTITY_TABLE_IDENTITY_COLUMN_NAME );
        if( countOnly )
        {
            mainColumn = c.colExp( l.func( SQLFunctions.COUNT, mainColumn ) );
        }

        QueryBuilder innerBuilder = this.processBooleanExpression(
            whereClause, false, vendor,
            this.createTypeCondition( resultType, vendor ), variables, values, valueSQLTypes );
View Full Code Here

    protected org.sql.generation.api.grammar.booleans.BooleanExpression createTypeCondition(
        Class<?> resultType,
        SQLVendor vendor )
    {
        BooleanFactory b = vendor.getBooleanFactory();
        LiteralFactory l = vendor.getLiteralFactory();
        ColumnsFactory c = vendor.getColumnsFactory();

        List<Integer> typeIDs = this.getEntityTypeIDs( resultType );
        InBuilder in = b.inBuilder( c.colName( TABLE_NAME_PREFIX + TYPE_TABLE_SUFFIX,
                                               DBNames.ENTITY_TYPES_TABLE_PK_COLUMN_NAME ) );
        for( Integer i : typeIDs )
        {
            in.addValues( l.n( i ) );
        }

        return in.createExpression();
    }
View Full Code Here

            @Override
            public void processWhereClause( QuerySpecificationBuilder builder,
                                            BooleanBuilder afterWhere,
                                            JoinType joinStyle, Integer firstTableIndex, Integer lastTableIndex )
            {
                LiteralFactory l = vendor.getLiteralFactory();
                ColumnsFactory c = vendor.getColumnsFactory();

                builder.getWhere().reset(
                    vendor.getBooleanFactory().regexp(
                        c.colName( TABLE_NAME_PREFIX + lastTableIndex,
                                   DBNames.QNAME_TABLE_VALUE_COLUMN_NAME ),
                        l.param() ) );

                Object value = predicate.value();
                if( value instanceof Variable )
                {
                    value = variables.get( ( (Variable) value ).variableName() );
View Full Code Here

            @Override
            public void processWhereClause( QuerySpecificationBuilder builder,
                                            BooleanBuilder afterWhere,
                                            JoinType joinStyle, Integer firstTableIndex, Integer lastTableIndex )
            {
                LiteralFactory l = vendor.getLiteralFactory();
                ColumnsFactory c = vendor.getColumnsFactory();
                BooleanFactory b = vendor.getBooleanFactory();

                builder.getWhere().reset(
                    getOperator( predicate ).getExpression(
                        b,
                        c.colName( TABLE_NAME_PREFIX + lastTableIndex,
                                   DBNames.ENTITY_TABLE_IDENTITY_COLUMN_NAME ),
                        l.param() ) );

                Object value = predicate.value();
                // TODO Is it really certain that this value is always instance of
                // EntityComposite?
                if( value instanceof EntityComposite )
View Full Code Here

            public void processWhereClause( QuerySpecificationBuilder builder,
                                            BooleanBuilder afterWhere,
                                            JoinType joinStyle, Integer firstTableIndex, Integer lastTableIndex )
            {
                BooleanFactory b = vendor.getBooleanFactory();
                LiteralFactory l = vendor.getLiteralFactory();
                ColumnsFactory c = vendor.getColumnsFactory();

                builder.getWhere().reset(
                    b.regexp( c.colName( TABLE_NAME_PREFIX + lastTableIndex,
                                         DBNames.QNAME_TABLE_COLLECTION_PATH_COLUMN_NAME ), l
                        .s( DBNames.QNAME_TABLE_COLLECTION_PATH_TOP_LEVEL_NAME + ".*{1,}" ) ) );

                Object value = predicate.value();
                if( value instanceof Collection<?> )
                {
View Full Code Here

            public void processWhereClause( QuerySpecificationBuilder builder,
                                            BooleanBuilder afterWhere,
                                            JoinType joinStyle, Integer firstTableIndex, Integer lastTableIndex )
            {
                BooleanFactory b = vendor.getBooleanFactory();
                LiteralFactory l = vendor.getLiteralFactory();
                ColumnsFactory c = vendor.getColumnsFactory();

                Iterable<?> collection = predicate.containedValues();
                List<QNameJoin> joins = new ArrayList<>();
                for( Object value : collection )
                {
                    if( value instanceof Collection<?> )
                    {
                        throw new IllegalArgumentException(
                            "ContainsAllPredicate may not have nested collections as value." );
                    }

                    BooleanBuilder conditionForItem = b.booleanBuilder(
                        b.regexp( c.colName( TABLE_NAME_PREFIX + lastTableIndex,
                                             DBNames.QNAME_TABLE_COLLECTION_PATH_COLUMN_NAME ),
                                  l.s( DBNames.QNAME_TABLE_COLLECTION_PATH_TOP_LEVEL_NAME + ".*{1,}" ) ) );
                    modifyFromClauseAndWhereClauseToGetValue(
                        QualifiedName.fromAccessor( predicate.collectionProperty().accessor() ),
                        value, predicate, false, lastTableIndex,
                        new ModifiableInt( lastTableIndex ),
                        DBNames.QNAME_TABLE_VALUE_COLUMN_NAME,
                        DBNames.QNAME_TABLE_COLLECTION_PATH_TOP_LEVEL_NAME, vendor,
                        conditionForItem, afterWhere,
                        builder.getFrom().getTableReferences().iterator().next(),
                        builder.getGroupBy(), builder.getHaving(),
                        joins, variables, values, valueSQLTypes );
                    builder.getWhere().or( conditionForItem.createExpression() );

                }

                builder.getHaving()
                    .and(
                        b.geq(
                            l.func( "COUNT", c.colName( TABLE_NAME_PREFIX + lastTableIndex,
                                                        DBNames.QNAME_TABLE_VALUE_COLUMN_NAME ) ),
                            l.n( Iterables.count( collection ) ) ) );
            }

            } //
        );

View Full Code Here

TOP

Related Classes of org.sql.generation.api.grammar.factories.LiteralFactory

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.