/** * 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 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);
Map<String, Boolean> isRequiredMap = new HashMap(); for (Column tableColumn : table.getColumns()) { isRequiredMap.put(StringUtils.lowerCase(tableColumn.getName()), tableColumn.isRequired()); isRequiredMap.put(StringUtils.lowerCase(tableColumn.getName()), tableColumn.isRequired());
/** * {@inheritDoc} */ public void apply(Database model, boolean caseSensitive) { Column column = findChangedColumn(model, caseSensitive); column.setTypeCode(_newColumnDef.getTypeCode()); column.setSize(_newColumnDef.getSize()); column.setAutoIncrement(_newColumnDef.isAutoIncrement()); column.setRequired(_newColumnDef.isRequired()); column.setDescription(_newColumnDef.getDescription()); column.setDefaultValue(_newColumnDef.getDefaultValue()); } }
/** * Returns a clone of the given source column. * * @param source The source column * @param clonePrimaryKeyStatus Whether to clone the column's primary key status; if <code>false</code> * then the clone will not be a primary key column * @return The clone */ public Column clone(Column source, boolean clonePrimaryKeyStatus) { Column result = new Column(); result.setName(source.getName()); result.setJavaName(source.getJavaName()); result.setPrimaryKey(clonePrimaryKeyStatus ? source.isPrimaryKey() : false); result.setRequired(source.isRequired()); result.setAutoIncrement(source.isAutoIncrement()); result.setTypeCode(source.getTypeCode()); result.setSize(source.getSize()); result.setDefaultValue(source.getDefaultValue()); return result; }
Column metricColumn = new Column(); metricColumn.setName(JdbcConstants.METRIC_NAME_COLUMN_NAME); metricColumn.setTypeCode(Types.VARCHAR); metricColumn.setDescription("eagle entity metric column"); table.addColumn(metricColumn); Column pkColumn = new Column(); pkColumn.setName(JdbcConstants.ROW_KEY_COLUMN_NAME); pkColumn.setPrimaryKey(true); pkColumn.setRequired(true); pkColumn.setTypeCode(Types.VARCHAR); pkColumn.setDescription("eagle entity row-key column"); table.addColumn(pkColumn); Column tsColumn = new Column(); tsColumn.setName(JdbcConstants.TIMESTAMP_COLUMN_NAME); tsColumn.setTypeCode(Types.BIGINT); tsColumn.setDescription("eagle entity timestamp column"); table.addColumn(tsColumn); tagColumn.setSize(String.valueOf(JdbcConstants.DEFAULT_TAG_VARCHAR_SIZE)); table.addColumn(tagColumn); Column fieldColumn = new Column(); fieldColumn.setName(entry.getKey()); fieldColumn.setJavaName(entry.getKey()); Integer typeCode = entityDefinition.getJdbcColumnTypeCodeOrNull(entry.getKey());
if (column.getDefaultValue() != null) column.setDefaultValue(column.getDefaultValue().trim()); if (column.getDefaultValue().startsWith("DEFAULT SERIAL")) column.setAutoIncrement(true); column.setDefaultValue(null); if (column.getTypeCode() == Types.DECIMAL) column.setPrecisionRadix(column.getSizeAsInt()); if ((column.getSizeAsInt() == 38) && (column.getScale() == 0)) column.setTypeCode(Types.BIGINT);
private Column createTagColumn(String tagName){ Column tagColumn = new Column(); tagColumn.setName(tagName); tagColumn.setTypeCode(Types.VARCHAR); tagColumn.setJavaName(tagName); // tagColumn.setScale(1024); tagColumn.setSize(String.valueOf(JdbcConstants.DEFAULT_FIELD_VARCHAR_SIZE)); tagColumn.setDefaultValue(null); tagColumn.setDescription("eagle entity tag column for "+tagName); return tagColumn; }
Column column = new Column(); column.setName(xmlReader.getAttributeValue(idx)); column.setPrimaryKey(getAttributeValueAsBoolean(xmlReader, idx)); column.setRequired(getAttributeValueAsBoolean(xmlReader, idx)); column.setType(xmlReader.getAttributeValue(idx)); column.setSize(getAttributeValueBeingNullAware(xmlReader, idx)); column.setDefaultValue(xmlReader.getAttributeValue(idx)); column.setAutoIncrement(getAttributeValueAsBoolean(xmlReader, idx)); column.setDescription(xmlReader.getAttributeValue(idx)); column.setJavaName(xmlReader.getAttributeValue(idx));
if (column.getSize() != null) if (column.getSizeAsInt() <= 0) column.setSize(null); String defaultValue = column.getDefaultValue(); defaultValue.toLowerCase().startsWith("uniquekey('")) column.setDefaultValue(null); column.setAutoIncrement(true); else if (TypeMap.isTextType(column.getTypeCode())) column.setDefaultValue(unescape(column.getDefaultValue(), "'", "\\'"));
private void buildTable(Table table) { Column id = new Column(); id.setName("id"); id.setPrimaryKey(true); id.setRequired(true); id.setTypeCode(Types.VARCHAR); id.setSize("50"); table.addColumn(id); Column value = new Column(); value.setName("value"); value.setTypeCode(Types.CLOB); table.addColumn(value); } }
@Test public void testTable(){ Table table = new Table(); Column column = new Column(); column.setName("id"); column.setDefaultValue("-1"); column.setDescription("rowkey"); column.setPrimaryKey(true); column.setType(TypeMap.VARCHAR); table.addColumn(column); table.setName("eagle_table"); System.out.println(table.toString()); } }
/** * Sets the local column. * * @param localColumn The local column */ public void setLocalColumn(Column localColumn) { _localColumn = localColumn; _localColumnName = (localColumn == null ? null : localColumn.getName()); }
/** * Returns the converter registered for the specified column. * * @param table The table * @param column The column * @return The converter */ public SqlTypeConverter getRegisteredConverter(Table table, Column column) { SqlTypeConverter result = (SqlTypeConverter)_convertersPerPath.get(table.getQualifiedName() + "/" + column.getName()); if (result == null) { result = (SqlTypeConverter)_convertersPerType.get(Integer.valueOf(column.getTypeCode())); } return result; } }
/** * {@inheritDoc} */ protected Column readColumn(DatabaseMetaDataWrapper metaData, Map 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.getTypeCode() == Types.TIMESTAMP) && "0000-00-00 00:00:00".equals(column.getDefaultValue())) { column.setDefaultValue(null); } return column; }
if (column.getDefaultValue() != null) column.setDefaultValue(column.getDefaultValue().trim()); if (column.getTypeCode() == Types.DECIMAL) switch (column.getSizeAsInt()) if (column.getScale() == 0) column.setTypeCode(Types.BIT); if (column.getScale() == 0) column.setTypeCode(Types.TINYINT); if (column.getScale() == 0) column.setTypeCode(Types.SMALLINT); column.setTypeCode(Types.REAL); break; case 22: if (column.getScale() == 0) column.setTypeCode(Types.INTEGER); if (column.getScale() == 0)
/** * Writes the column object to the given XML writer. * * @param column The column object * @param xmlWriter The XML writer */ private void writeColumnElement(Column column, PrettyPrintingXmlWriter xmlWriter) throws DdlUtilsXMLException { xmlWriter.indentIfPrettyPrinting(2); writeElementStart(xmlWriter, QNAME_ELEMENT_COLUMN); writeAttribute(xmlWriter, QNAME_ATTRIBUTE_NAME, column.getName()); writeAttribute(xmlWriter, QNAME_ATTRIBUTE_PRIMARY_KEY, String.valueOf(column.isPrimaryKey())); writeAttribute(xmlWriter, QNAME_ATTRIBUTE_REQUIRED, String.valueOf(column.isRequired())); writeAttribute(xmlWriter, QNAME_ATTRIBUTE_TYPE, column.getType()); writeAttribute(xmlWriter, QNAME_ATTRIBUTE_SIZE, column.getSize()); writeAttribute(xmlWriter, QNAME_ATTRIBUTE_DEFAULT, column.getDefaultValue()); writeAttribute(xmlWriter, QNAME_ATTRIBUTE_AUTO_INCREMENT, String.valueOf(column.isAutoIncrement())); writeAttribute(xmlWriter, QNAME_ATTRIBUTE_DESCRIPTION, column.getDescription()); writeAttribute(xmlWriter, QNAME_ATTRIBUTE_JAVA_NAME, column.getJavaName()); writeElementEnd(xmlWriter); }
/** * {@inheritDoc} */ protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException { Column column = super.readColumn(metaData, values); if (column.getTypeCode() == Types.FLOAT) { column.setTypeCode(Types.REAL); } else if (TypeMap.isTextType(column.getTypeCode())) { column.setDefaultValue(unescape(column.getDefaultValue(), "'", "''")); } return column; }
/** * Determines whether the jdbc type of the given target column is different from the one of the given source column. * This method uses the platform info object to determine the actual jdbc type that the target column would have * in the database, and compares that to the type of he source column. * * @param platformInfo The info object for the current platform * @param sourceColumn The source column * @param targetColumn The target column * @return <code>true</code> if the jdbc types differ */ public static boolean isTypeChanged(PlatformInfo platformInfo, Column sourceColumn, Column targetColumn) { int targetTypeCode = platformInfo.getTargetJdbcType(targetColumn.getTypeCode()); return targetTypeCode != sourceColumn.getTypeCode(); }
/** * {@inheritDoc} */ protected String getNativeDefaultValue(Column column) { if ((column.getTypeCode() == Types.BIT) || (column.getTypeCode() == Types.BOOLEAN)) { return getDefaultValueHelper().convert(column.getDefaultValue(), column.getTypeCode(), Types.SMALLINT); } else { return super.getNativeDefaultValue(column); } }