Search in sources :

Example 1 with Temporal

use of javax.persistence.Temporal in project CloudStack-archive by CloudStack-extras.

the class Attribute method setupColumnInfo.

protected void setupColumnInfo(Class<?> clazz, AttributeOverride[] overrides, String tableName, boolean isEmbedded, boolean isId) {
    flags = Flag.Selectable.setTrue(flags);
    GeneratedValue gv = field.getAnnotation(GeneratedValue.class);
    if (gv != null) {
        if (gv.strategy() == GenerationType.IDENTITY) {
            flags = Flag.DbGenerated.setTrue(flags);
        } else if (gv.strategy() == GenerationType.SEQUENCE) {
            assert (false) : "Sequence generation not supported.";
            flags = Flag.DaoGenerated.setTrue(flags);
            flags = Flag.Insertable.setTrue(flags);
            flags = Flag.SequenceGV.setTrue(flags);
        } else if (gv.strategy() == GenerationType.TABLE) {
            flags = Flag.DaoGenerated.setTrue(flags);
            flags = Flag.Insertable.setTrue(flags);
            flags = Flag.TableGV.setTrue(flags);
        } else if (gv.strategy() == GenerationType.AUTO) {
            flags = Flag.DaoGenerated.setTrue(flags);
            flags = Flag.Insertable.setTrue(flags);
            flags = Flag.AutoGV.setTrue(flags);
        }
    }
    if (isEmbedded) {
        flags = Flag.Embedded.setTrue(flags);
    }
    if (isId) {
        flags = Flag.Id.setTrue(flags);
    } else {
        Id id = field.getAnnotation(Id.class);
        if (id != null) {
            flags = Flag.Id.setTrue(flags);
        }
    }
    column = field.getAnnotation(Column.class);
    if (gv == null) {
        if (column == null || (column.insertable() && column.table().length() == 0)) {
            flags = Flag.Insertable.setTrue(flags);
        }
        if (column == null || (column.updatable() && column.table().length() == 0)) {
            flags = Flag.Updatable.setTrue(flags);
        }
        if (column == null || column.nullable()) {
            flags = Flag.Nullable.setTrue(flags);
        }
        if (column != null && column.encryptable()) {
            flags = Flag.Encrypted.setTrue(flags);
        }
    }
    ElementCollection ec = field.getAnnotation(ElementCollection.class);
    if (ec != null) {
        flags = Flag.Insertable.setFalse(flags);
        flags = Flag.Selectable.setFalse(flags);
    }
    Temporal temporal = field.getAnnotation(Temporal.class);
    if (temporal != null) {
        if (temporal.value() == TemporalType.DATE) {
            flags = Flag.Date.setTrue(flags);
        } else if (temporal.value() == TemporalType.TIME) {
            flags = Flag.Time.setTrue(flags);
        } else if (temporal.value() == TemporalType.TIMESTAMP) {
            flags = Flag.TimeStamp.setTrue(flags);
        }
    }
    if (column != null && column.table().length() > 0) {
        table = column.table();
    }
    columnName = DbUtil.getColumnName(field, overrides);
}
Also used : GeneratedValue(javax.persistence.GeneratedValue) Temporal(javax.persistence.Temporal) Column(javax.persistence.Column) Id(javax.persistence.Id) ElementCollection(javax.persistence.ElementCollection)

Example 2 with Temporal

use of javax.persistence.Temporal in project cloudstack by apache.

the class Attribute method setupColumnInfo.

protected void setupColumnInfo(Class<?> clazz, AttributeOverride[] overrides, String tableName, boolean isEmbedded, boolean isId) {
    flags = Flag.Selectable.setTrue(flags);
    GeneratedValue gv = field.getAnnotation(GeneratedValue.class);
    if (gv != null) {
        if (gv.strategy() == GenerationType.IDENTITY) {
            flags = Flag.DbGenerated.setTrue(flags);
        } else if (gv.strategy() == GenerationType.SEQUENCE) {
            assert (false) : "Sequence generation not supported.";
            flags = Flag.DaoGenerated.setTrue(flags);
            flags = Flag.Insertable.setTrue(flags);
            flags = Flag.SequenceGV.setTrue(flags);
        } else if (gv.strategy() == GenerationType.TABLE) {
            flags = Flag.DaoGenerated.setTrue(flags);
            flags = Flag.Insertable.setTrue(flags);
            flags = Flag.TableGV.setTrue(flags);
        } else if (gv.strategy() == GenerationType.AUTO) {
            flags = Flag.DaoGenerated.setTrue(flags);
            flags = Flag.Insertable.setTrue(flags);
            flags = Flag.AutoGV.setTrue(flags);
        }
    }
    if (isEmbedded) {
        flags = Flag.Embedded.setTrue(flags);
    }
    if (isId) {
        flags = Flag.Id.setTrue(flags);
    } else {
        Id id = field.getAnnotation(Id.class);
        if (id != null) {
            flags = Flag.Id.setTrue(flags);
        }
    }
    column = field.getAnnotation(Column.class);
    if (gv == null) {
        if (column == null || (column.insertable() && column.table().length() == 0)) {
            flags = Flag.Insertable.setTrue(flags);
        }
        if (column == null || (column.updatable() && column.table().length() == 0)) {
            flags = Flag.Updatable.setTrue(flags);
        }
        if (column == null || column.nullable()) {
            flags = Flag.Nullable.setTrue(flags);
        }
        Encrypt encrypt = field.getAnnotation(Encrypt.class);
        if (encrypt != null && encrypt.encrypt()) {
            flags = Flag.Encrypted.setTrue(flags);
        }
    }
    ElementCollection ec = field.getAnnotation(ElementCollection.class);
    if (ec != null) {
        flags = Flag.Insertable.setFalse(flags);
        flags = Flag.Selectable.setFalse(flags);
    }
    Temporal temporal = field.getAnnotation(Temporal.class);
    if (temporal != null) {
        if (temporal.value() == TemporalType.DATE) {
            flags = Flag.Date.setTrue(flags);
        } else if (temporal.value() == TemporalType.TIME) {
            flags = Flag.Time.setTrue(flags);
        } else if (temporal.value() == TemporalType.TIMESTAMP) {
            flags = Flag.TimeStamp.setTrue(flags);
        }
    }
    if (column != null && column.table().length() > 0) {
        table = column.table();
    }
    columnName = DbUtil.getColumnName(field, overrides);
}
Also used : GeneratedValue(javax.persistence.GeneratedValue) Temporal(javax.persistence.Temporal) Column(javax.persistence.Column) Id(javax.persistence.Id) ElementCollection(javax.persistence.ElementCollection)

Aggregations

Column (javax.persistence.Column)2 ElementCollection (javax.persistence.ElementCollection)2 GeneratedValue (javax.persistence.GeneratedValue)2 Id (javax.persistence.Id)2 Temporal (javax.persistence.Temporal)2