Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
d832e4c0
提交
d832e4c0
authored
11月 21, 2008
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove GPL licensed file
上级
8b03f980
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
14 行增加
和
465 行删除
+14
-465
JdbcMetaData.java.txt
h2/src/tools/com/caucho/jdbc/JdbcMetaData.java.txt
+14
-465
没有找到文件。
h2/src/tools/com/caucho/jdbc/JdbcMetaData.java.txt
浏览文件 @
d832e4c0
/*
Sorry I can not include this file because it is GPL licensed, and
* Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
http://ohloh.org says that this may conflict with another license.
*
* This file is part of Resin(R) Open Source
*
* Each copy or derived work must preserve the copyright notice and
* this notice unmodified.
*
* Resin Open Source is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Resin Open Source 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,
* or any warranty of NON-INFRINGEMENT. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General
* Public License along with Resin Open Source; if not, write to the
*
* Free Software Foundation, Inc.
* 59 Temple Place, Suite 330
* Boston, MA 02111-1307 USA
*
* @author Scott Ferguson
*/
package com.caucho.jdbc;
In the file JdbcMetaData.java in package com.caucho.jdbc
in method public static JdbcMetaData create(DataSource ds),
import com.caucho.util.L10N;
you need to add
import com.caucho.util.Log;
import javax.sql.DataSource;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Abstract way of grabbing data from the JDBC connection.
*/
public class JdbcMetaData {
private static final L10N L = new L10N(JdbcMetaData.class);
private static final Logger log = Log.open(JdbcMetaData.class);
private DataSource _ds;
/**
* Create a new JDBC backing store.
*/
protected JdbcMetaData(DataSource ds)
{
_ds = ds;
}
/**
* Create based on the connection.
*/
public static JdbcMetaData create(DataSource ds)
{
Connection conn = null;
try {
conn = ds.getConnection();
DatabaseMetaData md = conn.getMetaData();
String name = md.getDatabaseProductName();
log.fine(L.l("Database '{0}' metadata.", name));
if ("H2".equalsIgnoreCase(name))
if ("H2".equalsIgnoreCase(name))
return new H2MetaData(ds);
return new H2MetaData(ds);
else if ("oracle".equalsIgnoreCase(name))
return new OracleMetaData(ds);
else if ("resin".equalsIgnoreCase(name))
return new ResinMetaData(ds);
else if ("postgres".equalsIgnoreCase(name) ||
"PostgreSQL".equalsIgnoreCase(name))
return new PostgresMetaData(ds);
else if ("mysql".equalsIgnoreCase(name))
return new MysqlMetaData(ds);
else if ("Microsoft SQL Server".equalsIgnoreCase(name))
return new SqlServerMetaData(ds);
else {
log.fine(name + " is an unknown database type");
return new JdbcMetaData(ds);
}
} catch (SQLException e) {
log.log(Level.FINE, e.toString(), e);
return new JdbcMetaData(ds);
} finally {
try {
if (conn != null) conn.close();
} catch (SQLException e) {
}
}
}
/**
* Returns the database name.
*/
public String getDatabaseName()
{
Connection conn = null;
try {
conn = getConnection();
DatabaseMetaData md = conn.getMetaData();
return md.getDatabaseProductName();
} catch (SQLException e) {
log.log(Level.WARNING, e.toString(), e);
return "unknown";
} finally {
try {
if (conn != null) conn.close();
} catch (SQLException e) {
}
}
}
/**
* Returns the blob type.
*/
public String getBlobType()
{
Connection conn = null;
try {
conn = getConnection();
DatabaseMetaData md = conn.getMetaData();
ResultSet rs;
rs = md.getTypeInfo();
try {
while (rs.next()) {
if (rs.getShort("DATA_TYPE") == Types.BLOB) {
return rs.getString("TYPE_NAME");
}
}
} finally {
rs.close();
}
rs = md.getTypeInfo();
try {
while (rs.next()) {
int dataType = rs.getShort("DATA_TYPE");
if (rs.getShort("DATA_TYPE") == Types.LONGVARBINARY) {
return rs.getString("TYPE_NAME");
}
}
} finally {
rs.close();
}
rs = md.getTypeInfo();
try {
while (rs.next()) {
if (rs.getShort("DATA_TYPE") == Types.BINARY) {
return rs.getString("TYPE_NAME");
}
}
} finally {
rs.close();
}
rs = md.getTypeInfo();
try {
while (rs.next()) {
if (rs.getShort("DATA_TYPE") == Types.VARBINARY) {
return rs.getString("TYPE_NAME");
}
}
} finally {
rs.close();
}
} catch (SQLException e) {
log.log(Level.FINE, e.toString(), e);
} finally {
try {
if (conn != null)
conn.close();
} catch (Exception e) {
}
}
return null;
}
/**
* Returns the long type.
*/
public String getLongType()
{
Connection conn = null;
try {
conn = getConnection();
DatabaseMetaData md = conn.getMetaData();
ResultSet rs;
rs = md.getTypeInfo();
try {
while (rs.next()) {
if (rs.getShort("DATA_TYPE") == Types.BIGINT) {
return rs.getString("TYPE_NAME");
}
}
} finally {
rs.close();
}
} catch (SQLException e) {
log.log(Level.FINE, e.toString(), e);
} finally {
try {
if (conn != null) conn.close();
} catch (SQLException e) {
}
}
return null;
}
/**
* Returns true if identity is supported.
*/
public boolean supportsIdentity()
{
return false;
}
/**
* Returns the identity property
*/
public String createIdentitySQL(String sqlType)
{
throw new UnsupportedOperationException(getClass().getName());
}
/**
* Returns true if sequences are supported.
*/
public boolean supportsSequences()
{
return false;
}
/**
* Returns a sequence select expression.
*/
public String createSequenceSQL(String name, int size)
{
throw new UnsupportedOperationException(getClass().getName());
}
/**
* Returns a sequence select expression.
*/
public String selectSequenceSQL(String name)
{
throw new UnsupportedOperationException(getClass().getName());
}
/**
* Returns a sequence select expression.
*/
public String testSequenceSQL(String name)
{
return selectSequenceSQL(name) + " WHERE 1=0";
}
/**
* Returns the code to test for a boolean value for a term.
*/
public String generateBoolean(String term)
{
return term;
}
/**
* Returns a limit.
*/
public String limit(String sql, int max)
{
return sql;
}
/**
* New version to Return SQL for the table with the given
* SQL type. Takes, length, precision and scale.
*/
public String getCreateColumnSQL(int sqlType, int length, int precision, int scale)
{
String type = null;
switch (sqlType) {
case Types.BOOLEAN:
type = getCreateColumnSQLImpl(sqlType, length, precision, scale);
if (type == null)
type = getCreateColumnSQLImpl(Types.BIT, length, precision, scale);
break;
case Types.DATE:
type = getCreateColumnSQLImpl(sqlType, length, precision, scale);
if (type == null)
type = getCreateColumnSQLImpl(Types.TIMESTAMP, length, precision, scale);
break;
case Types.TIME:
type = getCreateColumnSQLImpl(sqlType, length, precision, scale);
if (type == null)
type = getCreateColumnSQLImpl(Types.TIMESTAMP, length, precision, scale);
break;
case Types.DOUBLE:
type = getCreateColumnSQLImpl(Types.DOUBLE, length, precision, scale);
break;
case Types.NUMERIC:
type = getCreateColumnSQLImpl(Types.NUMERIC, length, precision, scale);
break;
default:
type = getCreateColumnSQLImpl(sqlType, length, precision, scale);
break;
}
if (type == null)
type = getDefaultCreateTableSQL(sqlType, length, precision, scale);
return type;
}
/**
* Returns the SQL for the table with the given SQL type.
*/
protected String getCreateColumnSQLImpl(int sqlType, int length, int precision, int scale)
{
Connection conn = null;
try {
conn = getConnection();
DatabaseMetaData md = conn.getMetaData();
ResultSet rs;
rs = md.getTypeInfo();
try {
while (rs.next()) {
if (rs.getShort("DATA_TYPE") == sqlType) {
String typeName = rs.getString("TYPE_NAME");
String params = rs.getString("CREATE_PARAMS");
if (params == null || params.equals(""))
return typeName;
else if (params.startsWith("(M)")) {
if (length > 0)
return typeName + "(" + length + ")";
else
else
return typeName;
}
else if (params.startsWith("(M,D)") || params.equals("precision,scale")) {
if (precision > 0) {
typeName += "(" + precision;
if (scale > 0) {
typeName += "," + scale;
}
typeName += ")";
}
return typeName;
}
else if (params.startsWith("(")) {
int tail = params.indexOf(')');
if (tail > 0) {
String value = params.substring(1, tail);
boolean isConstant = true;
for (int i = 0; i < value.length(); i++) {
if (value.charAt(i) >= 'a' && value.charAt(i) <= 'z')
isConstant = false;
else if (value.charAt(i) >= 'A' && value.charAt(i) <= 'Z')
isConstant = false;
}
if (isConstant)
return typeName + "(" + value + ")";
}
return typeName;
}
else {
return typeName;
}
}
}
} finally {
rs.close();
}
} catch (Throwable e) {
log.log(Level.FINE, e.toString(), e);
} finally {
try {
if (conn != null)
conn.close();
} catch (Exception e) {
}
}
return null;
}
protected String getDefaultCreateTableSQL(int sqlType, int length, int precision, int scale)
just before
{
switch (sqlType) {
case java.sql.Types.BOOLEAN:
return "CHAR";
case java.sql.Types.BIT:
case java.sql.Types.TINYINT:
case java.sql.Types.SMALLINT:
case java.sql.Types.INTEGER:
case java.sql.Types.BIGINT:
return "INTEGER";
case java.sql.Types.NUMERIC:
case java.sql.Types.DECIMAL:
String typeString = "NUMERIC";
if (precision > 0) {
typeString += "(" + precision;
if (scale > 0) {
typeString += "," + scale;
}
typeString += ")";
}
return typeString;
case java.sql.Types.DOUBLE:
case java.sql.Types.FLOAT:
return "DOUBLE";
case java.sql.Types.CHAR:
return "CHAR";
case java.sql.Types.DATE:
case java.sql.Types.TIME:
case java.sql.Types.TIMESTAMP:
return "TIMESTAMP";
default:
return "VARCHAR(" + length + ")";
}
}
/**
if ("oracle".equalsIgnoreCase(name))
* Returns a connection.
*/
protected Connection getConnection()
throws SQLException
{
return _ds.getConnection();
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论