Skip to content
Snippets Groups Projects
Commit 911a0fbd authored by felmer's avatar felmer
Browse files

LMS-1445 bug fixed.

SVN: 15828
parent 42ca652d
No related branches found
No related tags found
No related merge requests found
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.knime.query;
import java.io.Serializable;
import org.knime.core.data.DataCell;
import org.knime.core.data.DataType;
import org.knime.core.data.def.DoubleCell;
import org.knime.core.data.def.LongCell;
import org.knime.core.data.def.StringCell;
enum ColumnType
{
DOUBLE(DoubleCell.TYPE)
{
@Override
public DataCell createCell(Serializable valueOrNull)
{
if (valueOrNull instanceof Double)
{
return new DoubleCell((Double) valueOrNull);
}
return null;
}
},
LONG(LongCell.TYPE)
{
@Override
public DataCell createCell(Serializable valueOrNull)
{
if (valueOrNull instanceof Long)
{
return new LongCell((Long) valueOrNull);
}
return null;
}
},
STRING(StringCell.TYPE)
{
@Override
public DataCell createCell(Serializable valueOrNull)
{
return new StringCell(valueOrNull == null ? "" : valueOrNull.toString());
}
};
private final DataType dataType;
private ColumnType(DataType dataType)
{
this.dataType = dataType;
}
public DataType getDataType()
{
return dataType;
}
public abstract DataCell createCell(Serializable valueOrNull);
}
\ No newline at end of file
......@@ -25,9 +25,6 @@ import org.knime.core.data.DataCell;
import org.knime.core.data.DataTableSpec;
import org.knime.core.data.DataType;
import org.knime.core.data.def.DefaultRow;
import org.knime.core.data.def.DoubleCell;
import org.knime.core.data.def.LongCell;
import org.knime.core.data.def.StringCell;
import org.knime.core.node.BufferedDataContainer;
import org.knime.core.node.BufferedDataTable;
import org.knime.core.node.CanceledExecutionException;
......@@ -125,14 +122,16 @@ public class QueryNodeModel extends NodeModel
QueryTableModel result = facade.executeQuery(queryDescription.getId(), parameterBindings.getBindings());
List<QueryTableColumn> columns = result.getColumns();
String[] columnTitles = new String[columns.size()];
DataType[] columnTypes = new DataType[columns.size()];
DataType[] dataTypes = new DataType[columns.size()];
ColumnType[] columnTypes = new ColumnType[columns.size()];
for (int i = 0, n = columns.size(); i < n; i++)
{
QueryTableColumn column = columns.get(i);
columnTitles[i] = column.getTitle();
columnTypes[i] = Util.translateDataType(column.getDataType());
columnTypes[i] = Util.getColumnType(column.getDataType());
dataTypes[i] = columnTypes[i].getDataType();
}
DataTableSpec dataTableSpec = new DataTableSpec(columnTitles, columnTypes);
DataTableSpec dataTableSpec = new DataTableSpec(columnTitles, dataTypes);
BufferedDataContainer container = exec.createDataContainer(dataTableSpec);
List<Serializable[]> rows = result.getRows();
for (int i = 0, n = rows.size(); i < n; i++)
......@@ -141,19 +140,7 @@ public class QueryNodeModel extends NodeModel
DataCell[] cells = new DataCell[row.length];
for (int c = 0; c < row.length; c++)
{
Serializable value = row[c];
DataCell cell = null;
if (value instanceof Double)
{
cell = new DoubleCell((Double) value);
} else if (value instanceof Long)
{
cell = new LongCell((Long) value);
} else
{
cell = new StringCell(value.toString());
}
cells[c] = cell;
cells[c] = columnTypes[c].createCell(row[c]);
}
container.addRowToTable(new DefaultRow(Integer.toString(i), cells));
}
......
......@@ -22,11 +22,6 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import org.knime.core.data.DataType;
import org.knime.core.data.def.DoubleCell;
import org.knime.core.data.def.LongCell;
import org.knime.core.data.def.StringCell;
import ch.systemsx.cisd.openbis.plugin.query.shared.api.v1.dto.QueryDescription;
import ch.systemsx.cisd.openbis.plugin.query.shared.api.v1.dto.QueryTableColumnDataType;
......@@ -70,13 +65,13 @@ class Util
}
}
static DataType translateDataType(QueryTableColumnDataType dataType)
static ColumnType getColumnType(QueryTableColumnDataType dataType)
{
switch (dataType)
{
case DOUBLE: return DoubleCell.TYPE;
case LONG: return LongCell.TYPE;
default: return StringCell.TYPE;
case DOUBLE: return ColumnType.DOUBLE;
case LONG: return ColumnType.LONG;
default: return ColumnType.STRING;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment