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

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


        }

        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,
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() ) )
                    );
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

    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()
            )
            .setTableName( t.tableName( schemaName, tableName ) )
            .setColumnSource( columnBuilder.createExpression() )
            .createExpression();
    }
View Full Code Here

            SQLUtil.closeQuietly( rs );
        }

        SQLVendor vendor = this._vendor;
        DefinitionFactory d = vendor.getDefinitionFactory();
        TableReferenceFactory t = vendor.getTableReferenceFactory();

        Statement stmt = connection.createStatement();

        // @formatter:off
        try
        {
            if( !schemaFound )
            {
                stmt.execute(
                    vendor.toString(
                        d
                        .createSchemaDefinitionBuilder()
                        .setSchemaName( schemaName )
                        .createExpression()
                    )
                );
                LOGGER.debug( "Database schema created" );
            }

            this.testRequiredCapabilities( connection );
            LOGGER.debug( "Underlying database fullfill required capabilities" );

            stmt.execute(
                vendor.toString(
                    d.createTableDefinitionBuilder()
                    .setTableName( t.tableName( schemaName, USED_CLASSES_TABLE_NAME ) )
                    .setTableContentsSource(
                        d.createTableElementListBuilder()
                        .addTableElement( d.createColumnDefinition( USED_CLASSES_TABLE_PK_COLUMN_NAME, this._primitiveTypes
                                .get( Integer.class ), false ) )
                        .addTableElement( d.createColumnDefinition( USED_CLASSES_TABLE_CLASS_NAME_COLUMN_NAME, this._primitiveTypes
                                .get( String.class ), false ) )
                        .addTableElement( d.createTableConstraintDefinition( d.createUniqueConstraintBuilder()
                                .setUniqueness( UniqueSpecification.PRIMARY_KEY )
                                .addColumns( USED_CLASSES_TABLE_PK_COLUMN_NAME )
                                .createExpression()
                            ) )
                        .addTableElement( d.createTableConstraintDefinition( d.createUniqueConstraintBuilder()
                                .setUniqueness( UniqueSpecification.UNIQUE )
                                .addColumns( USED_CLASSES_TABLE_CLASS_NAME_COLUMN_NAME )
                                .createExpression()
                            ) )
                        .createExpression()
                    )
                    .createExpression()
                )
            );

            tablePKs.put( USED_CLASSES_TABLE_NAME, 0L );

            stmt.execute(
                vendor.toString(
                    d.createTableDefinitionBuilder()
                    .setTableName( t.tableName( schemaName, ENTITY_TYPES_TABLE_NAME ) )
                    .setTableContentsSource(
                        d.createTableElementListBuilder()
                        .addTableElement( d.createColumnDefinition( ENTITY_TYPES_TABLE_PK_COLUMN_NAME, this._primitiveTypes
                                .get( ENTITY_TYPE_PK_TYPE ), false ) )
                        .addTableElement( d.createColumnDefinition( ENTITY_TYPES_TABLE_TYPE_NAME_COLUMN_NAME, this._primitiveTypes
                                .get( String.class ), false ) )
                        .addTableElement( d.createTableConstraintDefinition( d.createUniqueConstraintBuilder()
                                .setUniqueness( UniqueSpecification.PRIMARY_KEY )
                                .addColumns( ENTITY_TYPES_TABLE_PK_COLUMN_NAME )
                                .createExpression()
                            ) )
                        .addTableElement( d.createTableConstraintDefinition( d.createUniqueConstraintBuilder()
                                .setUniqueness( UniqueSpecification.UNIQUE )
                                .addColumns( ENTITY_TYPES_TABLE_TYPE_NAME_COLUMN_NAME )
                                .createExpression()
                            ) )
                        .createExpression()
                    )
                    .createExpression()
                )
            );

            tablePKs.put( ENTITY_TYPES_TABLE_NAME, 0L );

            stmt.execute(
                vendor.toString(
                    d.createTableDefinitionBuilder()
                    .setTableName( t.tableName( schemaName, ENTITY_TABLE_NAME ) )
                    .setTableContentsSource(
                        d.createTableElementListBuilder()
                        .addTableElement( d.createColumnDefinition( ENTITY_TABLE_PK_COLUMN_NAME, this._primitiveTypes
                                .get( ENTITY_PK_TYPE ), false, AutoGenerationPolicy.BY_DEFAULT ) )
                        .addTableElement( d.createColumnDefinition( ENTITY_TABLE_IDENTITY_COLUMN_NAME, this._primitiveTypes
                                .get( String.class ), false ) )
                        .addTableElement( d.createColumnDefinition( ENTITY_TABLE_MODIFIED_COLUMN_NAME, this._primitiveTypes
                                .get( Date.class ), false ) )
                        .addTableElement( d.createColumnDefinition( ENTITY_TABLE_VERSION_COLUMN_NAME, this._primitiveTypes
                                .get( String.class ), false ) )
                        .addTableElement( d.createColumnDefinition( ENTITY_TABLE_APPLICATION_VERSION_COLUMN_NAME, this._primitiveTypes
                                .get( String.class ), false ) )
                        .addTableElement( d.createTableConstraintDefinition( d.createUniqueConstraintBuilder()
                                .setUniqueness( UniqueSpecification.PRIMARY_KEY )
                                .addColumns( ENTITY_TABLE_PK_COLUMN_NAME )
                                .createExpression()
                            ) )
                        .addTableElement( d.createTableConstraintDefinition( d.createUniqueConstraintBuilder()
                                .setUniqueness( UniqueSpecification.UNIQUE )
                                .addColumns( ENTITY_TABLE_IDENTITY_COLUMN_NAME )
                                .createExpression()
                            ) )
                        .createExpression()
                    )
                    .createExpression()
                )
            );
            tablePKs.put( ENTITY_TABLE_NAME, 0L );

            stmt.execute(
                d.createTableDefinitionBuilder()
                .setTableName( t.tableName( schemaName, ENTITY_TYPES_JOIN_TABLE_NAME ) )
                .setTableContentsSource(
                    d.createTableElementListBuilder()
                    .addTableElement( d.createColumnDefinition( ENTITY_TABLE_PK_COLUMN_NAME, this._primitiveTypes
                            .get( ENTITY_PK_TYPE ), false ) )
                    .addTableElement( d.createColumnDefinition( ENTITY_TYPES_TABLE_PK_COLUMN_NAME, this._primitiveTypes
                            .get( ENTITY_TYPE_PK_TYPE ), false ) )
                    .addTableElement( d.createTableConstraintDefinition( d.createUniqueConstraintBuilder()
                            .setUniqueness( UniqueSpecification.PRIMARY_KEY )
                            .addColumns( ENTITY_TABLE_PK_COLUMN_NAME, ENTITY_TYPES_TABLE_PK_COLUMN_NAME )
                            .createExpression()
                        ) )
                    .addTableElement( d.createTableConstraintDefinition( d.createForeignKeyConstraintBuilder()
                            .addSourceColumns( ENTITY_TABLE_PK_COLUMN_NAME )
                            .setTargetTableName( t.tableName( schemaName, ENTITY_TABLE_NAME ) )
                            .addTargetColumns( ENTITY_TABLE_PK_COLUMN_NAME )
                            .setOnDelete( ReferentialAction.CASCADE )
                            .setOnUpdate( ReferentialAction.CASCADE )
                            .createExpression(), ConstraintCharacteristics.INITIALLY_DEFERRED_DEFERRABLE
                        ) )
                    .addTableElement( d.createTableConstraintDefinition( d.createForeignKeyConstraintBuilder()
                            .addSourceColumns( ENTITY_TYPES_TABLE_PK_COLUMN_NAME )
                            .setTargetTableName( t.tableName( schemaName, ENTITY_TYPES_TABLE_NAME ) )
                            .addTargetColumns( ENTITY_TYPES_TABLE_PK_COLUMN_NAME )
                            .setOnDelete( ReferentialAction.RESTRICT )
                            .setOnDelete( ReferentialAction.CASCADE )
                            .createExpression(), ConstraintCharacteristics.NOT_DEFERRABLE ) )
                    .createExpression()
                ).createExpression()
                .toString()
            );

            stmt.execute(
                vendor.toString(
                    d.createTableDefinitionBuilder()
                    .setTableName( t.tableName( schemaName, ENUM_LOOKUP_TABLE_NAME ) )
                    .setTableContentsSource(
                        d.createTableElementListBuilder()
                        .addTableElement( d.createColumnDefinition( ENUM_LOOKUP_TABLE_PK_COLUMN_NAME, this._primitiveTypes
                                .get( Integer.class ), false ) )
                        .addTableElement( d.createColumnDefinition( ENUM_LOOKUP_TABLE_ENUM_VALUE_NAME, this._primitiveTypes
                                .get( String.class ), false ) )
                        .addTableElement( d.createTableConstraintDefinition( d.createUniqueConstraintBuilder()
                                .setUniqueness( UniqueSpecification.PRIMARY_KEY )
                                .addColumns( ENUM_LOOKUP_TABLE_PK_COLUMN_NAME )
                                .createExpression()
                            ) )
                        .createExpression()
                    )
                    .createExpression()
                )
            );

            tablePKs.put( ENUM_LOOKUP_TABLE_NAME, 0L );

            stmt.execute(
                vendor.toString(
                    d.createTableDefinitionBuilder()
                    .setTableName( t.tableName( schemaName, USED_QNAMES_TABLE_NAME ) )
                    .setTableContentsSource(
                        d.createTableElementListBuilder()
                        .addTableElement( d.createColumnDefinition( USED_QNAMES_TABLE_QNAME_COLUMN_NAME, this._primitiveTypes
                                .get( String.class ), false ) )
                        .addTableElement( d.createColumnDefinition( USED_QNAMES_TABLE_TABLE_NAME_COLUMN_NAME, this._primitiveTypes
                                .get( String.class ), false ) )
                        .addTableElement( d.createTableConstraintDefinition( d.createUniqueConstraintBuilder()
                                .setUniqueness( UniqueSpecification.PRIMARY_KEY )
                                .addColumns( USED_QNAMES_TABLE_QNAME_COLUMN_NAME, USED_QNAMES_TABLE_TABLE_NAME_COLUMN_NAME )
                                .createExpression()
                            ) )
                        .createExpression()
                    )
                    .createExpression()
                )
            );

            stmt.execute(
                vendor.toString(
                    d.createTableDefinitionBuilder()
                    .setTableName( t.tableName( schemaName, ALL_QNAMES_TABLE_NAME ) )
                    .setTableContentsSource(
                        d.createTableElementListBuilder()
                        .addTableElement( d.createColumnDefinition( ALL_QNAMES_TABLE_PK_COLUMN_NAME, this._primitiveTypes
                                .get( Integer.class ), false ) )
                        .addTableElement( d.createColumnDefinition( ENTITY_TABLE_PK_COLUMN_NAME, this._primitiveTypes
                                .get( ENTITY_PK_TYPE ), false ) )
                        .addTableElement( d.createTableConstraintDefinition( d.createUniqueConstraintBuilder()
                                .setUniqueness( UniqueSpecification.PRIMARY_KEY )
                                .addColumns( ALL_QNAMES_TABLE_PK_COLUMN_NAME, ENTITY_TABLE_PK_COLUMN_NAME )
                                .createExpression()
                            ) )
                        .addTableElement( d.createTableConstraintDefinition( d.createForeignKeyConstraintBuilder()
                                .addSourceColumns( ENTITY_TABLE_PK_COLUMN_NAME )
                                .setTargetTableName( t.tableName( schemaName, ENTITY_TABLE_NAME ) )
                                .addTargetColumns( ENTITY_TABLE_PK_COLUMN_NAME )
                                .setOnUpdate( ReferentialAction.CASCADE )
                                .setOnDelete( ReferentialAction.CASCADE )
                                .createExpression(), ConstraintCharacteristics.INITIALLY_DEFERRED_DEFERRABLE
                            ) )
                        .createExpression()
                    )
                    .createExpression()
                )
            );

            tablePKs.put( ALL_QNAMES_TABLE_NAME, 0L );

            stmt.execute(
                vendor.toString(
                    d.createTableDefinitionBuilder()
                    .setTableName( t.tableName( schemaName, APP_VERSION_TABLE_NAME ) )
                    .setTableContentsSource(
                        d.createTableElementListBuilder()
                        .addTableElement( d.createColumnDefinition( APP_VERSION_PK_COLUMN_NAME, this._primitiveTypes
                                .get( String.class ), false ) )
                        .addTableElement( d.createTableConstraintDefinition( d.createUniqueConstraintBuilder()
                                .setUniqueness( UniqueSpecification.PRIMARY_KEY )
                                .addColumns( APP_VERSION_PK_COLUMN_NAME )
                                .createExpression()
                            ) )
                        .createExpression()
                    )
                    .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()
                    )
View Full Code Here

        String schemaName = this._state.schemaName().get();
        Statement stmt = connection.createStatement();

        SQLVendor vendor = this._vendor;
        QueryFactory q = vendor.getQueryFactory();
        TableReferenceFactory t = vendor.getTableReferenceFactory();

        try
        {
            // @formatter:off

            q.simpleQueryBuilder()
                .select( ENTITY_TYPES_TABLE_PK_COLUMN_NAME, ENTITY_TYPES_TABLE_TYPE_NAME_COLUMN_NAME )
                .from( t.tableName( schemaName, ENTITY_TYPES_TABLE_NAME ) )
                .createExpression();

            ResultSet rs = stmt.executeQuery(
                vendor.toString(
                    q.simpleQueryBuilder()
                    .select( ENTITY_TYPES_TABLE_PK_COLUMN_NAME, ENTITY_TYPES_TABLE_TYPE_NAME_COLUMN_NAME )
                    .from( t.tableName( schemaName, ENTITY_TYPES_TABLE_NAME ) )
                    .createExpression()
                )
            );

            long pk;
            try
            {
                while( rs.next() )
                {
                    pk = rs.getInt( 1 );
                    String entityTypeName = rs.getString( 2 );
                    this._state.entityTypePKs().get().put( entityTypeName, (int) pk );
//                    this._state.entityTypeInfos().get()
//                        .put( entityTypeName, new EntityTypeInfo( entityDescriptors.get( entityTypeName ), (int) pk ) );
                }
            }
            finally
            {
                SQLUtil.closeQuietly( rs );
            }
            rs = stmt.executeQuery(
                vendor.toString(
                    q.simpleQueryBuilder()
                    .select( USED_CLASSES_TABLE_PK_COLUMN_NAME, USED_CLASSES_TABLE_CLASS_NAME_COLUMN_NAME )
                    .from( t.tableName( schemaName, USED_CLASSES_TABLE_NAME ) )
                    .createExpression()
                )
            );

            try
            {
                while( rs.next() )
                {
                    pk = rs.getInt( 1 );
                    String descriptorTextualFormat = rs.getString( 2 );
                    this._state.usedClassesPKs().get().put(
                        stringToCompositeDescriptor( ValueDescriptor.class,
                                                     this._app.descriptor(),
                                                     descriptorTextualFormat ),
                        (int) pk );
                }
            }
            finally
            {
                SQLUtil.closeQuietly( rs );
            }

            rs = stmt.executeQuery(
                vendor.toString(
                    q.simpleQueryBuilder()
                    .select( ENUM_LOOKUP_TABLE_PK_COLUMN_NAME, ENUM_LOOKUP_TABLE_ENUM_VALUE_NAME )
                    .from( t.tableName( schemaName, ENUM_LOOKUP_TABLE_NAME ) )
                    .createExpression()
                )
            );

            try
            {
                while( rs.next() )
                {
                    pk = rs.getInt( 1 );
                    String enumName = rs.getString( 2 );
                    this._state.enumPKs().get().put( enumName, (int) pk );
                }
            }
            finally
            {
                SQLUtil.closeQuietly( rs );
            }

            rs = stmt.executeQuery(
                q.simpleQueryBuilder()
                .select( USED_QNAMES_TABLE_QNAME_COLUMN_NAME, USED_QNAMES_TABLE_TABLE_NAME_COLUMN_NAME )
                .from( t.tableName( schemaName, USED_QNAMES_TABLE_NAME ) )
                .createExpression()
                .toString()
            );
            try
            {
View Full Code Here

    {
        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()
            )
        );

        try
        {
            for( String enumValue : appInfo.enumValues )
            {
                long pk = tablePKs.get( ENUM_LOOKUP_TABLE_NAME );
                ps.setInt( 1, (int) pk );
                ps.setString( 2, enumValue );
                ps.executeUpdate();
                this._state.enumPKs().get().put( enumValue, (int) pk );
                tablePKs.put( ENUM_LOOKUP_TABLE_NAME, pk + 1 );
            }
        }
        finally
        {
            SQLUtil.closeQuietly( ps );
        }

        Statement stmt = connection.createStatement();
        ps = connection.prepareStatement(
            this.createInsertStatementForQNameInfo( connection, schemaName, vendor ).toString()
        );

        try
        {
            DefinitionFactory d = vendor.getDefinitionFactory();

            for( QNameInfo qNameInfo : this._state.qNameInfos().get().values() )
            {
                QNameType type = qNameInfo.getQNameType();

                TableElementListBuilder builder = d.createTableElementListBuilder();
                builder
                    .addTableElement( d.createColumnDefinition( ALL_QNAMES_TABLE_PK_COLUMN_NAME, this._primitiveTypes
                            .get( Integer.class ), false ) )
                    .addTableElement( d.createColumnDefinition( ENTITY_TABLE_PK_COLUMN_NAME, this._primitiveTypes
                            .get( ENTITY_PK_TYPE ), false ) );

                if( type.equals( QNameType.PROPERTY ) )
                {
                    builder.addTableElement( d.createColumnDefinition( QNAME_TABLE_PARENT_QNAME_COLUMN_NAME, this._primitiveTypes
                        .get( Integer.class ), true ) );

                    if( qNameInfo.getCollectionDepth() > 0 )
                    {
                        builder.addTableElement( d.createColumnDefinition( QNAME_TABLE_COLLECTION_PATH_COLUMN_NAME, this
                            .getCollectionPathDataType(), false ) );
                    }

                    this.appendColumnDefinitionsForProperty( builder, qNameInfo );

                    builder.addTableElement( d.createTableConstraintDefinition( d.createForeignKeyConstraintBuilder()
                        .addSourceColumns( QNAME_TABLE_PARENT_QNAME_COLUMN_NAME, ENTITY_TABLE_PK_COLUMN_NAME )
                        .setTargetTableName( t.tableName( schemaName, ALL_QNAMES_TABLE_NAME ) )
                        .addTargetColumns( ALL_QNAMES_TABLE_PK_COLUMN_NAME, ENTITY_TABLE_PK_COLUMN_NAME )
                        .setOnUpdate( ReferentialAction.CASCADE )
                        .setOnDelete( ReferentialAction.CASCADE )
                        .createExpression(), ConstraintCharacteristics.INITIALLY_DEFERRED_DEFERRABLE
                    ) );
                }
                else
                {
                    if( type.equals( QNameType.ASSOCIATION ) )
                    {
                        builder
                            .addTableElement( d.createColumnDefinition( QNAME_TABLE_VALUE_COLUMN_NAME, this._primitiveTypes
                                    .get( ENTITY_PK_TYPE ), false ) )
                            .addTableElement( d.createTableConstraintDefinition( d.createUniqueConstraintBuilder()
                                    .setUniqueness( UniqueSpecification.PRIMARY_KEY )
                                    .addColumns( ALL_QNAMES_TABLE_PK_COLUMN_NAME, ENTITY_TABLE_PK_COLUMN_NAME )
                                    .createExpression()
                                ) );
                    }
                    else if( type.equals( QNameType.MANY_ASSOCIATION ) )
                    {
                        builder
                            .addTableElement( d.createColumnDefinition( QNAME_TABLE_ASSOCIATION_INDEX_COLUMN_NAME, this._primitiveTypes
                                    .get( Integer.class ), false ) )
                            .addTableElement( d.createColumnDefinition( QNAME_TABLE_VALUE_COLUMN_NAME, this._primitiveTypes
                                    .get( ENTITY_PK_TYPE ), false ) )
                            .addTableElement( d.createTableConstraintDefinition( d.createUniqueConstraintBuilder()
                                    .setUniqueness( UniqueSpecification.PRIMARY_KEY )
                                    .addColumns( ALL_QNAMES_TABLE_PK_COLUMN_NAME, ENTITY_TABLE_PK_COLUMN_NAME )
                                    .createExpression()
                                ) );
                    }
                    else
                    {
                        throw new IllegalArgumentException( "Did not how to create table for qName type: " + type + "." );
                    }

                    builder
                        .addTableElement( d.createTableConstraintDefinition( d.createForeignKeyConstraintBuilder()
                                .addSourceColumns( QNAME_TABLE_VALUE_COLUMN_NAME )
                                .setTargetTableName( t.tableName( schemaName, ENTITY_TABLE_NAME ) )
                                .addTargetColumns( ENTITY_TABLE_PK_COLUMN_NAME )
                                .setOnUpdate( ReferentialAction.CASCADE )
                                .setOnDelete( ReferentialAction.CASCADE )
                                .createExpression(), ConstraintCharacteristics.INITIALLY_DEFERRED_DEFERRABLE
                            )
                        );

                    tablePKs.put( qNameInfo.getTableName(), 0L );
                }

                builder
                    .addTableElement(
                        d.createTableConstraintDefinition( d.createForeignKeyConstraintBuilder()
                            .addSourceColumns( ALL_QNAMES_TABLE_PK_COLUMN_NAME, ENTITY_TABLE_PK_COLUMN_NAME )
                            .setTargetTableName( t.tableName( schemaName, ALL_QNAMES_TABLE_NAME ) )
                            .addTargetColumns( ALL_QNAMES_TABLE_PK_COLUMN_NAME, ENTITY_TABLE_PK_COLUMN_NAME )
                            .setOnUpdate( ReferentialAction.CASCADE )
                            .setOnDelete( ReferentialAction.CASCADE )
                            .createExpression(), ConstraintCharacteristics.INITIALLY_DEFERRED_DEFERRABLE
                        )
                    );

                stmt.execute( this._vendor.toString( d.createTableDefinitionBuilder()
                    .setTableName( t.tableName( schemaName, qNameInfo.getTableName() ) )
                    .setTableContentsSource( builder.createExpression() )
                    .createExpression()
                ) );

                //                stmt.execute( "COMMENT ON TABLE " + schemaName + "." + qNameInfo.getTableName() + " IS '"
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

            valueRefTablePKColumnName = USED_CLASSES_TABLE_PK_COLUMN_NAME;
        }

        SQLVendor vendor = this._vendor;
        DefinitionFactory d = vendor.getDefinitionFactory();
        TableReferenceFactory t = vendor.getTableReferenceFactory();

        builder
            .addTableElement(
                d.createColumnDefinition( QNAME_TABLE_VALUE_COLUMN_NAME, sqlType,
                                          qNameInfo.getCollectionDepth() > 0 ) )
            .addTableElement( d.createTableConstraintDefinition( d.createUniqueConstraintBuilder()
                    .setUniqueness( UniqueSpecification.PRIMARY_KEY )
                    .addColumns( ALL_QNAMES_TABLE_PK_COLUMN_NAME, ENTITY_TABLE_PK_COLUMN_NAME )
                    .createExpression()
                ) );

        if( valueRefTableName != null && valueRefTablePKColumnName != null )
        {
            builder
                .addTableElement( d.createTableConstraintDefinition( d
                        .createForeignKeyConstraintBuilder()
                        .addSourceColumns( QNAME_TABLE_VALUE_COLUMN_NAME )
                        .setTargetTableName( t.tableName( this._state
                                .schemaName()
                                .get(), valueRefTableName ) )
                        .addTargetColumns( valueRefTablePKColumnName )
                        .setOnUpdate( ReferentialAction.CASCADE )
                        .setOnDelete( ReferentialAction.RESTRICT )
View Full Code Here

                                                     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

TOP

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

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.