Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 45246 Details for
Bug 148539
Remove shared prefixes in column names when generating entities
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
patch that adds common prefix scanning to GenTable
148539-find-common-prefixes-in-field-names.patch.txt (text/plain), 3.01 KB, created by
Gunnar Wagenknecht
on 2006-06-24 14:45:00 EDT
(
hide
)
Description:
patch that adds common prefix scanning to GenTable
Filename:
MIME Type:
Creator:
Gunnar Wagenknecht
Created:
2006-06-24 14:45:00 EDT
Size:
3.01 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.dali.gen >Index: source/org/eclipse/dali/gen/GenTable.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.dali/plugins/org.eclipse.dali.gen/source/org/eclipse/dali/gen/GenTable.java,v >retrieving revision 1.5 >diff -u -r1.5 GenTable.java >--- source/org/eclipse/dali/gen/GenTable.java 22 Jun 2006 17:26:08 -0000 1.5 >+++ source/org/eclipse/dali/gen/GenTable.java 24 Jun 2006 18:36:13 -0000 >@@ -40,6 +40,7 @@ > private Collection manyToOneRelations = new ArrayList(); > private Collection oneToManyRelations = new ArrayList(); > private Set foreignKeyColumns = new HashSet(); >+ private String commonFieldNamePrefix; > > // key=column/relation; value=name > private final Map fieldNames = new HashMap(); >@@ -142,6 +143,7 @@ > // field names for the columns etc. > this.configureFieldName(EMBEDDED_ID_VIRTUAL_COLUMN, "pk"); > } >+ this.findSharedFieldNamePrefix(columns); > this.configureManyToOneFieldNames(columns); > this.configureBasicFieldNames(columns); > this.configureOneToManyFieldNames(); >@@ -150,6 +152,51 @@ > } > > /** >+ * Detects if all columns share a common prefix. >+ * @param columns >+ */ >+ private void findSharedFieldNamePrefix(Set columns) { >+ commonFieldNamePrefix = null; >+ if(columns.size() < 2) >+ return; >+ >+ String[] columnNames = new String[columns.size()]; >+ int i = 0; >+ for (Iterator stream = columns.iterator(); stream.hasNext();) { >+ Column column = (Column) stream.next(); >+ columnNames[i] = column.javaFieldName(); >+ i++; >+ } >+ String prefix = columnNames[0]; >+ for (int j = 1; j < columnNames.length; j++) { >+ String columnName = columnNames[j]; >+ i = 0; >+ if(!columnName.startsWith(prefix)) { >+ // adjust prefix >+ if(prefix.length() > columnName.length()) >+ prefix = prefix.substring(0, columnName.length()-1); >+ while(i < prefix.length() && prefix.charAt(i) == columnName.charAt(i)) { >+ i++; >+ } >+ if(i == 0) { >+ // give up looking for common prefix >+ return; >+ } >+ prefix = prefix.substring(0, i); >+ } >+ } >+ >+ // clean up prefix a bit >+ // make sure that we catch "xyz_b" where column names are "xyz_bla_nbr" and "xyz_bid_id" >+ i = prefix.lastIndexOf('_'); >+ if(i != -1 && i < prefix.length()-1) { >+ prefix = prefix.substring(0,i+1); >+ } >+ >+ commonFieldNamePrefix = prefix; >+ } >+ >+ /** > * return the columns that are part of the table's primary key > * but are also part of an "in-scope" foreign key > */ >@@ -290,6 +337,8 @@ > } > > private String configureFieldName(Object o, String fieldName) { >+ if(null != commonFieldNamePrefix && fieldName.length() > commonFieldNamePrefix.length() && fieldName.startsWith(commonFieldNamePrefix)) >+ fieldName = fieldName.substring(commonFieldNamePrefix.length()); > fieldName = this.camelCase(fieldName); > fieldName = NameTools.uniqueNameFor(fieldName, this.fieldNames.values()); > this.fieldNames.put(o, fieldName);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 148539
:
45246