@Override public void updateColumnDefinition(TableDefinition table, WbConnection conn) { String typeNames = conn.getDbSettings().getProperty("qualifier.typenames", "datetime,interval"); Set<String> types = CollectionUtil.caseInsensitiveSet(); types.addAll(StringUtil.stringToList(typeNames, ",", true, true, false, false)); boolean checkRequired = false; for (ColumnIdentifier col : table.getColumns()) { String plainType = SqlUtil.getPlainTypeName(col.getDbmsType()); if (types.contains(plainType)) { checkRequired = true; } int type = col.getDataType(); String val = col.getDefaultValue(); if (defaultNeedsQuotes(val, type, plainType)) { val = "'" + val + "'"; col.setDefaultValue(val); } } if (checkRequired) { updateDateColumns(table, conn); } }
private void updateComputedColumns(TableDefinition table, WbConnection conn) { PreparedStatement stmt = null; ResultSet rs = null; String tablename = table.getTable().getRawTableName(); String schema = table.getTable().getRawSchema(); String sql = "select column_name, \n" + " generation_type \n" + "from sys.table_columns \n" + "where table_name = ? \n" + "and schema_name = ? \n" + "and generation_type is not null"; Map<String, String> expressions = new HashMap<>(); try { stmt = conn.getSqlConnection().prepareStatement(sql); stmt.setString(1, tablename); stmt.setString(2, schema); rs = stmt.executeQuery(); while (rs.next()) { String colname = rs.getString(1); String generated = rs.getString(2); if (StringUtil.isNonEmpty(generated)) { expressions.put(colname, "GENERATED " + generated); } } } catch (Exception e) { LogMgr.logError("HanaColumnEnhancer.updateComputedColumns()", "Error retrieving remarks", e); } finally { SqlUtil.closeAll(rs, stmt); } for (ColumnIdentifier col : table.getColumns()) { String expr = expressions.get(col.getColumnName()); if (StringUtil.isNonBlank(expr)) { col.setDefaultValue(null); col.setComputedColumnExpression(expr); col.setIsAutoincrement(true); } } }