com.arcadedb.database.async.CreateDestinationVertexAndEdgeAsyncTask Maven / Gradle / Ivy
/*
* Copyright © 2021-present Arcade Data Ltd ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-FileCopyrightText: 2021-present Arcade Data Ltd ([email protected])
* SPDX-License-Identifier: Apache-2.0
*/
package com.arcadedb.database.async;
import com.arcadedb.database.DatabaseInternal;
import com.arcadedb.database.RID;
import com.arcadedb.graph.MutableVertex;
/**
* Asynchronous Task that creates the destination vertex and the edge that connects it to the existent source vertex.
*/
public class CreateDestinationVertexAndEdgeAsyncTask extends CreateEdgeAsyncTask {
private final String destinationVertexType;
private final String[] destinationVertexAttributeNames;
private final Object[] destinationVertexAttributeValues;
public CreateDestinationVertexAndEdgeAsyncTask(final RID sourceVertex, final String destinationVertexType, final String[] destinationVertexAttributeNames,
final Object[] destinationVertexAttributeValues, final String edgeType, final Object[] edgeAttributes, final boolean bidirectional, final boolean light,
final NewEdgeCallback callback) {
super(sourceVertex, null, edgeType, edgeAttributes, bidirectional, light, callback);
this.destinationVertexType = destinationVertexType;
this.destinationVertexAttributeNames = destinationVertexAttributeNames;
this.destinationVertexAttributeValues = destinationVertexAttributeValues;
}
@Override
public void execute(DatabaseAsyncExecutorImpl.AsyncThread async, DatabaseInternal database) {
final MutableVertex destinationVertex = database.newVertex(destinationVertexType);
for (int i = 0; i < destinationVertexAttributeNames.length; ++i)
destinationVertex.set(destinationVertexAttributeNames[i], destinationVertexAttributeValues[i]);
destinationVertex.save();
createEdge(database, sourceVertex, destinationVertex, false, true);
}
@Override
public String toString() {
return "CreateDestinationVertexAndEdgeAsyncTask(" + sourceVertex + "->" + destinationVertexType + ")";
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy