提交 034fdea3 编写于 作者: J jurgen

Remove redundant makeNull from DBDValue

Former-commit-id: eb226e03
上级 9b545153
......@@ -29,6 +29,7 @@ import org.jkiss.dbeaver.model.exec.*;
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.struct.*;
import org.jkiss.dbeaver.model.struct.rdb.*;
import org.jkiss.dbeaver.registry.DataSourceProviderRegistry;
......@@ -377,13 +378,32 @@ public final class DBUtils {
return (value == null || (value instanceof DBDValue && ((DBDValue) value).isNull()));
}
public static Object makeNullValue(Object value)
public static Object makeNullValue(DBCExecutionContext context, DBDValueHandler valueHandler, DBSTypedObject type) throws DBCException
{
if (value instanceof DBDValue) {
return ((DBDValue) value).makeNull();
} else {
return null;
}
return valueHandler.getValueFromObject(context, type, null, false);
}
public static Object makeNullValue(final DBDValueController valueController)
{
DBRRunnableWithResult<Object> runnable = new DBRRunnableWithResult<Object>() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException
{
DBCExecutionContext context = valueController.getDataSource().openContext(monitor, DBCExecutionPurpose.UTIL, "Set NULL value");
try {
result = DBUtils.makeNullValue(
context,
valueController.getValueHandler(),
valueController.getAttributeMetaData());
} catch (DBCException e) {
throw new InvocationTargetException(e);
} finally {
context.close();
}
}
};
DBeaverUI.runInUI(valueController.getValueSite().getWorkbenchWindow(), runnable);
return runnable.getResult();
}
public static DBDAttributeBinding getColumnBinding(DBCExecutionContext context, DBCAttributeMetaData attributeMeta)
......
......@@ -24,15 +24,11 @@ package org.jkiss.dbeaver.model.data;
*/
public interface DBDValue extends DBDObject {
boolean isNull();
DBDValue makeNull();
/**
* Checks transactional state (transactional values valid only during transaction at which thy were retrieved
* @return
* check this value is NULL
* @return true for NULL values
*/
//boolean isTransactional();
boolean isNull();
/**
* Releases allocated resources. Resets to original value
......
......@@ -26,7 +26,6 @@ import org.jkiss.dbeaver.model.DBPDataTypeProvider;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.data.DBDArray;
import org.jkiss.dbeaver.model.data.DBDValue;
import org.jkiss.dbeaver.model.data.DBDValueCloneable;
import org.jkiss.dbeaver.model.data.DBDValueHandler;
import org.jkiss.dbeaver.model.exec.DBCException;
......@@ -152,12 +151,6 @@ public class JDBCArray implements DBDArray, DBDValueCloneable {
return contents == null;
}
@Override
public DBDValue makeNull()
{
return new JDBCArray(type, null);
}
@Override
public void release()
{
......
......@@ -171,12 +171,6 @@ public class JDBCContentBytes extends JDBCContentAbstract implements DBDContent,
return data == null;
}
@Override
public JDBCContentBytes makeNull()
{
return new JDBCContentBytes(dataSource, null);
}
@Override
public void release()
{
......
......@@ -43,8 +43,6 @@ import java.sql.SQLException;
*/
public class JDBCContentChars extends JDBCContentAbstract implements DBDContent, DBDValueCloneable, DBDContentStorage {
//static final Log log = LogFactory.getLog(JDBCContentChars.class);
private String originalData;
private String data;
......@@ -172,12 +170,6 @@ public class JDBCContentChars extends JDBCContentAbstract implements DBDContent,
return data == null;
}
@Override
public JDBCContentChars makeNull()
{
return new JDBCContentChars(dataSource, null);
}
@Override
public void release()
{
......
......@@ -18,8 +18,6 @@
*/
package org.jkiss.dbeaver.model.impl.jdbc.data;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.data.DBDContent;
......@@ -35,8 +33,6 @@ import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
*/
public abstract class JDBCContentLOB extends JDBCContentAbstract implements DBDContent {
static final Log log = LogFactory.getLog(JDBCContentLOB.class);
private DBDContentStorage originalStorage;
protected DBDContentStorage storage;
......@@ -95,12 +91,6 @@ public abstract class JDBCContentLOB extends JDBCContentAbstract implements DBDC
}
}
@Override
public JDBCContentLOB makeNull()
{
return createNewContent();
}
@Override
public DBDValueCloneable cloneValue(DBRProgressMonitor monitor)
throws DBCException
......
......@@ -18,11 +18,7 @@
*/
package org.jkiss.dbeaver.model.impl.jdbc.data;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.model.data.DBDCursor;
import org.jkiss.dbeaver.model.data.DBDValue;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCExecutionContext;
import org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCResultSetImpl;
......@@ -33,8 +29,6 @@ import java.sql.ResultSet;
*/
public class JDBCCursor extends JDBCResultSetImpl implements DBDCursor {
static final Log log = LogFactory.getLog(JDBCCursor.class);
public JDBCCursor(JDBCExecutionContext context, ResultSet original, String description)
{
super(context, original, description);
......@@ -46,12 +40,6 @@ public class JDBCCursor extends JDBCResultSetImpl implements DBDCursor {
return false;
}
@Override
public DBDValue makeNull()
{
throw new IllegalStateException(CoreMessages.model_jdbc_cant_create_null_cursor);
}
@Override
public void release()
{
......
......@@ -24,7 +24,6 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.SQLUtils;
import org.jkiss.dbeaver.model.data.DBDStructure;
import org.jkiss.dbeaver.model.data.DBDValue;
import org.jkiss.dbeaver.model.data.DBDValueCloneable;
import org.jkiss.dbeaver.model.data.DBDValueHandler;
import org.jkiss.dbeaver.model.exec.DBCException;
......@@ -102,16 +101,6 @@ public class JDBCStruct implements DBDStructure, DBDValueCloneable {
return contents == null;
}
@Override
public DBDValue makeNull()
{
JDBCStruct nullStruct = new JDBCStruct();
nullStruct.type = this.type;
nullStruct.contents = null;
nullStruct.values = new LinkedHashMap<DBSAttributeBase, Object>();
return nullStruct;
}
@Override
public void release()
{
......
/*
* Copyright (C) 2010-2012 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.model.runtime;
/**
*
*/
public abstract class DBRRunnableWithResult<TYPE> implements DBRRunnableWithProgress {
protected TYPE result;
public TYPE getResult()
{
return result;
}
}
\ No newline at end of file
......@@ -608,23 +608,25 @@ public class DataSourceDescriptor
// If there are some executions in last savepoint then ask user about commit/rollback
QMMCollector qmm = DBeaverCore.getInstance().getQueryManager().getMetaCollector();
QMMSessionInfo qmmSession = qmm.getSession(dataSource);
QMMTransactionInfo txn = qmmSession == null ? null : qmmSession.getTransaction();
QMMTransactionSavepointInfo sp = txn == null ? null : txn.getCurrentSavepoint();
if (sp != null && (sp.getPrevious() != null || sp.getLastExecute() != null)) {
// Ask for confirmation
TransactionCloseConfirmer closeConfirmer = new TransactionCloseConfirmer();
UIUtils.runInUI(null, closeConfirmer);
switch (closeConfirmer.result) {
case IDialogConstants.YES_ID:
context.getTransactionManager().commit();
break;
case IDialogConstants.NO_ID:
context.getTransactionManager().rollback(null);
break;
default:
return false;
if (qmm != null) {
QMMSessionInfo qmmSession = qmm.getSession(dataSource);
QMMTransactionInfo txn = qmmSession == null ? null : qmmSession.getTransaction();
QMMTransactionSavepointInfo sp = txn == null ? null : txn.getCurrentSavepoint();
if (sp != null && (sp.getPrevious() != null || sp.getLastExecute() != null)) {
// Ask for confirmation
TransactionCloseConfirmer closeConfirmer = new TransactionCloseConfirmer();
UIUtils.runInUI(null, closeConfirmer);
switch (closeConfirmer.result) {
case IDialogConstants.YES_ID:
context.getTransactionManager().commit();
break;
case IDialogConstants.NO_ID:
context.getTransactionManager().rollback(null);
break;
default:
return false;
}
}
}
}
......
......@@ -1196,7 +1196,8 @@ public class ResultSetViewer extends Viewer implements IDataSourceProvider, ISpr
@Override
public void run()
{
valueController.updateValue(DBUtils.makeNullValue(value));
valueController.updateValue(
DBUtils.makeNullValue(valueController));
}
});
}
......@@ -1771,15 +1772,20 @@ public class ResultSetViewer extends Viewer implements IDataSourceProvider, ISpr
cells[i] = metaColumn.getValueHandler().getValueFromObject(context, metaColumn.getTableColumn(), origRow[i], true);
} catch (DBCException e) {
log.warn(e);
cells[i] = DBUtils.makeNullValue(origRow[i]);
try {
cells[i] = DBUtils.makeNullValue(context, metaColumn.getValueHandler(), metaColumn.getAttribute());
} catch (DBCException e1) {
log.warn(e1);
}
}
}
}
} else {
// Initialize new values
for (int i = 0; i < metaColumns.length; i++) {
DBDAttributeBinding metaColumn = metaColumns[i];
try {
cells[i] = metaColumns[i].getValueHandler().getValueFromObject(context, metaColumns[i].getTableColumn(), null, false);
cells[i] = DBUtils.makeNullValue(context, metaColumn.getValueHandler(), metaColumn.getAttribute());
} catch (DBCException e) {
log.warn(e);
}
......
......@@ -52,6 +52,7 @@ import org.jkiss.dbeaver.model.navigator.DBNDatabaseNode;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress;
import org.jkiss.dbeaver.model.struct.*;
import org.jkiss.dbeaver.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.runtime.jobs.DataSourceJob;
import org.jkiss.dbeaver.ui.DBIcon;
import org.jkiss.dbeaver.ui.UIUtils;
......@@ -370,12 +371,7 @@ public abstract class ValueViewDialog extends Dialog implements DBDValueEditorEx
if (buttonId == IDialogConstants.IGNORE_ID) {
if (!valueController.isReadOnly()) {
editedValue = valueController.getValue();
if (editedValue instanceof DBDValue) {
editedValue = ((DBDValue)editedValue).makeNull();
} else {
editedValue = null;
}
editedValue = DBUtils.makeNullValue(valueController);
}
super.okPressed();
} else {
......
......@@ -58,12 +58,6 @@ public class MySQLTypeEnum implements DBDValue {
return value == null;
}
@Override
public DBDValue makeNull()
{
return new MySQLTypeEnum(column, null);
}
@Override
public void release()
{
......
......@@ -43,12 +43,6 @@ public class OracleObjectValue implements DBDValue{
return value == null;
}
@Override
public DBDValue makeNull()
{
return new OracleObjectValue(null);
}
@Override
public void release()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册