use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class AbstractBinaryQueryValue method appendParameters.
@Override
public int appendParameters(int index, final PreparedStatement statement) {
if (this.left != null) {
if (this.right instanceof Column && !(this.left instanceof Column)) {
final FieldDefinition rightFieldDefinition = ((Column) this.right).getFieldDefinition();
this.left.setFieldDefinition(rightFieldDefinition);
}
index = this.left.appendParameters(index, statement);
}
if (this.right != null) {
if (this.left instanceof Column && !(this.right instanceof Column)) {
final FieldDefinition rightFieldDefinition = ((Column) this.left).getFieldDefinition();
this.right.setFieldDefinition(rightFieldDefinition);
}
index = this.right.appendParameters(index, statement);
}
return index;
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class FileGdbRecordStore method insertRecord.
void insertRecord(final Table table, final Record record) {
final RecordDefinition sourceRecordDefinition = record.getRecordDefinition();
final RecordDefinition recordDefinition = getRecordDefinition(sourceRecordDefinition);
validateRequired(record, recordDefinition);
final PathName typePath = recordDefinition.getPathName();
if (table == null) {
throw new ObjectException(record, "Cannot find table: " + typePath);
} else {
try {
final Row row = newRowObject(table);
try {
for (final FieldDefinition field : recordDefinition.getFields()) {
final String name = field.getName();
try {
final Object value = record.getValue(name);
final AbstractFileGdbFieldDefinition esriField = (AbstractFileGdbFieldDefinition) field;
esriField.setInsertValue(record, row, value);
} catch (final Throwable e) {
throw new ObjectPropertyException(record, name, e);
}
}
insertRow(table, row);
if (sourceRecordDefinition == recordDefinition) {
for (final FieldDefinition field : recordDefinition.getFields()) {
final AbstractFileGdbFieldDefinition esriField = (AbstractFileGdbFieldDefinition) field;
try {
esriField.setPostInsertValue(record, row);
} catch (final Throwable e) {
throw new ObjectPropertyException(record, field.getName(), e);
}
}
record.setState(RecordState.PERSISTED);
}
} finally {
row.delete();
addStatistic("Insert", record);
}
} catch (final ObjectException e) {
if (e.getObject() == record) {
throw e;
} else {
throw new ObjectException(record, e);
}
} catch (final Throwable e) {
throw new ObjectException(record, e);
}
}
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class SwingUtil method newField.
@SuppressWarnings("unchecked")
static <T extends Field> T newField(final RecordDefinition recordDefinition, final String fieldName, final boolean editable) {
Field field;
final FieldDefinition fieldDefinition = recordDefinition.getField(fieldName);
if (fieldDefinition == null) {
throw new IllegalArgumentException("Cannot find field " + fieldName);
} else {
final boolean required = fieldDefinition.isRequired();
final int length = fieldDefinition.getLength();
CodeTable codeTable;
if (recordDefinition.getIdFieldNames().contains(fieldName)) {
codeTable = null;
} else {
codeTable = recordDefinition.getCodeTableByFieldName(fieldName);
}
final DataType type = fieldDefinition.getDataType();
int columns = length;
if (columns <= 0) {
columns = 10;
} else if (columns > 50) {
columns = 50;
}
final Class<?> javaClass = type.getJavaClass();
if (codeTable != null) {
if (editable) {
final JComponent component = codeTable.getSwingEditor();
if (component == null) {
field = newComboBox(fieldName, codeTable, required, -1, false);
} else {
field = ((Field) component).clone();
}
} else {
field = new ObjectLabelField(fieldName, columns, codeTable);
}
} else if (!editable) {
final TextField textField = newTextField(fieldName, columns);
textField.setEditable(false);
field = textField;
} else if (Number.class.isAssignableFrom(javaClass)) {
final int scale = fieldDefinition.getScale();
final Number minValue = fieldDefinition.getMinValue();
final Number maxValue = fieldDefinition.getMaxValue();
final NumberTextField numberTextField = new NumberTextField(fieldName, type, length, scale, minValue, maxValue);
field = numberTextField;
} else if (Date.class.isAssignableFrom(javaClass)) {
field = newDateField(fieldName);
} else if (Geometry.class.isAssignableFrom(javaClass)) {
field = new ObjectLabelField(fieldName);
} else {
field = newTextField(fieldName, columns);
}
}
if (field instanceof JTextField) {
final JTextField textField = (JTextField) field;
final int preferedWidth = textField.getPreferredSize().width;
textField.setMinimumSize(new Dimension(preferedWidth, 0));
textField.setMaximumSize(new Dimension(preferedWidth, Integer.MAX_VALUE));
}
((JComponent) field).setFont(FONT);
return (T) field;
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class PostgreSQLJdbcQueryResultPager method getList.
@Override
public List<Record> getList() {
synchronized (this) {
if (this.results == null) {
final ArrayList<Record> results = new ArrayList<>();
final int pageSize = getPageSize();
final int pageNumber = getPageNumber();
if (pageNumber != -1) {
String sql = getSql();
final int startRowNum = (pageNumber - 1) * pageSize;
sql = getSql() + " OFFSET " + startRowNum + " LIMIT " + pageSize;
final RecordDefinition recordDefinition = getRecordDefinition();
if (recordDefinition != null) {
final RecordFactory recordFactory = getRecordFactory();
final JdbcRecordStore recordStore = getRecordStore();
try (JdbcConnection connection = recordStore.getJdbcConnection()) {
final List<FieldDefinition> attributes = recordDefinition.getFields();
try (final PreparedStatement statement = connection.prepareStatement(sql);
final ResultSet resultSet = JdbcQueryIterator.getResultSet(statement, getQuery())) {
if (resultSet.next()) {
int i = 0;
do {
final Record object = JdbcQueryIterator.getNextRecord(recordStore, recordDefinition, attributes, recordFactory, resultSet, this.internStrings);
results.add(object);
i++;
} while (resultSet.next() && i < pageSize);
}
} catch (final SQLException e) {
throw connection.getException("updateResults", sql, e);
}
}
}
}
this.results = results;
}
return this.results;
}
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class QueryWhereConditionField method actionAddInCondition.
private void actionAddInCondition() {
final FieldDefinition fieldDefinition = this.fieldNamesList.getSelectedItem();
if (fieldDefinition != null) {
Object fieldValue = ((Field) this.searchField).getFieldValue();
if (Property.hasValue(fieldValue)) {
int position = this.whereTextField.getCaretPosition();
DataType fieldType = fieldDefinition.getDataType();
if (fieldValue != null) {
if (this.codeTable == null) {
try {
fieldValue = fieldDefinition.toFieldValue(fieldValue);
} catch (final Throwable e) {
setInvalidMessage("'" + fieldValue + "' is not a valid " + fieldType.getValidationName());
return;
}
} else {
fieldValue = this.codeTable.getValue(fieldValue);
if (fieldValue != null) {
fieldType = DataTypes.STRING;
}
}
if (fieldValue != null) {
final StringBuilder text = new StringBuilder();
try {
final Document document = this.whereTextField.getDocument();
final String currentText = document.getText(0, position);
final Matcher matcher = Pattern.compile("(?:.+ )?" + fieldDefinition.getName() + " IN \\((?:.+,\\s*)*'?((?:[^']|'')*)'?\\) $").matcher(currentText);
if (matcher.matches()) {
final String previousValue = matcher.group(1).replace("''", "'");
if (!DataType.equal(fieldValue, previousValue)) {
position -= 2;
text.append(", ");
appendValue(text, fieldType, fieldValue);
}
} else {
if (position > 0) {
text.append(" ");
}
text.append(fieldDefinition.getName());
text.append(" IN (");
appendValue(text, fieldType, fieldValue);
text.append(") ");
}
document.insertString(position, text.toString(), null);
} catch (final BadLocationException e) {
Logs.error(this, "Error inserting text: " + text, e);
}
}
}
}
}
}
Aggregations