提交 16a62526 编写于 作者: S Serge Rider

Attribute transformers model

上级 6f0a8306
......@@ -2401,8 +2401,25 @@
id="org.jkiss.dbeaver.core.EpochTimeAttributeTransformer"
name="Epoch Time"
description="Evaluate integer value as timestamp in Epoch (C, Unix, Java, etc) time"
applyByDefault="false">
applyByDefault="false"
custom="true">
<type kind="NUMERIC"/>
<propertyGroup label="Properties">
<property id="unit" label="Unit" type="string" description="Measure unit - seconds, milliseconds, etc" defaultValue="milliseconds" required="true" validValues="seconds,milliseconds,nanoseconds"/>
</propertyGroup>
</transformer>
<transformer
class="org.jkiss.dbeaver.model.impl.data.transformers.RadixAttributeTransformer"
id="org.jkiss.dbeaver.core.RadixAttributeTransformer"
name="Number Radix"
description="Represents numbers in a specified radix"
applyByDefault="false"
custom="true">
<type kind="NUMERIC"/>
<propertyGroup label="Properties">
<property id="radix" label="Radix" type="integer" description="Number radix" defaultValue="10" required="true" validValues="2,8,10,16,32"/>
<property id="prefix" label="Show prefix" type="boolean" description="Shows radix prefix (0x for hex)" defaultValue="false" required="true"/>
</propertyGroup>
</transformer>
</extension>
......
......@@ -254,11 +254,11 @@ public abstract class DBDAttributeBinding implements DBSObject, DBSAttributeBase
public void lateBinding(@NotNull DBCSession session, List<Object[]> rows) throws DBException {
DBSAttributeBase attribute = getAttribute();
final DBDAttributeTransformer[] transformers = DBVUtils.findAttributeTransformers(this, false);
final DBDAttributeTransformer[] transformers = DBVUtils.findAttributeTransformers(this, null);
if (transformers != null) {
session.getProgressMonitor().subTask("Transform attribute '" + attribute.getName() + "'");
for (DBDAttributeTransformer transformer : transformers) {
transformer.transformAttribute(session, this, rows);
transformer.transformAttribute(session, this, rows, null);
}
}
}
......
......@@ -23,6 +23,7 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.exec.DBCSession;
import java.util.List;
import java.util.Map;
/**
* DBD binding transformer.
......@@ -33,7 +34,11 @@ public interface DBDAttributeTransformer
/**
* Transforms attribute
*/
void transformAttribute(@NotNull DBCSession session, @NotNull DBDAttributeBinding attribute, @NotNull List<Object[]> rows)
void transformAttribute(
@NotNull DBCSession session,
@NotNull DBDAttributeBinding attribute,
@NotNull List<Object[]> rows,
@NotNull Map<String, Object> options)
throws DBException;
}
......@@ -28,6 +28,7 @@ import org.jkiss.dbeaver.model.struct.DBSEntity;
import org.jkiss.dbeaver.model.struct.DBSTypedObjectEx;
import java.util.List;
import java.util.Map;
/**
* Transforms attribute of array type into hierarchy of attributes
......@@ -35,7 +36,7 @@ import java.util.List;
public class ArrayAttributeTransformer implements DBDAttributeTransformer {
@Override
public void transformAttribute(@NotNull DBCSession session, @NotNull DBDAttributeBinding attribute, @NotNull List<Object[]> rows) throws DBException {
public void transformAttribute(@NotNull DBCSession session, @NotNull DBDAttributeBinding attribute, @NotNull List<Object[]> rows, Map<String, Object> options) throws DBException {
DBSDataType collectionType;
if (attribute.getAttribute() instanceof DBSTypedObjectEx) {
collectionType = ((DBSTypedObjectEx) attribute.getAttribute()).getDataType();
......
......@@ -32,6 +32,7 @@ import org.jkiss.utils.CommonUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Transforms attribute of complex type into hierarchy of attributes
......@@ -39,7 +40,7 @@ import java.util.List;
public class ComplexTypeAttributeTransformer implements DBDAttributeTransformer {
@Override
public void transformAttribute(@NotNull DBCSession session, @NotNull DBDAttributeBinding attribute, @NotNull List<Object[]> rows) throws DBException {
public void transformAttribute(@NotNull DBCSession session, @NotNull DBDAttributeBinding attribute, @NotNull List<Object[]> rows, Map<String, Object> options) throws DBException {
DBSDataType dataType;
if (attribute.getAttribute() instanceof DBSTypedObjectEx) {
dataType = ((DBSTypedObjectEx) attribute.getAttribute()).getDataType();
......
......@@ -30,6 +30,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
/**
* Transforms numeric attribute value into epoch time
......@@ -37,7 +38,7 @@ import java.util.Locale;
public class EpochTimeAttributeTransformer implements DBDAttributeTransformer {
@Override
public void transformAttribute(@NotNull DBCSession session, @NotNull DBDAttributeBinding attribute, @NotNull List<Object[]> rows) throws DBException {
public void transformAttribute(@NotNull DBCSession session, @NotNull DBDAttributeBinding attribute, @NotNull List<Object[]> rows, Map<String, Object> options) throws DBException {
// TODO: Change attribute type (to DATETIME)
attribute.setValueHandler(new EpochValueHandler(attribute.getValueHandler()));
}
......
......@@ -28,6 +28,7 @@ import org.jkiss.utils.Pair;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* Transforms attribute of map type into hierarchy of attributes
......@@ -35,7 +36,7 @@ import java.util.List;
public class MapAttributeTransformer implements DBDAttributeTransformer {
@Override
public void transformAttribute(@NotNull DBCSession session, @NotNull DBDAttributeBinding attribute, @NotNull List<Object[]> rows) throws DBException {
public void transformAttribute(@NotNull DBCSession session, @NotNull DBDAttributeBinding attribute, @NotNull List<Object[]> rows, Map<String, Object> options) throws DBException {
resolveMapsFromData(session, attribute, rows);
}
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.model.impl.data.transformers;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.data.DBDAttributeBinding;
import org.jkiss.dbeaver.model.data.DBDAttributeTransformer;
import org.jkiss.dbeaver.model.data.DBDDisplayFormat;
import org.jkiss.dbeaver.model.data.DBDValueHandler;
import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.impl.data.ProxyValueHandler;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import java.util.List;
import java.util.Map;
/**
* Transforms numeric attribute value into string in a specified radix
*/
public class RadixAttributeTransformer implements DBDAttributeTransformer {
@Override
public void transformAttribute(@NotNull DBCSession session, @NotNull DBDAttributeBinding attribute, @NotNull List<Object[]> rows, Map<String, Object> options) throws DBException {
attribute.setValueHandler(new RadixValueHandler(attribute.getValueHandler()));
}
private class RadixValueHandler extends ProxyValueHandler {
public RadixValueHandler(DBDValueHandler target) {
super(target);
}
@NotNull
@Override
public String getValueDisplayString(@NotNull DBSTypedObject column, @Nullable Object value, @NotNull DBDDisplayFormat format) {
if (value instanceof Number) {
return Long.toHexString(((Number) value).longValue());
}
return DBUtils.getDefaultValueDisplayString(value, format);
}
}
}
......@@ -31,7 +31,7 @@ import java.util.Set;
public class DBVTransformSettings {
private Set<String> excludedTransformers, includedTransformers;
private String customTransformer;
private Map<String, String> rendererProperties;
private Map<String, Object> transformOptions;
public Set<String> getExcludedTransformers() {
return excludedTransformers;
......@@ -70,8 +70,8 @@ public class DBVTransformSettings {
return customTransformer;
}
public Map<String, String> getRendererProperties() {
return rendererProperties;
public Map<String, Object> getTransformOptions() {
return transformOptions;
}
public boolean hasValuableData() {
......
......@@ -71,7 +71,7 @@ public abstract class DBVUtils {
}
@Nullable
public static DBDAttributeTransformer[] findAttributeTransformers(DBDAttributeBinding binding, boolean custom)
public static DBDAttributeTransformer[] findAttributeTransformers(DBDAttributeBinding binding, Boolean custom)
{
DBPDataSource dataSource = binding.getDataSource();
DBPDataSourceContainer container = dataSource.getContainer();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册