Author: vyemialyanchyk
Date: 2009-04-01 12:16:50 -0400 (Wed, 01 Apr 2009)
New Revision: 14405
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/CollectEntityInfo.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ProcessEntityInfo.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/fields/DocumentBase.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/fields/Foto.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/getters/DocumentBase.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/getters/Foto.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/fields/DocumentBase.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/fields/Foto.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/getters/DocumentBase.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/getters/Foto.java
Log:
JBIDE-3842
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/CollectEntityInfo.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/CollectEntityInfo.java 2009-04-01
14:37:23 UTC (rev 14404)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/CollectEntityInfo.java 2009-04-01
16:16:50 UTC (rev 14405)
@@ -89,40 +89,50 @@
}
return processAnnotation(node, mappedBy);
}
-
- public boolean processAnnotation(Annotation node, String mappedBy) {
- String fullyQualifiedName = node.getTypeName().getFullyQualifiedName();
- if (JPAConst.isAnnotationEntity(fullyQualifiedName)) {
- ITypeBinding tb = node.resolveTypeBinding();
- CompilationUnit cu = null;
- ASTNode astNode = node.getParent();
+
+ public CompilationUnit getCUFromFieldMethod(ASTNode node) {
+ CompilationUnit cu = null;
+ ASTNode astNode = node.getParent();
+ if (astNode instanceof FieldDeclaration ||
+ astNode instanceof MethodDeclaration) {
+ astNode = astNode.getParent();
if (astNode instanceof TypeDeclaration) {
astNode = astNode.getParent();
if (astNode instanceof CompilationUnit) {
cu = (CompilationUnit)astNode;
}
}
+ }
+ return cu;
+ }
+
+ public CompilationUnit getCUFromTypeDeclaration(ASTNode node) {
+ CompilationUnit cu = null;
+ ASTNode astNode = node.getParent();
+ if (astNode instanceof TypeDeclaration) {
+ astNode = astNode.getParent();
+ if (astNode instanceof CompilationUnit) {
+ cu = (CompilationUnit)astNode;
+ }
+ }
+ return cu;
+ }
+
+ public boolean processAnnotation(Annotation node, String mappedBy) {
+ String fullyQualifiedName = node.getTypeName().getFullyQualifiedName();
+ if (JPAConst.isAnnotationEntity(fullyQualifiedName)) {
+ ITypeBinding tb = node.resolveTypeBinding();
+ CompilationUnit cu = getCUFromTypeDeclaration(node);
if (cu != null) {
- entityInfo.setAddEntityFlag(false);
if (tb == null) {
entityInfo.addRequiredImport(JPAConst.IMPORT_ENTITY);
}
+ entityInfo.setAddEntityFlag(false);
}
}
else if (JPAConst.isAnnotationId(fullyQualifiedName)) {
ITypeBinding tb = node.resolveTypeBinding();
- CompilationUnit cu = null;
- ASTNode astNode = node.getParent();
- if (astNode instanceof FieldDeclaration ||
- astNode instanceof MethodDeclaration) {
- astNode = astNode.getParent();
- if (astNode instanceof TypeDeclaration) {
- astNode = astNode.getParent();
- if (astNode instanceof CompilationUnit) {
- cu = (CompilationUnit)astNode;
- }
- }
- }
+ CompilationUnit cu = getCUFromFieldMethod(node);
if (cu != null) {
if (tb == null) {
entityInfo.addRequiredImport(JPAConst.IMPORT_ID);
@@ -132,18 +142,7 @@
}
else if (JPAConst.isAnnotationGeneratedValue(fullyQualifiedName)) {
ITypeBinding tb = node.resolveTypeBinding();
- CompilationUnit cu = null;
- ASTNode astNode = node.getParent();
- if (astNode instanceof FieldDeclaration ||
- astNode instanceof MethodDeclaration) {
- astNode = astNode.getParent();
- if (astNode instanceof TypeDeclaration) {
- astNode = astNode.getParent();
- if (astNode instanceof CompilationUnit) {
- cu = (CompilationUnit)astNode;
- }
- }
- }
+ CompilationUnit cu = getCUFromFieldMethod(node);
if (cu != null) {
if (tb == null) {
entityInfo.addRequiredImport(JPAConst.IMPORT_GENERATED_VALUE);
@@ -168,12 +167,25 @@
RefType.MANY2MANY, JPAConst.ANNOTATION_MANY2MANY, JPAConst.IMPORT_MANY2MANY);
}
else if (JPAConst.isAnnotationMappedSuperclass(fullyQualifiedName)) {
- entityInfo.setAddEntityFlag(false);
- entityInfo.setAddMappedSuperclassFlag(false);
- entityInfo.removeRequiredImport(JPAConst.IMPORT_ENTITY);
- entityInfo.addRequiredImport(JPAConst.IMPORT_MAPPEDSUPERCLASS);
+ ITypeBinding tb = node.resolveTypeBinding();
+ CompilationUnit cu = getCUFromTypeDeclaration(node);
+ if (cu != null) {
+ if (tb == null) {
+ entityInfo.addRequiredImport(JPAConst.IMPORT_MAPPEDSUPERCLASS);
+ }
+ entityInfo.setAddEntityFlag(false);
+ entityInfo.setAddMappedSuperclassFlag(false);
+ }
}
else if (JPAConst.isAnnotationVersion(fullyQualifiedName)) {
+ ITypeBinding tb = node.resolveTypeBinding();
+ CompilationUnit cu = getCUFromFieldMethod(node);
+ if (cu != null) {
+ if (tb == null) {
+ entityInfo.addRequiredImport(JPAConst.IMPORT_VERSION);
+ }
+ entityInfo.setAddVersionFlag(false);
+ }
}
return true;
}
@@ -192,13 +204,7 @@
entityInfo.updateReference(name, true, type, mappedBy,
0 != annNameShort.compareTo(fullyQualifiedName), true);
}
- astNode = astNode.getParent();
- if (astNode instanceof TypeDeclaration) {
- astNode = astNode.getParent();
- if (astNode instanceof CompilationUnit) {
- cu = (CompilationUnit)astNode;
- }
- }
+ cu = getCUFromTypeDeclaration(node);
}
else if (astNode instanceof MethodDeclaration) {
MethodDeclaration md = (MethodDeclaration)astNode;
@@ -208,13 +214,7 @@
// process it like FieldDeclaration
entityInfo.updateReference(name, true, type, mappedBy,
0 != annNameShort.compareTo(fullyQualifiedName), false);
- astNode = astNode.getParent();
- if (astNode instanceof TypeDeclaration) {
- astNode = astNode.getParent();
- if (astNode instanceof CompilationUnit) {
- cu = (CompilationUnit)astNode;
- }
- }
+ cu = getCUFromTypeDeclaration(node);
}
else {
// ignore others
@@ -253,8 +253,6 @@
if (isAbstruct) {
entityInfo.setAddEntityFlag(false);
entityInfo.setAddMappedSuperclassFlag(true);
- entityInfo.removeRequiredImport(JPAConst.IMPORT_ENTITY);
- entityInfo.addRequiredImport(JPAConst.IMPORT_MAPPEDSUPERCLASS);
}
entityInfo.setInterfaceFlag(node.isInterface());
Type superType = node.getSuperclassType();
@@ -391,7 +389,12 @@
Iterator itVarNames = list.iterator();
while (itVarNames.hasNext()) {
String name = (String)itVarNames.next();
- entityInfo.addPrimaryIdCandidate(name);
+ if ("version".equalsIgnoreCase(name)) { //$NON-NLS-1$
+ entityInfo.setAddVersionFlag(true);
+ }
+ else {
+ entityInfo.addPrimaryIdCandidate(name);
+ }
}
}
}
@@ -417,13 +420,30 @@
}
else if (tb.getJavaElement() instanceof BinaryType) {
ITypeBinding tbParent = tb.getTypeDeclaration().getSuperclass();
- if (tbParent != null &&
"java.lang.Number".equals(tbParent.getBinaryName())) { //$NON-NLS-1$
- // this is candidate for primary id
- Iterator itVarNames = list.iterator();
- while (itVarNames.hasNext()) {
- String name = (String)itVarNames.next();
- entityInfo.addPrimaryIdCandidate(name);
+ if (tbParent != null) {
+ if ("java.lang.Number".equals(tbParent.getBinaryName())) { //$NON-NLS-1$
+ // this is candidate for primary id
+ Iterator itVarNames = list.iterator();
+ while (itVarNames.hasNext()) {
+ String name = (String)itVarNames.next();
+ if ("version".equalsIgnoreCase(name)) { //$NON-NLS-1$
+ entityInfo.setAddVersionFlag(true);
+ }
+ else {
+ entityInfo.addPrimaryIdCandidate(name);
+ }
+ }
}
+ else if ("java.util.Date".equals(tbParent.getBinaryName())) {
//$NON-NLS-1$
+ // this is candidate for version
+ Iterator itVarNames = list.iterator();
+ while (itVarNames.hasNext()) {
+ String name = (String)itVarNames.next();
+ if ("version".equalsIgnoreCase(name)) { //$NON-NLS-1$
+ entityInfo.setAddVersionFlag(true);
+ }
+ }
+ }
}
}
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java 2009-04-01
14:37:23 UTC (rev 14404)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java 2009-04-01
16:16:50 UTC (rev 14405)
@@ -93,6 +93,10 @@
*/
protected boolean addGeneratedValueFlag = true;
/*
+ * if true - add version marker for "version" property
+ */
+ protected boolean addVersionFlag = false;
+ /*
* define relations between entities
* field id -> RefEntityInfo
*/
@@ -192,6 +196,21 @@
if (isAddEntityFlag()) {
addRequiredImport(JPAConst.IMPORT_ENTITY);
}
+ else {
+ removeRequiredImport(JPAConst.IMPORT_ENTITY);
+ }
+ if (isAddMappedSuperclassFlag()) {
+ addRequiredImport(JPAConst.IMPORT_MAPPEDSUPERCLASS);
+ }
+ else {
+ removeRequiredImport(JPAConst.IMPORT_MAPPEDSUPERCLASS);
+ }
+ if (isAddVersionFlag()) {
+ addRequiredImport(JPAConst.IMPORT_VERSION);
+ }
+ else {
+ removeRequiredImport(JPAConst.IMPORT_VERSION);
+ }
Iterator<Map.Entry<String, RefEntityInfo>> referencesIt =
getReferences().entrySet().iterator();
while (referencesIt.hasNext()) {
@@ -422,6 +441,14 @@
this.addGeneratedValueFlag = addGeneratedValueFlag;
}
+ public boolean isAddVersionFlag() {
+ return addVersionFlag;
+ }
+
+ public void setAddVersionFlag(boolean addVersionFlag) {
+ this.addVersionFlag = addVersionFlag;
+ }
+
public void addExistingImport(String existingImport) {
setExistingImports.add(existingImport);
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ProcessEntityInfo.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ProcessEntityInfo.java 2009-04-01
14:37:23 UTC (rev 14404)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ProcessEntityInfo.java 2009-04-01
16:16:50 UTC (rev 14405)
@@ -22,16 +22,13 @@
import org.eclipse.jdt.core.dom.BodyDeclaration;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.FieldDeclaration;
-import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.ImportDeclaration;
import org.eclipse.jdt.core.dom.MarkerAnnotation;
import org.eclipse.jdt.core.dom.MemberValuePair;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.NormalAnnotation;
-import org.eclipse.jdt.core.dom.ParameterizedType;
import org.eclipse.jdt.core.dom.QualifiedName;
-import org.eclipse.jdt.core.dom.ReturnStatement;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SimpleType;
import org.eclipse.jdt.core.dom.StringLiteral;
@@ -247,6 +244,24 @@
lrw.insertFirst(matd, null);
}
}
+ if (entityInfo.isAddVersionFlag()) {
+ Iterator itVarNames = node.fragments().iterator();
+ boolean addVersionMarker = false;
+ while (itVarNames.hasNext()) {
+ VariableDeclarationFragment var = (VariableDeclarationFragment)itVarNames.next();
+ String name = var.getName().getIdentifier();
+ if ("version".equals(name)) { //$NON-NLS-1$
+ addVersionMarker = true;
+ break;
+ }
+ }
+ if (addVersionMarker) {
+ MarkerAnnotation matd = rewriter.getAST().newMarkerAnnotation();
+ matd.setTypeName(rewriter.getAST().newSimpleName(JPAConst.ANNOTATION_VERSION));
+ ListRewrite lrw = rewriter.getListRewrite(node,
FieldDeclaration.MODIFIERS2_PROPERTY);
+ lrw.insertFirst(matd, null);
+ }
+ }
}
if (type.isSimpleType() || type.isParameterizedType() || type.isArrayType()) {
Iterator itVarNames = node.fragments().iterator();
@@ -349,6 +364,18 @@
lrw.insertFirst(matd, null);
}
}
+ if (entityInfo.isAddVersionFlag()) {
+ boolean addVersionMarker = false;
+ if ("version".equals(returnIdentifier)) { //$NON-NLS-1$
+ addVersionMarker = true;
+ }
+ if (addVersionMarker) {
+ MarkerAnnotation matd = rewriter.getAST().newMarkerAnnotation();
+ matd.setTypeName(rewriter.getAST().newSimpleName(JPAConst.ANNOTATION_VERSION));
+ ListRewrite lrw = rewriter.getListRewrite(node,
MethodDeclaration.MODIFIERS2_PROPERTY);
+ lrw.insertFirst(matd, null);
+ }
+ }
}
if (type.isSimpleType() || type.isParameterizedType() || type.isArrayType()) {
String fieldId = ""; //$NON-NLS-1$
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/fields/DocumentBase.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/fields/DocumentBase.java 2009-04-01
14:37:23 UTC (rev 14404)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/fields/DocumentBase.java 2009-04-01
16:16:50 UTC (rev 14405)
@@ -15,4 +15,6 @@
public abstract class DocumentBase {
protected String globalDocumentIdentificator;
+
+ protected Integer version;
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/fields/Foto.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/fields/Foto.java 2009-04-01
14:37:23 UTC (rev 14404)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/fields/Foto.java 2009-04-01
16:16:50 UTC (rev 14405)
@@ -10,6 +10,8 @@
******************************************************************************/
package test.annotated.fields;
+import java.sql.Date;
+
public class Foto {
protected Long fid;
@@ -21,6 +23,9 @@
protected Short width_IDtest;
protected Short height_testID;
+
+ @javax.persistence.Version
+ protected Date version;
public Foto() {
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/getters/DocumentBase.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/getters/DocumentBase.java 2009-04-01
14:37:23 UTC (rev 14404)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/getters/DocumentBase.java 2009-04-01
16:16:50 UTC (rev 14405)
@@ -10,8 +10,20 @@
******************************************************************************/
package test.annotated.getters;
-@MappedSuperclass
+import javax.persistence.Version;
+
+(a)javax.persistence.MappedSuperclass
public abstract class DocumentBase {
protected String globalDocumentIdentificator;
+
+ protected Integer version;
+
+ public Integer getVersion() {
+ return version;
+ }
+
+ public void setVersion(Integer version) {
+ this.version = version;
+ }
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/getters/Foto.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/getters/Foto.java 2009-04-01
14:37:23 UTC (rev 14404)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/getters/Foto.java 2009-04-01
16:16:50 UTC (rev 14405)
@@ -10,6 +10,8 @@
******************************************************************************/
package test.annotated.getters;
+import java.sql.Date;
+
public class Foto {
private Long fid;
@@ -21,6 +23,8 @@
private Short width_IDtest;
private Short height_testID;
+
+ private Date version;
public Foto() {
}
@@ -64,5 +68,13 @@
public void setHeight_testID(Short height_testID) {
this.height_testID = height_testID;
}
+
+ public Date getVersion() {
+ return version;
+ }
+
+ public void setVersion(Date version) {
+ this.version = version;
+ }
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/fields/DocumentBase.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/fields/DocumentBase.java 2009-04-01
14:37:23 UTC (rev 14404)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/fields/DocumentBase.java 2009-04-01
16:16:50 UTC (rev 14405)
@@ -11,9 +11,13 @@
package test.annotated.fields;
import javax.persistence.MappedSuperclass;
+import javax.persistence.Version;
@MappedSuperclass
public abstract class DocumentBase {
protected String globalDocumentIdentificator;
+
+ @Version
+ protected Integer version;
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/fields/Foto.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/fields/Foto.java 2009-04-01
14:37:23 UTC (rev 14404)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/fields/Foto.java 2009-04-01
16:16:50 UTC (rev 14405)
@@ -10,6 +10,8 @@
******************************************************************************/
package test.annotated.fields;
+import java.sql.Date;
+
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@@ -29,6 +31,9 @@
protected Short width_IDtest;
protected Short height_testID;
+
+ @javax.persistence.Version
+ protected Date version;
public Foto() {
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/getters/DocumentBase.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/getters/DocumentBase.java 2009-04-01
14:37:23 UTC (rev 14404)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/getters/DocumentBase.java 2009-04-01
16:16:50 UTC (rev 14405)
@@ -10,10 +10,21 @@
******************************************************************************/
package test.annotated.getters;
-import javax.persistence.MappedSuperclass;
+import javax.persistence.Version;
-@MappedSuperclass
+(a)javax.persistence.MappedSuperclass
public abstract class DocumentBase {
protected String globalDocumentIdentificator;
+
+ protected Integer version;
+
+ @Version
+ public Integer getVersion() {
+ return version;
+ }
+
+ public void setVersion(Integer version) {
+ this.version = version;
+ }
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/getters/Foto.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/getters/Foto.java 2009-04-01
14:37:23 UTC (rev 14404)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/getters/Foto.java 2009-04-01
16:16:50 UTC (rev 14405)
@@ -10,10 +10,13 @@
******************************************************************************/
package test.annotated.getters;
+import java.sql.Date;
+
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToOne;
+import javax.persistence.Version;
@Entity
public class Foto {
@@ -27,6 +30,8 @@
private Short width_IDtest;
private Short height_testID;
+
+ private Date version;
public Foto() {
}
@@ -72,5 +77,14 @@
public void setHeight_testID(Short height_testID) {
this.height_testID = height_testID;
}
+
+ @Version
+ public Date getVersion() {
+ return version;
+ }
+
+ public void setVersion(Date version) {
+ this.version = version;
+ }
}