本文整理汇总了Java中java.sql.JDBCType.valueOf方法的典型用法代码示例。如果您正苦于以下问题:Java JDBCType.valueOf方法的具体用法?Java JDBCType.valueOf怎么用?Java JDBCType.valueOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.JDBCType
的用法示例。
在下文中一共展示了JDBCType.valueOf方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MetaData
import java.sql.JDBCType; //导入方法依赖的package包/类
/**
* Constructs meta-data from given statement.
* @param stmt Prepared statement for a query.
* @throws SQLException If an error occurs during meta-data creation.
*/
MetaData(PreparedStatement stmt) throws SQLException {
ResultSetMetaData md = stmt.getMetaData();
int n = md.getColumnCount();
ArrayList<ColumnInfo> info = new ArrayList<>(n);
for (int i = 1; i <= n; i++) {
ColumnInfo ci =
new ColumnInfo(md.getColumnLabel(i),
JDBCType.valueOf(md.getColumnType(i)));
info.add(ci);
}
columns = Collections.unmodifiableList(info);
}
示例2: getJsonTypedValue
import java.sql.JDBCType; //导入方法依赖的package包/类
public Object getJsonTypedValue(int type, Object value, String name) throws SQLException {
if (value == null) {
return null;
}
JDBCType current = JDBCType.valueOf(type);
switch (current) {
case TIMESTAMP:
Timestamp timestamp = (Timestamp) value;
return timestamp.getTime();
case TIMESTAMP_WITH_TIMEZONE:
Timestamp ts = (Timestamp) value;
JsonObject tsWithTz = JsonObject.create();
tsWithTz.put("timestamp", ts.getTime());
tsWithTz.put("timezone", ts.getTimezoneOffset());
return tsWithTz;
case DATE:
Date sqlDate = (Date) value;
return sqlDate.getTime();
case DECIMAL:
case NUMERIC:
BigDecimal bigDecimal = (BigDecimal) value;
return bigDecimal.doubleValue();
case ARRAY:
Array array = (Array) value;
Object[] objects = (Object[]) array.getArray();
return JsonArray.from(objects);
case BINARY:
case BLOB:
case LONGVARBINARY:
return Base64.getEncoder().encodeToString((byte[]) value);
case OTHER:
case JAVA_OBJECT:
// database specific, default to String value
return value.toString();
default:
return value;
}
}
示例3: initialized
import java.sql.JDBCType; //导入方法依赖的package包/类
/**
* 初始化阶段
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
* @param introspectedTable
* @return
*/
@Override
public void initialized(IntrospectedTable introspectedTable) {
// 1. 首先获取全局配置
Properties properties = getProperties();
String logicalDeleteColumn = properties.getProperty(PRO_LOGICAL_DELETE_COLUMN);
this.logicalDeleteValue = properties.getProperty(PRO_LOGICAL_DELETE_VALUE);
this.logicalUnDeleteValue = properties.getProperty(PRO_LOGICAL_UN_DELETE_VALUE);
// 2. 获取表单独配置,如果有则覆盖全局配置
if (introspectedTable.getTableConfigurationProperty(PRO_LOGICAL_DELETE_COLUMN) != null) {
logicalDeleteColumn = introspectedTable.getTableConfigurationProperty(PRO_LOGICAL_DELETE_COLUMN);
}
if (introspectedTable.getTableConfigurationProperty(PRO_LOGICAL_DELETE_VALUE) != null) {
this.logicalDeleteValue = introspectedTable.getTableConfigurationProperty(PRO_LOGICAL_DELETE_VALUE);
}
if (introspectedTable.getTableConfigurationProperty(PRO_LOGICAL_UN_DELETE_VALUE) != null) {
this.logicalUnDeleteValue = introspectedTable.getTableConfigurationProperty(PRO_LOGICAL_UN_DELETE_VALUE);
}
// 3. 判断该表是否存在逻辑删除列
this.logicalDeleteColumn = null;
List<IntrospectedColumn> columns = introspectedTable.getAllColumns();
for (IntrospectedColumn column : columns) {
if (column.getActualColumnName().equalsIgnoreCase(logicalDeleteColumn)) {
// 判断字段类型
JDBCType type = JDBCType.valueOf(column.getJdbcType());
if (JDBCType.BIGINT == type
|| JDBCType.BIT == type
|| JDBCType.BOOLEAN == type
|| JDBCType.CHAR == type
|| JDBCType.DECIMAL == type
|| JDBCType.DOUBLE == type
|| JDBCType.FLOAT == type
|| JDBCType.INTEGER == type
|| JDBCType.LONGNVARCHAR == type
|| JDBCType.LONGVARCHAR == type
|| JDBCType.NCHAR == type
|| JDBCType.NUMERIC == type
|| JDBCType.NVARCHAR == type
|| JDBCType.SMALLINT == type
|| JDBCType.TINYINT == type
|| JDBCType.VARCHAR == type) {
this.logicalDeleteColumn = column;
} else {
warnings.add("itfsw(逻辑删除插件):" + introspectedTable.getFullyQualifiedTable() + "逻辑删除列(" + introspectedTable.getTableConfigurationProperty(PRO_LOGICAL_DELETE_COLUMN) + ")的类型不在支持范围(请使用数字列,字符串列,布尔列)!");
}
}
}
if (introspectedTable.getTableConfigurationProperty(PRO_LOGICAL_DELETE_COLUMN) != null && this.logicalDeleteColumn == null) {
warnings.add("itfsw(逻辑删除插件):" + introspectedTable.getFullyQualifiedTable() + "没有找到您配置的逻辑删除列(" + introspectedTable.getTableConfigurationProperty(PRO_LOGICAL_DELETE_COLUMN) + ")!");
}
// 4. 判断逻辑删除值是否配置了
if (this.logicalDeleteColumn != null && (this.logicalDeleteValue == null || this.logicalUnDeleteValue == null)) {
warnings.add("itfsw(逻辑删除插件):" + introspectedTable.getFullyQualifiedTable() + "没有找到您配置的逻辑删除值,请全局或者局部配置logicalDeleteValue和logicalUnDeleteValue值!");
}
// 5. 获取逻辑删除常量值
this.logicalDeleteConstName = properties.getProperty(PRO_LOGICAL_DELETE_CONST_NAME) != null ? properties.getProperty(PRO_LOGICAL_DELETE_CONST_NAME).toUpperCase() : DEFAULT_LOGICAL_DELETE_CONST_NAME;
this.logicalUnDeleteConstName = properties.getProperty(PRO_LOGICAL_UN_DELETE_CONST_NAME) != null ? properties.getProperty(PRO_LOGICAL_UN_DELETE_CONST_NAME).toUpperCase() : DEFAULT_LOGICAL_UN_DELETE_CONST_NAME;
// 6. 防止增强的selectByPrimaryKey中逻辑删除键冲突
if (this.logicalDeleteColumn != null) {
Field logicalDeleteField = JavaBeansUtil.getJavaBeansField(this.logicalDeleteColumn, context, introspectedTable);
if (logicalDeleteField.getName().equals(PARAMETER_LOGICAL_DELETED)) {
this.logicalDeleteColumn = null;
warnings.add("itfsw(逻辑删除插件):" + introspectedTable.getFullyQualifiedTable() + "配置的逻辑删除列和插件保留关键字(" + PARAMETER_LOGICAL_DELETED + ")冲突!");
}
}
}
示例4: getTypeDescription
import java.sql.JDBCType; //导入方法依赖的package包/类
/**
* Create a data type description for this column
*
* @param columnResultSet
* @return
* @throws SQLException
*/
protected String getTypeDescription(ResultSet columnResultSet)
throws SQLException {
StringBuffer buffer = new StringBuffer();
// initialize with a proper value, if type cannot be resolved
JDBCType type = JDBCType.OTHER;
String typeName = type.getName();
int typeValue = columnResultSet.getInt("DATA_TYPE");
try {
type = JDBCType.valueOf(typeValue);
} catch (IllegalArgumentException exception) {
LOGGER.warn(
"Integer constant '{}' does not seem to represent a known JDBCType.",
Integer.toString(typeValue));
}
int size = columnResultSet.getInt("COLUMN_SIZE");
if (type != null) {
buffer.append(type.name());
if (type.equals(JDBCType.CHAR) || type.equals(JDBCType.VARCHAR)
|| type.equals(JDBCType.LONGNVARCHAR)
|| type.equals(JDBCType.LONGVARCHAR)
|| type.equals(JDBCType.NCHAR)
|| type.equals(JDBCType.NVARCHAR)) {
buffer.append("(");
buffer.append(size);
buffer.append(")");
} else if (type.equals(JDBCType.DECIMAL)
|| type.equals(JDBCType.DOUBLE)
|| type.equals(JDBCType.FLOAT)
|| type.equals(JDBCType.REAL)
|| type.equals(JDBCType.NUMERIC)) {
buffer.append("(");
buffer.append(size);
if (columnResultSet.getObject("DECIMAL_DIGITS")!=null) {
int fractionalDigits =columnResultSet.getInt("DECIMAL_DIGITS");
buffer.append(',');
buffer.append(fractionalDigits);
}
buffer.append(")");
}
}
return buffer.toString();
}
示例5: Column
import java.sql.JDBCType; //导入方法依赖的package包/类
/**
* コンストラクタ
*
* @param columnName カラム名
* @param dataType データタイプ
* @param remarks コメント文字列
* @param isNullable NULL可かどうか
* @param ordinalPosition 列インデックス
*/
public Column(final String columnName, final int dataType, final String remarks, final String isNullable,
final int ordinalPosition) {
this(columnName, JDBCType.valueOf(dataType), remarks, isNullable, ordinalPosition);
}