Commit 15d67e52 by Richard Ding Committed by Madhan Neethiraj

ATLAS-2083: Refactor Atlas<Type>DefStore classes to reduce code duplication

parent 4820a20b
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package org.apache.atlas.repository.store.graph;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasClassificationDef.AtlasClassificationDefs;
import java.util.List;
/**
* Interface for graph persistence store for AtlasClassificationDef
*/
public interface AtlasClassificationDefStore {
Object preCreate(AtlasClassificationDef classificationDef) throws AtlasBaseException;
AtlasClassificationDef create(AtlasClassificationDef classifiDef, Object preCreateResult) throws AtlasBaseException;
List<AtlasClassificationDef> getAll() throws AtlasBaseException;
AtlasClassificationDef getByName(String name) throws AtlasBaseException;
AtlasClassificationDef getByGuid(String guid) throws AtlasBaseException;
AtlasClassificationDef update(AtlasClassificationDef classifiDef) throws AtlasBaseException;
AtlasClassificationDef updateByName(String name, AtlasClassificationDef classifiDef) throws AtlasBaseException;
AtlasClassificationDef updateByGuid(String guid, AtlasClassificationDef classifiDef) throws AtlasBaseException;
Object preDeleteByName(String name) throws AtlasBaseException;
void deleteByName(String name, Object preDeleteResult) throws AtlasBaseException;
Object preDeleteByGuid(String guid) throws AtlasBaseException;
void deleteByGuid(String guid, Object preDeleteResult) throws AtlasBaseException;
}
......@@ -18,31 +18,36 @@
package org.apache.atlas.repository.store.graph;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumDefs;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import java.util.List;
/**
* Interface for graph persistence store for AtlasEnumDef
* Interface for graph persistence store for AtlasTypeDef
*/
public interface AtlasEnumDefStore {
AtlasEnumDef create(AtlasEnumDef enumDef) throws AtlasBaseException;
public interface AtlasDefStore<T extends AtlasBaseTypeDef> {
AtlasVertex preCreate(T typeDef) throws AtlasBaseException;
List<AtlasEnumDef> getAll() throws AtlasBaseException;
T create(T typeDef, AtlasVertex preCreateResult) throws AtlasBaseException;
AtlasEnumDef getByName(String name) throws AtlasBaseException;
List<T> getAll() throws AtlasBaseException;
AtlasEnumDef getByGuid(String guid) throws AtlasBaseException;
T getByName(String name) throws AtlasBaseException;
AtlasEnumDef update(AtlasEnumDef enumDef) throws AtlasBaseException;
T getByGuid(String guid) throws AtlasBaseException;
AtlasEnumDef updateByName(String name, AtlasEnumDef enumDef) throws AtlasBaseException;
T update(T typeDef) throws AtlasBaseException;
AtlasEnumDef updateByGuid(String guid, AtlasEnumDef enumDef) throws AtlasBaseException;
T updateByName(String name, T typeDef) throws AtlasBaseException;
void deleteByName(String name) throws AtlasBaseException;
T updateByGuid(String guid, T typeDef) throws AtlasBaseException;
void deleteByGuid(String guid) throws AtlasBaseException;
AtlasVertex preDeleteByName(String name) throws AtlasBaseException;
void deleteByName(String name, AtlasVertex preDeleteResult) throws AtlasBaseException;
AtlasVertex preDeleteByGuid(String guid) throws AtlasBaseException;
void deleteByGuid(String guid, AtlasVertex preDeleteResult) throws AtlasBaseException;
}
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package org.apache.atlas.repository.store.graph;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasEntityDef.AtlasEntityDefs;
import java.util.List;
/**
* Interface for graph persistence store for AtlasEntityDef
*/
public interface AtlasEntityDefStore {
Object preCreate(AtlasEntityDef entityDef) throws AtlasBaseException;
AtlasEntityDef create(AtlasEntityDef entityDef, Object preCreateResult) throws AtlasBaseException;
List<AtlasEntityDef> getAll() throws AtlasBaseException;
AtlasEntityDef getByName(String name) throws AtlasBaseException;
AtlasEntityDef getByGuid(String guid) throws AtlasBaseException;
AtlasEntityDef update(AtlasEntityDef entityDef) throws AtlasBaseException;
AtlasEntityDef updateByName(String name, AtlasEntityDef entityDef) throws AtlasBaseException;
AtlasEntityDef updateByGuid(String guid, AtlasEntityDef entityDef) throws AtlasBaseException;
Object preDeleteByName(String name) throws AtlasBaseException;
void deleteByName(String name, Object preDeleteResult) throws AtlasBaseException;
Object preDeleteByGuid(String guid) throws AtlasBaseException;
void deleteByGuid(String guid, Object preDeleteResult) throws AtlasBaseException;
}
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package org.apache.atlas.repository.store.graph;
import java.util.List;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.typedef.AtlasRelationshipDef;
/**
* Interface for graph persistence store for AtlasRelationshipDef
*/
public interface AtlasRelationshipDefStore {
Object preCreate(AtlasRelationshipDef relationshipDef) throws AtlasBaseException;
AtlasRelationshipDef create(AtlasRelationshipDef relationshipDef, Object preCreateResult) throws AtlasBaseException;
List<AtlasRelationshipDef> getAll() throws AtlasBaseException;
AtlasRelationshipDef getByName(String name) throws AtlasBaseException;
AtlasRelationshipDef getByGuid(String guid) throws AtlasBaseException;
AtlasRelationshipDef update(AtlasRelationshipDef relationshipDef) throws AtlasBaseException;
AtlasRelationshipDef updateByName(String name, AtlasRelationshipDef relationshipDef) throws AtlasBaseException;
AtlasRelationshipDef updateByGuid(String guid, AtlasRelationshipDef relationshipDef) throws AtlasBaseException;
Object preDeleteByName(String name) throws AtlasBaseException;
void deleteByName(String name, Object preDeleteResult) throws AtlasBaseException;
Object preDeleteByGuid(String guid) throws AtlasBaseException;
void deleteByGuid(String guid, Object preDeleteResult) throws AtlasBaseException;
}
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package org.apache.atlas.repository.store.graph;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasStructDefs;
import java.util.List;
/**
* Interface for graph persistence store for AtlasStructDef
*/
public interface AtlasStructDefStore {
Object preCreate(AtlasStructDef structDef) throws AtlasBaseException;
AtlasStructDef create(AtlasStructDef structDef, Object preCreateResult) throws AtlasBaseException;
List<AtlasStructDef> getAll() throws AtlasBaseException;
AtlasStructDef getByName(String name) throws AtlasBaseException;
AtlasStructDef getByGuid(String guid) throws AtlasBaseException;
AtlasStructDef update(AtlasStructDef structDef) throws AtlasBaseException;
AtlasStructDef updateByName(String name, AtlasStructDef structDef) throws AtlasBaseException;
AtlasStructDef updateByGuid(String guid, AtlasStructDef structDef) throws AtlasBaseException;
Object preDeleteByName(String name) throws AtlasBaseException;
void deleteByName(String name, Object preDeleteResult) throws AtlasBaseException;
Object preDeleteByGuid(String name) throws AtlasBaseException;
void deleteByGuid(String guid, Object preDeleteResult) throws AtlasBaseException;
}
......@@ -27,6 +27,7 @@ import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.*;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.util.FilterUtil;
import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.type.*;
......@@ -65,15 +66,15 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
this.typeUpdateLockMaxWaitTimeSeconds = AtlasRepositoryConfiguration.getTypeUpdateLockMaxWaitTimeInSeconds();
}
protected abstract AtlasEnumDefStore getEnumDefStore(AtlasTypeRegistry typeRegistry);
protected abstract AtlasDefStore<AtlasEnumDef> getEnumDefStore(AtlasTypeRegistry typeRegistry);
protected abstract AtlasStructDefStore getStructDefStore(AtlasTypeRegistry typeRegistry);
protected abstract AtlasDefStore<AtlasStructDef> getStructDefStore(AtlasTypeRegistry typeRegistry);
protected abstract AtlasClassificationDefStore getClassificationDefStore(AtlasTypeRegistry typeRegistry);
protected abstract AtlasDefStore<AtlasClassificationDef> getClassificationDefStore(AtlasTypeRegistry typeRegistry);
protected abstract AtlasEntityDefStore getEntityDefStore(AtlasTypeRegistry typeRegistry);
protected abstract AtlasDefStore<AtlasEntityDef> getEntityDefStore(AtlasTypeRegistry typeRegistry);
protected abstract AtlasRelationshipDefStore getRelationshipDefStore(AtlasTypeRegistry typeRegistry);
protected abstract AtlasDefStore<AtlasRelationshipDef> getRelationshipDefStore(AtlasTypeRegistry typeRegistry);
@Override
public void init() throws AtlasBaseException {
......@@ -471,16 +472,16 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();
AtlasEnumDefStore enumDefStore = getEnumDefStore(ttr);
AtlasStructDefStore structDefStore = getStructDefStore(ttr);
AtlasClassificationDefStore classifiDefStore = getClassificationDefStore(ttr);
AtlasEntityDefStore entityDefStore = getEntityDefStore(ttr);
AtlasRelationshipDefStore relationshipDefStore = getRelationshipDefStore(ttr);
AtlasDefStore<AtlasEnumDef> enumDefStore = getEnumDefStore(ttr);
AtlasDefStore<AtlasStructDef> structDefStore = getStructDefStore(ttr);
AtlasDefStore<AtlasClassificationDef> classifiDefStore = getClassificationDefStore(ttr);
AtlasDefStore<AtlasEntityDef> entityDefStore = getEntityDefStore(ttr);
AtlasDefStore<AtlasRelationshipDef> relationshipDefStore = getRelationshipDefStore(ttr);
List<Object> preDeleteStructDefs = new ArrayList<>();
List<Object> preDeleteClassifiDefs = new ArrayList<>();
List<Object> preDeleteEntityDefs = new ArrayList<>();
List<Object> preDeleteRelationshipDefs = new ArrayList<>();
List<AtlasVertex> preDeleteStructDefs = new ArrayList<>();
List<AtlasVertex> preDeleteClassifiDefs = new ArrayList<>();
List<AtlasVertex> preDeleteEntityDefs = new ArrayList<>();
List<AtlasVertex> preDeleteRelationshipDefs = new ArrayList<>();
// pre deletes
......@@ -578,9 +579,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) {
for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
if (StringUtils.isNotBlank(enumDef.getGuid())) {
enumDefStore.deleteByGuid(enumDef.getGuid());
enumDefStore.deleteByGuid(enumDef.getGuid(), null);
} else {
enumDefStore.deleteByName(enumDef.getName());
enumDefStore.deleteByName(enumDef.getName(), null);
}
}
}
......@@ -792,21 +793,21 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
private AtlasTypesDef addToGraphStore(AtlasTypesDef typesDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException {
AtlasTypesDef ret = new AtlasTypesDef();
AtlasEnumDefStore enumDefStore = getEnumDefStore(ttr);
AtlasStructDefStore structDefStore = getStructDefStore(ttr);
AtlasClassificationDefStore classifiDefStore = getClassificationDefStore(ttr);
AtlasEntityDefStore entityDefStore = getEntityDefStore(ttr);
AtlasRelationshipDefStore relationshipDefStore = getRelationshipDefStore(ttr);
AtlasDefStore<AtlasEnumDef> enumDefStore = getEnumDefStore(ttr);
AtlasDefStore<AtlasStructDef> structDefStore = getStructDefStore(ttr);
AtlasDefStore<AtlasClassificationDef> classifiDefStore = getClassificationDefStore(ttr);
AtlasDefStore<AtlasEntityDef> entityDefStore = getEntityDefStore(ttr);
AtlasDefStore<AtlasRelationshipDef> relationshipDefStore = getRelationshipDefStore(ttr);
List<Object> preCreateStructDefs = new ArrayList<>();
List<Object> preCreateClassifiDefs = new ArrayList<>();
List<Object> preCreateEntityDefs = new ArrayList<>();
List<Object> preCreateRelationshipDefs = new ArrayList<>();
List<AtlasVertex> preCreateStructDefs = new ArrayList<>();
List<AtlasVertex> preCreateClassifiDefs = new ArrayList<>();
List<AtlasVertex> preCreateEntityDefs = new ArrayList<>();
List<AtlasVertex> preCreateRelationshipDefs = new ArrayList<>();
// for enumerations run the create
if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) {
for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
AtlasEnumDef createdDef = enumDefStore.create(enumDef);
AtlasEnumDef createdDef = enumDefStore.create(enumDef, null);
ttr.updateGuid(createdDef.getName(), createdDef.getGuid());
......@@ -892,11 +893,11 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
private AtlasTypesDef updateGraphStore(AtlasTypesDef typesDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException {
AtlasTypesDef ret = new AtlasTypesDef();
AtlasEnumDefStore enumDefStore = getEnumDefStore(ttr);
AtlasStructDefStore structDefStore = getStructDefStore(ttr);
AtlasClassificationDefStore classifiDefStore = getClassificationDefStore(ttr);
AtlasEntityDefStore entityDefStore = getEntityDefStore(ttr);
AtlasRelationshipDefStore relationDefStore = getRelationshipDefStore(ttr);
AtlasDefStore<AtlasEnumDef> enumDefStore = getEnumDefStore(ttr);
AtlasDefStore<AtlasStructDef> structDefStore = getStructDefStore(ttr);
AtlasDefStore<AtlasClassificationDef> classifiDefStore = getClassificationDefStore(ttr);
AtlasDefStore<AtlasEntityDef> entityDefStore = getEntityDefStore(ttr);
AtlasDefStore<AtlasRelationshipDef> relationDefStore = getRelationshipDefStore(ttr);
if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) {
for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
......
......@@ -24,6 +24,8 @@ import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.query.QueryParser;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.store.graph.AtlasDefStore;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -35,7 +37,7 @@ import java.util.regex.Pattern;
/**
* Abstract typedef-store for v1 format.
*/
public abstract class AtlasAbstractDefStoreV1 {
abstract class AtlasAbstractDefStoreV1 <T extends AtlasBaseTypeDef> implements AtlasDefStore<T> {
private static final Logger LOG = LoggerFactory.getLogger(AtlasAbstractDefStoreV1.class);
protected final AtlasTypeDefGraphStoreV1 typeDefStore;
protected final AtlasTypeRegistry typeRegistry;
......@@ -77,4 +79,34 @@ public abstract class AtlasAbstractDefStoreV1 {
return m.matches();
}
@Override
public void deleteByName(String name, AtlasVertex preDeleteResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasAbstractDefStoreV1.deleteByName({}, {})", name, preDeleteResult);
}
AtlasVertex vertex = (preDeleteResult == null) ? preDeleteByName(name) : preDeleteResult;
typeDefStore.deleteTypeVertex(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasAbstractDefStoreV1.deleteByName({}, {})", name, preDeleteResult);
}
}
@Override
public void deleteByGuid(String guid, AtlasVertex preDeleteResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasAbstractDefStoreV1.deleteByGuid({}, {})", guid, preDeleteResult);
}
AtlasVertex vertex = (preDeleteResult == null) ? preDeleteByGuid(guid) : preDeleteResult;
typeDefStore.deleteTypeVertex(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasAbstractDefStoreV1.deleteByGuid({}, {})", guid, preDeleteResult);
}
}
}
......@@ -23,7 +23,6 @@ import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.store.graph.AtlasClassificationDefStore;
import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
......@@ -41,7 +40,7 @@ import java.util.regex.Pattern;
/**
* ClassificationDef store in v1 format.
*/
public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 implements AtlasClassificationDefStore {
class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1<AtlasClassificationDef> {
private static final Logger LOG = LoggerFactory.getLogger(AtlasClassificationDefStoreV1.class);
private static final String TRAIT_NAME_REGEX = "[a-zA-Z][a-zA-Z0-9_ .]*";
......@@ -84,19 +83,13 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
}
@Override
public AtlasClassificationDef create(AtlasClassificationDef classificationDef, Object preCreateResult)
public AtlasClassificationDef create(AtlasClassificationDef classificationDef, AtlasVertex preCreateResult)
throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasClassificationDefStoreV1.create({}, {})", classificationDef, preCreateResult);
}
AtlasVertex vertex;
if (preCreateResult == null || !(preCreateResult instanceof AtlasVertex)) {
vertex = preCreate(classificationDef);
} else {
vertex = (AtlasVertex)preCreateResult;
}
AtlasVertex vertex = (preCreateResult == null) ? preCreate(classificationDef) : preCreateResult;
updateVertexAddReferences(classificationDef, vertex);
......@@ -281,27 +274,6 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
}
@Override
public void deleteByName(String name, Object preDeleteResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasClassificationDefStoreV1.deleteByName({})", name);
}
AtlasVertex vertex;
if (preDeleteResult == null || !(preDeleteResult instanceof AtlasVertex)) {
vertex = preDeleteByName(name);
} else {
vertex = (AtlasVertex)preDeleteResult;
}
typeDefStore.deleteTypeVertex(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasClassificationDefStoreV1.deleteByName({})", name);
}
}
@Override
public AtlasVertex preDeleteByGuid(String guid) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasClassificationDefStoreV1.preDeleteByGuid({})", guid);
......@@ -328,27 +300,6 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
return ret;
}
@Override
public void deleteByGuid(String guid, Object preDeleteResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasClassificationDefStoreV1.deleteByGuid({})", guid);
}
AtlasVertex vertex;
if (preDeleteResult == null || !(preDeleteResult instanceof AtlasVertex)) {
vertex = preDeleteByGuid(guid);
} else {
vertex = (AtlasVertex)preDeleteResult;
}
typeDefStore.deleteTypeVertex(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasClassificationDefStoreV1.deleteByGuid({})", guid);
}
}
private void updateVertexPreCreate(AtlasClassificationDef classificationDef,
AtlasClassificationType classificationType,
AtlasVertex vertex) throws AtlasBaseException {
......
......@@ -22,7 +22,6 @@ import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.store.graph.AtlasEntityDefStore;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
......@@ -39,7 +38,7 @@ import java.util.List;
/**
* EntityDef store in v1 format.
*/
public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements AtlasEntityDefStore {
public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1<AtlasEntityDef> {
private static final Logger LOG = LoggerFactory.getLogger(AtlasEntityDefStoreV1.class);
@Inject
......@@ -79,18 +78,12 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
}
@Override
public AtlasEntityDef create(AtlasEntityDef entityDef, Object preCreateResult) throws AtlasBaseException {
public AtlasEntityDef create(AtlasEntityDef entityDef, AtlasVertex preCreateResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEntityDefStoreV1.create({}, {})", entityDef, preCreateResult);
}
AtlasVertex vertex;
if (preCreateResult == null || !(preCreateResult instanceof AtlasVertex)) {
vertex = preCreate(entityDef);
} else {
vertex = (AtlasVertex)preCreateResult;
}
AtlasVertex vertex = (preCreateResult == null) ? preCreate(entityDef) : preCreateResult;
updateVertexAddReferences(entityDef, vertex);
......@@ -280,27 +273,6 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
}
@Override
public void deleteByName(String name, Object preDeleteResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEntityDefStoreV1.deleteByName({}, {})", name, preDeleteResult);
}
AtlasVertex vertex;
if (preDeleteResult == null || !(preDeleteResult instanceof AtlasVertex)) {
vertex = preDeleteByName(name);
} else {
vertex = (AtlasVertex)preDeleteResult;
}
typeDefStore.deleteTypeVertex(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasEntityDefStoreV1.deleteByName({}, {})", name, preDeleteResult);
}
}
@Override
public AtlasVertex preDeleteByGuid(String guid) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEntityDefStoreV1.preDeleteByGuid({})", guid);
......@@ -332,27 +304,6 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
return ret;
}
@Override
public void deleteByGuid(String guid, Object preDeleteResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEntityDefStoreV1.deleteByGuid({}, {})", guid, preDeleteResult);
}
AtlasVertex vertex;
if (preDeleteResult == null || !(preDeleteResult instanceof AtlasVertex)) {
vertex = preDeleteByGuid(guid);
} else {
vertex = (AtlasVertex)preDeleteResult;
}
typeDefStore.deleteTypeVertex(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasEntityDefStoreV1.deleteByGuid({}, {})", guid, preDeleteResult);
}
}
private void updateVertexPreCreate(AtlasEntityDef entityDef, AtlasEntityType entityType, AtlasVertex vertex) throws AtlasBaseException {
AtlasStructDefStoreV1.updateVertexPreCreate(entityDef, entityType, vertex, typeDefStore);
}
......
......@@ -23,9 +23,7 @@ import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.store.graph.AtlasEnumDefStore;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.typesystem.types.DataTypes.TypeCategory;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -39,7 +37,7 @@ import java.util.List;
/**
* EnumDef store in v1 format.
*/
public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements AtlasEnumDefStore {
class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1<AtlasEnumDef> {
private static final Logger LOG = LoggerFactory.getLogger(AtlasEnumDefStoreV1.class);
public AtlasEnumDefStoreV1(AtlasTypeDefGraphStoreV1 typeDefStore, AtlasTypeRegistry typeRegistry) {
......@@ -47,9 +45,9 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
}
@Override
public AtlasEnumDef create(AtlasEnumDef enumDef) throws AtlasBaseException {
public AtlasVertex preCreate(AtlasEnumDef enumDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEnumDefStoreV1.create({})", enumDef);
LOG.debug("==> AtlasEnumDefStoreV1.preCreate({})", enumDef);
}
validateType(enumDef);
......@@ -64,10 +62,25 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
toVertex(enumDef, vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasEnumDefStoreV1.preCreate({}): {}", enumDef, vertex);
}
return vertex;
}
@Override
public AtlasEnumDef create(AtlasEnumDef enumDef, AtlasVertex preCreateResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEnumDefStoreV1.create({}, {})", enumDef, preCreateResult);
}
AtlasVertex vertex = (preCreateResult == null) ? preCreate(enumDef) : preCreateResult;
AtlasEnumDef ret = toEnumDef(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasEnumDefStoreV1.create({}): {}", enumDef, ret);
LOG.debug("<== AtlasEntityDefStoreV1.create({}, {}): {}", enumDef, preCreateResult, ret);
}
return ret;
......@@ -210,41 +223,25 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
}
@Override
public void deleteByName(String name) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEnumDefStoreV1.deleteByName({})", name);
}
public AtlasVertex preDeleteByName(String name) throws AtlasBaseException {
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.ENUM);
if (vertex == null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
}
typeDefStore.deleteTypeVertex(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasEnumDefStoreV1.deleteByName({})", name);
}
return vertex;
}
@Override
public void deleteByGuid(String guid) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEnumDefStoreV1.deleteByGuid({})", guid);
}
public AtlasVertex preDeleteByGuid(String guid) throws AtlasBaseException {
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.ENUM);
if (vertex == null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
}
typeDefStore.deleteTypeVertex(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasEnumDefStoreV1.deleteByGuid({})", guid);
}
return vertex;
}
private void toVertex(AtlasEnumDef enumDef, AtlasVertex vertex) throws AtlasBaseException {
......
......@@ -29,7 +29,6 @@ import org.apache.atlas.query.QueryParser;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.store.graph.AtlasRelationshipDefStore;
import org.apache.atlas.type.AtlasRelationshipType;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
......@@ -46,7 +45,7 @@ import java.util.List;
/**
* RelationshipDef store in v1 format.
*/
public class AtlasRelationshipDefStoreV1 extends AtlasAbstractDefStoreV1 implements AtlasRelationshipDefStore {
public class AtlasRelationshipDefStoreV1 extends AtlasAbstractDefStoreV1<AtlasRelationshipDef> {
private static final Logger LOG = LoggerFactory.getLogger(AtlasRelationshipDefStoreV1.class);
@Inject
......@@ -124,19 +123,13 @@ public class AtlasRelationshipDefStoreV1 extends AtlasAbstractDefStoreV1 impleme
}
@Override
public AtlasRelationshipDef create(AtlasRelationshipDef relationshipDef, Object preCreateResult)
public AtlasRelationshipDef create(AtlasRelationshipDef relationshipDef, AtlasVertex preCreateResult)
throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasRelationshipDefStoreV1.create({}, {})", relationshipDef, preCreateResult);
}
AtlasVertex vertex;
if (preCreateResult == null || !(preCreateResult instanceof AtlasVertex)) {
vertex = preCreate(relationshipDef);
} else {
vertex = (AtlasVertex) preCreateResult;
}
AtlasVertex vertex = (preCreateResult == null) ? preCreate(relationshipDef) : preCreateResult;
AtlasRelationshipDef ret = toRelationshipDef(vertex);
......@@ -321,27 +314,6 @@ public class AtlasRelationshipDefStoreV1 extends AtlasAbstractDefStoreV1 impleme
}
@Override
public void deleteByName(String name, Object preDeleteResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasRelationshipDefStoreV1.deleteByName({}, {})", name, preDeleteResult);
}
AtlasVertex vertex;
if (preDeleteResult == null || !(preDeleteResult instanceof AtlasVertex)) {
vertex = preDeleteByName(name);
} else {
vertex = (AtlasVertex) preDeleteResult;
}
typeDefStore.deleteTypeVertex(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasRelationshipDefStoreV1.deleteByName({}, {})", name, preDeleteResult);
}
}
@Override
public AtlasVertex preDeleteByGuid(String guid) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasRelationshipDefStoreV1.preDeleteByGuid({})", guid);
......@@ -368,27 +340,6 @@ public class AtlasRelationshipDefStoreV1 extends AtlasAbstractDefStoreV1 impleme
return ret;
}
@Override
public void deleteByGuid(String guid, Object preDeleteResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasRelationshipDefStoreV1.deleteByGuid({}, {})", guid, preDeleteResult);
}
AtlasVertex vertex;
if (preDeleteResult == null || !(preDeleteResult instanceof AtlasVertex)) {
vertex = preDeleteByGuid(guid);
} else {
vertex = (AtlasVertex) preDeleteResult;
}
typeDefStore.deleteTypeVertex(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasRelationshipDefStoreV1.deleteByGuid({}, {})", guid, preDeleteResult);
}
}
private void updateVertexPreCreate(AtlasRelationshipDef relationshipDef, AtlasRelationshipType relationshipType,
AtlasVertex vertex) throws AtlasBaseException {
AtlasRelationshipEndDef end1 = relationshipDef.getEndDef1();
......
......@@ -26,7 +26,6 @@ import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.store.graph.AtlasStructDefStore;
import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
import org.apache.atlas.type.AtlasType;
......@@ -51,7 +50,7 @@ import java.util.Set;
/**
* StructDef store in v1 format.
*/
public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements AtlasStructDefStore {
public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1<AtlasStructDef> {
private static final Logger LOG = LoggerFactory.getLogger(AtlasStructDefStoreV1.class);
public AtlasStructDefStoreV1(AtlasTypeDefGraphStoreV1 typeDefStore, AtlasTypeRegistry typeRegistry) {
......@@ -90,18 +89,12 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
}
@Override
public AtlasStructDef create(AtlasStructDef structDef, Object preCreateResult) throws AtlasBaseException {
public AtlasStructDef create(AtlasStructDef structDef, AtlasVertex preCreateResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasStructDefStoreV1.create({}, {})", structDef, preCreateResult);
}
AtlasVertex vertex;
if (preCreateResult == null || !(preCreateResult instanceof AtlasVertex)) {
vertex = preCreate(structDef);
} else {
vertex = (AtlasVertex)preCreateResult;
}
AtlasVertex vertex = (preCreateResult == null) ? preCreate(structDef) : preCreateResult;
if (CollectionUtils.isEmpty(structDef.getAttributeDefs())) {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "Missing attributes for structdef");
......@@ -289,27 +282,6 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
}
@Override
public void deleteByName(String name, Object preDeleteResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasStructDefStoreV1.deleteByName({}, {})", name, preDeleteResult);
}
AtlasVertex vertex;
if (preDeleteResult == null || !(preDeleteResult instanceof AtlasVertex)) {
vertex = preDeleteByName(name);
} else {
vertex = (AtlasVertex)preDeleteResult;
}
typeDefStore.deleteTypeVertex(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasStructDefStoreV1.deleteByName({}, {})", name, preDeleteResult);
}
}
@Override
public AtlasVertex preDeleteByGuid(String guid) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasStructDefStoreV1.preDeleteByGuid({})", guid);
......@@ -336,27 +308,6 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
return ret;
}
@Override
public void deleteByGuid(String guid, Object preDeleteResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasStructDefStoreV1.deleteByGuid({}, {})", guid, preDeleteResult);
}
AtlasVertex vertex;
if (preDeleteResult == null || !(preDeleteResult instanceof AtlasVertex)) {
vertex = preDeleteByGuid(guid);
} else {
vertex = (AtlasVertex)preDeleteResult;
}
typeDefStore.deleteTypeVertex(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasStructDefStoreV1.deleteByGuid({}, {})", guid, preDeleteResult);
}
}
private AtlasStructDef toStructDef(AtlasVertex vertex) throws AtlasBaseException {
AtlasStructDef ret = null;
......
......@@ -34,18 +34,13 @@ import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.RequestContextV1;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.listener.TypeDefChangeListener;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.*;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasEdgeDirection;
import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.store.graph.AtlasClassificationDefStore;
import org.apache.atlas.repository.store.graph.AtlasEntityDefStore;
import org.apache.atlas.repository.store.graph.AtlasEnumDefStore;
import org.apache.atlas.repository.store.graph.AtlasRelationshipDefStore;
import org.apache.atlas.repository.store.graph.AtlasStructDefStore;
import org.apache.atlas.repository.store.graph.AtlasTypeDefGraphStore;
import org.apache.atlas.repository.store.graph.*;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.types.DataTypes.TypeCategory;
......@@ -81,27 +76,27 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore {
}
@Override
protected AtlasEnumDefStore getEnumDefStore(AtlasTypeRegistry typeRegistry) {
protected AtlasDefStore<AtlasEnumDef> getEnumDefStore(AtlasTypeRegistry typeRegistry) {
return new AtlasEnumDefStoreV1(this, typeRegistry);
}
@Override
protected AtlasStructDefStore getStructDefStore(AtlasTypeRegistry typeRegistry) {
protected AtlasDefStore<AtlasStructDef> getStructDefStore(AtlasTypeRegistry typeRegistry) {
return new AtlasStructDefStoreV1(this, typeRegistry);
}
@Override
protected AtlasClassificationDefStore getClassificationDefStore(AtlasTypeRegistry typeRegistry) {
protected AtlasDefStore<AtlasClassificationDef> getClassificationDefStore(AtlasTypeRegistry typeRegistry) {
return new AtlasClassificationDefStoreV1(this, typeRegistry);
}
@Override
protected AtlasEntityDefStore getEntityDefStore(AtlasTypeRegistry typeRegistry) {
protected AtlasDefStore<AtlasEntityDef> getEntityDefStore(AtlasTypeRegistry typeRegistry) {
return new AtlasEntityDefStoreV1(this, typeRegistry);
}
@Override
protected AtlasRelationshipDefStore getRelationshipDefStore(AtlasTypeRegistry typeRegistry) {
protected AtlasDefStore<AtlasRelationshipDef> getRelationshipDefStore(AtlasTypeRegistry typeRegistry) {
return new AtlasRelationshipDefStoreV1(this, typeRegistry);
}
......
......@@ -40,10 +40,7 @@ import org.apache.atlas.repository.graph.HardDeleteHandler;
import org.apache.atlas.repository.graph.SoftDeleteHandler;
import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.impexp.ExportService;
import org.apache.atlas.repository.store.graph.AtlasEntityDefStore;
import org.apache.atlas.repository.store.graph.AtlasEntityStore;
import org.apache.atlas.repository.store.graph.AtlasRelationshipDefStore;
import org.apache.atlas.repository.store.graph.AtlasRelationshipStore;
import org.apache.atlas.repository.store.graph.*;
import org.apache.atlas.repository.store.graph.v1.*;
import org.apache.atlas.repository.typestore.GraphBackedTypeStore;
import org.apache.atlas.repository.typestore.ITypeStore;
......@@ -123,9 +120,6 @@ public class TestModules {
bind(ITypeStore.class).to(GraphBackedTypeStore.class).asEagerSingleton();
bind(AtlasTypeDefStore.class).to(AtlasTypeDefGraphStoreV1.class).asEagerSingleton();
//For testing
bind(AtlasEntityDefStore.class).to(AtlasEntityDefStoreV1.class).asEagerSingleton();
bind(AtlasRelationshipDefStore.class).to(AtlasRelationshipDefStoreV1.class).asEagerSingleton();
bind(AtlasTypeRegistry.class).asEagerSingleton();
bind(EntityGraphMapper.class).asEagerSingleton();
bind(ExportService.class).asEagerSingleton();
......
......@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.repository.store.graph;
package org.apache.atlas.repository.store.graph.v1;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject;
......@@ -26,7 +26,6 @@ import org.apache.atlas.TestModules;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.store.graph.v1.AtlasAbstractDefStoreV1;
import org.apache.atlas.type.AtlasTypeUtil;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
......@@ -42,7 +41,7 @@ public class AtlasEntityDefStoreV1Test {
@Inject
private
AtlasEntityDefStore entityDefStore;
AtlasEntityDefStoreV1 entityDefStore;
@DataProvider
public Object[][] invalidAttributeNameWithReservedKeywords(){
......
......@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.repository.store.graph;
package org.apache.atlas.repository.store.graph.v1;
import com.google.inject.Inject;
import org.apache.atlas.ApplicationProperties;
......@@ -27,8 +27,6 @@ import org.apache.atlas.model.typedef.AtlasRelationshipDef;
import org.apache.atlas.model.typedef.AtlasRelationshipEndDef;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.store.graph.v1.AtlasAbstractDefStoreV1;
import org.apache.atlas.repository.store.graph.v1.AtlasRelationshipDefStoreV1;
import org.apache.atlas.type.AtlasTypeUtil;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
......@@ -46,7 +44,7 @@ public class AtlasRelationshipDefStoreV1Test {
@Inject
private
AtlasRelationshipDefStore relationshipDefStore;
AtlasRelationshipDefStoreV1 relationshipDefStore;
@DataProvider
public Object[][] invalidAttributeNameWithReservedKeywords(){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment