提交 9dd36d08 编写于 作者: J jurgen

SQL dialect model initial interfaces

Former-commit-id: 13fecb26
上级 61e787c6
......@@ -4,6 +4,7 @@ Major:
2. Async autocomplete
3. Check on MacOS
4. Query manager fixes. + keep only primitive props + persistence
5. Client-side filters
Minor:
......
......@@ -44,6 +44,7 @@ Export-Package: org.apache.commons.logging,
org.jkiss.dbeaver.model.project,
org.jkiss.dbeaver.model.qm,
org.jkiss.dbeaver.model.runtime,
org.jkiss.dbeaver.model.sql,
org.jkiss.dbeaver.model.struct,
org.jkiss.dbeaver.model.struct.rdb,
org.jkiss.dbeaver.model.virtual,
......
......@@ -20,7 +20,7 @@
package org.jkiss.dbeaver;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.utils.CommonUtils;
......
......@@ -30,6 +30,7 @@ import org.jkiss.dbeaver.model.impl.DBCDefaultValueHandler;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress;
import org.jkiss.dbeaver.model.runtime.DBRRunnableWithResult;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.struct.*;
import org.jkiss.dbeaver.model.struct.rdb.*;
import org.jkiss.dbeaver.registry.DataSourceProviderRegistry;
......
......@@ -21,10 +21,8 @@ package org.jkiss.dbeaver.model.exec;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPCloseableObject;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPDataSourceInfo;
import org.jkiss.dbeaver.model.DBPObject;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSDataSourceContainer;
/**
* Execution context.
......
......@@ -71,7 +71,4 @@ public interface DBCSession extends DBPCloseableObject, DBDPreferences {
boolean updatable,
boolean returnGeneratedKeys) throws DBCException;
}
......@@ -23,7 +23,7 @@ import org.apache.commons.logging.LogFactory;
import org.jkiss.dbeaver.model.DBPDataKind;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPDataTypeProvider;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
......
......@@ -24,7 +24,7 @@ import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.model.DBConstants;
import org.jkiss.dbeaver.model.DBPDataTypeProvider;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.data.DBDArray;
import org.jkiss.dbeaver.model.data.DBDDisplayFormat;
import org.jkiss.dbeaver.model.data.DBDValueCloneable;
......
......@@ -24,7 +24,7 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPDataKind;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.data.DBDDisplayFormat;
import org.jkiss.dbeaver.model.data.DBDStructure;
import org.jkiss.dbeaver.model.data.DBDValueCloneable;
......
......@@ -22,7 +22,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
......
......@@ -16,37 +16,17 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.mssql.model;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCQueryTransformer;
import org.jkiss.dbeaver.model.exec.DBCStatement;
import java.sql.SQLException;
import java.sql.Statement;
package org.jkiss.dbeaver.model.sql;
/**
* Query transformer for fetch-all selects
*/
class QueryTransformerFetchAll implements DBCQueryTransformer {
@Override
public void setParameters(Object... parameters)
{
}
* Data source which supports SQL
*/
public interface SQLDataSource {
@Override
public String transformQueryString(String query) throws DBCException {
return query;
}
/**
* SQL dialect provided by this data source
* @return dialect
*/
SQLDialect getSQLDialect();
@Override
public void transformStatement(DBCStatement statement, int parameterIndex) throws DBCException {
// Set fetch size to Integer.MIN_VALUE to enable result set streaming
try {
((Statement)statement).setFetchSize(Integer.MIN_VALUE);
} catch (SQLException e) {
throw new DBCException(e);
}
}
}
\ No newline at end of file
}
......@@ -16,64 +16,13 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.mssql.data;
import org.jkiss.dbeaver.ext.mssql.model.MSSQLTableColumn;
import org.jkiss.dbeaver.model.data.DBDValue;
import org.jkiss.utils.CommonUtils;
package org.jkiss.dbeaver.model.sql;
/**
* Enum type
* SQL dialect
*/
public class MSSQLTypeEnum implements DBDValue {
private MSSQLTableColumn column;
private String value;
public MSSQLTypeEnum(MSSQLTypeEnum source)
{
this.column = source.column;
this.value = source.value;
}
public MSSQLTypeEnum(MSSQLTableColumn column, String value)
{
this.column = column;
this.value = value;
}
public MSSQLTableColumn getColumn()
{
return column;
}
public String getValue()
{
return value;
}
@Override
public boolean isNull()
{
return value == null;
}
@Override
public void release()
{
// do nothing
}
public interface SQLDialect {
@Override
public int hashCode()
{
return value == null ? super.hashCode() : value.hashCode();
}
String getDialectName();
@Override
public boolean equals(Object obj)
{
return this == obj ||
(obj instanceof MSSQLTypeEnum && CommonUtils.equalObjects(((MSSQLTypeEnum)obj).getValue(), value));
}
}
......@@ -16,8 +16,11 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.model;
package org.jkiss.dbeaver.model.sql;
import org.jkiss.dbeaver.model.DBPDataKind;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPKeywordManager;
import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.dbeaver.ui.editors.sql.SQLConstants;
......@@ -120,7 +123,7 @@ public final class SQLUtils {
public static String makeLikePattern(String like)
{
return like.replace("%", ".*").replace("_", ".");
return like.replace("%", ".*").replace("_", ".?");
}
public static boolean matchesLike(String string, String like)
......
......@@ -18,7 +18,7 @@
*/
package org.jkiss.dbeaver.model.struct;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.utils.CommonUtils;
import java.util.ArrayList;
......
......@@ -51,7 +51,7 @@ import org.eclipse.ui.IWorkbenchPartSite;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.qm.QMUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSDataSourceContainer;
......
......@@ -53,7 +53,7 @@ import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.ext.IDataSourceProvider;
import org.jkiss.dbeaver.model.DBPCommentsManager;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.runtime.sql.SQLStatementInfo;
import org.jkiss.dbeaver.ui.ICommandIds;
import org.jkiss.dbeaver.ui.TextUtils;
......
......@@ -31,7 +31,7 @@ import org.jkiss.dbeaver.ext.db2.model.dict.DB2RoutineValidType;
import org.jkiss.dbeaver.ext.db2.model.dict.DB2YesNo;
import org.jkiss.dbeaver.ext.db2.model.module.DB2Module;
import org.jkiss.dbeaver.model.DBPRefreshableObject;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.meta.Property;
......
......@@ -24,7 +24,7 @@ import org.jkiss.dbeaver.ext.db2.editors.DB2SourceObject;
import org.jkiss.dbeaver.ext.db2.model.dict.DB2OwnerType;
import org.jkiss.dbeaver.ext.db2.model.dict.DB2TableCheckConstraintType;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCTableConstraint;
......
......@@ -29,7 +29,7 @@ import org.jkiss.dbeaver.ext.db2.model.dict.DB2TriggerTime;
import org.jkiss.dbeaver.ext.db2.model.dict.DB2TriggerValid;
import org.jkiss.dbeaver.ext.db2.model.dict.DB2YesNo;
import org.jkiss.dbeaver.model.DBPRefreshableObject;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.meta.Association;
......
......@@ -22,7 +22,7 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.db2.editors.DB2SourceObject;
import org.jkiss.dbeaver.ext.db2.model.cache.DB2ViewBaseDepCache;
import org.jkiss.dbeaver.ext.db2.model.dict.DB2ViewStatus;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.meta.Association;
......
......@@ -211,24 +211,6 @@
</editor>
</extension>
<extension point="org.jkiss.dbeaver.dataTypeProvider">
<provider
class="org.jkiss.dbeaver.ext.mssql.data.MSSQLValueHandlerProvider"
description="MSSQL data types provider"
id="org.jkiss.dbeaver.ext.mssql.data.MSSQLValueHandlerProvider"
label="MSSQL data types provider">
<datasource id="mssql"/>
<type name="ENUM"/>
<type name="SET"/>
<type name="DATE"/>
<type name="DATETIME"/>
<type name="TIMESTAMP"/>
</provider>
</extension>
<extension point="org.eclipse.ui.editors">
<editor
name="%editor.session_manager.name"
......
/*
* Copyright (C) 2010-2013 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.mssql.data;
import org.jkiss.dbeaver.model.data.DBDDataFormatterProfile;
import org.jkiss.dbeaver.model.data.DBDDisplayFormat;
import org.jkiss.dbeaver.model.impl.jdbc.data.JDBCDateTimeValueHandler;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import java.util.Calendar;
import java.util.Date;
/**
* MSSQL datetime handler
*/
public class MSSQLDateTimeValueHandler extends JDBCDateTimeValueHandler {
public MSSQLDateTimeValueHandler(DBDDataFormatterProfile formatterProfile)
{
super(formatterProfile);
}
@Override
public String getValueDisplayString(DBSTypedObject column, Object value, DBDDisplayFormat format)
{
if (value instanceof Date && format == DBDDisplayFormat.NATIVE) {
Calendar cal = Calendar.getInstance();
cal.setTime((Date) value);
final String hourOfDay = getTwoDigitValue(cal.get(Calendar.HOUR_OF_DAY) + 1);
final String minutes = getTwoDigitValue(cal.get(Calendar.MINUTE));
final String seconds = getTwoDigitValue(cal.get(Calendar.SECOND));
final String year = String.valueOf(cal.get(Calendar.YEAR));
final String month = getTwoDigitValue(cal.get(Calendar.MONTH) + 1);
final String dayOfMonth = getTwoDigitValue(cal.get(Calendar.DAY_OF_MONTH));
switch (column.getTypeID()) {
case java.sql.Types.TIME:
return "STR_TO_DATE('" + hourOfDay + ":" + minutes + ":" + seconds + "','%H:%i:%s')";
case java.sql.Types.DATE:
return "STR_TO_DATE('" + year + "-" + month + "-" + dayOfMonth + "','%Y-%m-%d')";
default:
return "STR_TO_DATE('" + year + "-" + month + "-" + dayOfMonth +
" " + hourOfDay + ":" + minutes + ":" + seconds +
"','%Y-%m-%d %H:%i:%s')";
}
} else {
return super.getValueDisplayString(column, value, format);
}
}
}
/*
* Copyright (C) 2010-2013 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.mssql.data;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.List;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.mssql.model.MSSQLTableColumn;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.data.DBDDisplayFormat;
import org.jkiss.dbeaver.model.data.DBDValueController;
import org.jkiss.dbeaver.model.data.DBDValueEditor;
import org.jkiss.dbeaver.model.exec.DBCAttributeMetaData;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.impl.jdbc.data.JDBCAbstractValueHandler;
import org.jkiss.dbeaver.model.struct.DBSEntityAttribute;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.dbeaver.model.struct.rdb.DBSTableColumn;
import org.jkiss.dbeaver.ui.dialogs.data.DefaultValueViewDialog;
import org.jkiss.utils.CommonUtils;
import java.sql.SQLException;
import java.util.Collection;
/**
* MSSQL ENUM value handler
*/
public class MSSQLEnumValueHandler extends JDBCAbstractValueHandler {
public static final MSSQLEnumValueHandler INSTANCE = new MSSQLEnumValueHandler();
@Override
public Object getValueFromObject(DBCSession session, DBSTypedObject type, Object object, boolean copy) throws DBCException
{
if (object == null) {
return new MSSQLTypeEnum((MSSQLTableColumn) type, null);
} else if (object instanceof MSSQLTypeEnum) {
return copy ? new MSSQLTypeEnum((MSSQLTypeEnum) object) : object;
} else if (object instanceof String && type instanceof MSSQLTableColumn) {
return new MSSQLTypeEnum((MSSQLTableColumn) type, (String) object);
} else {
throw new DBCException("Unsupported ");
}
}
@Override
public String getValueDisplayString(DBSTypedObject column, Object value, DBDDisplayFormat format)
{
if (!(value instanceof MSSQLTypeEnum)) {
return super.getValueDisplayString(column, value, format);
}
String strValue = ((MSSQLTypeEnum) value).getValue();
return DBUtils.getDefaultValueDisplayString(strValue, format);
}
@Override
protected Object fetchColumnValue(
DBCSession session,
JDBCResultSet resultSet,
DBSTypedObject type,
int index)
throws SQLException
{
DBSEntityAttribute attribute = null;
if (type instanceof DBSTableColumn) {
attribute = (DBSTableColumn) type;
} else if (type instanceof DBCAttributeMetaData) {
try {
attribute = ((DBCAttributeMetaData) type).getAttribute(session.getProgressMonitor());
} catch (DBException e) {
throw new SQLException(e);
}
}
if (attribute == null) {
throw new SQLException("Could not find table column for column '" + index + "'");
}
MSSQLTableColumn enumColumn;
if (attribute instanceof MSSQLTableColumn) {
enumColumn = (MSSQLTableColumn) attribute;
} else {
throw new SQLException("Bad column type: " + attribute.getClass().getName());
}
return new MSSQLTypeEnum(enumColumn, resultSet.getString(index));
}
@Override
public void bindParameter(JDBCSession session, JDBCPreparedStatement statement, DBSTypedObject paramType, int paramIndex, Object value)
throws SQLException
{
// Sometimes we have String in value instead of MSSQLTypeEnum
// It happens when we edit result sets as MSSQL reports RS column type as CHAR for enum/set types
String strValue;
if (value instanceof MSSQLTypeEnum) {
strValue = ((MSSQLTypeEnum) value).getValue();
} else {
strValue = CommonUtils.toString(value);
}
if (strValue == null) {
statement.setNull(paramIndex, paramType.getTypeID());
} else {
statement.setString(paramIndex, strValue);
}
}
@Override
public DBDValueEditor createEditor(final DBDValueController controller)
throws DBException
{
switch (controller.getEditType()) {
case INLINE:
{
return new ValueEditor<Combo>(controller) {
@Override
public void primeEditorValue(Object value) throws DBException
{
MSSQLTypeEnum enumValue = (MSSQLTypeEnum) value;
control.setText(enumValue.isNull() ? "" : enumValue.getValue());
}
@Override
public Object extractEditorValue()
{
int selIndex = control.getSelectionIndex();
if (selIndex < 0) {
return new MSSQLTypeEnum(getColumn(), null);
} else {
return new MSSQLTypeEnum(getColumn(), control.getItem(selIndex));
}
}
@Override
protected Combo createControl(Composite editPlaceholder)
{
final Combo editor = new Combo(controller.getEditPlaceholder(), SWT.READ_ONLY);
Collection<String> enumValues = getColumn().getEnumValues();
if (enumValues != null) {
for (String enumValue : enumValues) {
editor.add(enumValue);
}
}
if (editor.getSelectionIndex() < 0) {
editor.select(0);
}
return editor;
}
private MSSQLTableColumn getColumn()
{
return ((MSSQLTypeEnum) controller.getValue()).getColumn();
}
};
}
case PANEL:
{
return new ValueEditor<List>(controller) {
@Override
public void primeEditorValue(Object value) throws DBException
{
MSSQLTypeEnum enumValue = (MSSQLTypeEnum) value;
if (enumValue.isNull()) {
control.setSelection(-1);
}
int itemCount = control.getItemCount();
for (int i = 0 ; i < itemCount; i++) {
if (control.getItem(i).equals(enumValue.getValue())) {
control.setSelection(i);
break;
}
}
}
@Override
public Object extractEditorValue()
{
int selIndex = control.getSelectionIndex();
if (selIndex < 0) {
return new MSSQLTypeEnum(getColumn(), null);
} else {
return new MSSQLTypeEnum(getColumn(), control.getItem(selIndex));
}
}
@Override
protected List createControl(Composite editPlaceholder)
{
final MSSQLTableColumn column = ((MSSQLTypeEnum) controller.getValue()).getColumn();
final List editor = new List(controller.getEditPlaceholder(), SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL);
Collection<String> enumValues = column.getEnumValues();
if (enumValues != null) {
for (String enumValue : enumValues) {
editor.add(enumValue);
}
}
if (editor.getSelectionIndex() < 0) {
editor.select(0);
}
if (controller.getEditType() == DBDValueController.EditType.INLINE) {
editor.setFocus();
}
return editor;
}
private MSSQLTableColumn getColumn()
{
return ((MSSQLTypeEnum) controller.getValue()).getColumn();
}
};
}
case EDITOR:
return new DefaultValueViewDialog(controller);
default:
return null;
}
}
@Override
public int getFeatures()
{
return FEATURE_VIEWER | FEATURE_EDITOR | FEATURE_INLINE_EDITOR;
}
@Override
public Class getValueObjectType()
{
return MSSQLTypeEnum.class;
}
/*
public void fillProperties(PropertySourceAbstract propertySource, DBDValueController controller)
{
propertySource.addProperty(
"max_length",
"Max Length",
controller.getAttributeMetaData().getMaxLength());
}
*/
}
\ No newline at end of file
/*
* Copyright (C) 2010-2013 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.mssql.data;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.mssql.model.MSSQLTableColumn;
import org.jkiss.dbeaver.model.data.DBDValueController;
import org.jkiss.dbeaver.model.data.DBDValueEditor;
import org.jkiss.dbeaver.ui.dialogs.data.DefaultValueViewDialog;
import org.jkiss.utils.CommonUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
/**
* MSSQL SET value handler
*/
public class MSSQLSetValueHandler extends MSSQLEnumValueHandler {
public static final MSSQLSetValueHandler INSTANCE = new MSSQLSetValueHandler();
@Override
public DBDValueEditor createEditor(final DBDValueController controller)
throws DBException
{
switch (controller.getEditType()) {
case INLINE:
case PANEL:
final MSSQLTableColumn column = ((MSSQLTypeEnum) controller.getValue()).getColumn();
return new ValueEditor<org.eclipse.swt.widgets.List>(controller) {
@Override
public void primeEditorValue(Object value) throws DBException
{
MSSQLTypeEnum enumValue = (MSSQLTypeEnum) value;
fillSetList(control, enumValue);
}
@Override
public Object extractEditorValue()
{
String[] selection = control.getSelection();
StringBuilder resultString = new StringBuilder();
for (String selString : selection) {
if (CommonUtils.isEmpty(selString)) {
continue;
}
if (resultString.length() > 0) resultString.append(',');
resultString.append(selString);
}
return new MSSQLTypeEnum(column, resultString.toString());
}
@Override
protected org.eclipse.swt.widgets.List createControl(Composite editPlaceholder)
{
return new org.eclipse.swt.widgets.List(controller.getEditPlaceholder(), SWT.BORDER | SWT.MULTI);
}
};
case EDITOR:
return new DefaultValueViewDialog(controller);
default:
return null;
}
}
static void fillSetList(org.eclipse.swt.widgets.List editor, MSSQLTypeEnum value)
{
editor.removeAll();
List<String> enumValues = value.getColumn().getEnumValues();
String setString = value.getValue();
List<String> setValues = new ArrayList<String>();
if (!CommonUtils.isEmpty(setString)) {
StringTokenizer st = new StringTokenizer(setString, ",");
while (st.hasMoreTokens()) {
setValues.add(st.nextToken());
}
}
if (enumValues != null) {
int[] selIndices = new int[setValues.size()];
int selIndex = 0;
for (int i = 0; i < enumValues.size(); i++) {
String enumValue = enumValues.get(i);
editor.add(enumValue);
if (setValues.contains(enumValue)) {
selIndices[selIndex++] = i;
}
}
editor.select(selIndices);
}
}
}
\ No newline at end of file
/*
* Copyright (C) 2010-2013 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.mssql.data;
import org.eclipse.swt.graphics.Image;
import org.jkiss.dbeaver.ext.mssql.MSSQLConstants;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.data.DBDPreferences;
import org.jkiss.dbeaver.model.data.DBDValueHandler;
import org.jkiss.dbeaver.model.data.DBDValueHandlerProvider;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import java.sql.Types;
/**
* MSSQL data types provider
*/
public class MSSQLValueHandlerProvider implements DBDValueHandlerProvider {
@Override
public Image getTypeImage(DBSTypedObject type)
{
return DBUtils.getDataIcon(type).getImage();
}
@Override
public DBDValueHandler getHandler(DBDPreferences preferences, String typeName, int valueType)
{
if (MSSQLConstants.TYPE_NAME_ENUM.equalsIgnoreCase(typeName)) {
return MSSQLEnumValueHandler.INSTANCE;
} else if (MSSQLConstants.TYPE_NAME_SET.equalsIgnoreCase(typeName)) {
return MSSQLSetValueHandler.INSTANCE;
} else if (valueType == Types.DATE || valueType == Types.TIME || valueType == Types.TIMESTAMP) {
return new MSSQLDateTimeValueHandler(preferences.getDataFormatterProfile());
} else {
return null;
}
}
}
\ No newline at end of file
......@@ -22,7 +22,7 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.IDatabasePersistAction;
import org.jkiss.dbeaver.ext.mssql.MSSQLMessages;
import org.jkiss.dbeaver.ext.mssql.model.MSSQLUser;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.edit.prop.DBECommandComposite;
import org.jkiss.dbeaver.model.impl.edit.AbstractDatabasePersistAction;
import org.jkiss.utils.CommonUtils;
......
......@@ -515,16 +515,6 @@ public class MSSQLDataSource extends JDBCDataSource implements DBSObjectSelector
}
}
@Override
public DBCQueryTransformer createQueryTransformer(DBCQueryTransformType type) {
if (type == DBCQueryTransformType.RESULT_SET_LIMIT) {
return new QueryTransformerLimit();
} else if (type == DBCQueryTransformType.FETCH_ALL_TABLE) {
return new QueryTransformerFetchAll();
}
return super.createQueryTransformer(type);
}
@Override
public DBCPlan planQueryExecution(DBCSession session, String query) throws DBCException
{
......
/*
* Copyright (C) 2010-2013 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.mssql.model;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCQueryTransformer;
import org.jkiss.dbeaver.model.exec.DBCStatement;
/**
* Query transformer for RS limit
*/
class QueryTransformerLimit implements DBCQueryTransformer {
private Object offset;
private Object length;
private boolean limitSet;
@Override
public void setParameters(Object... parameters) {
this.offset = parameters[0];
this.length = parameters[1];
}
@Override
public String transformQueryString(String query) throws DBCException {
String testQuery = query.toUpperCase().trim();
if (!testQuery.startsWith("SELECT") || testQuery.contains(" LIMIT") || testQuery.contains(" INTO")) {
// Do not use limit if it is not a select or it already has LIMIT or it is SELECT INTO statement
limitSet = false;
} else {
query = query + SQLUtils.TOKEN_TRANSFORM_START + " LIMIT " + offset + ", " + length + SQLUtils.TOKEN_TRANSFORM_END;
limitSet = true;
}
return query;
}
@Override
public void transformStatement(DBCStatement statement, int parameterIndex) throws DBCException {
if (!limitSet) {
statement.setLimit(((Number)offset).longValue(), ((Number)length).longValue());
}
}
}
......@@ -20,7 +20,7 @@ package org.jkiss.dbeaver.ext.mssql.model;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.mssql.MSSQLConstants;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCExecutionPurpose;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
......
......@@ -19,7 +19,7 @@
package org.jkiss.dbeaver.ext.mssql.model.plan;
import org.jkiss.dbeaver.ext.mssql.model.MSSQLDataSource;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
......
......@@ -22,7 +22,7 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.IDatabasePersistAction;
import org.jkiss.dbeaver.ext.mysql.MySQLMessages;
import org.jkiss.dbeaver.ext.mysql.model.MySQLUser;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.edit.prop.DBECommandComposite;
import org.jkiss.dbeaver.model.impl.edit.AbstractDatabasePersistAction;
import org.jkiss.utils.CommonUtils;
......
......@@ -20,7 +20,7 @@ package org.jkiss.dbeaver.ext.mysql.model;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.mysql.MySQLConstants;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCExecutionPurpose;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
......
......@@ -18,7 +18,7 @@
*/
package org.jkiss.dbeaver.ext.mysql.model;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCQueryTransformer;
import org.jkiss.dbeaver.model.exec.DBCStatement;
......
......@@ -19,7 +19,7 @@
package org.jkiss.dbeaver.ext.mysql.model.plan;
import org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册