From bf7cf464bbf0374bc414b19971ff80a691730539 Mon Sep 17 00:00:00 2001 From: Jihoon Song Date: Wed, 16 Oct 2013 18:30:28 +0900 Subject: [PATCH] [Title] common-eplugin: fixed a clean build exception. [Desc.] [Issue] Change-Id: Iaa1331abe3f3ab62d997135f425618cae1a1a4bd --- .../common/builder/dependency/DependencyInDB.java | 205 ++++++++++++--------- 1 file changed, 114 insertions(+), 91 deletions(-) diff --git a/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyInDB.java b/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyInDB.java index 501877e..e58cffc 100755 --- a/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyInDB.java +++ b/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyInDB.java @@ -29,13 +29,16 @@ package org.tizen.common.builder.dependency; import java.io.File; +import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tizen.common.builder.BuildDependency; +import org.tizen.common.builder.BuildProcess; import org.tizen.common.builder.Dependency; import org.tizen.common.builder.Resource; import org.tizen.common.builder.ResourceLayer; @@ -62,6 +65,7 @@ public class DependencyInDB implements BuildDependency { protected String projectName; // project of resource protected ResourceLayer lastLayer; // last resource layer for data sync + protected static final Object syncObj = new Object(); /** * Root URL setter for storing. If dbAbsoultePath is an empty, use the previous path. @@ -128,6 +132,8 @@ public class DependencyInDB implements BuildDependency { // create indexes if ( bCreateIndex ) { graph.createKeyIndex( DependencyConstant.RESOURCE_KEY_PATH, Vertex.class ); + graph.createKeyIndex( DependencyConstant.RESOURCE_KEY_LAYER, Vertex.class ); + graph.createKeyIndex( DependencyConstant.RESOURCE_KEY_PROJECT, Vertex.class ); } logger.info( "Open OrientGraphDB : {}", url ); @@ -167,42 +173,48 @@ public class DependencyInDB implements BuildDependency { @Override public boolean clear() { - Assert.notNull( this.projectName ); - - // remove database from local storage. - Iterator eIter = graph.getEdges( DependencyConstant.RESOURCE_KEY_PROJECT, this.projectName ).iterator(); - while ( eIter.hasNext() ) { - Edge next = eIter.next(); - graph.removeEdge( next ); - } - Iterator vIter = graph.getVertices( DependencyConstant.RESOURCE_KEY_PROJECT, this.projectName ).iterator(); - while ( vIter.hasNext() ) { - Vertex next = vIter.next(); - graph.removeVertex( next ); + synchronized( syncObj ) { + Assert.notNull( this.projectName ); + + // remove database from local storage. + // INFO: Gremlin actually deletes all the edges for you if you delete the vertex. + Iterator vIter = graph.getVertices( DependencyConstant.RESOURCE_KEY_PROJECT, this.projectName ).iterator(); + List list = new ArrayList(); + while ( vIter.hasNext() ) { + list.add( vIter.next() ); + } + for ( Vertex v : list ) { + v.remove(); + } + + logger.trace( "Remove all resources" ); + + return true; } - - logger.trace( "Remove all resources" ); - - return true; } public void clearAll() { - Assert.notNull( graph ); - - graph.drop(); + synchronized( syncObj ) { + Assert.notNull( graph ); + + graph.drop(); + } } @Override public void addVertex(Resource resource) { - Assert.notNull( this.projectName ); - Assert.notNull( resource ); - - OrientVertex vertex = graph.addVertex( null ); - vertex.setProperty( DependencyConstant.RESOURCE_KEY_PATH, resource.getPath() ); - vertex.setProperty( DependencyConstant.RESOURCE_KEY_LAYER, resource.getLayer().getName() ); - vertex.setProperty( DependencyConstant.RESOURCE_KEY_PROJECT, this.projectName ); - - logger.trace( "an added vertex : {}", resource ); + synchronized( syncObj ) { + Assert.notNull( this.projectName ); + Assert.notNull( resource ); + + OrientVertex vertex = graph.addVertex( null ); + vertex.setProperty( DependencyConstant.RESOURCE_KEY_PATH, resource.getPath() ); + vertex.setProperty( DependencyConstant.RESOURCE_KEY_LAYER, resource.getLayer().getName() ); + vertex.setProperty( DependencyConstant.RESOURCE_KEY_PROJECT, this.projectName ); + vertex.save(); + + logger.trace( "an added vertex : {}", resource ); + } } /** @@ -219,16 +231,12 @@ public class DependencyInDB implements BuildDependency { String layerName = layer.getName(); - Iterator iterator = graph.getVertices( - DependencyConstant.RESOURCE_KEY_PATH, - resource.getPath() - ).iterator(); + Iterator iterator = graph.getVertices( DependencyConstant.RESOURCE_KEY_PATH, resource.getPath() ).iterator(); while( iterator.hasNext() ) { Vertex vertex = iterator.next(); Object value = vertex.getProperty( DependencyConstant.RESOURCE_KEY_LAYER ); Object project = vertex.getProperty( DependencyConstant.RESOURCE_KEY_PROJECT ); - if ( ( value instanceof String ) && ( project instanceof String ) ) { if ( ((String) value).equals( layerName ) && ((String) project).equals( this.projectName ) ) { @@ -242,87 +250,102 @@ public class DependencyInDB implements BuildDependency { @Override public boolean containsVertex(Resource resource) { - return getVertexFromDB( resource ) != null; + synchronized( syncObj ) { + return getVertexFromDB( resource ) != null; + } } @Override public void removeVertex(Resource resource) { - Vertex vertex = getVertexFromDB( resource ); - if ( vertex != null ) { - graph.removeVertex( vertex ); - logger.trace( "a removed vertex : {}", resource ); + synchronized( syncObj ) { + Vertex vertex = getVertexFromDB( resource ); + if ( vertex != null ) { + vertex.remove(); + logger.trace( "a removed vertex : {}", resource ); + } } } @Override public void addEdge(Resource in, Resource out, Dependency dependency) { - Vertex inVertex = getVertexFromDB( in ); - Vertex outVertex = getVertexFromDB( out ); - - Assert.notNull( inVertex ); - Assert.notNull( outVertex ); - - OrientEdge edge = graph.addEdge( null, outVertex, inVertex, DependencyConstant.EDGE_LABEL ); - logger.trace( "an added edge : {}", edge ); + synchronized( syncObj ) { + Vertex inVertex = getVertexFromDB( in ); + Vertex outVertex = getVertexFromDB( out ); + + Assert.notNull( inVertex ); + Assert.notNull( outVertex ); + + OrientEdge edge = graph.addEdge( null, outVertex, inVertex, DependencyConstant.EDGE_LABEL ); + edge.save(); + + logger.trace( "an added edge : {}", edge ); + } } @Override public void removeEdge(Dependency dependency) { - Assert.notNull( dependency ); - - OrientVertex inVertex = null; - OrientVertex outVertex = null; - - // get vertex values from dependency - if ( dependency instanceof OrientDBDependency ) { - OrientDBDependency depen = (OrientDBDependency) dependency; - inVertex = (OrientVertex) depen.getSourceVertex(); - outVertex = (OrientVertex) depen.getTargetVertex(); - } else { - // find a vertex from source resource - Vertex in = this.getVertexFromDB( dependency.getSource() ); - if ( in instanceof OrientVertex ) { - inVertex = (OrientVertex) in; + synchronized( syncObj ) { + Assert.notNull( dependency ); + + OrientVertex inVertex = null; + OrientVertex outVertex = null; + + // get vertex values from dependency + if ( dependency instanceof OrientDBDependency ) { + OrientDBDependency depen = (OrientDBDependency) dependency; + inVertex = (OrientVertex) depen.getSourceVertex(); + outVertex = (OrientVertex) depen.getTargetVertex(); + } else { + // find a vertex from source resource + Vertex in = this.getVertexFromDB( dependency.getSource() ); + if ( in instanceof OrientVertex ) { + inVertex = (OrientVertex) in; + } + + // find a vertex from target resource + Vertex out = this.getVertexFromDB( dependency.getTarget() ); + if ( out instanceof OrientVertex ) { + outVertex = (OrientVertex) out; + } } - // find a vertex from target resource - Vertex out = this.getVertexFromDB( dependency.getTarget() ); - if ( out instanceof OrientVertex ) { - outVertex = (OrientVertex) out; + Assert.notNull( inVertex ); + Assert.notNull( outVertex ); + + // remove edges + Iterator iterator = inVertex.getEdges( outVertex, Direction.IN ).iterator(); + List edges = new ArrayList(); + while( iterator.hasNext() ) { + edges.add( iterator.next() ); + } + for ( Edge edge : edges ) { + logger.trace( "an removed edge : {}", edge ); + edge.remove(); } - } - - Assert.notNull( inVertex ); - Assert.notNull( outVertex ); - - // remove edges - Iterator iterator = inVertex.getEdges( outVertex, Direction.IN ).iterator(); - while( iterator.hasNext() ) { - Edge edge = iterator.next(); - graph.removeEdge( edge ); - logger.trace( "an removed edge : {}", edge ); } } @Override public Set edgesOf(Resource resource) { - Assert.notNull( this.lastLayer ); - - Set result = new HashSet(); - - Vertex vertex = getVertexFromDB( resource ); - if ( vertex != null ) { - Iterator iterator = vertex.getEdges( Direction.BOTH ).iterator(); - while( iterator.hasNext() ) { - Edge edge = iterator.next(); - - Vertex in = edge.getVertex( Direction.IN ); - Vertex out = edge.getVertex( Direction.OUT ); - result.add( new OrientDBDependency( in, out, this.lastLayer ) ); + synchronized( syncObj ) { + Assert.notNull( this.lastLayer ); + + Set result = new HashSet(); + + Vertex vertex = getVertexFromDB( resource ); + if ( vertex != null ) { + Iterator iterator = vertex.getEdges( Direction.BOTH ).iterator(); + while( iterator.hasNext() ) { + Edge edge = iterator.next(); + + Vertex in = edge.getVertex( Direction.IN ); + Vertex out = edge.getVertex( Direction.OUT ); + result.add( new OrientDBDependency( in, out, this.lastLayer ) ); + } } + + return result; } - - return result; } @Override -- 2.7.4