提交 7e105cd2 编写于 作者: S Serge Rider

#438 Properties custom format.

DB2 plan costs format.
上级 73b6291f
......@@ -34,6 +34,10 @@ import org.osgi.framework.FrameworkUtil;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.DecimalFormat;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.ResourceBundle;
/**
......@@ -48,6 +52,7 @@ public class ObjectPropertyDescriptor extends ObjectAttributeDescriptor implemen
private IPropertyValueTransformer valueTransformer;
private IPropertyValueTransformer valueRenderer;
private final Class<?> declaringClass;
private Format displayFormat = null;
public ObjectPropertyDescriptor(
DBPPropertySource source,
......@@ -123,6 +128,12 @@ public class ObjectPropertyDescriptor extends ObjectAttributeDescriptor implemen
return propType != null && BeanUtils.isNumericType(propType);
}
public boolean isDateTime()
{
Class<?> propType = getGetter().getReturnType();
return propType != null && Date.class.isAssignableFrom(propType);
}
public boolean supportsPreview()
{
return propInfo.supportsPreview();
......@@ -177,6 +188,24 @@ public class ObjectPropertyDescriptor extends ObjectAttributeDescriptor implemen
return propName;
}
public Format getDisplayFormat() {
if (displayFormat == null) {
final String format = propInfo.format();
if (format == null || format.isEmpty()) {
return null;
}
if (isNumeric()) {
displayFormat = new DecimalFormat(format);
} else if (isDateTime()) {
displayFormat = new SimpleDateFormat(format);
} else {
log.debug("Don't know how to apply format to property " + getId());
displayFormat = null;
}
}
return displayFormat;
}
public Object readValue(Object object, DBRProgressMonitor progressMonitor)
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
......@@ -202,6 +231,12 @@ public class ObjectPropertyDescriptor extends ObjectAttributeDescriptor implemen
if (valueRenderer != null) {
value = valueRenderer.transform(object, value);
}
if (value instanceof Number) {
final Format displayFormat = getDisplayFormat();
if (displayFormat != null) {
return displayFormat.format(value);
}
}
return value;
}
......
......@@ -92,6 +92,8 @@ public class DB2Constants {
public static final String CAT_STATS = "Statistics";
public static final String CAT_TABLESPACE = "Tablespace";
public static final String PLAN_COST_FORMAT = "###,###,###,##0.000";
// Schema for system datatypes
public static final String SYSTEM_DATATYPE_SCHEMA = "SYSIBM";
......
......@@ -209,7 +209,7 @@ public class DB2PlanObject extends DB2PlanNode {
return displayName;
}
@Property(editable = false, viewable = true, order = 2, category = DB2Constants.CAT_PERFORMANCE)
@Property(editable = false, viewable = true, order = 2, category = DB2Constants.CAT_PERFORMANCE, format = DB2Constants.PLAN_COST_FORMAT)
public Double getEstimatedCardinality()
{
return Double.valueOf(rowCount);
......
......@@ -18,10 +18,7 @@
*/
package org.jkiss.dbeaver.ext.db2.model.plan;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.jkiss.dbeaver.ext.db2.DB2Constants;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
......@@ -29,6 +26,10 @@ import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.utils.CommonUtils;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* DB2 EXPLAIN_OPERATOR table
*
......@@ -141,13 +142,13 @@ public class DB2PlanOperator extends DB2PlanNode {
return ""; // Looks better without a name...
}
@Property(viewable = true, order = 4)
@Property(viewable = true, order = 4, format = DB2Constants.PLAN_COST_FORMAT)
public Double getTotalCost()
{
return totalCost;
}
@Property(viewable = true, order = 5)
@Property(viewable = true, order = 5, format = DB2Constants.PLAN_COST_FORMAT)
public Double getEstimatedCardinality()
{
return estimatedCardinality;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册