protected String aliasedPrimaryKeyJoinVar(String alias, String prefix, Column[] columns) { String text = ""; for (int i = 0; i < columns.length; i++) { text += alias + ".\"" + columns[i].getName() + "\""; text += "=@" + prefix + "pk" + i; if (i + 1 < columns.length) { text += " and "; } } return text; }
protected void adjustColumns(Table table) { Column[] columns = table.getColumns(); for (int idx = 0; idx < columns.length; idx++) { if (columns[idx].getMappedTypeCode() == Types.FLOAT) { columns[idx].setMappedTypeCode(Types.REAL); } else if ((columns[idx].getMappedTypeCode() == Types.NUMERIC) || (columns[idx].getMappedTypeCode() == Types.DECIMAL)) { if ((columns[idx].getMappedTypeCode() == Types.NUMERIC) && (columns[idx].getSizeAsInt() == 18) && (columns[idx].getScale() == 0)) { columns[idx].setMappedTypeCode(Types.BIGINT); } } else if (TypeMap.isTextType(columns[idx].getMappedTypeCode())) { columns[idx].setDefaultValue(unescape(columns[idx].getDefaultValue(), "'", "''")); } } }
protected Column readColumn(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException { Column column = new Column(); PlatformColumn platformColumn = new PlatformColumn(); platformColumn.setName(platform.getName()); column.setName((String) values.get("COLUMN_NAME")); String defaultValue = (String) values.get("COLUMN_DEF"); if (defaultValue == null) { column.setDefaultValue(defaultValue.trim()); column.setMappedTypeCode(mappedType); } else { column.setMappedTypeCode((Integer) values.get("DATA_TYPE")); column.setJdbcTypeCode((Integer) values.get("DATA_TYPE")); column.setPrecisionRadix(((Integer) values.get("NUM_PREC_RADIX")).intValue()); column.addPlatformColumn(platformColumn); } catch (Exception ex) { log.warn(ex.getMessage(), ex); column.setJdbcTypeName(typeName); columnSize = (String) _defaultSizes.get(new Integer(column.getMappedTypeCode())); column.setSize(columnSize); if (decimalDigits != 0) {
@Override public boolean canColumnBeUsedInWhereClause(Column column) { String jdbcTypeName = column.getJdbcTypeName(); return !column.isOfBinaryType() || "RAW".equals(jdbcTypeName); }
protected Column readColumn(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException { Column column = super.readColumn(metaData, values); if (column.getMappedTypeCode() == Types.VARCHAR) { int size = Integer.parseInt(column.getSize()); if (size >= InterbaseDdlBuilder.SWITCH_TO_LONGVARCHAR_SIZE) { column.setMappedTypeCode(Types.LONGVARCHAR); } } return column; }
PlatformColumn platformColumn = column.findPlatformColumn(platform.getName()); if (platformColumn != null && "serial".equals(platformColumn.getType()) || "serial4".equals(platformColumn.getType())) { if (column.getSize() != null) { if (column.getSizeAsInt() <= 0) { column.setSize(null); if (column.getMappedTypeCode() == Types.BINARY) { column.setMappedTypeCode(Types.LONGVARBINARY); } else if (column.getMappedTypeCode() == Types.VARCHAR) { column.setMappedTypeCode(Types.LONGVARCHAR); else if (column.getSizeAsInt() == Integer.MAX_VALUE) { column.setSize(null); if (column.getMappedTypeCode() == Types.VARCHAR) { column.setMappedTypeCode(Types.LONGVARCHAR); } else if (column.getMappedTypeCode() == Types.BINARY) { column.setMappedTypeCode(Types.LONGVARBINARY); } else if (column.getSizeAsInt() == 131089 && column.getJdbcTypeCode() == Types.NUMERIC) { column.setSizeAndScale(0, 0); column.setMappedTypeCode(Types.DECIMAL); if (platformColumn != null) { platformColumn.setSize(-1); String defaultValue = column.getDefaultValue(); column.setAutoIncrement(true);
protected boolean doesColumnNeedUpdated(int columnIndex, Column column, CsvData data, String[] rowData, String[] oldData, boolean applyChangesOnly) { boolean needsUpdated = true; if (!platform.getDatabaseInfo().isAutoIncrementUpdateAllowed() && column.isAutoIncrement()) { needsUpdated = false; } else if (oldData != null && applyChangesOnly) { boolean containsEmptyLobColumn = platform.isLob(column.getMappedTypeCode()) && StringUtils.isBlank(oldData[columnIndex]); needsUpdated = !StringUtils.equals(rowData[columnIndex], oldData[columnIndex]) if (containsEmptyLobColumn) { Column sourceColumn = sourceTable.findColumn(column.getName(), false); data.getChangedDataIndicators()[sourceTable.getColumnIndex(sourceColumn.getName())] = true; needsUpdated = !column.isPrimaryKey() || !StringUtils.equals(rowData[columnIndex], getPkDataFor(data, column));
Object[] args = new Object[pkColumns.length]; for (int i = 0; i < pkColumns.length; i++) { args[i] = columnDataMap.get(pkColumns[i].getName()); String sql = buildSelect(table, lobColumn, pkColumns); String valueForCsv = null; if (platform.isBlob(lobColumn.getMappedTypeCode())) { byte[] binaryData = sqlTemplate.queryForBlob(sql, lobColumn.getJdbcTypeCode(),lobColumn.getJdbcTypeName(), args); if (binaryData != null) { if (batch.getBinaryEncoding() == BinaryEncoding.BASE64) { int index = ArrayUtils.indexOf(columnNames, lobColumn.getName()); rowData[index] = valueForCsv;
Column column = columns[i]; if (column != null) { boolean isLob = symmetricDialect.getPlatform().isLob(column.getMappedTypeCode()); String templateToUse = null; switch (column.getMappedTypeCode()) { case Types.TINYINT: case Types.SMALLINT: if (column.getJdbcTypeName()!=null && (column.getJdbcTypeName().toUpperCase() .contains(TypeMap.GEOMETRY)) && StringUtils.isNotBlank(geometryColumnTemplate)) { templateToUse = geometryColumnTemplate; } else if (column.getJdbcTypeName()!=null && (column.getJdbcTypeName().toUpperCase() .contains(TypeMap.IMAGE)) && StringUtils.isNotBlank(imageColumnTemplate)) { break; default: if (column.getJdbcTypeName() != null) { if (column.getJdbcTypeName().toUpperCase().equals(TypeMap.INTERVAL)) { templateToUse = numberColumnTemplate; break; } else if (column.getJdbcTypeName().toUpperCase() .contains(TypeMap.GEOMETRY) && StringUtils.isNotBlank(geometryColumnTemplate)) { templateToUse = geometryColumnTemplate; break; } else if (column.getMappedType().equals(TypeMap.TIMESTAMPTZ) && StringUtils
for (ForeignKey fk : table.getForeignKeys()) { for (Reference ref : fk.getReferences()) { if (ref.getLocalColumnName().equalsIgnoreCase(column.getName())) { objectValue = columnValues.get(fk.getForeignTableName() + "." + ref.getForeignColumnName()); if (objectValue != null) { columnValues.put(table.getName() + "." + column.getName(), objectValue); continue for_column; } else { throw new RuntimeException("The foreign key column, " + column.getName() + ", found in " + table.getName() + " references " + "table " + fk.getForeignTableName() + " which was not included. Dependent tables will automatically be added if cascading is turned on."); if (objectValue == null) { throw new RuntimeException("No random value generated for the object " + table.getName() + "." + column.getName() + " of code " + column.getMappedTypeCode() + " jdbc name " + column.getJdbcTypeName()); columnValues.put(table.getName() + "." + column.getName(), objectValue);
private Object generateRandomValueForColumn(Column column) { Object objectValue = null; int type = column.getMappedTypeCode(); if (column.isTimestampWithTimezone()) { objectValue = String.format("%s %s", FormatUtils.TIMESTAMP_FORMATTER.format(randomDate()), } else if (type == Types.NUMERIC || type == Types.DECIMAL || type == Types.REAL) { objectValue = randomBigDecimal(column.getSizeAsInt(), column.getScale()); } else if (type == Types.BOOLEAN || type == Types.BIT) { objectValue = randomBoolean(); int size = 0; if (column.getSizeAsInt() != 0) { size = column.getSizeAsInt()>50?50:column.getSizeAsInt(); } else { if ("UUID".equalsIgnoreCase(column.getJdbcTypeName())) { objectValue = randomUUID();
if (isNotBlank(maxLength)) { Integer size = new Integer(maxLength); column.setSize(size.toString()); column.findPlatformColumn(platform.getName()).setSize(size); column.setDefaultValue(values.get("COLUMN_DEFAULT").toString()); column.setScale(scale); column.findPlatformColumn(platform.getName()).setDecimalDigits(scale); if (TypeMap.isTextType(column.getMappedTypeCode()) && (column.getDefaultValue() != null)) { column.setDefaultValue(unescape(column.getDefaultValue(), "'", "''")); column.setAutoIncrement(true); column.setDefaultValue(null);
@Override protected Column readColumn(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException { Column column = super.readColumn(metaData, values); // MySQL converts illegal date/time/timestamp values to // "0000-00-00 00:00:00", but this // is an illegal ISO value, so we replace it with NULL if ((column.getMappedTypeCode() == Types.TIMESTAMP) && "0000-00-00 00:00:00".equals(column.getDefaultValue())) { column.setDefaultValue(null); } // make sure the defaultvalue is null when an empty is returned. if ("".equals(column.getDefaultValue())) { column.setDefaultValue(null); } if (column.getJdbcTypeName().equalsIgnoreCase(TypeMap.POINT) || column.getJdbcTypeName().equalsIgnoreCase(TypeMap.LINESTRING) || column.getJdbcTypeName().equalsIgnoreCase(TypeMap.POLYGON) ) { column.setJdbcTypeName(TypeMap.GEOMETRY); } return column; }
protected String buildColumnNameString(String tableAlias, boolean quote, Trigger trigger, Column[] columns) { StringBuilder columnsText = new StringBuilder(); for (Column column : columns) { boolean isLob = symmetricDialect.getPlatform().isLob(column.getMappedTypeCode()); String columnName = column.getName(); if (quote) { columnName = SymmetricUtils.quote(symmetricDialect, columnName); } if (!(isLob && trigger.isUseStreamLobs())) { if (StringUtils.isNotBlank(tableAlias)) { columnsText.append(tableAlias); columnsText.append("."); } columnsText.append(columnName); } else { columnsText.append("null"); } columnsText.append(","); } return columnsText.substring(0, columnsText.length() - 1); }
protected Table toAuditTable(Table table) { Table auditTable = table.copy(); String tableName = table.getName(); if (!FormatUtils.isMixedCase(tableName)) { tableName = tableName.toUpperCase(); } auditTable.setName(String.format("%s_AUDIT", tableName)); Column[] columns = auditTable.getColumns(); auditTable.removeAllColumns(); auditTable.addColumn(new Column(COLUMN_AUDIT_ID, true, Types.BIGINT, 0, 0)); auditTable.addColumn(new Column(COLUMN_AUDIT_TIME, false, Types.TIMESTAMP, 0, 0)); auditTable.addColumn(new Column(COLUMN_AUDIT_EVENT, false, Types.CHAR, 1, 0)); for (Column column : columns) { column.setRequired(false); column.setPrimaryKey(false); column.setAutoIncrement(false); auditTable.addColumn(column); } auditTable.removeAllForeignKeys(); auditTable.removeAllIndices(); engine.getDatabasePlatform().alterCaseToMatchDatabaseDefaultCase(auditTable); return auditTable; }
@Override protected Column readColumn(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException { Column column = super.readColumn(metaData, values); if (TypeMap.isTextType(column.getMappedTypeCode()) && (column.getDefaultValue() != null)) { column.setDefaultValue(unescape(column.getDefaultValue(), "'", "''")); } String autoIncrement = (String) values.get("IS_AUTOINCREMENT"); if (autoIncrement != null) { column.setAutoIncrement("YES".equalsIgnoreCase(autoIncrement.trim())); } return column; }
if (column != null) { if (doesColumnNeedUpdated(i, column, data, rowData, oldData, applyChangesOnly)) { changedColumnNameList.add(column.getName()); changedColumnsList.add(column); changedColumnValueList.add(rowData[i]); while (it.hasNext()) { Column col = it.next(); if ((col.isOfBinaryType() && data.isNoBinaryOldData()) || !platform.canColumnBeUsedInWhereClause(col)) { it.remove(); nullKeyValues[i] = !column.isRequired() && lookupDataMap.get(column.getName()) == null;
@Override protected Table readTable(Connection connection, DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException { Table table = super.readTable(connection, metaData, values); if (table != null) { // PostgreSQL also returns unique indices for non-pk auto-increment // columns which are of the form "[table]_[column]_key" HashMap<String,IIndex> uniquesByName = new HashMap<String,IIndex>(); for (int indexIdx = 0; indexIdx < table.getIndexCount(); indexIdx++) { IIndex index = table.getIndex(indexIdx); if (index.isUnique() && (index.getName() != null)) { uniquesByName.put(index.getName(), index); } } for (int columnIdx = 0; columnIdx < table.getColumnCount(); columnIdx++) { Column column = table.getColumn(columnIdx); if (column.isAutoIncrement() && !column.isPrimaryKey()) { String indexName = table.getName() + "_" + column.getName() + "_key"; if (uniquesByName.containsKey(indexName)) { table.removeIndex((IIndex) uniquesByName.get(indexName)); uniquesByName.remove(indexName); } } } } setPrimaryKeyConstraintName(connection, table); return table; }
@Override protected Column readColumn(DatabaseMetaDataWrapper metaData, Map<String,Object> values) throws SQLException { Column column = super.readColumn(metaData, values); if (column.getMappedTypeCode() == Types.FLOAT) { column.setMappedTypeCode(Types.REAL); } else if (TypeMap.isTextType(column.getMappedTypeCode())) { column.setDefaultValue(unescape(column.getDefaultValue(), "'", "''")); } return column; }
@Override protected Column readColumn(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException { Column column = super.readColumn(metaData, values); if (TypeMap.isTextType(column.getMappedTypeCode()) && (column.getDefaultValue() != null)) { column.setDefaultValue(unescape(column.getDefaultValue(), "'", "''")); } return column; }