提交 60191a5f 编写于 作者: S serge-rider

#5370 Composite (struct) values string representation


Former-commit-id: 9b26ff1d
上级 6da9ded0
......@@ -81,7 +81,7 @@ public class PostgreStructValueHandler extends JDBCStructValueHandler {
}
try {
if (object == null) {
return new JDBCCompositeStatic(session, structType, new JDBCStructImpl(structType.getTypeName(), null));
return new JDBCCompositeStatic(session, structType, new JDBCStructImpl(structType.getTypeName(), null, ""));
} else if (object instanceof JDBCCompositeStatic) {
return copy ? ((JDBCCompositeStatic) object).cloneValue(session.getProgressMonitor()) : object;
} else {
......@@ -118,7 +118,7 @@ public class PostgreStructValueHandler extends JDBCStructValueHandler {
attrValues[i] = PostgreUtils.convertStringToValue(session, itemAttr, parsedValues[i], true);
}
Struct contents = new JDBCStructImpl(compType.getTypeName(), attrValues);
Struct contents = new JDBCStructImpl(compType.getTypeName(), attrValues, value);
return new JDBCCompositeStatic(session, compType, contents);
}
......
......@@ -29,10 +29,12 @@ public class JDBCStructImpl implements Struct {
private final String typeName;
private final Object[] attributes;
private final String stringValue;
public JDBCStructImpl(String typeName, Object[] attributes) {
public JDBCStructImpl(String typeName, Object[] attributes, String stringValue) {
this.typeName = typeName;
this.attributes = attributes;
this.stringValue = stringValue;
}
@Override
......@@ -49,4 +51,10 @@ public class JDBCStructImpl implements Struct {
public Object[] getAttributes(Map<String, Class<?>> map) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public String toString() {
return stringValue;
}
}
......@@ -48,6 +48,9 @@ public abstract class JDBCComposite implements DBDComposite, DBDValueCloneable {
private static final Log log = Log.getLog(JDBCComposite.class);
@Nullable
private Struct rawStruct;
@NotNull
protected DBSDataType type;
@NotNull
......@@ -59,6 +62,10 @@ public abstract class JDBCComposite implements DBDComposite, DBDValueCloneable {
protected JDBCComposite() {
}
public JDBCComposite(Struct rawStruct) {
this.rawStruct = rawStruct;
}
protected JDBCComposite(@NotNull JDBCComposite struct, @NotNull DBRProgressMonitor monitor) throws DBCException {
this.type = struct.type;
this.attributes = Arrays.copyOf(struct.attributes, struct.attributes.length);
......@@ -102,7 +109,7 @@ public abstract class JDBCComposite implements DBDComposite, DBDValueCloneable {
public String getStringRepresentation()
{
return getTypeName();
return CommonUtils.toString(getRawValue());
}
@NotNull
......@@ -111,6 +118,9 @@ public abstract class JDBCComposite implements DBDComposite, DBDValueCloneable {
}
public Struct getStructValue() throws DBCException {
if (rawStruct != null) {
return rawStruct;
}
Object[] attrs = new Object[values.length];
for (int i = 0; i < values.length; i++) {
Object attr = values[i];
......@@ -124,7 +134,7 @@ public abstract class JDBCComposite implements DBDComposite, DBDValueCloneable {
if (session instanceof Connection) {
return ((Connection) session).createStruct(dataType.getTypeName(), attrs);
} else {
return new JDBCStructImpl(dataType.getTypeName(), attrs);
return new JDBCStructImpl(dataType.getTypeName(), attrs, getStringRepresentation());
}
} catch (Throwable e) {
throw new DBCException("Error creating struct", e);
......@@ -139,6 +149,9 @@ public abstract class JDBCComposite implements DBDComposite, DBDValueCloneable {
@Override
public Struct getRawValue() {
if (rawStruct != null) {
return rawStruct;
}
try {
return getStructValue();
} catch (Throwable e) {
......@@ -269,8 +282,8 @@ public abstract class JDBCComposite implements DBDComposite, DBDValueCloneable {
return CommonUtils.equalObjects(name, attr.name) &&
valueType == attr.valueType &&
maxLength == attr.maxLength &&
scale == attr.scale &&
precision == attr.precision &&
CommonUtils.equalObjects(scale, attr.scale) &&
CommonUtils.equalObjects(precision, attr.precision) &&
CommonUtils.equalObjects(typeName, attr.typeName) &&
ordinalPosition == attr.ordinalPosition;
}
......
......@@ -46,6 +46,8 @@ public class JDBCCompositeDynamic extends JDBCComposite {
public JDBCCompositeDynamic(@NotNull DBCSession session, @Nullable Struct contents, @Nullable ResultSetMetaData metaData) throws DBCException
{
super(contents);
this.type = new StructType(session.getDataSource());
// Extract structure data
......
......@@ -48,6 +48,7 @@ public class JDBCCompositeStatic extends JDBCComposite {
public JDBCCompositeStatic(DBCSession session, @NotNull DBSDataType type, @Nullable Struct contents) throws DBCException
{
super(contents);
this.type = type;
// Extract structure data
......
......@@ -127,7 +127,7 @@ public class JDBCStructValueHandler extends JDBCComplexValueHandler implements D
}
}
if (object == null) {
return new JDBCCompositeStatic(session, dataType, new JDBCStructImpl(dataType.getTypeName(), null));
return new JDBCCompositeStatic(session, dataType, new JDBCStructImpl(dataType.getTypeName(), null, ""));
} else if (object instanceof JDBCCompositeStatic) {
return copy ? ((JDBCCompositeStatic) object).cloneValue(session.getProgressMonitor()) : object;
} else if (object instanceof Struct) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册