public FieldMetadata getFieldMetadata()

in modello-plugins/modello-plugin-jpox/src/main/java/org/apache/archiva/redback/components/modello/jpox/metadata/JPoxMetadataPlugin.java [208:335]


    public FieldMetadata getFieldMetadata( ModelField field, Map data ) throws ModelloException
    {
        JPoxFieldMetadata metadata = new JPoxFieldMetadata();

        JPoxClassMetadata classMetadata = (JPoxClassMetadata) field.getModelClass().getMetadata( JPoxClassMetadata.ID );

        boolean useIdentifiersAsPrimaryKey = classMetadata.useIdentifiersAsPrimaryKey();

        metadata.setPrimaryKey( getBoolean( data, PRIMARY_KEY, ( field.isIdentifier() && useIdentifiersAsPrimaryKey ) ) );

        // Backwards Compatibility Syntax.
        String fetchGroupNames = (String) data.get( "jpox.fetchGroupNames" );

        if ( fetchGroupNames != null )
        {
            getLogger().warn(
                              "You are using the <field jpox.fetchGroupNames=\"\"> attribute syntax.  "
                                              + "It has been deprecated in favor of the <field jpox.fetch-groups=\"\"> syntax instead." );
        }
        else
        {
            // Correct Syntax.
            fetchGroupNames = (String) data.get( FETCH_GROUPS );
        }

        if ( !StringUtils.isEmpty( fetchGroupNames ) )
        {
            List fetchGroups = Arrays.asList( StringUtils.split( fetchGroupNames ) );

            metadata.setFetchGroupNames( fetchGroups );
        }

        // Backwards Compatibility Syntax.
        String mappedBy = (String) data.get( "jpox.mappedBy" );

        if ( mappedBy != null )
        {
            getLogger().warn(
                              "You are using the <field jpox.mappedBy=\"\"> attribute syntax.  "
                                              + "It has been deprecated in favor of the <field jpox.mapped-by=\"\"> syntax instead." );
        }
        else
        {
            // Correct Syntax.
            mappedBy = (String) data.get( MAPPED_BY );
        }

        if ( !StringUtils.isEmpty( mappedBy ) )
        {
            metadata.setMappedBy( mappedBy );
        }

        // Backwards Compatibility Syntax.
        String nullValue = (String) data.get( "jpox.nullValue" );

        if ( nullValue != null )
        {
            getLogger().warn(
                              "You are using the <field jpox.nullValue=\"\"> attribute syntax.  "
                                              + "It has been deprecated in favor of the <field jpox.null-value=\"\"> syntax instead." );
        }
        else
        {
            // Correct Syntax.
            nullValue = (String) data.get( NULL_VALUE );
        }

        if ( !StringUtils.isEmpty( nullValue ) )
        {
            metadata.setNullValue( nullValue );
        }

        String column = (String) data.get( COLUMN );

        if ( StringUtils.isNotEmpty( column ) )
        {
            metadata.setColumnName( column );
        }

        String joinTable = (String) data.get( JOIN_TABLE );

        if ( StringUtils.isNotEmpty( joinTable ) )
        {
            metadata.setJoinTableName( joinTable );
        }

        String indexed = (String) data.get( INDEXED );

        if ( StringUtils.isNotEmpty( indexed ) )
        {
            metadata.setIndexed( indexed );
        }

        String persistenceModifier = (String) data.get( PERSISTENCE_MODIFIER );

        if ( StringUtils.isNotEmpty( persistenceModifier ) )
        {
            metadata.setPersistenceModifier( persistenceModifier );
        }

        // According to http://www.jpox.org/docs/1_1/identity_generation.html the default value for
        // this should be 'native', however this is untrue in jpox-1.1.1
        metadata.setValueStrategy( "native" );

        if ( StringUtils.isNotEmpty( (String) data.get( VALUE_STRATEGY ) ) )
        {
            String valueStrategy = (String) data.get( VALUE_STRATEGY );

            if ( StringUtils.equals( valueStrategy, "off" ) )
            {
                metadata.setValueStrategy( null );
            }
            else
            {
                metadata.setValueStrategy( valueStrategy );
            }
        }

        metadata.setUnique( getBoolean( data, UNIQUE, false ) );
        metadata.setForeignKey( getBoolean( data, FOREIGN_KEY_DEFERRED, false ) );
        metadata.setForeignKeyDeferred( getEnumString( data, FOREIGN_KEY_DEFERRED, JPoxFieldMetadata.BOOLEANS, null ) );
        metadata.setForeignKeyDeleteAction( getEnumString( data, FOREIGN_KEY_DELETE_ACTION,
                                                           JPoxFieldMetadata.FOREIGN_KEY_ACTIONS, null ) );
        metadata.setForeignKeyUpdateAction( getEnumString( data, FOREIGN_KEY_UPDATE_ACTION,
                                                           JPoxFieldMetadata.FOREIGN_KEY_ACTIONS, null ) );

        return metadata;
    }