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;
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.
// 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 );
@Override
public boolean clear() {
- Assert.notNull( this.projectName );
-
- // remove database from local storage.
- Iterator<Edge> eIter = graph.getEdges( DependencyConstant.RESOURCE_KEY_PROJECT, this.projectName ).iterator();
- while ( eIter.hasNext() ) {
- Edge next = eIter.next();
- graph.removeEdge( next );
- }
- Iterator<Vertex> 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<Vertex> vIter = graph.getVertices( DependencyConstant.RESOURCE_KEY_PROJECT, this.projectName ).iterator();
+ List<Vertex> list = new ArrayList<Vertex>();
+ 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 );
+ }
}
/**
String layerName = layer.getName();
- Iterator<Vertex> iterator = graph.getVertices(
- DependencyConstant.RESOURCE_KEY_PATH,
- resource.getPath()
- ).iterator();
+ Iterator<Vertex> 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 ) ) {
@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<Edge> iterator = inVertex.getEdges( outVertex, Direction.IN ).iterator();
+ List<Edge> edges = new ArrayList<Edge>();
+ 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<Edge> 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<Dependency> edgesOf(Resource resource) {
- Assert.notNull( this.lastLayer );
-
- Set<Dependency> result = new HashSet<Dependency>();
-
- Vertex vertex = getVertexFromDB( resource );
- if ( vertex != null ) {
- Iterator<Edge> 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<Dependency> result = new HashSet<Dependency>();
+
+ Vertex vertex = getVertexFromDB( resource );
+ if ( vertex != null ) {
+ Iterator<Edge> 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