use of org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCollection in project dbeaver by serge-rider.
the class PostgreArrayValueHandler method getValueDisplayString.
@NotNull
@Override
public String getValueDisplayString(@NotNull DBSTypedObject column, Object value, @NotNull DBDDisplayFormat format) {
DBDCollection collection = (DBDCollection) value;
if (!DBUtils.isNullValue(value)) {
DBDValueHandler valueHandler = collection.getComponentValueHandler();
StringBuilder str = new StringBuilder();
str.append("{");
for (int i = 0; i < collection.getItemCount(); i++) {
if (i > 0) {
//$NON-NLS-1$
str.append(',');
}
final Object item = collection.getItem(i);
String itemString;
if (item instanceof JDBCCollection) {
// Multi-dimensional arrays case
itemString = getValueDisplayString(column, item, format);
} else {
itemString = valueHandler.getValueDisplayString(collection.getComponentType(), item, DBDDisplayFormat.NATIVE);
}
str.append(itemString);
}
str.append("}");
return str.toString();
}
return super.getValueDisplayString(column, value, format);
}
use of org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCollection in project dbeaver by serge-rider.
the class PostgreArrayValueHandler method convertStringToArray.
private JDBCCollection convertStringToArray(@NotNull DBCSession session, @NotNull PostgreDataType itemType, @NotNull String value) {
List<String> strings = new ArrayList<>(10);
StringTokenizer st = new StringTokenizer(value, " ");
while (st.hasMoreTokens()) {
strings.add(st.nextToken());
}
Object[] contents = new Object[strings.size()];
for (int i = 0; i < strings.size(); i++) {
contents[i] = PostgreUtils.convertStringToValue(itemType, strings.get(i), false);
}
return new JDBCCollection(itemType, DBUtils.findValueHandler(session, itemType), contents);
}
use of org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCollection in project dbeaver by dbeaver.
the class PostgreArrayValueHandler method getValueDisplayString.
@NotNull
@Override
public String getValueDisplayString(@NotNull DBSTypedObject column, Object value, @NotNull DBDDisplayFormat format) {
DBDCollection collection = (DBDCollection) value;
if (!DBUtils.isNullValue(value)) {
DBDValueHandler valueHandler = collection.getComponentValueHandler();
StringBuilder str = new StringBuilder();
if (format == DBDDisplayFormat.NATIVE) {
str.append("'");
}
str.append("{");
for (int i = 0; i < collection.getItemCount(); i++) {
if (i > 0) {
// $NON-NLS-1$
str.append(',');
}
final Object item = collection.getItem(i);
String itemString;
if (item instanceof JDBCCollection) {
// Multi-dimensional arrays case
itemString = getValueDisplayString(column, item, format);
} else {
itemString = valueHandler.getValueDisplayString(collection.getComponentType(), item, DBDDisplayFormat.NATIVE);
}
str.append(itemString);
}
str.append("}");
if (format == DBDDisplayFormat.NATIVE) {
str.append("'");
}
return str.toString();
}
return super.getValueDisplayString(column, value, format);
}
use of org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCollection in project dbeaver by dbeaver.
the class PostgreArrayValueHandler method convertStringToArray.
private JDBCCollection convertStringToArray(@NotNull DBCSession session, @NotNull PostgreDataType itemType, @NotNull String value) {
List<String> strings = new ArrayList<>(10);
StringTokenizer st = new StringTokenizer(value, " ");
while (st.hasMoreTokens()) {
strings.add(st.nextToken());
}
Object[] contents = new Object[strings.size()];
for (int i = 0; i < strings.size(); i++) {
contents[i] = PostgreUtils.convertStringToValue(itemType, strings.get(i), false);
}
return new JDBCCollection(itemType, DBUtils.findValueHandler(session, itemType), contents);
}
use of org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCollection in project dbeaver by serge-rider.
the class PostgreValueParserTest method convertArrayToString.
@Test
public void convertArrayToString() {
PostgreArrayValueHandler arrayVH = new PostgreArrayValueHandler();
String[] stringItems = new String[] { "one", "two", " four with spaces ", "f{i,v}e" };
JDBCCollection array = new JDBCCollection(stringItemType, arrayVH, stringItems);
JDBCCollection array3D = new JDBCCollection(stringItemType, arrayVH, new Object[] { array, array });
String arrayString = arrayVH.getValueDisplayString(arrayStringItemType, array, DBDDisplayFormat.NATIVE);
Assert.assertEquals("'{\"one\",\"two\",\" four with spaces \",\"f{i,v}e\"}'", arrayString);
String arrayString3D = arrayVH.getValueDisplayString(arrayStringItemType, array3D, DBDDisplayFormat.NATIVE);
Assert.assertEquals("'{{\"one\",\"two\",\" four with spaces \",\"f{i,v}e\"},{\"one\",\"two\",\" four with spaces \",\"f{i,v}e\"}}'", arrayString3D);
}
Aggregations