获得表的所有列名

@param ds 数据源
@param tableName 表名
@return 列数组
@throws DbRuntimeException SQL执行异常
543499
public static String[] getColumnNames(DataSource ds, String tableName) {
		List<String> columnNames = new ArrayList<String>();
		Connection conn = null;
		ResultSet rs = null;
		try {
			conn = ds.getConnection();
			final DatabaseMetaData metaData = conn.getMetaData();
			rs = metaData.getColumns(conn.getCatalog(), null, tableName, null);
			while (rs.next()) {
				columnNames.add(rs.getString("COLUMN_NAME"));
			}
			return columnNames.toArray(new String[columnNames.size()]);
		} catch (Exception e) {
			throw new DbRuntimeException("Get columns error!", e);
		} finally {
			DbUtil.close(rs, conn);
		}
	}
1252155
DataSource getFastDatasource() {
		if(delegatedDataSource==null){
			delegatedDataSource = dbms.getFastDataSource(this);
			if(delegatedDataSource == null){
				throw new RuntimeException("Unable to obtain datasource from dbms");
			}
		}
		return delegatedDataSource;
	}
609567
public int deleteByTableName(String tableName) throws SQLException {

		DeleteBuilder<Extensions, Void> db = deleteBuilder();

		db.where().eq(Extensions.COLUMN_TABLE_NAME, tableName);

		int deleted = db.delete();

		return deleted;
	}
1051590
@GuardedBy("this")
    private TableSource getTableSource(String databaseName, String tableName)
    {
        checkHoldsLock();

        checkReadable();
        Action<TableAndMore> tableAction = tableActions.get(new SchemaTableName(databaseName, tableName));
        if (tableAction == null) {
            return TableSource.PRE_EXISTING_TABLE;
        }
        switch (tableAction.getType()) {
            case ADD:
                return TableSource.CREATED_IN_THIS_TRANSACTION;
            case ALTER:
                throw new IllegalStateException("Tables are never altered in the current implementation");
            case DROP:
                throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
            case INSERT_EXISTING:
                return TableSource.PRE_EXISTING_TABLE;
            default:
                throw new IllegalStateException("Unknown action type");
        }
    }
1164138
private TableName snapshotExists(String snapshotName,
      List<SnapshotDescription> snapshotDescriptions) {
    if (snapshotDescriptions != null) {
      Optional<SnapshotDescription> descriptor =
          snapshotDescriptions.stream()
              .filter(desc -> desc.getName().equals(snapshotName))
              .findFirst();
      return descriptor.isPresent() ? descriptor.get().getTableName() : null;
    }
    return null;
  }
1114745
public List<Map<String, String>> getMetadataByTable(String schema, String tableName) throws SQLException {
		
		List<Map<String, String>> table = new ArrayList<Map<String, String>>();

		DatabaseMetaData metadata = conn.getMetaData();
		ResultSet rs = metadata.getColumns(null, schema, tableName, null);
		
		while (rs.next()) {
			
			Map<String, String> field = new HashMap<String, String>();
			
			field.put("NAME",  rs.getString("COLUMN_NAME"));// 字段名称
			field.put("TYPE", rs.getString("TYPE_NAME")); //字段类型名称(例如：VACHAR2)
			field.put("SIZE", Integer.toString(rs.getInt("COLUMN_SIZE"))); //字段长度
			field.put("NULLABLE", rs.getString("IS_NULLABLE")); //是否为空
			field.put("REMARK", rs.getString("REMARKS")); //字段注释
			
			table.add(field);
			
		}

		return table;
	}
601103
public Boolean deletes(String tableName, Set<byte[]> rowKeys) {
        boolean flag = false;
        try {
            HTable table = (HTable) getConnection().getTable(TableName.valueOf(tableName));
            List<Delete> deletes = new ArrayList<>();
            for (byte[] rowKey : rowKeys) {
                Delete delete = new Delete(rowKey);
                deletes.add(delete);
            }
            if (!deletes.isEmpty()) {
                table.delete(deletes);
            }
            flag = true;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new RuntimeException(e);
        }
        return flag;
    }
1134420
public Crud<T, K> table(Connection connection, String table) throws SQLException {
        CrudMeta crudMeta = CrudMeta.of(connection, table, jdbcMapperFactory.columnDefinitions());
        return CrudFactory.<T, K>newInstance(target, keyTarget, crudMeta, jdbcMapperFactory);
    }
1070482
public static String[] getColumnNames(ResultSet rs) throws DbRuntimeException {
		try {
			ResultSetMetaData rsmd = rs.getMetaData();
			int columnCount = rsmd.getColumnCount();
			String[] labelNames = new String[columnCount];
			for (int i = 0; i < labelNames.length; i++) {
				labelNames[i] = rsmd.getColumnLabel(i + 1);
			}
			return labelNames;
		} catch (Exception e) {
			throw new DbRuntimeException("Get colunms error!", e);
		}
	}
579954
public static String getDynamicTableName(Class<?> entityClass, String tableName) {
        if (IDynamicTableName.class.isAssignableFrom(entityClass)) {
            StringBuilder sql = new StringBuilder();
            sql.append("<choose>");
            sql.append("<when test=\"@tk.mybatis.mapper.util.OGNL@isDynamicParameter(_parameter) and dynamicTableName != null and dynamicTableName != ''\">");
            sql.append("${dynamicTableName}\n");
            sql.append("</when>");
            //不支持指定列的时候查询全部列
            sql.append("<otherwise>");
            sql.append(tableName);
            sql.append("</otherwise>");
            sql.append("</choose>");
            return sql.toString();
        } else {
            return tableName;
        }
    }
612478
public TableMetadata getTableMetadata(String tableName){
		if(tableName == null) return null;
		
		try {
			tableMetadataStatement.setInt(1, tableName.hashCode());
			ResultSet set = tableMetadataStatement.executeQuery();
			
			return transformToTableMetadata(set);
		} catch (SQLException e) {
			throw new BackendException("Could not get TableMetadata for table '" + tableName + "'", e);
		}
	}
261468
public boolean renameTable(String tableName, String newTableName) throws DBException
    {
        try {
            if (DBConstants.TRUE.equals((String)this.getDatabase().getProperties().get(SQLParams.NO_PREPARED_STATEMENTS_ON_CREATE)))
                this.setStatement(null, DBConstants.SQL_CREATE_TYPE);
            if (this.getStatement(DBConstants.SQL_CREATE_TYPE) == null)
            	this.setStatement(((JdbcDatabase)this.getDatabase()).getJDBCConnection().createStatement(), DBConstants.SQL_CREATE_TYPE);

            String sql = "RENAME TABLE " + tableName + " TO " + newTableName;
            this.getStatement(DBConstants.SQL_CREATE_TYPE).execute(sql);
            
            if (DBConstants.TRUE.equals((String)this.getDatabase().getProperties().get(SQLParams.NO_PREPARED_STATEMENTS_ON_CREATE)))
                this.setStatement(null, DBConstants.SQL_CREATE_TYPE);
        } catch (SQLException e) {
            throw this.getDatabase().convertError(e);
        }
        return true;
    }
51427
public String generateSqlSelectAll(String tableName) {
        try {
            return cacheSQLs.get("SELECT-ALL:" + tableName, () -> {
                return MessageFormat.format("SELECT {2} FROM {0} ORDER BY {1}", tableName,
                        strPkColumns, strAllColumns);
            });
        } catch (ExecutionException e) {
            throw new DaoException(e);
        }
    }
70692
public static SqlRunner create(DataSource ds, String driverClassName) {
		return new SqlRunner(ds, DialectFactory.newDialect(driverClassName));
	}
609858
public static <T, ID> RuntimeExceptionDao<T, ID> createDao(ConnectionSource connectionSource,
			DatabaseTableConfig<T> tableConfig) throws SQLException {
		@SuppressWarnings("unchecked")
		Dao<T, ID> castDao = (Dao<T, ID>) DaoManager.createDao(connectionSource, tableConfig);
		return new RuntimeExceptionDao<T, ID>(castDao);
	}
271675
public static String generateDropTableDDL(String dbName, String tableName) {
    return String.format("DROP TABLE IF EXISTS `%s`.`%s`", dbName, tableName);
  }
853781
public static DataSource getJndiDs(String jndiName) {
		try {
			return (DataSource) new InitialContext().lookup(jndiName);
		} catch (NamingException e) {
			throw new DbRuntimeException(e);
		}
	}