Search in sources :

Example 1 with DetectedDbAttribute

use of org.apache.cayenne.dbsync.model.DetectedDbAttribute in project cayenne by apache.

the class EntityMergeSupport method getTypeForObjAttribute.

private String getTypeForObjAttribute(DbAttribute dbAttribute) {
    String java8Type;
    if (!usingJava7Types && (java8Type = SQL_TYPE_TO_JAVA8_TYPE.get(dbAttribute.getType())) != null) {
        return java8Type;
    }
    // Check additional common DB types, like 'json' or 'geometry'
    if (dbAttribute instanceof DetectedDbAttribute) {
        DetectedDbAttribute detectedDbAttribute = (DetectedDbAttribute) dbAttribute;
        String jdbcTypeName = detectedDbAttribute.getJdbcTypeName();
        if (jdbcTypeName != null) {
            String type = SQL_ADDITIONAL_TYPES_TO_JAVA_TYPE.get(jdbcTypeName.toLowerCase());
            if (type != null) {
                return type;
            }
        }
    }
    String type = TypesMapping.getJavaBySqlType(dbAttribute.getType());
    String primitiveType;
    if (usingPrimitives && (primitiveType = CLASS_TO_PRIMITIVE.get(type)) != null) {
        return primitiveType;
    }
    return type;
}
Also used : DetectedDbAttribute(org.apache.cayenne.dbsync.model.DetectedDbAttribute)

Example 2 with DetectedDbAttribute

use of org.apache.cayenne.dbsync.model.DetectedDbAttribute in project cayenne by apache.

the class AttributeLoader method createDbAttribute.

private DbAttribute createDbAttribute(ResultSet rs) throws SQLException {
    // gets attribute's (column's) information
    int columnType = rs.getInt("DATA_TYPE");
    // ignore precision of non-decimal columns
    int decimalDigits = -1;
    if (TypesMapping.isDecimal(columnType)) {
        decimalDigits = rs.getInt("DECIMAL_DIGITS");
        if (rs.wasNull()) {
            decimalDigits = -1;
        }
    }
    // create attribute delegating this task to adapter
    DetectedDbAttribute detectedDbAttribute = new DetectedDbAttribute(adapter.buildAttribute(rs.getString("COLUMN_NAME"), rs.getString("TYPE_NAME"), columnType, rs.getInt("COLUMN_SIZE"), decimalDigits, rs.getBoolean("NULLABLE")));
    // store raw type name
    detectedDbAttribute.setJdbcTypeName(rs.getString("TYPE_NAME"));
    if (supportAutoIncrement) {
        if ("YES".equals(rs.getString("IS_AUTOINCREMENT"))) {
            detectedDbAttribute.setGenerated(true);
        }
    }
    return detectedDbAttribute;
}
Also used : DetectedDbAttribute(org.apache.cayenne.dbsync.model.DetectedDbAttribute)

Aggregations

DetectedDbAttribute (org.apache.cayenne.dbsync.model.DetectedDbAttribute)2