Package net.sourceforge.jpaxjc.ns.persistence.orm

Examples of net.sourceforge.jpaxjc.ns.persistence.orm.Column


                }

                attributes.getId().add( id );
                mapped = true;

                final Column defaultColumn =
                    this.applySchemaDefaults( f.getPropertyInfo().getSchemaComponent(), id.getColumn() );

                id.setColumn( defaultColumn );

                if ( !pc.isAcknowledged() )
                {
                    pc.markAsAcknowledged();
                }
            }

            if ( f.getPropertyInfo().getCustomizations().find( ORM_NS, "basic" ) != null )
            {
                final CPluginCustomization pc = f.getPropertyInfo().getCustomizations().find( ORM_NS, "basic" );
                final Basic basic = JAXB.unmarshal( new DOMSource( pc.element ), Basic.class );

                if ( basic.getName() == null )
                {
                    basic.setName( f.getPropertyInfo().getName( false ) );
                }

                attributes.getBasic().add( basic );
                mapped = true;

                if ( !pc.isAcknowledged() )
                {
                    pc.markAsAcknowledged();
                }

                final Column defaultColumn =
                    this.applySchemaDefaults( f.getPropertyInfo().getSchemaComponent(), basic.getColumn() );

                basic.setColumn( defaultColumn );
            }

            if ( f.getPropertyInfo().getCustomizations().find( ORM_NS, "version" ) != null )
            {
                final CPluginCustomization pc = f.getPropertyInfo().getCustomizations().find( ORM_NS, "version" );
                final Version version = JAXB.unmarshal( new DOMSource( pc.element ), Version.class );

                if ( version.getName() == null )
                {
                    version.setName( f.getPropertyInfo().getName( false ) );
                }

                attributes.getVersion().add( version );
                mapped = true;

                if ( !pc.isAcknowledged() )
                {
                    pc.markAsAcknowledged();
                }

                final Column defaultColumn =
                    this.applySchemaDefaults( f.getPropertyInfo().getSchemaComponent(), version.getColumn() );

                version.setColumn( defaultColumn );
            }
View Full Code Here


                    {
                        final OneToOne o = new OneToOne();
                        o.setName( f.getPropertyInfo().getName( false ) );
                        a.getOneToOne().add( o );

                        final Column col = this.toColumn( f.getPropertyInfo().getSchemaComponent() );
                        o.setOptional( col != null && col.isNullable() );

                        mapped = true;
                    }
                }
            }
View Full Code Here

                    }
                    else
                    {
                        final Id id = new Id();
                        final GeneratedValue gv = new GeneratedValue();
                        final Column col = new Column();
                        a.getId().add( id );

                        gv.setStrategy( GenerationType.AUTO );
                        col.setScale( 0 );
                        col.setPrecision( 20 );
                        col.setNullable( false );
                        id.setName( "jpaId" );
                        id.setGeneratedValue( gv );
                        id.setColumn( col );

                        generateProperty( id.getName(), Long.TYPE, c );
                    }
                }
            }

            void recurseAddVersion( final EntityMappings orm, final Attributes a, final ClassOutline c )
            {
                if ( a.getVersion().isEmpty() )
                {
                    if ( c.getSuperClass() != null )
                    {
                        final Attributes attr = getAttributes( orm, c.getSuperClass().implClass.binaryName() );
                        if ( attr != null )
                        {
                            this.recurseAddVersion( orm, attr, c.getSuperClass() );
                        }
                    }
                    else
                    {
                        final Version v = new Version();
                        final Column col = new Column();
                        a.getVersion().add( v );

                        col.setScale( 0 );
                        col.setPrecision( 20 );
                        col.setNullable( false );
                        v.setName( "jpaVersion" );
                        v.setColumn( col );

                        generateProperty( v.getName(), Long.TYPE, c );
                    }
View Full Code Here

        return b;
    }

    private Column toColumn( final XSComponent xs )
    {
        Column col = null;
        boolean columnEmpty = true;

        XSSimpleType type = null;
        if ( xs instanceof XSParticle )
        {
            col = new Column();
            col.setNullable( ( (XSParticle) xs ).getMinOccurs() == 0 );
            columnEmpty = false;
        }
        else if ( xs instanceof XSSimpleType )
        {
            col = new Column();
            type = (XSSimpleType) xs;
        }
        else if ( xs instanceof XSAttributeDecl )
        {
            col = new Column();
            type = ( (XSAttributeDecl) xs ).getType();
        }
        else if ( xs instanceof XSAttributeUse )
        {
            final XSAttributeUse au = (XSAttributeUse) xs;
            col = new Column();
            col.setNullable( !au.isRequired() );
            columnEmpty = false;
            type = ( (XSAttributeUse) xs ).getDecl().getType();
        }
        else if ( xs instanceof XSElementDecl )
        {
            col = new Column();
            final XSElementDecl decl = (XSElementDecl) xs;
            col.setNullable( decl.isNillable() );
            columnEmpty = false;
            type = ( (XSElementDecl) xs ).getType().asSimpleType();
        }

        if ( type != null )
        {
            final XSFacet length = type.getFacet( XSFacet.FACET_LENGTH );
            final XSFacet maxLength = type.getFacet( XSFacet.FACET_MAXLENGTH );
            final XSFacet fractionDigits = type.getFacet( XSFacet.FACET_FRACTIONDIGITS );
            final XSFacet totalDigits = type.getFacet( XSFacet.FACET_TOTALDIGITS );

            if ( length != null )
            {
                col.setLength( new Integer( length.getValue().value ) );
                columnEmpty = false;
            }
            else if ( maxLength != null )
            {
                col.setLength( new Integer( maxLength.getValue().value ) );
                columnEmpty = false;
            }

            if ( fractionDigits != null )
            {
                col.setScale( new Integer( fractionDigits.getValue().value ) );
                columnEmpty = false;
            }
            if ( totalDigits != null )
            {
                col.setPrecision( new Integer( totalDigits.getValue().value ) );
                columnEmpty = false;
            }

            if ( this.getSchemaSimpleType( type, "decimal" ) != null
                 && ( col.getScale() == null || col.getPrecision() == null ) )
            {
                XSSimpleType schemaType = this.getSchemaSimpleType( type, "integer" );
                if ( schemaType != null && col.getScale() == null )
                {
                    col.setScale( new Integer( 0 ) );
                    columnEmpty = false;
                }

                if ( col.getPrecision() == null )
                {
                    schemaType = this.getSchemaSimpleType( type, "long" );
                    if ( schemaType != null )
                    {
                        col.setPrecision( new Integer( 20 ) );
                        columnEmpty = false;
                    }
                    schemaType = this.getSchemaSimpleType( type, "int" );
                    if ( schemaType != null )
                    {
                        col.setPrecision( new Integer( 10 ) );
                        columnEmpty = false;
                    }
                    schemaType = this.getSchemaSimpleType( type, "short" );
                    if ( schemaType != null )
                    {
                        col.setPrecision( new Integer( 5 ) );
                        columnEmpty = false;
                    }
                    schemaType = this.getSchemaSimpleType( type, "byte" );
                    if ( schemaType != null )
                    {
                        col.setPrecision( new Integer( 3 ) );
                        columnEmpty = false;
                    }
                    schemaType = this.getSchemaSimpleType( type, "unsignedLong" );
                    if ( schemaType != null )
                    {
                        col.setPrecision( new Integer( 20 ) );
                        columnEmpty = false;
                    }
                    schemaType = this.getSchemaSimpleType( type, "unsignedInt" );
                    if ( schemaType != null )
                    {
                        col.setPrecision( new Integer( 10 ) );
                        columnEmpty = false;
                    }
                    schemaType = this.getSchemaSimpleType( type, "unsignedShort" );
                    if ( schemaType != null )
                    {
                        col.setPrecision( new Integer( 5 ) );
                        columnEmpty = false;
                    }
                    schemaType = this.getSchemaSimpleType( type, "unsignedByte" );
                    if ( schemaType != null )
                    {
                        col.setPrecision( new Integer( 3 ) );
                        columnEmpty = false;
                    }
                }
            }
        }
View Full Code Here

        return columnEmpty ? null : col;
    }

    private Column applySchemaDefaults( final XSComponent comp, final Column column )
    {
        final Column defaultColumn = this.toColumn( comp );
        if ( defaultColumn != null )
        {
            if ( column == null )
            {
                return defaultColumn;
            }

            if ( column.isInsertable() == null )
            {
                column.setInsertable( defaultColumn.isInsertable() );
            }
            if ( column.isNullable() == null )
            {
                column.setNullable( defaultColumn.isNullable() );
            }
            if ( column.isUnique() == null )
            {
                column.setUnique( defaultColumn.isUnique() );
            }
            if ( column.isUpdatable() == null )
            {
                column.setUpdatable( defaultColumn.isUpdatable() );
            }
            if ( column.getColumnDefinition() == null )
            {
                column.setColumnDefinition( defaultColumn.getColumnDefinition() );
            }
            if ( column.getLength() == null )
            {
                column.setLength( defaultColumn.getLength() );
            }
            if ( column.getName() == null )
            {
                column.setName( defaultColumn.getName() );
            }
            if ( column.getPrecision() == null )
            {
                column.setPrecision( defaultColumn.getPrecision() );
            }
            if ( column.getScale() == null )
            {
                column.setScale( defaultColumn.getScale() );
            }
            if ( column.getTable() == null )
            {
                column.setTable( defaultColumn.getTable() );
            }
        }

        return column;
    }
View Full Code Here

                    }
                    else
                    {
                        final Id id = new Id();
                        final GeneratedValue gv = new GeneratedValue();
                        final Column col = new Column();
                        a.getId().add( id );

                        gv.setStrategy( GenerationType.AUTO );
                        col.setScale( 0 );
                        col.setPrecision( 20 );
                        col.setNullable( false );
                        id.setName( "jpaId" );
                        id.setGeneratedValue( gv );
                        id.setColumn( col );

                        generateProperty( id.getName(), Long.TYPE, c );
View Full Code Here

                        }
                    }
                    else
                    {
                        final Version v = new Version();
                        final Column col = new Column();
                        a.getVersion().add( v );

                        col.setScale( 0 );
                        col.setPrecision( 20 );
                        col.setNullable( false );
                        v.setName( "jpaVersion" );
                        v.setColumn( col );

                        generateProperty( v.getName(), Long.TYPE, c );
                    }
View Full Code Here

TOP

Related Classes of net.sourceforge.jpaxjc.ns.persistence.orm.Column

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.