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

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


            // @formatter:on
        }

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


            // @formatter:on
        }

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

            // @formatter:on
        }

        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

    @Override
    protected InsertStatement createInsertStatementWithAutoGeneratedIDForEntitiesTable(
        String schemaName, String tableName, SQLVendor vendor )
    {
        ModificationFactory m = vendor.getModificationFactory();
        LiteralFactory l = vendor.getLiteralFactory();
        TableReferenceFactory t = vendor.getTableReferenceFactory();
        ColumnsFactory c = vendor.getColumnsFactory();

        ColumnSourceByValuesBuilder columnBuilder = m.columnSourceByValues();
        columnBuilder.addValues( ValueSource.Default.INSTANCE );
        for( Integer x = 1; x < AMOUNT_OF_COLUMNS_IN_ENTITY_TABLE; ++x )
        {
            columnBuilder.addValues( l.param() );
        }

        return ( (PgSQLInsertStatementBuilder) m.insert() )
            .setReturningClause(
                vendor.getQueryFactory().columnsBuilder()
                .addUnnamedColumns( c.colName( DBNames.ENTITY_TABLE_PK_COLUMN_NAME ) )
                .createExpression()
            )
View Full Code Here

                    )
                    .createExpression()
                )
            );

            ModificationFactory m = vendor.getModificationFactory();

            PreparedStatement ps = connection.prepareStatement(
                vendor.toString(
                    m.insert()
                    .setTableName( t.tableName( schemaName, APP_VERSION_TABLE_NAME ) )
                    .setColumnSource(
                        m.columnSourceByValues()
                        .addValues( vendor.getLiteralFactory().param() )
                        .createExpression()
                    )
                    .createExpression()
                )
View Full Code Here

        throws SQLException
    {
        String schemaName = this._state.schemaName().get();

        SQLVendor vendor = this._vendor;
        ModificationFactory m = vendor.getModificationFactory();
        TableReferenceFactory t = vendor.getTableReferenceFactory();
        LiteralFactory l = vendor.getLiteralFactory();

        // @formatter:off
        PreparedStatement ps = connection.prepareStatement(
            vendor.toString(
                m.insert()
                .setTableName( t.tableName( schemaName, ENTITY_TYPES_TABLE_NAME ) )
                .setColumnSource( m.columnSourceByValues()
                    .addValues( l.param(), l.param() )
                    .createExpression()
                )
                .createExpression()
            )
        );

        try
        {
            Set<String> insertedTypeNames = new HashSet<>();
            for( EntityDescriptor descriptor : appInfo.entityDescriptors.values() )
            {
                for( Class<?> entityType : descriptor.types() )
                {
                    String entityTypeName = entityType.getName();
                    if( !insertedTypeNames.contains( entityTypeName ) )
                    {
                        long pk = tablePKs.get( ENTITY_TYPES_TABLE_NAME );
                        ps.setInt( 1, (int) pk );
                        ps.setString( 2, entityTypeName );
                        ps.executeUpdate();
                        this._state.entityTypePKs().get().put( entityTypeName, (int) pk );
//                      this._state.entityTypeInfos().get().put( entityTypeName, new EntityTypeInfo( descriptor, (int) pk ) );
                        tablePKs.put( ENTITY_TYPES_TABLE_NAME, pk + 1 );
                    }
                }
            }
        }
        finally
        {
            SQLUtil.closeQuietly( ps );
        }

        ps = connection.prepareStatement(
            vendor.toString(
                m.insert()
                .setTableName( t.tableName( schemaName, USED_CLASSES_TABLE_NAME ) )
                .setColumnSource( m.columnSourceByValues()
                    .addValues( l.param(), l.param() )
                    .createExpression()
                )
                .createExpression()
            )
        );

        try
        {
            for( CompositeDescriptorInfo descInfo : appInfo.usedValueComposites )
            {
                String vDescStr = compositeDescriptorToString( descInfo.layer, descInfo.module, descInfo.composite );
                long pk = tablePKs.get( USED_CLASSES_TABLE_NAME );
                ps.setInt( 1, (int) pk );
                ps.setString( 2, vDescStr );
                ps.executeUpdate();
                this._state.usedClassesPKs().get().put( descInfo.composite, (int) pk );
                tablePKs.put( USED_CLASSES_TABLE_NAME, pk + 1 );
            }
        }
        finally
        {
            SQLUtil.closeQuietly( ps );
        }

        ps = connection.prepareStatement(
            vendor.toString(
                m.insert()
                .setTableName( t.tableName( schemaName, ENUM_LOOKUP_TABLE_NAME ) )
                .setColumnSource( m.columnSourceByValues()
                    .addValues( l.param(), l.param() )
                    .createExpression()
                )
                .createExpression()
            )
View Full Code Here

    }

    private InsertStatement createInsertStatementForQNameInfo( Connection connection,
                                                               String schemaName, SQLVendor vendor )
    {
        ModificationFactory m = vendor.getModificationFactory();
        TableReferenceFactory t = vendor.getTableReferenceFactory();
        LiteralFactory l = vendor.getLiteralFactory();

        return m.insert()
            .setTableName( t.tableName( schemaName, USED_QNAMES_TABLE_NAME ) )
            .setColumnSource( m.columnSourceByValues()
                .addValues( l.param(), l.param() )
                .createExpression()
            ).createExpression();
    }
View Full Code Here

    }

    private static void clearSchema( Connection connection, String schemaName, SQLVendor vendor )
        throws SQLException
    {
        ModificationFactory m = vendor.getModificationFactory();
        Statement stmt = null;
        try
        {
            connection.setReadOnly( false );
            stmt = connection.createStatement();
            stmt.execute( m.deleteBySearch().setTargetTable( m.createTargetTable(
                vendor.getTableReferenceFactory().tableName( schemaName, DBNames.ENTITY_TABLE_NAME ) ) )
                .createExpression().toString()
            );
            connection.commit();
        }
View Full Code Here

    protected InsertStatement createInsertStatement( String schemaName, String tableName,
                                                     Integer amountOfColumns,
                                                     SQLVendor vendor
    )
    {
        ModificationFactory m = vendor.getModificationFactory();
        LiteralFactory l = vendor.getLiteralFactory();
        TableReferenceFactory t = vendor.getTableReferenceFactory();

        ColumnSourceByValuesBuilder columnBuilder = m.columnSourceByValues();
        for( Integer x = 0; x < amountOfColumns; ++x )
        {
            columnBuilder.addValues( l.param() );
        }

        return m.insert().setTableName( t.tableName( schemaName, tableName ) )
            .setColumnSource( columnBuilder.createExpression() ).createExpression();
    }
View Full Code Here

        throws SQLException;

    protected UpdateStatement
        createUpdateEntityTableStatement( String schemaName, SQLVendor vendor )
    {
        ModificationFactory m = vendor.getModificationFactory();
        BooleanFactory b = vendor.getBooleanFactory();
        LiteralFactory l = vendor.getLiteralFactory();
        ColumnsFactory c = vendor.getColumnsFactory();
        TableReferenceFactory t = vendor.getTableReferenceFactory();

        // "UPDATE " + "%s" + "." + ENTITY_TABLE_NAME + "\n" + //
        // "SET " + ENTITY_TABLE_IDENTITY_COLUMN_NAME + " = ?, " + //
        // ENTITY_TABLE_MODIFIED_COLUMN_NAME + " = ?, " + //
        // ENTITY_TABLE_VERSION_COLUMN_NAME + " = ?, " + //
        // ENTITY_TABLE_APPLICATION_VERSION_COLUMN_NAME + " = ?" + "\n" + //
        // "WHERE " + ENTITY_TABLE_PK_COLUMN_NAME + " = ?" + "\n" + //
        // ";" //
        UpdateSourceByExpression paramSource = m.updateSourceByExp( l.param() );
        UpdateBySearchBuilder builder = m.updateBySearch();
        builder
            .setTargetTable(
                m.createTargetTable( t.tableName( schemaName, DBNames.ENTITY_TABLE_NAME ) ) )
            .addSetClauses( m.setClause( DBNames.ENTITY_TABLE_IDENTITY_COLUMN_NAME, paramSource ),
                            m.setClause( DBNames.ENTITY_TABLE_MODIFIED_COLUMN_NAME, paramSource ),
                            m.setClause( DBNames.ENTITY_TABLE_VERSION_COLUMN_NAME, paramSource ),
                            m.setClause( DBNames.ENTITY_TABLE_APPLICATION_VERSION_COLUMN_NAME, paramSource ) )
            .getWhereBuilder()
            .reset( b.eq( c.colName( DBNames.ENTITY_TABLE_PK_COLUMN_NAME ), l.param() ) );

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

TOP

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

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.