use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class RecordRowTableModel method getPrototypeValue.
@Override
public Object getPrototypeValue(final int columnIndex) {
FieldDefinition fieldDefinition = getColumnFieldDefinition(columnIndex);
if (fieldDefinition == null) {
return null;
} else {
final CodeTable codeTable = fieldDefinition.getCodeTable();
if (codeTable != null) {
final FieldDefinition valueFieldDefinition = codeTable.getValueFieldDefinition();
if (valueFieldDefinition != null) {
fieldDefinition = valueFieldDefinition;
} else {
Object maxValue = "";
int maxLength = 0;
for (final Object value : codeTable.getValues()) {
if (value != null) {
final int length = DataTypes.toString(value).length();
if (length > maxLength) {
maxValue = value;
maxLength = length;
}
}
}
return maxValue;
}
}
final DataType fieldType = fieldDefinition.getDataType();
final Class<?> fieldClass = fieldDefinition.getTypeClass();
final int fieldLength = fieldDefinition.getLength();
if (DataTypes.BOOLEAN.equals(fieldType)) {
return Byte.MIN_VALUE;
} else if (DataTypes.BYTE.equals(fieldType)) {
return Byte.MIN_VALUE;
} else if (DataTypes.SHORT.equals(fieldType)) {
return Short.MAX_VALUE;
} else if (DataTypes.INT.equals(fieldType)) {
return Integer.MAX_VALUE;
} else if (DataTypes.LONG.equals(fieldType)) {
return Long.MAX_VALUE;
} else if (DataTypes.SQL_DATE.equals(fieldType)) {
return Dates.getSqlDate("9999-12-31");
} else if (DataTypes.DATE.equals(fieldType)) {
return Dates.getDate("9999-12-29 23:59:59.999");
} else if (DataTypes.DATE_TIME.equals(fieldType)) {
return Dates.getTimestamp("9999-12-29 23:59:59.999");
} else if (DataTypes.TIMESTAMP.equals(fieldType)) {
return Dates.getTimestamp("9999-12-29 23:59:59.999");
} else if (Geometry.class.isAssignableFrom(fieldClass)) {
return fieldType.getName();
} else {
if (fieldLength < 1 || fieldLength > 30) {
return "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
} else {
final StringBuilder string = new StringBuilder();
for (int i = 0; i < fieldLength; i++) {
string.append("X");
}
return string.toString();
}
}
// if (Number.class.isAssignableFrom(fieldClass)) {
// final StringBuilder numberString = new StringBuilder();
// final Object maxValue = fieldDefinition.getMaxValue();
// final Object minValue = fieldDefinition.getMinValue();
// if (maxValue == null) {
// for (int i = 0; i <= maxLength; i++) {
// numberString.append("9");
// }
// return fieldType.toObject(numberString.toString());
// } else {
// if (minValue instanceof Number) {
// numberString.append(((Number)minValue).longValue());
// }
// }
// if (Float.class.isAssignableFrom(fieldClass) ||
// Double.class.isAssignableFrom(fieldClass)
// || BigDecimal.class.isAssignableFrom(fieldClass)) {
// numberString.append('.');
// final int fieldScale = fieldDefinition.getScale();
// for (int i = 0; i <= fieldScale; i++) {
// numberString.append("9");
// }
// final BigDecimal scaleValue = new BigDecimal(numberString.toString());
// }
// }
// return super.getPrototypeValue(columnIndex);
}
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class GeometryFactory method geometryCollection.
/**
* Does not flattern nested geometry collections.
*
* @param geometries
* @return
*/
@SuppressWarnings("unchecked")
public <G extends Geometry> G geometryCollection(final Iterable<? extends Geometry> geometries) {
if (geometries == null) {
return (G) geometryCollection();
} else {
DataType dataType = null;
boolean heterogeneous = false;
final List<Geometry> geometryList = new ArrayList<>();
if (geometries != null) {
for (final Geometry geometry : geometries) {
if (geometry != null) {
if (heterogeneous) {
} else {
final DataType geometryDataType = geometry.getDataType();
if (dataType == null) {
dataType = geometryDataType;
} else if (dataType != geometryDataType) {
heterogeneous = true;
dataType = null;
}
}
final Geometry copy = geometry.newGeometry(this);
geometryList.add(copy);
}
}
}
if (geometryList.size() == 0) {
return (G) geometryCollection();
} else if (geometryList.size() == 1) {
return (G) geometryList.get(0);
} else if (dataType == DataTypes.POINT) {
return (G) punctual(geometryList);
} else if (dataType == DataTypes.LINE_STRING) {
return (G) lineal(geometryList);
} else if (dataType == DataTypes.POLYGON) {
return (G) polygonal(geometryList);
} else {
final Geometry[] geometryArray = new Geometry[geometryList.size()];
geometryList.toArray(geometryArray);
return (G) new GeometryCollectionImpl(this, geometryArray);
}
}
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class MeasureOverlay method setMeasureDataType.
public void setMeasureDataType(final DataType measureDataType) {
final DataType oldValue = this.measureDataType;
if (oldValue != measureDataType) {
this.measureDataType = measureDataType;
setMeasureGeometry(EMPTY_GEOMETRY);
this.dragged = false;
this.measureDataType = measureDataType;
firePropertyChange("measureDataType", oldValue, measureDataType);
}
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class MeasureOverlay method modeMeasureClear.
private void modeMeasureClear() {
clearOverlayAction(MEASURE);
setMeasureGeometry(EMPTY_GEOMETRY);
this.dragged = false;
final DataType oldValue = this.measureDataType;
this.measureDataType = null;
firePropertyChange("measureDataType", oldValue, null);
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class FileGdbRecordStore method newIterator.
@Override
public AbstractIterator<Record> newIterator(final Query query, final Map<String, Object> properties) {
PathName typePath = query.getTypePath();
RecordDefinition recordDefinition = query.getRecordDefinition();
if (recordDefinition == null) {
recordDefinition = getRecordDefinition(typePath);
if (recordDefinition == null) {
throw new IllegalArgumentException("Type name does not exist " + typePath);
}
} else {
typePath = recordDefinition.getPathName();
}
final String catalogPath = getCatalogPath(typePath);
final BoundingBox boundingBox = QueryValue.getBoundingBox(query);
final Map<? extends CharSequence, Boolean> orderBy = query.getOrderBy();
final StringBuilder whereClause = getWhereClause(query);
StringBuilder sql = new StringBuilder();
if (orderBy.isEmpty() || boundingBox != null) {
if (!orderBy.isEmpty()) {
Logs.error(this, "Unable to sort on " + catalogPath + " " + orderBy.keySet() + " as the ESRI library can't sort with a bounding box query");
}
sql = whereClause;
} else {
sql.append("SELECT ");
final List<String> fieldNames = query.getFieldNames();
if (fieldNames.isEmpty()) {
StringBuilders.append(sql, recordDefinition.getFieldNames());
} else {
StringBuilders.append(sql, fieldNames);
}
sql.append(" FROM ");
sql.append(JdbcUtils.getTableName(catalogPath));
if (whereClause.length() > 0) {
sql.append(" WHERE ");
sql.append(whereClause);
}
boolean first = true;
for (final Entry<? extends CharSequence, Boolean> entry : orderBy.entrySet()) {
final CharSequence fieldName = entry.getKey();
final DataType dataType = recordDefinition.getFieldType(fieldName);
if (dataType != null && !Geometry.class.isAssignableFrom(dataType.getJavaClass())) {
if (first) {
sql.append(" ORDER BY ");
first = false;
} else {
sql.append(", ");
}
if (fieldName instanceof FieldDefinition) {
final FieldDefinition field = (FieldDefinition) fieldName;
field.appendColumnName(sql);
} else {
sql.append(fieldName);
}
final Boolean ascending = entry.getValue();
if (!ascending) {
sql.append(" DESC");
}
} else {
Logs.error(this, "Unable to sort on " + recordDefinition.getPath() + "." + fieldName + " as the ESRI library can't sort on " + dataType + " columns");
}
}
}
final FileGdbQueryIterator iterator = new FileGdbQueryIterator(this, catalogPath, sql.toString(), boundingBox, query, query.getOffset(), query.getLimit());
iterator.setStatistics(query.getStatistics());
return iterator;
}
Aggregations