[jbosstools-commits] JBoss Tools SVN: r43528 - in workspace/akazakov/db/org.jboss.tools.cdi.db/src/org/jboss/tools/cdi/db: entity and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Sep 7 16:33:55 EDT 2012


Author: akazakov
Date: 2012-09-07 16:33:55 -0400 (Fri, 07 Sep 2012)
New Revision: 43528

Modified:
   workspace/akazakov/db/org.jboss.tools.cdi.db/src/org/jboss/tools/cdi/db/CDIDataBase.java
   workspace/akazakov/db/org.jboss.tools.cdi.db/src/org/jboss/tools/cdi/db/entity/BeanEntity.java
   workspace/akazakov/db/org.jboss.tools.cdi.db/src/org/jboss/tools/cdi/db/entity/TypeEntity.java
Log:
https://issues.jboss.org/browse/JBIDE-12446

Modified: workspace/akazakov/db/org.jboss.tools.cdi.db/src/org/jboss/tools/cdi/db/CDIDataBase.java
===================================================================
--- workspace/akazakov/db/org.jboss.tools.cdi.db/src/org/jboss/tools/cdi/db/CDIDataBase.java	2012-09-07 20:22:42 UTC (rev 43527)
+++ workspace/akazakov/db/org.jboss.tools.cdi.db/src/org/jboss/tools/cdi/db/CDIDataBase.java	2012-09-07 20:33:55 UTC (rev 43528)
@@ -19,6 +19,7 @@
 import javax.persistence.EntityManager;
 import javax.persistence.EntityTransaction;
 
+import org.eclipse.jdt.core.IType;
 import org.jboss.tools.cdi.core.IBean;
 import org.jboss.tools.cdi.core.ICDICache;
 import org.jboss.tools.cdi.core.ICDIProject;
@@ -79,21 +80,15 @@
 			}
 
 			Collection<IParametedType> beanTypes = bean.getLegalTypes();
-			List<TypeEntity> typeEntities = new ArrayList<TypeEntity>();
 			for (IParametedType beanType : beanTypes) {
-				int id = 0;
-				TypeEntity typeEntity = types.get(id);
-				if(typeEntity==null) {
-					typeEntity = new TypeEntity();
-					typeEntity.setIndex(id);
-					typeEntity.setProjectIndex(projectIndex);
-					em.persist(typeEntity);
-				}
-				typeEntities.add(typeEntity);
+				long id = getTypeIndex(beanType);
+				TypeEntity typeEntity = new TypeEntity();
+				typeEntity.setIndex(id);
+				typeEntity.setBean(beanEntity);
+				em.persist(typeEntity);
 			}
 
 			beanEntity.setQualifiers(qualifierEntities);
-			beanEntity.setTypes(typeEntities);
 			em.persist(beanEntity);
 		}
 		transaction.commit();
@@ -110,12 +105,25 @@
 		EntityTransaction transaction = em.getTransaction();
 		transaction.begin();
 
-		em.createQuery("DELETE FROM BeanEntity b WHERE b.projectIndex = :p").setParameter("p", projectIndex).executeUpdate();
+		long typeIndex = getTypeIndex(legalType);
+		//TODO
+		List result = em.createQuery("SELECT FROM TypeEntity t, BeanEntity b WHERE t.index = :b AND t.bean.projectIndex = :p AND t.bean.id = b.id ").setParameter("p", projectIndex).setParameter("b", typeIndex).getResultList();
 
 		transaction.commit();
 		return null;
 	}
 
+	private long getTypeIndex(IParametedType type) {
+		IType iType = type.getType();
+		String name = iType!=null?iType.getFullyQualifiedName():type.getSimpleName();
+		return getTypeIndex(name);
+	}
+
+	private long getTypeIndex(String typeName) {
+		//TODO
+		return 0;
+	}
+
 	private Short getProjectIndex(ICDIProject project) {
 		String projectName = project.getNature().getProject().getName();
 		return projects.get(projectName);

Modified: workspace/akazakov/db/org.jboss.tools.cdi.db/src/org/jboss/tools/cdi/db/entity/BeanEntity.java
===================================================================
--- workspace/akazakov/db/org.jboss.tools.cdi.db/src/org/jboss/tools/cdi/db/entity/BeanEntity.java	2012-09-07 20:22:42 UTC (rev 43527)
+++ workspace/akazakov/db/org.jboss.tools.cdi.db/src/org/jboss/tools/cdi/db/entity/BeanEntity.java	2012-09-07 20:33:55 UTC (rev 43528)
@@ -12,12 +12,14 @@
 
 import java.util.List;
 
+import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
 import javax.persistence.JoinColumn;
-import javax.persistence.ManyToMany;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
 
 /**
  * @author Alexey Kazakov
@@ -60,8 +62,7 @@
 	/**
 	 * @return the types
 	 */
-	@ManyToMany
-	@JoinColumn(nullable=true)
+	@OneToMany(cascade={CascadeType.REMOVE}, mappedBy="bean")
 	public List<TypeEntity> getTypes() {
 		return types;
 	}
@@ -76,7 +77,7 @@
 	/**
 	 * @return the qualifiers
 	 */
-	@ManyToMany
+	@ManyToOne
 	@JoinColumn(nullable=true)
 	public List<QualifierEntity> getQualifiers() {
 		return qualifiers;

Modified: workspace/akazakov/db/org.jboss.tools.cdi.db/src/org/jboss/tools/cdi/db/entity/TypeEntity.java
===================================================================
--- workspace/akazakov/db/org.jboss.tools.cdi.db/src/org/jboss/tools/cdi/db/entity/TypeEntity.java	2012-09-07 20:22:42 UTC (rev 43527)
+++ workspace/akazakov/db/org.jboss.tools.cdi.db/src/org/jboss/tools/cdi/db/entity/TypeEntity.java	2012-09-07 20:33:55 UTC (rev 43528)
@@ -14,6 +14,8 @@
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
 
 /**
  * @author Alexey Kazakov
@@ -22,8 +24,8 @@
 public class TypeEntity {
 
 	private long id;
-	private int index;
-	private short projectIndex;
+	private long index;
+	private BeanEntity bean;
 
 	/**
 	 * @return the id
@@ -43,32 +45,27 @@
 	}
 
 	@Column(unique=true)
-	public int getIndex() {
+	public long getIndex() {
 		return index;
 	}
 
-	public void setIndex(int index) {
+	public void setIndex(long index) {
 		this.index = index;
 	}
 
-	/**
-	 * @return the projectIndex
-	 */
-	@Column(nullable=false)
-	public short getProjectIndex() {
-		return projectIndex;
+	@ManyToOne
+	@JoinColumn(nullable=false)
+	public BeanEntity getBean() {
+		return bean;
 	}
 
-	/**
-	 * @param projectIndex the projectIndex to set
-	 */
-	public void setProjectIndex(short projectIndex) {
-		this.projectIndex = projectIndex;
+	public void setBean(BeanEntity bean) {
+		this.bean = bean;
 	}
 
 	@Override
 	public int hashCode() {
-		return index;
+		return ("" + index).hashCode();
 	}
 
 	@Override



More information about the jbosstools-commits mailing list