MappingPolicy mappingPolicy) { int jdbcType = column.getType(); Integer scale = column.getScale(); Integer precision = column.getPrecision(); Integer length = column.getLength(); String sqlType = mappingPolicy.getSQLTypeName(jdbcType); StringBuffer columnContent = new StringBuffer(); columnContent.append(column.getName().getName()); columnContent.append(SPACE); columnContent.append(sqlType); if (column.isCharacterType() && length != null) { columnContent.append(START); columnContent.append(length.toString()); columnContent.append(END); } else if (column.isNumericType() && precision != null) { columnContent.append(START); columnContent.append(precision.toString()); } else if (column.isBlobType() && length != null) { columnContent.append(START); columnContent.append(length.toString()); if (column.isNullable()) { String nullText = mappingPolicy.getColumnNullability(); if (nullText != null && nullText.length() > 0) {
/** * Create column and add to the table. * @param columnName Name of the column to create. * @param declaringTbl The declaring table to which column gets added. * @return ColumnElement that represents the newly-added column. * @throws DBException */ static ColumnElement createAndAttachColumn(String columnName, TableElement table, JDBCInfo ji) throws DBException { // Create column id String fullName = NameUtil.getAbsoluteMemberName( table.getName().getName(), columnName); DBIdentifier columnId = DBIdentifier.create(columnName); ColumnElementImpl columnImpl = new ColumnElementImpl(); ColumnElement column = new ColumnElement(columnImpl, table); column.setName(columnId); column.setType(ji.getJdbcType()); column.setNullable(ji.getNullable()); column.setPrecision(ji.getPrecision()); column.setScale(ji.getScale()); column.setLength(ji.getLength()); table.addColumn(column); return column; }
private boolean isPrimaryKeyColumn (ColumnElement column) { if (column != null) { KeyElement key = column.getDeclaringTable().getPrimaryKey(); return ((key != null) && (key.getColumn(column.getName()) != null)); } return false; } private boolean isExactMatch (ArrayList columns1,
/** * Update column in the SchemaElement with jdbc type and its length, * scale and precision. * @param column a ColumnElement to be updated * @param jdbcType jdbc type from java.sql.Types * @param length an Integer for length or <code>null</code> * if it does not apply * @param scale an Integer for scale or <code>null</code> * if it does not apply * @param precision an Integer for precision or <code>null</code> * if it does not apply */ public static void updateColumn(ColumnElement column, int jdbcType, Integer length, Integer scale, Integer precision) throws DBException { column.setType(jdbcType); column.setLength(length); column.setScale(scale); column.setPrecision(precision); }
/** * Checks, if the column <code>ce</code> is part of the * primary key <code>pk</code>. * RESOLVE: Method isPrimaryKeyColumn in ModelValidator * implements similar functionality. * * @param ce Column element for the column to be tested. * @param pk Primary key element. The column to be tested * <b>must</b> be defined in the same table. * @return True, if the column is part of the primary key, * false otherwise. * @see com.sun.jdo.api.persistence.model.util.ModelValidator */ private boolean isPartOfPrimaryKey(ColumnElement ce, UniqueKeyElement pk) { return null != pk && ce.equals(pk.getColumn(ce.getName())); }
if (column.isNullable() || !column.isNumericType()) keyName = "util.validation.version_field_column_type_invalid"; // NOI18N else // column must be non-PK and non-FK column TableElement table = column.getDeclaringTable(); UniqueKeyElement[] uks = table.getUniqueKeys(); ForeignKeyElement[] fks = table.getForeignKeys(); getModel().getField(className, fieldName), I18NHelper.getMessage(getMessages(), keyName, new Object[]{column.getName(), fieldName, className}));
/** * Returns a comma-separated list of column names. * @param columns Array of ColumnElements * @return String of form "columnA, columnB", with as many named columns * as there are in given array. */ private static String getColumnNames(ColumnElement[] columns) { StringBuffer columnNames = new StringBuffer(); for (int i = 0; i < columns.length; i++) { if (i > 0) { columnNames.append(COLUMN_SEPARATOR); } columnNames.append(columns[i].getName().getName()); } return columnNames.toString(); } }
refTblName, refColumn.getName().getName()); refColumn.getType(), refColumn.getPrecision(), refColumn.getScale(), refColumn.getLength(), true);
messages, "MESSAGE_CANDIDATE_PK", //NOI18N candidatePK.getName())); Integer pre = candidatePK.getPrecision(); if (null != candidatePK && !candidatePK.isNumericType()) { candidatePK = null;
org.netbeans.modules.dbschema.UniqueKeyElement tkey = new org.netbeans.modules.dbschema.UniqueKeyElement(); ColumnElement fakeKeyCol = new ColumnElement(); fakeKeyCol.setName(DBIdentifier.create(retVal.getName().getName()+ "."+"fookeyng")); //NOI18N fakeKeyCol.setType(2); fakeKeyCol.setPrecision(new Integer(MINIMUM_PRECISION)); tkey.setPrimaryKey(true); tkey.addColumn(fakeKeyCol);
private ColumnElement getColumnElement(TableElement sourceTableEl, DBIdentifier sourceColumnName, ConversionHelper helper) throws DBException, ConversionException { ColumnElement aCol = sourceTableEl.getColumn(sourceColumnName); if (null == aCol && !helper.ensureValidation()) { aCol = new ColumnElement(); aCol.setName(DBIdentifier.create(sourceTableEl.getName().toString()+"."+sourceColumnName.toString())); // NOI18N aCol.setDeclaringTable(sourceTableEl); aCol.setNullable(true); } if (aCol == null) { throw new ConversionException( I18NHelper.getMessage( messages, "ERR_INVALID_COLUMN", //NOI18N new Object [] {sourceColumnName, sourceTableEl})); } return aCol; }
/** Returns <code>true</code> if the specified FK has at least * one non-nullable column. Please note that the caller is * responsible for passing a non-null fk argument. */ private boolean hasNonNullableColumn (ForeignKeyElement fk) { ColumnElement[] localColumns = fk.getLocalColumns(); int count = ((localColumns != null) ? localColumns.length : 0); for (int i = 0; i < count; i++) { if (!localColumns[i].isNullable()) return true; } return false; }
private boolean isMappedToBlob (ColumnElement column) { return ((column != null) && SQLTypeUtil.isBlob(column.getType())); } };
/** Check if the table of the column matches one of the list of tables. * @param tableNames A list of table names in which to check for a match * @param column A ColumnElement object to be checked * @return <code>true</code> if the column belongs to a table found * in the supplied list of table names, <code>false</code> otherwise */ private boolean matchesTable (List tableNames, ColumnElement column) { return ((column == null) ? true : tableNames.contains( column.getDeclaringTable().getName().getName())); }
if (candidatePK != null && candidatePK.equals(aCol)) { candidatePK = null; fieldMappedToABlob |= aCol.isBlobType(); mfe.addColumn(aCol);
/** * Create mapping field and add to mapping class * @param fieldName a String for field name * @param mappingClass mapping class object that field belong to * @return mapping field object * @throws ModelException */ private MappingFieldElement createAndAttachMappingField( String fieldName, MappingClassElement mappingClass, ColumnElement column) throws ModelException { MappingFieldElement mappingField = new MappingFieldElementImpl(fieldName, mappingClass); mappingClass.addField(mappingField); mappingField.addColumn(column); if (column.isBlobType()) { mappingField.setFetchGroup(MappingFieldElement.GROUP_NONE); } else { mappingField.setFetchGroup(MappingFieldElement.GROUP_DEFAULT); } return mappingField; }
if (column.isNullable() || !column.isNumericType()) keyName = "util.validation.version_field_column_type_invalid"; // NOI18N else // column must be non-PK and non-FK column TableElement table = column.getDeclaringTable(); UniqueKeyElement[] uks = table.getUniqueKeys(); ForeignKeyElement[] fks = table.getForeignKeys(); getModel().getField(className, fieldName), I18NHelper.getMessage(getMessages(), keyName, new Object[]{column.getName(), fieldName, className}));
private List getRelativeColumnNames (ColumnElement[] columns) { int i, count = ((columns != null) ? columns.length : 0); List columnNames = new ArrayList(count); for (i = 0; i < count; i++) { columnNames.add(NameUtil.getRelativeMemberName( columns[i].getName().getFullName())); } return columnNames; } private boolean isKeyField (MappingFieldElement field)
/** * Checks, if the column <code>ce</code> is part of one * of the foreign key constraints defined in <code>fks</code>. * RESOLVE: Method matchesFK in ModelValidator implements similar * functionality. * * @param ce Column element for the column to be tested. * @param fks Array of foreign key elements. The column to be * tested <b>must</b> be defined in the same table. * @return True, if the column is part of one of the foreign keys, * false otherwise. * @see com.sun.jdo.api.persistence.model.util.ModelValidator */ private boolean isPartOfForeignKey(ColumnElement ce, ForeignKeyElement[] fks) { // RESOLVE: Column ce might be included in multiple foreign // keys. The foreign key check applies to ALL relationships // mapped to column ce. How can we find out, that a foreign // key matches exactly the relationship being checked here? if (fks != null) { for (int index = 0; index < fks.length; index++) { if (ce.equals(fks[index].getColumn(ce.getName()))) { // The current ce is part of the foreign key. return true; } } } return false; }
/** Returns <code>true</code> if the specified FK has at least * one non-nullable column. Please note that the caller is * responsible for passing a non-null fk argument. */ private boolean hasNonNullableColumn (ForeignKeyElement fk) { ColumnElement[] localColumns = fk.getLocalColumns(); int count = ((localColumns != null) ? localColumns.length : 0); for (int i = 0; i < count; i++) { if (!localColumns[i].isNullable()) return true; } return false; }