/** * Treat tables with no primary keys as a table with all primary keys. */ private static void makeAllColumnsPrimaryKeysIfNoPrimaryKeysFound(Table table) { if ((table != null) && (table.getPrimaryKeyColumns() != null) && (table.getPrimaryKeyColumns().length == 0)) { Column[] allCoumns = table.getColumns(); for (Column column : allCoumns) { column.setPrimaryKey(true); } } }
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 Column readColumn(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException { Column column = new Column(); column.setName((String) values.get("COLUMN_NAME")); column.setDefaultValue((String) values.get("COLUMN_DEF")); column.setTypeCode(((Integer) values.get("DATA_TYPE")).intValue()); column.setTypeCode(Types.TIMESTAMP); switch (column.getTypeCode()) { case Types.TINYINT: column.setTypeCode(Types.SMALLINT); break; case Types.SMALLINT: column.setTypeCode(Types.INTEGER); break; case Types.INTEGER: column.setTypeCode(Types.BIGINT); break; case Types.BIGINT: column.setTypeCode(Types.DECIMAL); break; default: column.setPrecisionRadix(precision.intValue()); size = (String) _defaultSizes.get(new Integer(column.getTypeCode())); column.setSize(size);
private void modifyVarBinaryColumn(Database targetModel, String tableName, String columnName) { Table table = targetModel.findTable(tableName); Column c = table.findColumn(columnName); c.setType("VARCHAR"); c.setSize("2000"); System.out.println("updating column " + c.getName() + " for table " + table.getName()); } /**
for (Column tableColumn : table.getColumns()) { isRequiredMap.put(StringUtils.lowerCase(tableColumn.getName()), tableColumn.isRequired()); for (Column tableColumn : table.getColumns()) { isRequiredMap.put(StringUtils.lowerCase(tableColumn.getName()), tableColumn.isRequired()); throw new CanalClientException(String.format("column name %s is not found in Table[%s]", column.getName(), table.toString()));
if (table.getName().equalsIgnoreCase(tableName)) { break;
/** * Determines whether this column is of a numeric type. * * @return <code>true</code> if this column is of a numeric type */ public boolean isOfNumericType() { return TypeMap.isNumericType(getTypeCode()); }
/** * Determines whether this column is of a special type. * * @return <code>true</code> if this column is of a special type */ public boolean isOfSpecialType() { return TypeMap.isSpecialType(getTypeCode()); }
/** * Determines whether this column is of a binary type. * * @return <code>true</code> if this column is of a binary type */ public boolean isOfBinaryType() { return TypeMap.isBinaryType(getTypeCode()); }
/** * Determines whether this column is of a text type. * * @return <code>true</code> if this column is of a text type */ public boolean isOfTextType() { return TypeMap.isTextType(getTypeCode()); }
/** * Creates a property instance for the given column that only accepts the given type. * * @param column The column * @param type The type of the property */ public SqlDynaProperty(Column column, Class type) { super(column.getName(), type); _column = column; }
/** * {@inheritDoc} */ public void apply(Database database, boolean caseSensitive) { Table table = new CloneHelper().clone(_newTable, true, false, database, caseSensitive); database.addTable(table); } }
/** * Determines whether the auto increment status of the given target column is different from that of the given source column. * * @param sourceColumn The source column * @param targetColumn The target column * @return <code>true</code> if the auto increment status is different in the target column */ public static boolean isAutoIncrementChanged(Column sourceColumn, Column targetColumn) { return sourceColumn.isAutoIncrement() != targetColumn.isAutoIncrement(); }
/** * Creates a new reference between the two given columns. * * @param localColumn The local column * @param foreignColumn The remote column */ public Reference(Column localColumn, Column foreignColumn) { setLocalColumn(localColumn); setForeignColumn(foreignColumn); }
/** * Finds the foreign key with the specified name, using case insensitive matching. * Note that this method is not called getForeignKey to avoid introspection * problems. * * @param name The name of the foreign key * @return The foreign key or <code>null</code> if there is no such foreigb key */ public ForeignKey findForeignKey(String name) { return findForeignKey(name, false); }
/** * Returns a list of all enum values. * * @return The list of enum values */ public static List getEnumList() { return getEnumList(JdbcTypeCategoryEnum.class); }
/** * Returns the enum value that corresponds to the given textual * representation. * * @param defaultTextRep The textual representation * @return The enum value */ public static CascadeActionEnum getEnum(String defaultTextRep) { return (CascadeActionEnum)getEnum(CascadeActionEnum.class, defaultTextRep); }
/** * Returns an iterator of all enum values. * * @return The iterator */ public static Iterator iterator() { return iterator(CascadeActionEnum.class); } }
/** * Treat tables with no primary keys as a table with all primary keys. */ private static void makeAllColumnsPrimaryKeysIfNoPrimaryKeysFound(Table table) { if ((table != null) && (table.getPrimaryKeyColumns() != null) && (table.getPrimaryKeyColumns().length == 0)) { Column[] allCoumns = table.getColumns(); for (Column column : allCoumns) { column.setPrimaryKey(true); } } }
/** * Treat tables with no primary keys as a table with all primary keys. */ private static void makeAllColumnsPrimaryKeysIfNoPrimaryKeysFound(Table table) { if ((table != null) && (table.getPrimaryKeyColumns() != null) && (table.getPrimaryKeyColumns().length == 0)) { Column[] allCoumns = table.getColumns(); for (Column column : allCoumns) { column.setPrimaryKey(true); } } }