private static Table readTable(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException { String tableName = (String) values.get("TABLE_NAME"); Table table = null; if ((tableName != null) && (tableName.length() > 0)) { table = new Table(); table.setName(tableName); table.setType((String) values.get("TABLE_TYPE")); table.setCatalog((String) values.get("TABLE_CAT")); table.setSchema((String) values.get("TABLE_SCHEM")); table.setDescription((String) values.get("REMARKS")); table.addColumns(readColumns(metaData, tableName)); Collection<String> primaryKeys = readPrimaryKeyNames(metaData, tableName); for (Object key : primaryKeys) { Column col = table.findColumn((String) key, true); if (col != null) { col.setPrimaryKey(true); } else { throw new NullPointerException(String.format("%s pk %s is null - %s %s", tableName, key, ToStringBuilder.reflectionToString(metaData, ToStringStyle.SIMPLE_STYLE), ToStringBuilder.reflectionToString(values, ToStringStyle.SIMPLE_STYLE))); } } } return table; }
private static Table readTable(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException { String tableName = (String) values.get("TABLE_NAME"); Table table = null; if ((tableName != null) && (tableName.length() > 0)) { table = new Table(); table.setName(tableName); table.setType((String) values.get("TABLE_TYPE")); table.setCatalog((String) values.get("TABLE_CAT")); table.setSchema((String) values.get("TABLE_SCHEM")); table.setDescription((String) values.get("REMARKS")); table.addColumns(readColumns(metaData, tableName)); Collection<String> primaryKeys = readPrimaryKeyNames(metaData, tableName); for (Object key : primaryKeys) { Column col = table.findColumn((String) key, true); if (col != null) { col.setPrimaryKey(true); } else { throw new NullPointerException(String.format("%s pk %s is null - %s %s", tableName, key, ToStringBuilder.reflectionToString(metaData, ToStringStyle.SIMPLE_STYLE), ToStringBuilder.reflectionToString(values, ToStringStyle.SIMPLE_STYLE))); } } } return table; }
private static Table generateTable(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException { String tableName = (String) values.get("TABLE_NAME"); Table table = null; if ((tableName != null) && (tableName.length() > 0)) { table = new Table(); table.setName(tableName); table.setType((String) values.get("TABLE_TYPE")); table.setCatalog((String) values.get("TABLE_CAT")); table.setSchema((String) values.get("TABLE_SCHEM")); table.setDescription((String) values.get("REMARKS")); table.addColumns(generateColumns(metaData, tableName)); table.addIndices(generateIndices(metaData, tableName)); Collection<String> primaryKeys = readPrimaryKeyNames(metaData, tableName); for (Object key : primaryKeys) { Column col = table.findColumn((String) key, true); if (col != null) { col.setPrimaryKey(true); } else { throw new NullPointerException(String.format("%s pk %s is null - %s %s", tableName, key, ToStringBuilder.reflectionToString(metaData, ToStringStyle.SIMPLE_STYLE), ToStringBuilder.reflectionToString(values, ToStringStyle.SIMPLE_STYLE))); } } } return table; }
int dotPos = tableName.indexOf('.'); if (dotPos > 0) { table.setSchema(tableName.substring(0, dotPos)); table.setName(tableName.substring(dotPos + 1));
table.setType((String)values.get("TABLE_TYPE")); table.setCatalog((String)values.get("TABLE_CAT")); table.setSchema((String)values.get("TABLE_SCHEM")); table.setDescription((String)values.get("REMARKS"));
/** * Creates a temporary table object that corresponds to the given table. * Database-specific implementations may redefine this method if e.g. the * database directly supports temporary tables. The default implementation * simply appends an underscore to the table name and uses that as the * table name. * * @param targetTable The target table * @return The temporary table */ protected Table getTemporaryTableFor(Table targetTable) { CloneHelper cloneHelper = new CloneHelper(); Table table = new Table(); table.setCatalog(targetTable.getCatalog()); table.setSchema(targetTable.getSchema()); table.setName(targetTable.getName() + "_"); table.setType(targetTable.getType()); for (int idx = 0; idx < targetTable.getColumnCount(); idx++) { // TODO: clone PK status ? table.addColumn(cloneHelper.clone(targetTable.getColumn(idx), true)); } return table; }
result.setSchema(source.getSchema()); result.setName(source.getName()); result.setType(source.getType());