[jbosstools-commits] JBoss Tools SVN: r43574 - 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
Mon Sep 10 20:10:29 EDT 2012


Author: akazakov
Date: 2012-09-10 20:10:28 -0400 (Mon, 10 Sep 2012)
New Revision: 43574

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/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-10 23:22:37 UTC (rev 43573)
+++ workspace/akazakov/db/org.jboss.tools.cdi.db/src/org/jboss/tools/cdi/db/CDIDataBase.java	2012-09-11 00:10:28 UTC (rev 43574)
@@ -103,57 +103,65 @@
 	 * @see org.jboss.tools.cdi.core.ICDICache#rebuild(org.jboss.tools.cdi.core.ICDIProject, java.util.Collection)
 	 */
 	@Override
-	public void rebuild(ICDIProject project, Collection<IBean> beans) {
+	public synchronized void rebuild(ICDIProject project, Collection<IBean> beans) {
 		Context context = null;
-		synchronized (currentContext) {
+//		synchronized (currentContext) {
 			context = (Context)currentContext.clone();
-		}
+//		}
 
 		Short projectIndex = context.removeProjectIndex(project);
 		EntityManager em = CDIDBManager.getInstance().getEntityManager();
 		EntityTransaction transaction = em.getTransaction();
 		transaction.begin();
-		if(projectIndex!=null) {
-			em.createQuery("DELETE FROM BeanEntity b WHERE b.projectIndex = :p").setParameter("p", projectIndex).executeUpdate();
-			em.createQuery("DELETE FROM QualifierEntity b WHERE b.projectIndex = :p").setParameter("p", projectIndex).executeUpdate();
-			em.createQuery("DELETE FROM TypeEntity b WHERE b.bean.projectIndex = :p").setParameter("p", projectIndex).executeUpdate();
-		}
-		projectIndex = context.generateProjectIndex(project);
+		try {
+			if(projectIndex!=null) {
+				em.createQuery("DELETE FROM TypeEntity t WHERE t.projectIndex = :p").setParameter("p", projectIndex).executeUpdate();
+				em.createQuery("DELETE FROM QualifierEntity q WHERE q.projectIndex = :p").setParameter("p", projectIndex).executeUpdate();
+				em.createQuery("DELETE FROM BeanEntity b WHERE b.projectIndex = :p").setParameter("p", projectIndex).executeUpdate();
+			}
+			projectIndex = context.generateProjectIndex(project);
 
-		Map<Integer, QualifierEntity> qualifiers = new HashMap<Integer, QualifierEntity>();
-		for (IBean bean : beans) {
-			context.getAllBeans().put(bean.getId(), bean);
-			BeanEntity beanEntity = new BeanEntity();
-			beanEntity.setIndex(bean.getId());
-			beanEntity.setProjectIndex(projectIndex);
+			Map<Integer, QualifierEntity> qualifiers = new HashMap<Integer, QualifierEntity>();
+			for (IBean bean : beans) {
+				context.getAllBeans().put(bean.getId(), bean);
+				BeanEntity beanEntity = new BeanEntity();
+				beanEntity.setIndex(bean.getId());
+				beanEntity.setProjectIndex(projectIndex);
 
-			Collection<IQualifier> beanQualifiers = bean.getQualifiers();
-			List<QualifierEntity> qualifierEntities = new ArrayList<QualifierEntity>();
-			for (IQualifier beanQualifier : beanQualifiers) {
-				int id = beanQualifier.getId();
-				QualifierEntity qualifierEntity = qualifiers.get(id);
-				if(qualifierEntity==null) {
-					qualifierEntity = new QualifierEntity();
-					qualifierEntity.setIndex(id);
-					qualifierEntity.setProjectIndex(projectIndex);
-					em.persist(qualifierEntity);
+				Collection<IQualifier> beanQualifiers = bean.getQualifiers();
+				List<QualifierEntity> qualifierEntities = new ArrayList<QualifierEntity>();
+				for (IQualifier beanQualifier : beanQualifiers) {
+					int id = beanQualifier.getId();
+					QualifierEntity qualifierEntity = qualifiers.get(id);
+					if(qualifierEntity==null) {
+						qualifierEntity = new QualifierEntity();
+						qualifierEntity.setIndex(id);
+						qualifierEntity.setProjectIndex(projectIndex);
+						em.persist(qualifierEntity);
+					}
+					qualifierEntities.add(qualifierEntity);
 				}
-				qualifierEntities.add(qualifierEntity);
-			}
 
-			beanEntity.setQualifiers(qualifierEntities);
-			em.persist(beanEntity);
+				beanEntity.setQualifiers(qualifierEntities);
+				em.persist(beanEntity);
 
-			Collection<IParametedType> beanTypes = bean.getLegalTypes();
-			for (IParametedType beanType : beanTypes) {
-				long id = context.getTypeIndex(beanType);
-				TypeEntity typeEntity = new TypeEntity();
-				typeEntity.setIndex(id);
-				typeEntity.setBean(beanEntity);
-				em.persist(typeEntity);
+				Collection<IParametedType> beanTypes = bean.getLegalTypes();
+				for (IParametedType beanType : beanTypes) {
+					long id = context.getTypeIndex(beanType);
+					TypeEntity typeEntity = new TypeEntity();
+					typeEntity.setIndex(id);
+					typeEntity.setBean(beanEntity);
+					typeEntity.setProjectIndex(projectIndex);
+					em.persist(typeEntity);
+				}
 			}
+		} finally {
+			if(transaction.getRollbackOnly()) {
+				transaction.rollback();
+			} else {
+				transaction.commit();
+			}
 		}
-		transaction.commit();
 
 		currentContext = context;
 	}
@@ -163,30 +171,31 @@
 	 * @see org.jboss.tools.cdi.core.ICDICache#getBeansByLegalType(org.jboss.tools.cdi.core.ICDIProject, java.lang.String)
 	 */
 	@Override
-	public Collection<IBean> getBeansByLegalType(ICDIProject project, String legalType) {
+	public synchronized Collection<IBean> getBeansByLegalType(ICDIProject project, String legalType) {
 		List<IBean> beans = new ArrayList<IBean>();
-		synchronized (currentContext) {
+//		synchronized (currentContext) {
 			Short projectIndex = currentContext.getProjectIndex(project);
 			EntityManager em = CDIDBManager.getInstance().getEntityManager();
 			EntityTransaction transaction = em.getTransaction();
-			if(!transaction.isActive())
-				transaction.begin();
+			transaction.begin();
 
-			long typeIndex = currentContext.getTypeIndex(legalType);
-			List results = em.createQuery("SELECT t.bean FROM TypeEntity t WHERE t.index = :b AND t.bean.projectIndex = :p").setParameter("p", projectIndex).setParameter("b", typeIndex).getResultList();
-			for (Object result : results) {
-				BeanEntity beanEntity = (BeanEntity)result;
-				int index = beanEntity.getIndex();
-				IBean bean = currentContext.allBeans.get(index);
-				if(bean != null) {
-					beans.add(bean);
-				} else {
-					//report a problem
+			try {
+				long typeIndex = currentContext.getTypeIndex(legalType);
+				List results = em.createQuery("SELECT t.bean FROM TypeEntity t WHERE t.index = :b AND t.bean.projectIndex = :p").setParameter("p", projectIndex).setParameter("b", typeIndex).getResultList();
+				for (Object result : results) {
+					BeanEntity beanEntity = (BeanEntity)result;
+					int index = beanEntity.getIndex();
+					IBean bean = currentContext.allBeans.get(index);
+					if(bean != null) {
+						beans.add(bean);
+					} else {
+						//report a problem
+					}
 				}
+			} finally {
+				transaction.rollback();
 			}
-//			transaction.commit();
-			transaction.rollback();
-		}
+//		}
 		return beans;
 	}
 }
\ No newline at end of file

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-10 23:22:37 UTC (rev 43573)
+++ workspace/akazakov/db/org.jboss.tools.cdi.db/src/org/jboss/tools/cdi/db/entity/TypeEntity.java	2012-09-11 00:10:28 UTC (rev 43574)
@@ -27,6 +27,7 @@
 	private long id;
 	private long index;
 	private BeanEntity bean;
+	private short projectIndex;
 
 	/**
 	 * @return the id
@@ -64,6 +65,21 @@
 		this.bean = bean;
 	}
 
+	/**
+	 * @return the projectIndex
+	 */
+	@Column(nullable=false)
+	public short getProjectIndex() {
+		return projectIndex;
+	}
+
+	/**
+	 * @param projectIndex the projectIndex to set
+	 */
+	public void setProjectIndex(short projectIndex) {
+		this.projectIndex = projectIndex;
+	}
+
 	@Override
 	public int hashCode() {
 		return ("" + index).hashCode();



More information about the jbosstools-commits mailing list