提交 595d50aa 编写于 作者: S serge-rider

Data type registry

上级 d4f73944
......@@ -9,6 +9,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Export-Package: org.jkiss.dbeaver,
org.jkiss.dbeaver.core,
org.jkiss.dbeaver.registry,
org.jkiss.dbeaver.registry.datatype,
org.jkiss.dbeaver.registry.driver,
org.jkiss.dbeaver.registry.editor,
org.jkiss.dbeaver.registry.encode,
......
......@@ -31,7 +31,7 @@ import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBPApplication;
import org.jkiss.dbeaver.model.DBPPreferenceStore;
import org.jkiss.dbeaver.model.DBPProjectManager;
import org.jkiss.dbeaver.model.data.DBDValueHandlerRegistry;
import org.jkiss.dbeaver.model.data.DBDRegistry;
import org.jkiss.dbeaver.model.edit.DBERegistry;
import org.jkiss.dbeaver.model.navigator.DBNModel;
import org.jkiss.dbeaver.model.qm.QMController;
......@@ -40,7 +40,7 @@ import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableContext;
import org.jkiss.dbeaver.model.runtime.OSDescriptor;
import org.jkiss.dbeaver.registry.DataSourceProviderRegistry;
import org.jkiss.dbeaver.registry.DataTypeProviderRegistry;
import org.jkiss.dbeaver.registry.datatype.DataTypeProviderRegistry;
import org.jkiss.dbeaver.registry.PluginServiceRegistry;
import org.jkiss.dbeaver.registry.ProjectRegistry;
import org.jkiss.dbeaver.registry.editor.EntityEditorsRegistry;
......@@ -360,7 +360,7 @@ public class DBeaverCore implements DBPApplication {
@NotNull
@Override
public DBDValueHandlerRegistry getValueHandlerRegistry() {
public DBDRegistry getValueHandlerRegistry() {
return DataTypeProviderRegistry.getInstance();
}
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 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.registry;
import org.eclipse.core.runtime.IConfigurationElement;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.data.DBDAttributeTransformer;
import org.jkiss.dbeaver.model.data.DBDValueHandlerProvider;
import org.jkiss.dbeaver.model.impl.AbstractDescriptor;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
/**
* DataTypeTransformerDescriptor
*/
public class DataTypeTransformerDescriptor extends AbstractDescriptor
{
static final Log log = Log.getLog(DataTypeTransformerDescriptor.class);
private String id;
private ObjectType implType;
private Set<Object> supportedTypes = new HashSet<>();
private Set<DataSourceProviderDescriptor> supportedDataSources = new HashSet<>();
private DBDAttributeTransformer instance;
public DataTypeTransformerDescriptor(IConfigurationElement config)
{
super(config);
this.id = config.getAttribute(RegistryConstants.ATTR_ID);
this.implType = new ObjectType(config.getAttribute(RegistryConstants.ATTR_CLASS));
IConfigurationElement[] typeElements = config.getChildren(RegistryConstants.TAG_TYPE);
for (IConfigurationElement typeElement : typeElements) {
String typeName = typeElement.getAttribute(RegistryConstants.ATTR_NAME);
if (typeName != null) {
supportedTypes.add(typeName.toLowerCase(Locale.ENGLISH));
} else {
typeName = typeElement.getAttribute(RegistryConstants.ATTR_STANDARD);
if (typeName == null) {
typeName = typeElement.getAttribute(RegistryConstants.ATTR_ID);
if (typeName == null) {
log.warn("Type element without name or standard type reference"); //$NON-NLS-1$
continue;
}
try {
int typeNumber = Integer.parseInt(typeName);
supportedTypes.add(typeNumber);
} catch (NumberFormatException e) {
log.warn("Type ID must be an integer while '" + typeName + "' was specified"); //$NON-NLS-1$
}
} else {
try {
Field typeField = java.sql.Types.class.getField(typeName);
int typeNumber = typeField.getInt(null);
supportedTypes.add(typeNumber);
} catch (NoSuchFieldException e) {
log.warn("Standard type '" + typeName + "' not found in " + java.sql.Types.class.getName(), e); //$NON-NLS-1$
} catch (IllegalAccessException e) {
log.warn("Standard type '" + typeName + "' cannot be accessed", e); //$NON-NLS-1$
}
}
}
}
IConfigurationElement[] dsElements = config.getChildren(RegistryConstants.TAG_DATASOURCE);
for (IConfigurationElement dsElement : dsElements) {
String dsId = dsElement.getAttribute(RegistryConstants.ATTR_ID);
if (dsId == null) {
log.warn("Datasource reference with null ID"); //$NON-NLS-1$
continue;
}
DataSourceProviderDescriptor dsProvider = DataSourceProviderRegistry.getInstance().getDataSourceProvider(dsId);
if (dsProvider == null) {
log.warn("Datasource provider '" + dsId + "' not found. Bad data type mapping."); //$NON-NLS-1$
continue;
}
supportedDataSources.add(dsProvider);
}
}
public String getId()
{
return id;
}
public DBDAttributeTransformer getInstance()
{
if (instance == null && implType != null) {
try {
this.instance = implType.createInstance(DBDAttributeTransformer.class);
}
catch (Exception e) {
log.error("Can't instantiate attribute transformer '" + this.id + "'", e); //$NON-NLS-1$
}
}
return instance;
}
public boolean supportsType(DBSTypedObject typedObject)
{
String typeName = typedObject.getTypeName();
return
supportedTypes.contains(typedObject.getTypeID()) ||
(typeName != null && supportedTypes.contains(typeName.toLowerCase(Locale.ENGLISH))) ||
supportedTypes.contains(typedObject.getDataKind());
}
public Set<Object> getSupportedTypes()
{
return supportedTypes;
}
public boolean isDefault()
{
return supportedDataSources.isEmpty();
}
public boolean supportsDataSource(DataSourceProviderDescriptor descriptor)
{
return supportedDataSources.contains(descriptor);
}
public Set<DataSourceProviderDescriptor> getSupportedDataSources()
{
return supportedDataSources;
}
}
\ No newline at end of file
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 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.registry;
import org.jkiss.dbeaver.Log;
import org.eclipse.core.runtime.IConfigurationElement;
import org.jkiss.dbeaver.model.data.DBDValueHandlerProvider;
import org.jkiss.dbeaver.model.impl.AbstractDescriptor;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
/**
* DataTypeProviderDescriptor
*/
public class DataTypeProviderDescriptor extends AbstractDescriptor
{
static final Log log = Log.getLog(DataTypeProviderDescriptor.class);
private static final String ALL_TYPES_PATTERN = "*";
private String id;
private ObjectType implType;
private Set<Object> supportedTypes = new HashSet<>();
private Set<DataSourceProviderDescriptor> supportedDataSources = new HashSet<>();
private DBDValueHandlerProvider instance;
public DataTypeProviderDescriptor(IConfigurationElement config)
{
super(config);
this.id = config.getAttribute(RegistryConstants.ATTR_ID);
this.implType = new ObjectType(config.getAttribute(RegistryConstants.ATTR_CLASS));
IConfigurationElement[] typeElements = config.getChildren(RegistryConstants.TAG_TYPE);
for (IConfigurationElement typeElement : typeElements) {
String typeName = typeElement.getAttribute(RegistryConstants.ATTR_NAME);
if (typeName != null) {
supportedTypes.add(typeName.toLowerCase(Locale.ENGLISH));
} else {
typeName = typeElement.getAttribute(RegistryConstants.ATTR_STANDARD);
if (typeName == null) {
typeName = typeElement.getAttribute(RegistryConstants.ATTR_ID);
if (typeName == null) {
log.warn("Type element without name or standard type reference"); //$NON-NLS-1$
continue;
}
try {
int typeNumber = Integer.parseInt(typeName);
supportedTypes.add(typeNumber);
} catch (NumberFormatException e) {
log.warn("Type ID must be an integer while '" + typeName + "' was specified"); //$NON-NLS-1$
}
} else {
try {
Field typeField = java.sql.Types.class.getField(typeName);
int typeNumber = typeField.getInt(null);
supportedTypes.add(typeNumber);
} catch (NoSuchFieldException e) {
log.warn("Standard type '" + typeName + "' not found in " + java.sql.Types.class.getName(), e); //$NON-NLS-1$
} catch (IllegalAccessException e) {
log.warn("Standard type '" + typeName + "' cannot be accessed", e); //$NON-NLS-1$
}
}
}
}
IConfigurationElement[] dsElements = config.getChildren(RegistryConstants.TAG_DATASOURCE);
for (IConfigurationElement dsElement : dsElements) {
String dsId = dsElement.getAttribute(RegistryConstants.ATTR_ID);
if (dsId == null) {
log.warn("Datasource reference with null ID"); //$NON-NLS-1$
continue;
}
DataSourceProviderDescriptor dsProvider = DataSourceProviderRegistry.getInstance().getDataSourceProvider(dsId);
if (dsProvider == null) {
log.warn("Datasource provider '" + dsId + "' not found. Bad data type mapping."); //$NON-NLS-1$
continue;
}
supportedDataSources.add(dsProvider);
}
}
public String getId()
{
return id;
}
public DBDValueHandlerProvider getInstance()
{
if (instance == null && implType != null) {
try {
this.instance = implType.createInstance(DBDValueHandlerProvider.class);
}
catch (Exception e) {
log.error("Can't instantiate data type provider '" + this.id + "'", e); //$NON-NLS-1$
}
}
return instance;
}
public boolean supportsType(DBSTypedObject typedObject)
{
String typeName = typedObject.getTypeName();
return
supportedTypes.contains(typedObject.getTypeID()) ||
(typeName != null && supportedTypes.contains(typeName.toLowerCase(Locale.ENGLISH))) ||
supportedTypes.contains(ALL_TYPES_PATTERN);
}
public Set<Object> getSupportedTypes()
{
return supportedTypes;
}
public boolean isDefault()
{
return supportedDataSources.isEmpty();
}
public boolean supportsDataSource(DataSourceProviderDescriptor descriptor)
{
return supportedDataSources.contains(descriptor);
}
public Set<DataSourceProviderDescriptor> getSupportedDataSources()
{
return supportedDataSources;
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 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.registry.datatype;
import org.eclipse.core.runtime.IConfigurationElement;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.data.DBDRegistryDescriptor;
import org.jkiss.dbeaver.model.impl.AbstractDescriptor;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.dbeaver.registry.DataSourceProviderDescriptor;
import org.jkiss.dbeaver.registry.DataSourceProviderRegistry;
import org.jkiss.dbeaver.registry.RegistryConstants;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
/**
* DataTypeAbstractDescriptor
*/
public abstract class DataTypeAbstractDescriptor<DESCRIPTOR> extends AbstractDescriptor implements DBDRegistryDescriptor<DESCRIPTOR>
{
private static final Log log = Log.getLog(DataTypeProviderDescriptor.class);
public static final String ALL_TYPES_PATTERN = "*";
private final Class<DESCRIPTOR> instanceType;
private final String id;
private final String name;
private final String description;
private ObjectType implType;
private Set<Object> supportedTypes = new HashSet<>();
private Set<DataSourceProviderDescriptor> supportedDataSources = new HashSet<>();
protected DESCRIPTOR instance;
public DataTypeAbstractDescriptor(IConfigurationElement config, Class<DESCRIPTOR> instanceType)
{
super(config);
this.instanceType = instanceType;
this.id = config.getAttribute(RegistryConstants.ATTR_ID);
this.name = config.getAttribute(RegistryConstants.ATTR_NAME);
this.description = config.getAttribute(RegistryConstants.ATTR_DESCRIPTION);
this.implType = new ObjectType(config.getAttribute(RegistryConstants.ATTR_CLASS));
IConfigurationElement[] typeElements = config.getChildren(RegistryConstants.TAG_TYPE);
for (IConfigurationElement typeElement : typeElements) {
String typeName = typeElement.getAttribute(RegistryConstants.ATTR_NAME);
if (typeName != null) {
supportedTypes.add(typeName.toLowerCase(Locale.ENGLISH));
} else {
typeName = typeElement.getAttribute(RegistryConstants.ATTR_STANDARD);
if (typeName == null) {
typeName = typeElement.getAttribute(RegistryConstants.ATTR_ID);
if (typeName == null) {
log.warn("Type element without name or standard type reference"); //$NON-NLS-1$
continue;
}
try {
int typeNumber = Integer.parseInt(typeName);
supportedTypes.add(typeNumber);
} catch (NumberFormatException e) {
log.warn("Type ID must be an integer while '" + typeName + "' was specified"); //$NON-NLS-1$
}
} else {
try {
Field typeField = java.sql.Types.class.getField(typeName);
int typeNumber = typeField.getInt(null);
supportedTypes.add(typeNumber);
} catch (NoSuchFieldException e) {
log.warn("Standard type '" + typeName + "' not found in " + java.sql.Types.class.getName(), e); //$NON-NLS-1$
} catch (IllegalAccessException e) {
log.warn("Standard type '" + typeName + "' cannot be accessed", e); //$NON-NLS-1$
}
}
}
}
IConfigurationElement[] dsElements = config.getChildren(RegistryConstants.TAG_DATASOURCE);
for (IConfigurationElement dsElement : dsElements) {
String dsId = dsElement.getAttribute(RegistryConstants.ATTR_ID);
if (dsId == null) {
log.warn("Datasource reference with null ID"); //$NON-NLS-1$
continue;
}
DataSourceProviderDescriptor dsProvider = DataSourceProviderRegistry.getInstance().getDataSourceProvider(dsId);
if (dsProvider == null) {
log.warn("Datasource provider '" + dsId + "' not found. Bad data type mapping."); //$NON-NLS-1$
continue;
}
supportedDataSources.add(dsProvider);
}
}
@Override
public String getId()
{
return id;
}
@Override
public String getName() {
return name;
}
@Override
public String getDescription() {
return description;
}
@Override
public DESCRIPTOR getInstance()
{
if (instance == null && implType != null) {
try {
this.instance = implType.createInstance(instanceType);
}
catch (Exception e) {
log.error("Can't instantiate data type provider '" + this.id + "'", e); //$NON-NLS-1$
}
}
return instance;
}
public boolean supportsType(DBSTypedObject typedObject)
{
String typeName = typedObject.getTypeName();
return
supportedTypes.contains(typedObject.getTypeID()) ||
(typeName != null && supportedTypes.contains(typeName.toLowerCase(Locale.ENGLISH))) ||
supportedTypes.contains(ALL_TYPES_PATTERN);
}
public Set<Object> getSupportedTypes()
{
return supportedTypes;
}
public boolean isDefault()
{
return supportedDataSources.isEmpty();
}
public boolean supportsDataSource(DataSourceProviderDescriptor descriptor)
{
return supportedDataSources.contains(descriptor);
}
public Set<DataSourceProviderDescriptor> getSupportedDataSources()
{
return supportedDataSources;
}
}
\ No newline at end of file
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 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.registry.datatype;
import org.eclipse.core.runtime.IConfigurationElement;
import org.jkiss.dbeaver.model.data.DBDValueHandlerProvider;
/**
* DataTypeProviderDescriptor
*/
public class DataTypeProviderDescriptor extends DataTypeAbstractDescriptor<DBDValueHandlerProvider>
{
public DataTypeProviderDescriptor(IConfigurationElement config)
{
super(config, DBDValueHandlerProvider.class);
}
}
\ No newline at end of file
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 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.registry;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.connection.DBPDriver;
import org.jkiss.dbeaver.model.data.DBDAttributeTransformer;
import org.jkiss.dbeaver.model.data.DBDValueHandlerProvider;
import org.jkiss.dbeaver.model.data.DBDValueHandlerRegistry;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.dbeaver.registry.driver.DriverDescriptor;
import java.util.ArrayList;
import java.util.List;
/**
* DataTypeProviderRegistry
*/
public class DataTypeProviderRegistry implements DBDValueHandlerRegistry
{
static final Log log = Log.getLog(DataTypeProviderRegistry.class);
public static final String EXTENSION_ID = "org.jkiss.dbeaver.dataTypeProvider"; //$NON-NLS-1$
private static DataTypeProviderRegistry instance = null;
public synchronized static DataTypeProviderRegistry getInstance()
{
if (instance == null) {
instance = new DataTypeProviderRegistry();
instance.loadExtensions(Platform.getExtensionRegistry());
}
return instance;
}
private final List<DataTypeProviderDescriptor> dataTypeProviders = new ArrayList<>();
private DataTypeProviderRegistry()
{
}
public void loadExtensions(IExtensionRegistry registry)
{
// Load data type providers from external plugins
{
IConfigurationElement[] extElements = registry.getConfigurationElementsFor(EXTENSION_ID);
for (IConfigurationElement ext : extElements) {
if ("provider".equals(ext.getName())) {
DataTypeProviderDescriptor provider = new DataTypeProviderDescriptor(ext);
dataTypeProviders.add(provider);
} else if ("transformer".equals(ext.getName())) {
}
}
}
}
public void dispose()
{
this.dataTypeProviders.clear();
}
////////////////////////////////////////////////////
// DataType providers
@Nullable
public DBDValueHandlerProvider getDataTypeProvider(DBPDataSource dataSource, DBSTypedObject typedObject)
{
DBPDriver driver = dataSource.getContainer().getDriver();
if (!(driver instanceof DriverDescriptor)) {
log.warn("Bad datasource specified (driver is not recognized by registry) - " + dataSource);
return null;
}
DataSourceProviderDescriptor dsProvider = ((DriverDescriptor) driver).getProviderDescriptor();
// First try to find type provider for specific datasource type
for (DataTypeProviderDescriptor dtProvider : dataTypeProviders) {
if (!dtProvider.isDefault() && dtProvider.supportsDataSource(dsProvider) && dtProvider.supportsType(typedObject)) {
return dtProvider.getInstance();
}
}
// Find in default providers
for (DataTypeProviderDescriptor dtProvider : dataTypeProviders) {
if (dtProvider.isDefault() && dtProvider.supportsType(typedObject)) {
return dtProvider.getInstance();
}
}
return null;
}
public DBDAttributeTransformer[] findTransformers(DBPDataSource dataSource, DBSTypedObject typedObject) {
return null;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 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.registry.datatype;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.connection.DBPDriver;
import org.jkiss.dbeaver.model.data.DBDRegistry;
import org.jkiss.dbeaver.model.data.DBDValueHandlerProvider;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.dbeaver.registry.DataSourceProviderDescriptor;
import org.jkiss.dbeaver.registry.driver.DriverDescriptor;
import java.util.ArrayList;
import java.util.List;
/**
* DataTypeProviderRegistry
*/
public class DataTypeProviderRegistry implements DBDRegistry
{
static final Log log = Log.getLog(DataTypeProviderRegistry.class);
public static final String EXTENSION_ID = "org.jkiss.dbeaver.dataTypeProvider"; //$NON-NLS-1$
private static DataTypeProviderRegistry instance = null;
public synchronized static DataTypeProviderRegistry getInstance()
{
if (instance == null) {
instance = new DataTypeProviderRegistry();
instance.loadExtensions(Platform.getExtensionRegistry());
}
return instance;
}
private final List<DataTypeProviderDescriptor> dataTypeProviders = new ArrayList<>();
private final List<DataTypeTransformerDescriptor> dataTypeTransformers = new ArrayList<>();
private final List<DataTypeRendererDescriptor> dataTypeRenderers = new ArrayList<>();
private DataTypeProviderRegistry()
{
}
public void loadExtensions(IExtensionRegistry registry)
{
// Load data type providers from external plugins
{
IConfigurationElement[] extElements = registry.getConfigurationElementsFor(EXTENSION_ID);
for (IConfigurationElement ext : extElements) {
if ("provider".equals(ext.getName())) {
DataTypeProviderDescriptor provider = new DataTypeProviderDescriptor(ext);
dataTypeProviders.add(provider);
} else if ("transformer".equals(ext.getName())) {
dataTypeTransformers.add(new DataTypeTransformerDescriptor(ext));
} else if ("renderer".equals(ext.getName())) {
dataTypeRenderers.add(new DataTypeRendererDescriptor(ext));
}
}
}
}
public void dispose()
{
this.dataTypeProviders.clear();
}
////////////////////////////////////////////////////
// DataType providers
@Nullable
public DBDValueHandlerProvider getDataTypeProvider(DBPDataSource dataSource, DBSTypedObject typedObject)
{
DBPDriver driver = dataSource.getContainer().getDriver();
if (!(driver instanceof DriverDescriptor)) {
log.warn("Bad datasource specified (driver is not recognized by registry) - " + dataSource);
return null;
}
DataSourceProviderDescriptor dsProvider = ((DriverDescriptor) driver).getProviderDescriptor();
// First try to find type provider for specific datasource type
for (DataTypeProviderDescriptor dtProvider : dataTypeProviders) {
if (!dtProvider.isDefault() && dtProvider.supportsDataSource(dsProvider) && dtProvider.supportsType(typedObject)) {
return dtProvider.getInstance();
}
}
// Find in default providers
for (DataTypeProviderDescriptor dtProvider : dataTypeProviders) {
if (dtProvider.isDefault() && dtProvider.supportsType(typedObject)) {
return dtProvider.getInstance();
}
}
return null;
}
@Override
public DataTypeTransformerDescriptor[] findTransformers(DBPDataSource dataSource, DBSTypedObject typedObject) {
for (DataTypeTransformerDescriptor descriptor : dataTypeTransformers) {
//descriptor.supportsDataSource()
}
return null;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 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.registry.datatype;
import org.eclipse.core.runtime.IConfigurationElement;
import org.jkiss.dbeaver.model.data.DBDValueRenderer;
import org.jkiss.dbeaver.registry.RegistryConstants;
/**
* DataTypeRendererDescriptor
*/
public class DataTypeRendererDescriptor extends DataTypeAbstractDescriptor<DBDValueRenderer>
{
private String name;
private String description;
public DataTypeRendererDescriptor(IConfigurationElement config)
{
super(config, DBDValueRenderer.class);
this.name = config.getAttribute(RegistryConstants.ATTR_NAME);
this.description = config.getAttribute(RegistryConstants.ATTR_DESCRIPTION);
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
}
\ No newline at end of file
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 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.registry.datatype;
import org.eclipse.core.runtime.IConfigurationElement;
import org.jkiss.dbeaver.model.data.DBDAttributeTransformer;
import org.jkiss.dbeaver.registry.RegistryConstants;
/**
* DataTypeTransformerDescriptor
*/
public class DataTypeTransformerDescriptor extends DataTypeAbstractDescriptor<DBDAttributeTransformer>
{
public DataTypeTransformerDescriptor(IConfigurationElement config)
{
super(config, DBDAttributeTransformer.class);
}
}
\ No newline at end of file
......@@ -21,7 +21,7 @@ package org.jkiss.dbeaver.model;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.data.DBDValueHandlerRegistry;
import org.jkiss.dbeaver.model.data.DBDRegistry;
import org.jkiss.dbeaver.model.edit.DBERegistry;
import org.jkiss.dbeaver.model.navigator.DBNModel;
import org.jkiss.dbeaver.model.qm.QMController;
......@@ -51,7 +51,7 @@ public interface DBPApplication
QMController getQueryManager();
@NotNull
DBDValueHandlerRegistry getValueHandlerRegistry();
DBDRegistry getValueHandlerRegistry();
@NotNull
DBERegistry getEditorsRegistry();
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 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.data;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
/**
* DBDValueHandlerRegistry
*/
public interface DBDValueHandlerRegistry
{
@Nullable
DBDValueHandlerProvider getDataTypeProvider(DBPDataSource dataSource, DBSTypedObject typedObject);
@Nullable
DBDAttributeTransformer[] findTransformers(DBPDataSource dataSource, DBSTypedObject typedObject);
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 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.data;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
/**
* DBDValueHandlerRegistry
*/
public interface DBDRegistry
{
@Nullable
DBDValueHandlerProvider getDataTypeProvider(DBPDataSource dataSource, DBSTypedObject typedObject);
@Nullable
DBDRegistryDescriptor<DBDAttributeTransformer>[] findTransformers(DBPDataSource dataSource, DBSTypedObject typedObject);
}
\ No newline at end of file
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 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.data;
/**
* DBDRegistryDescriptor
*/
public interface DBDRegistryDescriptor<TYPE>
{
String getId();
String getName();
String getDescription();
TYPE getInstance();
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册