Bug 248031

Summary: API enhancement request for org.eclipse.jpt.db.Column
Product: [WebTools] Dali JPA Tools Reporter: Danny Ju <danny.ju>
Component: FrameworkAssignee: Brian Vosburgh <brian.vosburgh>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: brian.vosburgh, karenfbutzke, konstantin, neil.hauge
Version: unspecifiedKeywords: plan
Target Milestone: 2.1 M3   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Proposed patch neil.hauge: iplog+

Description Danny Ju CLA 2008-09-19 16:52:06 EDT
Build ID: I20080617-2000

Steps To Reproduce:
org.eclipse.jpt.db.Column and its implementation class DTPColumnWrapper wrap DTP org.eclipse.datatools.modelbase.sql.tables.Column. But did not expose all the methods exposed by DTP Column.

We’d like to request enhancement to the interface/class to provide following methods:  
	/**
	 * Return whether the column is part of it's table's unique constraint.
	 */	
	public boolean isPartOfUniqueConstraint();
	
	/**
	 * Return whether the column is nullable.
	 */	
	public boolean isNullable();
	
	/**
	 * Return whether the column is of numeric type.
	 */	
	public boolean isNumeric() ;	

	/**
	 * Return precision of the column if it is NumericalDataType
	 * otherwise, return -1
	 */	
	public int getPrecision();	

	/**
	 * Return scale of the column if it is ExactNumericDataType
	 * otherwise, return -1
	 */	
	public int getScale();	

	/**
	 * Return size of the column:
	 * - if the column is CharacterStringDataType, return the length
	 * - otherwise, return -1
	 */	
	public int getLength() ;

These methods are necessary to generate appropriate JPA Entity annotations, e.g. 
	@Column(name="", nullable=false, precision=4)


More information:
Comment 1 Danny Ju CLA 2008-09-19 16:54:19 EDT
Created attachment 113051 [details]
Proposed patch
Comment 2 Karen Butzke CLA 2008-09-19 17:21:09 EDT
This seems reasonable, my only request is that you also look at adding to our unit tests.  These can be found in org.eclipse.jpt.db.tests.internal.platforms
Comment 3 Danny Ju CLA 2008-09-19 18:18:18 EDT
Sure, can you point me to the CVS path of the unit tests?
I did not find one named org.eclipse.jpt.db.tests.
Comment 4 Karen Butzke CLA 2008-09-19 18:30:18 EDT
The plugin is in org.eclipse.jpa/components/jpa/tests/org.eclipse.jpt.db.tests.  I'm not sure why they don't show up directly under the HEAD node, like most of the other plugins
Comment 5 Brian Vosburgh CLA 2008-09-29 14:28:51 EDT
I applied Danny's patch, with a few modifications and additions. It was released and is now part of M2. I also added some JUnit tests; these are in HEAD and will be part of the forthcoming Dali 2.1 branch.

To make the things more consistent, I changed some of the existing API in Column:
    dataTypeIsLOB() -> isLOB()
    isForeignKeyColumn() -> isPartOfForeignKey()
    isPrimaryKeyColumn() -> isPartOfPrimaryKey()
Comment 6 Danny Ju CLA 2008-10-03 18:43:22 EDT
Checked M2 and the APIs are added as expected. Thanks!

I have another new requirement for the Column class:

Column.isAutoIncrement()

which should return if the column is using a auto incremented ID sequence.
This one is not as straight forward as the ons above. I will create a new bug.