Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 148539
Collapse All | Expand All

(-)source/org/eclipse/dali/gen/GenTable.java (+49 lines)
Lines 40-45 Link Here
40
	private Collection manyToOneRelations = new ArrayList();
40
	private Collection manyToOneRelations = new ArrayList();
41
	private Collection oneToManyRelations = new ArrayList();
41
	private Collection oneToManyRelations = new ArrayList();
42
	private Set foreignKeyColumns = new HashSet();
42
	private Set foreignKeyColumns = new HashSet();
43
	private String commonFieldNamePrefix;
43
44
44
	// key=column/relation; value=name
45
	// key=column/relation; value=name
45
	private final Map fieldNames = new HashMap();
46
	private final Map fieldNames = new HashMap();
Lines 142-147 Link Here
142
			// field names for the columns etc.
143
			// field names for the columns etc.
143
			this.configureFieldName(EMBEDDED_ID_VIRTUAL_COLUMN, "pk");
144
			this.configureFieldName(EMBEDDED_ID_VIRTUAL_COLUMN, "pk");
144
		}
145
		}
146
		this.findSharedFieldNamePrefix(columns);
145
		this.configureManyToOneFieldNames(columns);
147
		this.configureManyToOneFieldNames(columns);
146
		this.configureBasicFieldNames(columns);
148
		this.configureBasicFieldNames(columns);
147
		this.configureOneToManyFieldNames();
149
		this.configureOneToManyFieldNames();
Lines 150-155 Link Here
150
	}
152
	}
151
153
152
	/**
154
	/**
155
	 * Detects if all columns share a common prefix.
156
	 * @param columns
157
	 */
158
	private void findSharedFieldNamePrefix(Set columns) {
159
		commonFieldNamePrefix = null;
160
		if(columns.size() < 2)
161
			return;
162
		
163
		String[] columnNames = new String[columns.size()];
164
		int i = 0;
165
		for (Iterator stream = columns.iterator(); stream.hasNext();) {
166
			Column column = (Column) stream.next();
167
			columnNames[i] = column.javaFieldName();
168
			i++;
169
		}
170
		String prefix = columnNames[0];
171
		for (int j = 1; j < columnNames.length; j++) {
172
			String columnName = columnNames[j];
173
			i = 0;
174
			if(!columnName.startsWith(prefix)) {
175
				// adjust prefix
176
				if(prefix.length() > columnName.length())
177
					prefix = prefix.substring(0, columnName.length()-1);
178
				while(i < prefix.length() && prefix.charAt(i) == columnName.charAt(i)) {
179
					i++;
180
				}
181
				if(i == 0) {
182
					// give up looking for common prefix
183
					return;
184
				}
185
				prefix = prefix.substring(0, i);	
186
			}
187
		}
188
		
189
		// clean up prefix a bit 
190
		// make sure that we catch "xyz_b" where column names are "xyz_bla_nbr" and "xyz_bid_id"
191
		i = prefix.lastIndexOf('_');
192
		if(i != -1 && i < prefix.length()-1) {
193
			prefix = prefix.substring(0,i+1);
194
		}
195
		
196
		commonFieldNamePrefix = prefix;
197
	}
198
199
	/**
153
	 * return the columns that are part of the table's primary key
200
	 * return the columns that are part of the table's primary key
154
	 * but are also part of an "in-scope" foreign key
201
	 * but are also part of an "in-scope" foreign key
155
	 */
202
	 */
Lines 290-295 Link Here
290
	}
337
	}
291
338
292
	private String configureFieldName(Object o, String fieldName) {
339
	private String configureFieldName(Object o, String fieldName) {
340
		if(null != commonFieldNamePrefix && fieldName.length() > commonFieldNamePrefix.length() && fieldName.startsWith(commonFieldNamePrefix))
341
			fieldName = fieldName.substring(commonFieldNamePrefix.length());
293
		fieldName = this.camelCase(fieldName);
342
		fieldName = this.camelCase(fieldName);
294
		fieldName = NameTools.uniqueNameFor(fieldName, this.fieldNames.values());
343
		fieldName = NameTools.uniqueNameFor(fieldName, this.fieldNames.values());
295
		this.fieldNames.put(o, fieldName);
344
		this.fieldNames.put(o, fieldName);

Return to bug 148539