forked from p81075629/datagear
数据管理添加不支持列类型的处理逻辑
This commit is contained in:
parent
93e9d82c12
commit
724a48cbb0
|
@ -36,6 +36,9 @@ public abstract class AbstractRowMapper extends PersistenceSupport implements Ro
|
|||
Column[] columns = table.getColumns();
|
||||
for (int i = 0; i < columns.length; i++)
|
||||
{
|
||||
if (!supportsColumn(columns[i]))
|
||||
continue;
|
||||
|
||||
Object value = mapColumn(cn, table, rs, rowIndex, columns[i]);
|
||||
rowObj.put(columns[i].getName(), value);
|
||||
}
|
||||
|
@ -54,6 +57,9 @@ public abstract class AbstractRowMapper extends PersistenceSupport implements Ro
|
|||
|
||||
/**
|
||||
* 映射列值。
|
||||
* <p>
|
||||
* 注意:{@linkplain #map(Connection, Table, ResultSet, int)}方法已过滤掉不支持的列(参考:{@linkplain #supportsColumn(Column)})。
|
||||
* </p>
|
||||
*
|
||||
* @param cn
|
||||
* @param table
|
||||
|
|
|
@ -91,6 +91,11 @@ public class DefaultPersistenceManager extends PersistenceSupport implements Per
|
|||
for (int i = 0; i < columns.length; i++)
|
||||
{
|
||||
Column column = columns[i];
|
||||
|
||||
// 忽略不支持的列,避免程序不可用
|
||||
if(!supportsColumn(column))
|
||||
continue;
|
||||
|
||||
String name = column.getName();
|
||||
Object value = row.get(name);
|
||||
|
||||
|
@ -162,6 +167,11 @@ public class DefaultPersistenceManager extends PersistenceSupport implements Per
|
|||
for (int i = 0; i < columns.length; i++)
|
||||
{
|
||||
Column column = columns[i];
|
||||
|
||||
// 忽略不支持的列,避免程序不可用
|
||||
if (!supportsColumn(column))
|
||||
continue;
|
||||
|
||||
String name = column.getName();
|
||||
|
||||
if (!update.containsKey(name))
|
||||
|
|
|
@ -7,6 +7,7 @@ package org.datagear.persistence.support;
|
|||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -281,8 +282,13 @@ public class PersistenceSupport extends JdbcSupport
|
|||
Column[] columns = table.getColumns();
|
||||
for (int i = 0; i < columns.length; i++)
|
||||
{
|
||||
Object value = getColumnValue(cn, rs, columns[i].getName(), columns[i].getType());
|
||||
row.put(columns[i].getName(), value);
|
||||
Column column = columns[i];
|
||||
|
||||
if (!supportsColumn(column))
|
||||
continue;
|
||||
|
||||
Object value = getColumnValue(cn, rs, column);
|
||||
row.put(column.getName(), value);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
|
@ -303,4 +309,61 @@ public class PersistenceSupport extends JdbcSupport
|
|||
{
|
||||
return new SqlParamValue(value, column.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否指定指定列的持久化操作。
|
||||
*
|
||||
* @param column
|
||||
* @return
|
||||
*/
|
||||
public boolean supportsColumn(Column column)
|
||||
{
|
||||
return supportsSqlType(column.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否指定指定SQL类型的持久化操作。
|
||||
*
|
||||
* @param sqlType
|
||||
* @return
|
||||
*/
|
||||
public boolean supportsSqlType(int sqlType)
|
||||
{
|
||||
switch (sqlType)
|
||||
{
|
||||
case Types.TINYINT:
|
||||
case Types.SMALLINT:
|
||||
case Types.INTEGER:
|
||||
case Types.BIGINT:
|
||||
case Types.REAL:
|
||||
case Types.FLOAT:
|
||||
case Types.DOUBLE:
|
||||
case Types.DECIMAL:
|
||||
case Types.NUMERIC:
|
||||
case Types.BIT:
|
||||
case Types.BOOLEAN:
|
||||
case Types.CHAR:
|
||||
case Types.VARCHAR:
|
||||
case Types.LONGVARCHAR:
|
||||
case Types.BINARY:
|
||||
case Types.VARBINARY:
|
||||
case Types.LONGVARBINARY:
|
||||
case Types.DATE:
|
||||
case Types.TIME:
|
||||
case Types.TIME_WITH_TIMEZONE:
|
||||
case Types.TIMESTAMP:
|
||||
case Types.TIMESTAMP_WITH_TIMEZONE:
|
||||
case Types.CLOB:
|
||||
case Types.BLOB:
|
||||
case Types.NCHAR:
|
||||
case Types.NVARCHAR:
|
||||
case Types.LONGNVARCHAR:
|
||||
case Types.NCLOB:
|
||||
case Types.SQLXML:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -855,7 +855,7 @@ public class JdbcSupport
|
|||
protected Object setParamValueExt(Connection cn, PreparedStatement st, int paramIndex, SqlParamValue paramValue)
|
||||
throws SQLException
|
||||
{
|
||||
throw new UnsupportedOperationException("Set JDBC [" + paramValue.getType() + "] type value is not supported");
|
||||
throw new UnsupportedOperationException("Set JDBC type [" + paramValue.getType() + "] value is not supported");
|
||||
}
|
||||
|
||||
protected void write(File file, OutputStream out) throws SQLException
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.convert.ConversionException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.MissingServletRequestParameterException;
|
||||
|
@ -89,6 +90,17 @@ public class ControllerAdvice extends AbstractController
|
|||
return getErrorView(request, response);
|
||||
}
|
||||
|
||||
@ExceptionHandler(HttpMessageNotReadableException.class)
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public String handleControllerHttpMessageNotReadableException(HttpServletRequest request,
|
||||
HttpServletResponse response, HttpMessageNotReadableException exception)
|
||||
{
|
||||
setOperationMessageForThrowable(request, buildMessageCode(HttpMessageNotReadableException.class), exception,
|
||||
false);
|
||||
|
||||
return getErrorView(request, response);
|
||||
}
|
||||
|
||||
@ExceptionHandler(IllegalInputException.class)
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public String handleControllerIllegalInputException(HttpServletRequest request, HttpServletResponse response,
|
||||
|
@ -104,7 +116,8 @@ public class ControllerAdvice extends AbstractController
|
|||
public String handleControllerIllegalArgumentException(HttpServletRequest request, HttpServletResponse response,
|
||||
IllegalArgumentException exception)
|
||||
{
|
||||
setOperationMessageForThrowable(request, buildMessageCode(IllegalArgumentException.class), exception, false);
|
||||
setOperationMessageForInternalServerError(request, buildMessageCode(IllegalArgumentException.class),
|
||||
exception);
|
||||
|
||||
return getErrorView(request, response);
|
||||
}
|
||||
|
@ -220,7 +233,8 @@ public class ControllerAdvice extends AbstractController
|
|||
public String handlePersistenceUnsupportedDialectException(HttpServletRequest request, HttpServletResponse response,
|
||||
UnsupportedDialectException exception)
|
||||
{
|
||||
setOperationMessageForThrowable(request, buildMessageCode(UnsupportedDialectException.class), exception, false);
|
||||
setOperationMessageForInternalServerError(request, buildMessageCode(UnsupportedDialectException.class),
|
||||
exception);
|
||||
|
||||
return getErrorView(request, response);
|
||||
}
|
||||
|
@ -234,7 +248,7 @@ public class ControllerAdvice extends AbstractController
|
|||
setOperationMessageForThrowable(request, buildMessageCode(PersistenceException.class), exception.getCause(),
|
||||
true);
|
||||
else
|
||||
setOperationMessageForThrowable(request, buildMessageCode(PersistenceException.class), exception, true);
|
||||
setOperationMessageForInternalServerError(request, buildMessageCode(PersistenceException.class), exception);
|
||||
|
||||
return getErrorView(request, response);
|
||||
}
|
||||
|
@ -369,14 +383,18 @@ public class ControllerAdvice extends AbstractController
|
|||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
public String handleThrowable(HttpServletRequest request, HttpServletResponse response, Throwable t)
|
||||
{
|
||||
setOperationMessageForThrowable(request, buildMessageCode(Throwable.class), t, false, t.getMessage());
|
||||
|
||||
if (LOGGER.isErrorEnabled())
|
||||
LOGGER.error("Controller exception", t);
|
||||
setOperationMessageForInternalServerError(request, buildMessageCode(Throwable.class), t);
|
||||
|
||||
return getErrorView(request, response);
|
||||
}
|
||||
|
||||
protected void setOperationMessageForInternalServerError(HttpServletRequest request, String messageCode,
|
||||
Throwable t)
|
||||
{
|
||||
setOperationMessageForThrowable(request, messageCode, t, false, t.getMessage());
|
||||
LOGGER.error("", t);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取错误信息视图。
|
||||
*
|
||||
|
|
|
@ -113,6 +113,7 @@ error.MethodArgumentNotValidException=\u8F93\u5165\u975E\u6CD5
|
|||
error.MissingServletRequestParameterException=\u8F93\u5165\u975E\u6CD5
|
||||
error.BindException=\u8F93\u5165\u6709\u8BEF\uFF0C\u8BF7\u68C0\u67E5
|
||||
error.ConversionException=\u8F93\u5165\u6709\u8BEF\uFF0C\u8BF7\u68C0\u67E5
|
||||
error.HttpMessageNotReadableException=\u8F93\u5165\u6709\u8BEF\uFF0C\u8BF7\u68C0\u67E5
|
||||
error.IllegalInputException=\u8F93\u5165\u6709\u8BEF\uFF0C\u8BF7\u68C0\u67E5
|
||||
error.IllegalArgumentException=\u8F93\u5165\u6709\u8BEF\uFF0C\u8BF7\u68C0\u67E5
|
||||
error.RecordNotFoundException=\u8BB0\u5F55\u672A\u627E\u5230\uFF0C\u6216\u8BB8\u5DF2\u88AB\u5220\u9664
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
if(!$meta.schemaTableCache)
|
||||
$meta.schemaTableCache = {};
|
||||
|
||||
//java.sql.Types
|
||||
$meta.typeEnum=
|
||||
//PersistenceSupport.supportsSqlType支持的SQL类型
|
||||
$meta.Types=
|
||||
{
|
||||
TINYINT: -6, SMALLINT: 5, INTEGER: 4, BIGINT: -5, REAL: 7, FLOAT: 6,
|
||||
DOUBLE: 8, DECIMAL: 3, NUMERIC: 2, BIT: -7, BOOLEAN: 16, CHAR: 1,
|
||||
|
@ -204,7 +204,7 @@
|
|||
else
|
||||
{
|
||||
columns = [];
|
||||
var Types = this.typeEnum;
|
||||
var Types = this.Types;
|
||||
for(var i=0; i<table.columns.length; i++)
|
||||
{
|
||||
var column = table.columns[i];
|
||||
|
@ -272,69 +272,85 @@
|
|||
|
||||
binaryColumnValueFilePrefix: "file:",
|
||||
|
||||
/**
|
||||
* 是否支持指定列的持久化操作,参考PersistenceSupport.supportsSqlType()。
|
||||
*/
|
||||
supportsColumn: function(column)
|
||||
{
|
||||
var type = column.type;
|
||||
|
||||
for(var p in this.Types)
|
||||
{
|
||||
if(this.Types[p] == type)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
isBinaryColumn: function(column)
|
||||
{
|
||||
var type = column.type;
|
||||
|
||||
return (type == this.typeEnum.BINARY
|
||||
|| type == this.typeEnum.VARBINARY || this.isBlobColumn(column));
|
||||
return (type == this.Types.BINARY
|
||||
|| type == this.Types.VARBINARY || this.isBlobColumn(column));
|
||||
},
|
||||
|
||||
isBlobColumn: function(column)
|
||||
{
|
||||
var type = column.type;
|
||||
|
||||
return (type == this.typeEnum.LONGVARBINARY
|
||||
|| type == this.typeEnum.BLOB);
|
||||
return (type == this.Types.LONGVARBINARY
|
||||
|| type == this.Types.BLOB);
|
||||
},
|
||||
|
||||
isTextColumn: function(column)
|
||||
{
|
||||
var type = column.type;
|
||||
|
||||
return (type == this.typeEnum.CHAR || type == this.typeEnum.VARCHAR
|
||||
|| type == this.typeEnum.LONGVARCHAR || type == this.typeEnum.CLOB
|
||||
|| type == this.typeEnum.NCHAR || type == this.typeEnum.NVARCHAR
|
||||
|| type == this.typeEnum.LONGNVARCHAR|| type == this.typeEnum.NCLOB
|
||||
|| type == this.typeEnum.SQLXML);
|
||||
return (type == this.Types.CHAR || type == this.Types.VARCHAR
|
||||
|| type == this.Types.LONGVARCHAR || type == this.Types.CLOB
|
||||
|| type == this.Types.NCHAR || type == this.Types.NVARCHAR
|
||||
|| type == this.Types.LONGNVARCHAR|| type == this.Types.NCLOB
|
||||
|| type == this.Types.SQLXML);
|
||||
},
|
||||
|
||||
isClobColumn: function(column)
|
||||
{
|
||||
var type = column.type;
|
||||
|
||||
return (type == this.typeEnum.LONGVARCHAR
|
||||
|| type == this.typeEnum.CLOB
|
||||
|| type == this.typeEnum.LONGNVARCHAR);
|
||||
return (type == this.Types.LONGVARCHAR
|
||||
|| type == this.Types.CLOB
|
||||
|| type == this.Types.LONGNVARCHAR);
|
||||
},
|
||||
|
||||
isSqlxmlColumn: function(column)
|
||||
{
|
||||
var type = column.type;
|
||||
return (type == this.typeEnum.SQLXML);
|
||||
return (type == this.Types.SQLXML);
|
||||
},
|
||||
|
||||
isDateColumn: function(column)
|
||||
{
|
||||
return (column.type == this.typeEnum.DATE);
|
||||
return (column.type == this.Types.DATE);
|
||||
},
|
||||
|
||||
isTimeColumn: function(column)
|
||||
{
|
||||
var type = column.type;
|
||||
return (type == this.typeEnum.TIME || type == this.typeEnum.TIME_WITH_TIMEZONE);
|
||||
return (type == this.Types.TIME || type == this.Types.TIME_WITH_TIMEZONE);
|
||||
},
|
||||
|
||||
isTimestampColumn: function(column)
|
||||
{
|
||||
var type = column.type;
|
||||
return (type == this.typeEnum.TIMESTAMP || type == this.typeEnum.TIMESTAMP_WITH_TIMEZONE);
|
||||
return (type == this.Types.TIMESTAMP || type == this.Types.TIMESTAMP_WITH_TIMEZONE);
|
||||
},
|
||||
|
||||
isBooleanColumn: function(column)
|
||||
{
|
||||
var type = column.type;
|
||||
return (type == this.typeEnum.BIT || type == this.typeEnum.BOOLEAN);
|
||||
return (type == this.Types.BIT || type == this.Types.BOOLEAN);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -444,7 +444,14 @@
|
|||
var labeldiv=$("<div class='form-item-label' />").appendTo(itemdiv);
|
||||
var valuediv=$("<div class='form-item-value' />").appendTo(itemdiv);
|
||||
|
||||
$("<label />").html(columnName).attr("title", (column.comment || columnName)).appendTo(labeldiv);
|
||||
var $label = $("<label />").html(columnName).attr("title", (column.comment || columnName)).appendTo(labeldiv);
|
||||
|
||||
if(!$.meta.supportsColumn(column))
|
||||
{
|
||||
$label.addClass("ui-state-disabled");
|
||||
$("<input type='text' />").addClass("ui-state-disabled").appendTo(valuediv);
|
||||
continue;
|
||||
}
|
||||
|
||||
var columnValue = $.meta.columnValue(data, columnName);
|
||||
|
||||
|
|
|
@ -931,7 +931,7 @@
|
|||
{
|
||||
return "<a title='"+$.escapeHtml(titleTip)+"'>"+$.escapeHtml(titleName)+"</a>";
|
||||
},
|
||||
|
||||
|
||||
buildDataTablesColumnTitleSearchable : function(titleName)
|
||||
{
|
||||
return "<a class='column-searchable'>"+$.escapeHtml(titleName)+"</a>";
|
||||
|
@ -962,11 +962,14 @@
|
|||
{
|
||||
var column = columns[i];
|
||||
|
||||
var disable = !$.meta.supportsColumn(column);
|
||||
|
||||
dtColumns.push(
|
||||
{
|
||||
title: $.meta.displayInfoHtml(column, "a"),
|
||||
data: $.escapeColumnNameForDataTable(column.name),
|
||||
columnIndex: i,
|
||||
columnName: column.name,
|
||||
options : options,
|
||||
render: function(data, type, row, meta)
|
||||
{
|
||||
|
@ -999,7 +1002,8 @@
|
|||
},
|
||||
defaultContent: "",
|
||||
orderable: column.sortable,
|
||||
searchable: true
|
||||
searchable: true,
|
||||
className: (disable ? "ui-state-disabled" : "")
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1013,11 +1017,9 @@
|
|||
{
|
||||
var columnInfos = this.getDataTableColumnInfos(settings);
|
||||
|
||||
var escapedName = $.escapeColumnNameForDataTable(columnName);
|
||||
|
||||
for(var i=0; i<columnInfos.length; i++)
|
||||
{
|
||||
if(escapedName == columnInfos[i].data)
|
||||
if(columnName == columnInfos[i].data || columnName == columnInfos[i].columnName)
|
||||
return i;
|
||||
}
|
||||
|
||||
|
@ -1056,7 +1058,9 @@
|
|||
getDataTableCellName : function(settings, cellIndex)
|
||||
{
|
||||
var columnInfos = this.getDataTableColumnInfos(settings);
|
||||
return $.unescapeColumnNameForDataTable(columnInfos[cellIndex.column].data);
|
||||
var dtColumn = columnInfos[cellIndex.column];
|
||||
|
||||
return (dtColumn.columnName || dtColumn.data);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -1070,7 +1074,7 @@
|
|||
for(var i=0; i<cellIndexes.length; i++)
|
||||
{
|
||||
var index = cellIndexes[i];
|
||||
var columnName = $.unescapeColumnNameForDataTable(columnInfos[index.column].data);
|
||||
var columnName = (columnInfos[index.column].columnName || columnInfos[index.column].data);
|
||||
|
||||
var indexes = (nameIndexes[columnName] || (nameIndexes[columnName] = []));
|
||||
indexes.push(index);
|
||||
|
@ -1597,11 +1601,25 @@
|
|||
|
||||
/**
|
||||
* ajax提交JSON数据。
|
||||
*
|
||||
* @param url 可选
|
||||
* @param options 必选
|
||||
*/
|
||||
ajaxJson: function(options)
|
||||
ajaxJson: function(url, options)
|
||||
{
|
||||
options.contentType = $.CONTENT_TYPE_JSON;
|
||||
$.ajax(options);
|
||||
if(options == undefined)
|
||||
{
|
||||
options = url;
|
||||
options.contentType = $.CONTENT_TYPE_JSON;
|
||||
options.type = "POST";
|
||||
$.ajax(options);
|
||||
}
|
||||
else
|
||||
{
|
||||
options.contentType = $.CONTENT_TYPE_JSON;
|
||||
options.type = "POST";
|
||||
$.ajax(url, options);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -449,7 +449,6 @@ ${detectNewVersionScript}
|
|||
|
||||
$.ajaxJson($.toPath(false, contextPath, "schema", schemaId, "pagingQueryTable"),
|
||||
{
|
||||
type: "POST",
|
||||
data : param,
|
||||
success : function(pagingData)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue