Search in sources :

Example 1 with ColumnMetadata

use of javax.jdo.metadata.ColumnMetadata in project motech by motech.

the class EntityMetadataBuilderImpl method processHistoryTrashRelationship.

private void processHistoryTrashRelationship(ClassMetadata cmd, FieldMetadata fmd, RelationshipHolder holder) {
    if (holder.isOneToOne() || holder.isManyToOne()) {
        fmd.setColumn(holder.getFieldName() + ID_SUFFIX);
    } else {
        fmd.setTable(cmd.getTable() + '_' + holder.getFieldName());
        CollectionMetadata collMd = fmd.newCollectionMetadata();
        collMd.setElementType(Long.class.getName());
        JoinMetadata joinMd = fmd.newJoinMetadata();
        ColumnMetadata joinColumnMd = joinMd.newColumnMetadata();
        joinColumnMd.setName(cmd.getName() + ID_SUFFIX);
        ElementMetadata elementMd = fmd.newElementMetadata();
        elementMd.setColumn(holder.getFieldName() + ID_SUFFIX);
    }
}
Also used : CollectionMetadata(javax.jdo.metadata.CollectionMetadata) ColumnMetadata(javax.jdo.metadata.ColumnMetadata) ElementMetadata(javax.jdo.metadata.ElementMetadata) JoinMetadata(javax.jdo.metadata.JoinMetadata)

Example 2 with ColumnMetadata

use of javax.jdo.metadata.ColumnMetadata in project motech by motech.

the class EntityMetadataBuilderImpl method addColumnMetadata.

private void addColumnMetadata(FieldMetadata fmd, FieldDto field, Value valueAnnotation) {
    SettingDto maxLengthSetting = field.getSetting(Constants.Settings.STRING_MAX_LENGTH);
    ColumnMetadata colMd = fmd.newColumnMetadata();
    // text(clob) fields don't have length
    if (maxLengthSetting != null && !isClob(field)) {
        colMd.setLength(Integer.parseInt(maxLengthSetting.getValueAsString()));
    }
    // if TextArea then change length
    if (field.getSetting(Constants.Settings.STRING_TEXT_AREA) != null && "true".equalsIgnoreCase(field.getSetting(Constants.Settings.STRING_TEXT_AREA).getValueAsString())) {
        fmd.setIndexed(false);
        colMd.setSQLType("CLOB");
    }
    if (field.getMetadata(DATABASE_COLUMN_NAME) != null) {
        colMd.setName(field.getMetadata(DATABASE_COLUMN_NAME).getValue());
    }
    if (valueAnnotation != null) {
        copyParametersFromValueAnnotation(fmd, valueAnnotation);
    }
}
Also used : ColumnMetadata(javax.jdo.metadata.ColumnMetadata) SettingDto(org.motechproject.mds.dto.SettingDto)

Example 3 with ColumnMetadata

use of javax.jdo.metadata.ColumnMetadata in project motech by motech.

the class EntityMetadataBuilderImpl method copyParametersFromValueAnnotation.

private void copyParametersFromValueAnnotation(FieldMetadata fmd, Value valueAnnotation) {
    ValueMetadata valueMetadata = fmd.newValueMetadata();
    for (Column column : valueAnnotation.columns()) {
        ColumnMetadata colMd = valueMetadata.newColumnMetadata();
        colMd.setName(column.name());
        colMd.setLength(column.length());
        colMd.setAllowsNull(Boolean.parseBoolean(column.allowsNull()));
        colMd.setDefaultValue(column.defaultValue());
        colMd.setInsertValue(column.insertValue());
        colMd.setJDBCType(column.jdbcType());
        colMd.setSQLType(column.sqlType());
    }
}
Also used : ColumnMetadata(javax.jdo.metadata.ColumnMetadata) Column(javax.jdo.annotations.Column) ValueMetadata(javax.jdo.metadata.ValueMetadata)

Aggregations

ColumnMetadata (javax.jdo.metadata.ColumnMetadata)3 Column (javax.jdo.annotations.Column)1 CollectionMetadata (javax.jdo.metadata.CollectionMetadata)1 ElementMetadata (javax.jdo.metadata.ElementMetadata)1 JoinMetadata (javax.jdo.metadata.JoinMetadata)1 ValueMetadata (javax.jdo.metadata.ValueMetadata)1 SettingDto (org.motechproject.mds.dto.SettingDto)1