You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2017/11/12 18:14:20 UTC
[11/42] atlas git commit: ATLAS-2251: Remove TypeSystem and related
implementation, to avoid unncessary duplicate of type details in cache
http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/typesystem/src/main/java/org/apache/atlas/typesystem/persistence/Id.java
----------------------------------------------------------------------
diff --git a/typesystem/src/main/java/org/apache/atlas/typesystem/persistence/Id.java b/typesystem/src/main/java/org/apache/atlas/typesystem/persistence/Id.java
deleted file mode 100755
index ba05a45..0000000
--- a/typesystem/src/main/java/org/apache/atlas/typesystem/persistence/Id.java
+++ /dev/null
@@ -1,307 +0,0 @@
-/**
- * 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.typesystem.persistence;
-
-import com.google.common.collect.ImmutableList;
-import org.apache.atlas.AtlasException;
-import org.apache.atlas.utils.ParamChecker;
-import org.apache.atlas.typesystem.IStruct;
-import org.apache.atlas.typesystem.ITypedReferenceableInstance;
-import org.apache.atlas.typesystem.types.FieldMapping;
-import org.apache.atlas.utils.SHA256Utils;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.nio.charset.Charset;
-import java.security.MessageDigest;
-import java.util.Date;
-import java.util.Map;
-import java.util.Objects;
-import java.util.UUID;
-import java.util.concurrent.atomic.AtomicLong;
-
-public class Id implements ITypedReferenceableInstance {
- public enum EntityState {
- ACTIVE, DELETED
- }
-
- public final String id;
- public final String typeName;
- public final int version;
- public EntityState state;
- private static AtomicLong s_nextId = new AtomicLong(System.nanoTime());
- public final AtlasSystemAttributes systemAttributes;
-
- public Id(String id, int version, String typeName, String state) {
- id = ParamChecker.notEmpty(id, "id");
- typeName = ParamChecker.notEmpty(typeName, "typeName");
- state = ParamChecker.notEmptyIfNotNull(state, "state");
- this.id = id;
- this.typeName = typeName;
- this.version = version;
- if (state == null) {
- this.state = EntityState.ACTIVE;
- } else {
- this.state = EntityState.valueOf(state.toUpperCase());
- }
- this.systemAttributes = new AtlasSystemAttributes();
- }
-
- public Id(String id, int version, String typeName) {
- this(id, version, typeName, null);
- }
-
- public Id(long id, int version, String typeName) {
- this("" + id, version, typeName);
- }
-
- public Id(long id, int version, String typeName, String state) {
- this("" + id, version, typeName, state);
- }
-
- public Id(String typeName) {
- this("" + Id.nextNegativeLong(), 0, typeName);
- }
-
- public boolean isUnassigned() {
- try {
- long l = Long.parseLong(id);
- return l < 0;
- } catch (NumberFormatException ne) {
- return false;
- }
- }
-
- public boolean isAssigned() {
- try {
- UUID.fromString(id);
- } catch (IllegalArgumentException e) {
- return false;
- }
-
- return true;
- }
-
- @Override
- public String toString() {
- return String.format("(type: %s, id: %s)", typeName, isUnassigned() ? "<unassigned>" : "" + id);
- }
-
- @Override
- public String toShortString() {
- return String.format("id[type=%s guid=%s state=%s]", typeName, id, state);
- }
-
- @Override
- public AtlasSystemAttributes getSystemAttributes(){
- return systemAttributes;
- }
-
- public String getClassName() {
- return typeName;
- }
-
- public int getVersion() {
- return version;
- }
-
- public String _getId() {
- return id;
- }
-
- public EntityState getState() {
- return state;
- }
-
- public String getStateAsString() {
- return state == null ? null : state.name();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- Id id1 = (Id) o;
- return version == id1.version &&
- Objects.equals(id, id1.id) &&
- Objects.equals(typeName, id1.typeName) &&
- state == id1.state;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(id, typeName, version, state);
- }
-
- @Override
- public ImmutableList<String> getTraits() {
- return null;
- }
-
- @Override
- public Id getId() {
- return this;
- }
-
- @Override
- public IStruct getTrait(String typeName) {
- return null;
- }
-
- @Override
- public String getTypeName() {
- return typeName;
- }
-
- @Override
- public Object get(String attrName) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- @Override
- public void set(String attrName, Object val) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- @Override
- public FieldMapping fieldMapping() {
- return null;
- }
-
- @Override
- public Map<String, Object> getValuesMap() throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public void setNull(String attrName) throws AtlasException {
- set(attrName, null);
- }
-
- public boolean getBoolean(String attrName) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public byte getByte(String attrName) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public short getShort(String attrName) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public int getInt(String attrName) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public long getLong(String attrName) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public float getFloat(String attrName) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public double getDouble(String attrName) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public BigInteger getBigInt(String attrName) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public BigDecimal getBigDecimal(String attrName) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public Date getDate(String attrName) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public String getString(String attrName) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public void setBoolean(String attrName, boolean val) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public void setByte(String attrName, byte val) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public void setShort(String attrName, short val) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public void setInt(String attrName, int val) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public void setLong(String attrName, long val) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public void setFloat(String attrName, float val) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public void setDouble(String attrName, double val) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public void setBigInt(String attrName, BigInteger val) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public void setBigDecimal(String attrName, BigDecimal val) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public void setDate(String attrName, Date val) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public void setString(String attrName, String val) throws AtlasException {
- throw new AtlasException("Get/Set not supported on an Id object");
- }
-
- public boolean isValueSet(String attrName) throws AtlasException {
- throw new AtlasException("Attributes not set on an Id object");
- }
-
- @Override
- public String getSignatureHash(MessageDigest digester) throws AtlasException {
- digester.update(id.getBytes(Charset.forName("UTF-8")));
- digester.update(typeName.getBytes(Charset.forName("UTF-8")));
- byte[] digest = digester.digest();
- return SHA256Utils.toString(digest);
- }
-
- private static long nextNegativeLong() {
- long ret = s_nextId.getAndDecrement();
-
- if (ret > 0) {
- ret *= -1;
- } else if (ret == 0) {
- ret = Long.MIN_VALUE;
- }
-
- return ret;
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/typesystem/src/main/java/org/apache/atlas/typesystem/persistence/MapIds.java
----------------------------------------------------------------------
diff --git a/typesystem/src/main/java/org/apache/atlas/typesystem/persistence/MapIds.java b/typesystem/src/main/java/org/apache/atlas/typesystem/persistence/MapIds.java
deleted file mode 100755
index e62f29d..0000000
--- a/typesystem/src/main/java/org/apache/atlas/typesystem/persistence/MapIds.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * 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.typesystem.persistence;
-
-import com.google.common.collect.ImmutableCollection;
-import com.google.common.collect.ImmutableMap;
-import org.apache.atlas.AtlasException;
-import org.apache.atlas.typesystem.IReferenceableInstance;
-import org.apache.atlas.typesystem.types.DataTypes;
-import org.apache.atlas.typesystem.types.ObjectGraphWalker;
-
-import java.util.Map;
-
-public class MapIds implements ObjectGraphWalker.NodeProcessor {
-
- final Map<Id, Id> idToNewIdMap;
-
- public MapIds(Map<Id, Id> idToNewIdMap) {
- this.idToNewIdMap = idToNewIdMap;
- }
-
- @Override
- public void processNode(ObjectGraphWalker.Node nd) throws AtlasException {
-
- IReferenceableInstance ref = null;
- Id id = null;
-
- if (nd.attributeName == null) {
- ref = (IReferenceableInstance) nd.instance;
- Id newId = idToNewIdMap.get(ref.getId());
- if (newId != null) {
- ((ReferenceableInstance) ref).replaceWithNewId(newId);
- }
- } else if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) {
- if (nd.value != null && nd.value instanceof IReferenceableInstance) {
- Id oldId = ((IReferenceableInstance) nd.value).getId();
- Id newId = idToNewIdMap.get(oldId);
- /*
- * Replace Instances with Ids, irrespective of whether they map to newIds or not.
- */
- newId = newId == null ? oldId : newId;
- nd.instance.set(nd.attributeName, newId);
- }
- } else if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.ARRAY) {
- DataTypes.ArrayType aT = (DataTypes.ArrayType) nd.aInfo.dataType();
- Object v = aT.mapIds((ImmutableCollection) nd.value, nd.aInfo.multiplicity, idToNewIdMap);
- nd.instance.set(nd.attributeName, v);
- } else if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.MAP) {
- DataTypes.MapType mT = (DataTypes.MapType) nd.aInfo.dataType();
- Object v = mT.mapIds((ImmutableMap) nd.value, nd.aInfo.multiplicity, idToNewIdMap);
- nd.instance.set(nd.attributeName, v);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/typesystem/src/main/java/org/apache/atlas/typesystem/persistence/ReferenceableInstance.java
----------------------------------------------------------------------
diff --git a/typesystem/src/main/java/org/apache/atlas/typesystem/persistence/ReferenceableInstance.java b/typesystem/src/main/java/org/apache/atlas/typesystem/persistence/ReferenceableInstance.java
deleted file mode 100755
index be2634d..0000000
--- a/typesystem/src/main/java/org/apache/atlas/typesystem/persistence/ReferenceableInstance.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/**
- * 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.typesystem.persistence;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-
-import org.apache.atlas.AtlasException;
-import org.apache.atlas.typesystem.IReferenceableInstance;
-import org.apache.atlas.typesystem.IStruct;
-import org.apache.atlas.typesystem.ITypedReferenceableInstance;
-import org.apache.atlas.typesystem.ITypedStruct;
-import org.apache.atlas.typesystem.types.ClassType;
-import org.apache.atlas.typesystem.types.FieldMapping;
-import org.apache.atlas.typesystem.types.TypeSystem;
-import org.apache.atlas.utils.SHA256Utils;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.security.MessageDigest;
-import java.util.Date;
-import java.util.HashSet;
-
-/*
- * @todo handle names prefixed by traitName.
- */
-public class ReferenceableInstance extends StructInstance implements ITypedReferenceableInstance {
-
- private final ImmutableMap<String, ITypedStruct> traits;
- private final ImmutableList<String> traitNames;
- private Id id;
- private AtlasSystemAttributes systemAttributes;
-
-
- public ReferenceableInstance(Id id, String dataTypeName, AtlasSystemAttributes systemAttributes, FieldMapping fieldMapping, boolean[] nullFlags,
- boolean[] explicitSets, boolean[] bools, byte[] bytes, short[] shorts, int[] ints, long[] longs, float[] floats, double[] doubles,
- BigDecimal[] bigDecimals, BigInteger[] bigIntegers, Date[] dates, String[] strings,
- ImmutableList<Object>[] arrays, ImmutableMap<Object, Object>[] maps, StructInstance[] structs,
- ReferenceableInstance[] referenceableInstances, Id[] ids, ImmutableMap<String, ITypedStruct> traits) {
- super(dataTypeName, fieldMapping, nullFlags, explicitSets, bools, bytes, shorts, ints, longs, floats, doubles, bigDecimals,
- bigIntegers, dates, strings, arrays, maps, structs, referenceableInstances, ids);
- this.id = id;
- this.traits = traits;
- ImmutableList.Builder<String> b = new ImmutableList.Builder<>();
- for (String t : traits.keySet()) {
- b.add(t);
- }
- this.traitNames = b.build();
- if (systemAttributes == null){
- this.systemAttributes = new AtlasSystemAttributes();
- }
- else {
- this.systemAttributes = systemAttributes;
- }
- }
-
- @Override
- public ImmutableList<String> getTraits() {
- return traitNames;
- }
-
- @Override
- public Id getId() {
- return id;
- }
-
- @Override
- public IStruct getTrait(String typeName) {
- return traits.get(typeName);
- }
-
- @Override
- public AtlasSystemAttributes getSystemAttributes(){
- return systemAttributes;
- }
-
- /**
- * @nopub
- * @param id
- */
- public void replaceWithNewId(Id id) {
- this.id = id;
- }
-
- @Override
- public String toString() {
- try {
- StringBuilder buf = new StringBuilder();
- String prefix = "";
-
- fieldMapping.output(this, buf, prefix, new HashSet<IReferenceableInstance>());
- return buf.toString();
-
- } catch (AtlasException me) {
- throw new RuntimeException(me);
- }
- }
-
- @Override
- public String toShortString() {
- String name = null;
- if (fieldMapping().fields.containsKey("name")) {
- try {
- name = getString("name");
- } catch (AtlasException e) {
- //ignore if there is no field name
- }
- }
- return String.format("entity[type=%s guid=%s name=%s]", getTypeName(), getId()._getId(), name);
- }
-
- @Override
- public String getSignatureHash(MessageDigest digester) throws AtlasException {
- ClassType classType = TypeSystem.getInstance().getDataType(ClassType.class, getTypeName());
- classType.updateSignatureHash(digester, this);
- byte[] digest = digester.digest();
- return SHA256Utils.toString(digest);
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/typesystem/src/main/java/org/apache/atlas/typesystem/persistence/StructInstance.java
----------------------------------------------------------------------
diff --git a/typesystem/src/main/java/org/apache/atlas/typesystem/persistence/StructInstance.java b/typesystem/src/main/java/org/apache/atlas/typesystem/persistence/StructInstance.java
deleted file mode 100755
index 766d2d0..0000000
--- a/typesystem/src/main/java/org/apache/atlas/typesystem/persistence/StructInstance.java
+++ /dev/null
@@ -1,790 +0,0 @@
-/**
- * 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.typesystem.persistence;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-
-import org.apache.atlas.AtlasException;
-import org.apache.atlas.typesystem.ITypedStruct;
-import org.apache.atlas.typesystem.types.AttributeInfo;
-import org.apache.atlas.typesystem.types.ClassType;
-import org.apache.atlas.typesystem.types.DataTypes;
-import org.apache.atlas.typesystem.types.EnumType;
-import org.apache.atlas.typesystem.types.EnumValue;
-import org.apache.atlas.typesystem.types.FieldMapping;
-import org.apache.atlas.typesystem.types.StructType;
-import org.apache.atlas.typesystem.types.TypeSystem;
-import org.apache.atlas.typesystem.types.ValueConversionException;
-import org.apache.atlas.utils.SHA256Utils;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.security.MessageDigest;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-public class StructInstance implements ITypedStruct {
- public final String dataTypeName;
- public final FieldMapping fieldMapping;
- public final boolean nullFlags[];
- public final boolean explicitSets[];
- public final boolean[] bools;
- public final byte[] bytes;
- public final short[] shorts;
- public final int[] ints;
- public final long[] longs;
- public final float[] floats;
- public final double[] doubles;
- public final BigDecimal[] bigDecimals;
- public final BigInteger[] bigIntegers;
- public final Date[] dates;
- public final String[] strings;
- public final ImmutableList<Object>[] arrays;
- public final ImmutableMap<Object, Object>[] maps;
- public final StructInstance[] structs;
- public final ReferenceableInstance[] referenceables;
- public final Id[] ids;
-
- public StructInstance(String dataTypeName, FieldMapping fieldMapping, boolean[] nullFlags, boolean[] explicitSets, boolean[] bools,
- byte[] bytes, short[] shorts, int[] ints, long[] longs, float[] floats, double[] doubles,
- BigDecimal[] bigDecimals, BigInteger[] bigIntegers, Date[] dates, String[] strings,
- ImmutableList<Object>[] arrays, ImmutableMap<Object, Object>[] maps, StructInstance[] structs,
- ReferenceableInstance[] referenceables, Id[] ids) {
- assert dataTypeName != null;
- this.dataTypeName = dataTypeName;
- this.fieldMapping = fieldMapping;
- this.nullFlags = nullFlags;
- this.explicitSets = explicitSets;
- this.bools = bools;
- this.bytes = bytes;
- this.shorts = shorts;
- this.ints = ints;
- this.longs = longs;
- this.floats = floats;
- this.doubles = doubles;
- this.bigDecimals = bigDecimals;
- this.bigIntegers = bigIntegers;
- this.dates = dates;
- this.strings = strings;
- this.arrays = arrays;
- this.maps = maps;
- this.structs = structs;
- this.referenceables = referenceables;
- this.ids = ids;
-
- for (int i = 0; i < nullFlags.length; i++) {
- nullFlags[i] = true;
- }
-
- for (int i = 0; i < explicitSets.length; i++) {
- explicitSets[i] = false;
- }
- }
-
- @Override
- public String getTypeName() {
- return dataTypeName;
- }
-
- @Override
- public FieldMapping fieldMapping() {
- return fieldMapping;
- }
-
- public void set(String attrName, Object val) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new ValueConversionException(getTypeName(), val, "Unknown field " + attrName);
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
- Object cVal = null;
-
- explicitSets[nullPos] = true;
-
- if (val != null && val instanceof Id) {
- ClassType clsType = TypeSystem.getInstance().getDataType(ClassType.class, i.dataType().getName());
- clsType.validateId((Id) val);
- cVal = val;
- } else {
- try {
- cVal = i.dataType().convert(val, i.multiplicity);
- } catch(ValueConversionException.NullConversionException e) {
- throw new ValueConversionException.NullConversionException("For field '" + attrName + "'", e);
- }
- }
- if (cVal == null) {
- nullFlags[nullPos] = true;
- return;
- }
- nullFlags[nullPos] = false;
- if (i.dataType() == DataTypes.BOOLEAN_TYPE) {
- bools[pos] = (Boolean) cVal;
- } else if (i.dataType() == DataTypes.BYTE_TYPE) {
- bytes[pos] = (Byte) cVal;
- } else if (i.dataType() == DataTypes.SHORT_TYPE) {
- shorts[pos] = (Short) cVal;
- } else if (i.dataType() == DataTypes.INT_TYPE) {
- ints[pos] = (Integer) cVal;
- } else if (i.dataType() == DataTypes.LONG_TYPE) {
- longs[pos] = (Long) cVal;
- } else if (i.dataType() == DataTypes.FLOAT_TYPE) {
- floats[pos] = (Float) cVal;
- } else if (i.dataType() == DataTypes.DOUBLE_TYPE) {
- doubles[pos] = (Double) cVal;
- } else if (i.dataType() == DataTypes.BIGINTEGER_TYPE) {
- bigIntegers[pos] = (BigInteger) cVal;
- } else if (i.dataType() == DataTypes.BIGDECIMAL_TYPE) {
- bigDecimals[pos] = (BigDecimal) cVal;
- } else if (i.dataType() == DataTypes.DATE_TYPE) {
- dates[pos] = (Date) cVal;
- } else if (i.dataType() == DataTypes.STRING_TYPE) {
- strings[pos] = (String) cVal;
- } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.ENUM) {
- ints[pos] = ((EnumValue) cVal).ordinal;
- } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.ARRAY) {
- arrays[pos] = (ImmutableList) cVal;
- } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.MAP) {
- maps[pos] = (ImmutableMap) cVal;
- } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.STRUCT
- || i.dataType().getTypeCategory() == DataTypes.TypeCategory.TRAIT) {
- structs[pos] = (StructInstance) cVal;
- } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) {
- if (cVal instanceof Id) {
- ids[pos] = (Id) cVal;
- } else {
- referenceables[pos] = (ReferenceableInstance) cVal;
- }
- } else {
- throw new AtlasException(String.format("Unknown datatype %s", i.dataType()));
- }
- }
-
- public Object get(String attrName) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- if (nullFlags[nullPos]) {
- if ( i.dataType().getTypeCategory() == DataTypes.TypeCategory.PRIMITIVE) {
- return ((DataTypes.PrimitiveType) i.dataType()).nullValue();
- } else {
- return null;
- }
- }
-
- if (i.dataType() == DataTypes.BOOLEAN_TYPE) {
- return bools[pos];
- } else if (i.dataType() == DataTypes.BYTE_TYPE) {
- return bytes[pos];
- } else if (i.dataType() == DataTypes.SHORT_TYPE) {
- return shorts[pos];
- } else if (i.dataType() == DataTypes.INT_TYPE) {
- return ints[pos];
- } else if (i.dataType() == DataTypes.LONG_TYPE) {
- return longs[pos];
- } else if (i.dataType() == DataTypes.FLOAT_TYPE) {
- return floats[pos];
- } else if (i.dataType() == DataTypes.DOUBLE_TYPE) {
- return doubles[pos];
- } else if (i.dataType() == DataTypes.BIGINTEGER_TYPE) {
- return bigIntegers[pos];
- } else if (i.dataType() == DataTypes.BIGDECIMAL_TYPE) {
- return bigDecimals[pos];
- } else if (i.dataType() == DataTypes.DATE_TYPE) {
- return dates[pos];
- } else if (i.dataType() == DataTypes.STRING_TYPE) {
- return strings[pos];
- } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.ENUM) {
- return ((EnumType) i.dataType()).fromOrdinal(ints[pos]);
- } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.ARRAY) {
- return arrays[pos];
- } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.MAP) {
- return maps[pos];
- } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.STRUCT
- || i.dataType().getTypeCategory() == DataTypes.TypeCategory.TRAIT) {
- return structs[pos];
- } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) {
- if (ids[pos] != null) {
- return ids[pos];
- } else {
- return referenceables[pos];
- }
- } else {
- throw new AtlasException(String.format("Unknown datatype %s", i.dataType()));
- }
- }
-
- public void setNull(String attrName) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
- nullFlags[nullPos] = true;
- explicitSets[nullPos] = true;
-
- int pos = fieldMapping.fieldPos.get(attrName);
-
- if (i.dataType() == DataTypes.BIGINTEGER_TYPE) {
- bigIntegers[pos] = null;
- } else if (i.dataType() == DataTypes.BIGDECIMAL_TYPE) {
- bigDecimals[pos] = null;
- } else if (i.dataType() == DataTypes.DATE_TYPE) {
- dates[pos] = null;
- } else if (i.dataType() == DataTypes.INT_TYPE) {
- ints[pos] = 0;
- } else if (i.dataType() == DataTypes.BOOLEAN_TYPE) {
- bools[pos] = false;
- } else if (i.dataType() == DataTypes.STRING_TYPE) {
- strings[pos] = null;
- } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.ARRAY) {
- arrays[pos] = null;
- } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.MAP) {
- maps[pos] = null;
- } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.STRUCT
- || i.dataType().getTypeCategory() == DataTypes.TypeCategory.TRAIT) {
- structs[pos] = null;
- } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) {
- ids[pos] = null;
- referenceables[pos] = null;
- } else {
- throw new AtlasException(String.format("Unknown datatype %s", i.dataType()));
- }
- }
-
- /*
- * Use only for json serialization
- * @nonpublic
- */
- @Override
- public Map<String, Object> getValuesMap() throws AtlasException {
- Map<String, Object> m = new HashMap<>();
- for (String attr : fieldMapping.fields.keySet()) {
-// int pos = fieldMapping.fieldNullPos.get(attr);
-// if ( explicitSets[pos] ) {
- m.put(attr, get(attr));
-// }
- }
- return m;
- }
-
- public boolean getBoolean(String attrName) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.BOOLEAN_TYPE) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic get method", attrName,
- getTypeName(), DataTypes.BOOLEAN_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- if (nullFlags[nullPos]) {
- return DataTypes.BOOLEAN_TYPE.nullValue();
- }
-
- return bools[pos];
- }
-
- public byte getByte(String attrName) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.BYTE_TYPE) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic get method", attrName,
- getTypeName(), DataTypes.BYTE_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- if (nullFlags[nullPos]) {
- return DataTypes.BYTE_TYPE.nullValue();
- }
-
- return bytes[pos];
- }
-
- public short getShort(String attrName) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.SHORT_TYPE) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic get method", attrName,
- getTypeName(), DataTypes.SHORT_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- if (nullFlags[nullPos]) {
- return DataTypes.SHORT_TYPE.nullValue();
- }
-
- return shorts[pos];
- }
-
- public int getInt(String attrName) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
-
- if (i.dataType() != DataTypes.INT_TYPE && !(i.dataType() instanceof EnumType)) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic get method", attrName,
- getTypeName(), DataTypes.INT_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- if (nullFlags[nullPos]) {
- return DataTypes.INT_TYPE.nullValue();
- }
-
- return ints[pos];
- }
-
- public long getLong(String attrName) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.LONG_TYPE) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic get method", attrName,
- getTypeName(), DataTypes.LONG_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- if (nullFlags[nullPos]) {
- return DataTypes.LONG_TYPE.nullValue();
- }
-
- return longs[pos];
- }
-
- public float getFloat(String attrName) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.FLOAT_TYPE) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic get method", attrName,
- getTypeName(), DataTypes.FLOAT_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- if (nullFlags[nullPos]) {
- return DataTypes.FLOAT_TYPE.nullValue();
- }
-
- return floats[pos];
- }
-
- public double getDouble(String attrName) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.DOUBLE_TYPE) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic get method", attrName,
- getTypeName(), DataTypes.DOUBLE_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- if (nullFlags[nullPos]) {
- return DataTypes.DOUBLE_TYPE.nullValue();
- }
-
- return doubles[pos];
- }
-
- public BigInteger getBigInt(String attrName) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.BIGINTEGER_TYPE) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic get method", attrName,
- getTypeName(), DataTypes.BIGINTEGER_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- if (nullFlags[nullPos]) {
- return DataTypes.BIGINTEGER_TYPE.nullValue();
- }
-
- return bigIntegers[pos];
- }
-
- public BigDecimal getBigDecimal(String attrName) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.BIGDECIMAL_TYPE) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic get method", attrName,
- getTypeName(), DataTypes.BIGDECIMAL_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- if (nullFlags[nullPos]) {
- return DataTypes.BIGDECIMAL_TYPE.nullValue();
- }
-
- return bigDecimals[pos];
- }
-
- public Date getDate(String attrName) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.DATE_TYPE) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic get method", attrName,
- getTypeName(), DataTypes.DATE_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- if (nullFlags[nullPos]) {
- return DataTypes.DATE_TYPE.nullValue();
- }
-
- return dates[pos];
- }
-
- public String getString(String attrName) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.STRING_TYPE) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic get method", attrName,
- getTypeName(), DataTypes.STRING_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- if (nullFlags[nullPos]) {
- return DataTypes.STRING_TYPE.nullValue();
- }
-
- return strings[pos];
- }
-
- public void setBoolean(String attrName, boolean val) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.BOOLEAN_TYPE) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic set method", attrName,
- getTypeName(), DataTypes.BOOLEAN_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- nullFlags[nullPos] = false;
- bools[pos] = val;
- explicitSets[nullPos] = true;
- }
-
- public void setByte(String attrName, byte val) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.BYTE_TYPE) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic set method", attrName,
- getTypeName(), DataTypes.BYTE_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- nullFlags[nullPos] = false;
- bytes[pos] = val;
- explicitSets[nullPos] = true;
- }
-
- public void setShort(String attrName, short val) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.SHORT_TYPE) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic set method", attrName,
- getTypeName(), DataTypes.SHORT_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- nullFlags[nullPos] = false;
- shorts[pos] = val;
- explicitSets[nullPos] = true;
- }
-
- public void setInt(String attrName, int val) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.INT_TYPE && !(i.dataType() instanceof EnumType)) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic set method", attrName,
- getTypeName(), DataTypes.INT_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- nullFlags[nullPos] = false;
- ints[pos] = val;
- explicitSets[nullPos] = true;
- }
-
- public void setLong(String attrName, long val) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.LONG_TYPE) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic set method", attrName,
- getTypeName(), DataTypes.LONG_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- nullFlags[nullPos] = false;
- longs[pos] = val;
- explicitSets[nullPos] = true;
- }
-
- public void setFloat(String attrName, float val) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.FLOAT_TYPE) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic set method", attrName,
- getTypeName(), DataTypes.FLOAT_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- nullFlags[nullPos] = false;
- floats[pos] = val;
- explicitSets[nullPos] = true;
- }
-
- public void setDouble(String attrName, double val) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.DOUBLE_TYPE) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic set method", attrName,
- getTypeName(), DataTypes.DOUBLE_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- nullFlags[nullPos] = false;
- doubles[pos] = val;
- explicitSets[nullPos] = true;
- }
-
- public void setBigInt(String attrName, BigInteger val) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.BIGINTEGER_TYPE) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic set method", attrName,
- getTypeName(), DataTypes.BIGINTEGER_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- nullFlags[nullPos] = val == null;
- bigIntegers[pos] = val;
- explicitSets[nullPos] = true;
- }
-
- public void setBigDecimal(String attrName, BigDecimal val) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.BIGDECIMAL_TYPE) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic set method", attrName,
- getTypeName(), DataTypes.BIGDECIMAL_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- nullFlags[nullPos] = val == null;
- bigDecimals[pos] = val;
- explicitSets[nullPos] = true;
- }
-
- public void setDate(String attrName, Date val) throws AtlasException {
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.DATE_TYPE) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic set method", attrName,
- getTypeName(), DataTypes.DATE_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- nullFlags[nullPos] = val == null;
- dates[pos] = val;
- explicitSets[nullPos] = true;
- }
-
- public void setString(String attrName, String val) throws AtlasException {
-
- AttributeInfo i = fieldMapping.fields.get(attrName);
- if (i == null) {
- throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
- }
-
- if (i.dataType() != DataTypes.STRING_TYPE) {
- throw new AtlasException(
- String.format("Field %s for Struct %s is not a %s, call generic set method", attrName,
- getTypeName(), DataTypes.STRING_TYPE.getName()));
- }
-
- int pos = fieldMapping.fieldPos.get(attrName);
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
-
- nullFlags[nullPos] = val == null;
- strings[pos] = val;
- explicitSets[nullPos] = true;
- }
-
- @Override
- public String toString() {
- try {
- StringBuilder buf = new StringBuilder();
- String prefix = "";
-
- fieldMapping.output(this, buf, prefix, null);
- return buf.toString();
-
- } catch (AtlasException me) {
- throw new RuntimeException(me);
- }
- }
-
- @Override
- public String getSignatureHash(MessageDigest digester) throws AtlasException {
- StructType structType = TypeSystem.getInstance().getDataType(StructType.class, getTypeName());
- structType.updateSignatureHash(digester, this);
- byte[] digest = digester.digest();
- return SHA256Utils.toString(digest);
- }
-
- @Override
- public boolean isValueSet(final String attrName) throws AtlasException {
- int nullPos = fieldMapping.fieldNullPos.get(attrName);
- return explicitSets[nullPos];
- }
-
- @Override
- public String toShortString() {
- return String.format("struct[type=%s]", dataTypeName);
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/typesystem/src/main/java/org/apache/atlas/typesystem/types/AbstractDataType.java
----------------------------------------------------------------------
diff --git a/typesystem/src/main/java/org/apache/atlas/typesystem/types/AbstractDataType.java b/typesystem/src/main/java/org/apache/atlas/typesystem/types/AbstractDataType.java
deleted file mode 100755
index 874138b..0000000
--- a/typesystem/src/main/java/org/apache/atlas/typesystem/types/AbstractDataType.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/**
- * 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.typesystem.types;
-
-import com.google.common.collect.ImmutableSortedMap;
-
-import org.apache.atlas.AtlasConstants;
-import org.apache.atlas.AtlasException;
-
-import java.io.IOException;
-import java.util.Map;
-import java.util.Set;
-
-abstract class AbstractDataType<T> implements IDataType<T> {
-
- public final String name;
- public final String description;
- public final String version;
-
- public AbstractDataType(String name, String description) {
-
- super();
- this.name = name;
- this.description = description;
- this.version = AtlasConstants.DEFAULT_TYPE_VERSION;
- }
-
- public AbstractDataType(String name, String description, String version) {
-
- super();
- this.name = name;
- this.description = description;
- this.version = version;
- }
-
- protected T convertNull(Multiplicity m) throws AtlasException {
- if (!m.nullAllowed()) {
- throw new ValueConversionException.NullConversionException(m);
- }
- return null;
- }
-
- @Override
- public void output(T val, Appendable buf, String prefix, Set<T> inProcess) throws AtlasException {
- final String strValue;
-
- if (val == null) {
- strValue = "<null>";
- } else if (val instanceof Map) {
- ImmutableSortedMap immutableSortedMap = ImmutableSortedMap.copyOf((Map) val);
- strValue = immutableSortedMap.toString();
- } else {
- strValue = val.toString();
- }
-
- TypeUtils.outputVal(strValue, buf, prefix);
- }
-
- @Override
- public void output(Appendable buf, Set<String> typesInProcess) throws AtlasException {
-
- try {
- buf.append(toString());
- } catch (IOException e) {
- throw new AtlasException(e);
- }
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "{name=" + name + ", description=" + description + "}";
- }
-
- /**
- * Validate that current definition can be updated with the new definition
- * @param newType
- */
- @Override
- public void validateUpdate(IDataType newType) throws TypeUpdateException {
- if (!getName().equals(newType.getName()) || !getClass().getName().equals(newType.getClass().getName())) {
- throw new TypeUpdateException(newType);
- }
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getDescription() {
- return description;
- }
-
- @Override
- public String getVersion() {
- return version;
- }
-}
-
http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/typesystem/src/main/java/org/apache/atlas/typesystem/types/AttributeDefinition.java
----------------------------------------------------------------------
diff --git a/typesystem/src/main/java/org/apache/atlas/typesystem/types/AttributeDefinition.java b/typesystem/src/main/java/org/apache/atlas/typesystem/types/AttributeDefinition.java
deleted file mode 100755
index 5561f0b..0000000
--- a/typesystem/src/main/java/org/apache/atlas/typesystem/types/AttributeDefinition.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * 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.typesystem.types;
-
-import org.apache.atlas.utils.ParamChecker;
-
-import java.util.Objects;
-
-public final class AttributeDefinition {
-
- public final String name;
- public final String dataTypeName;
- public final Multiplicity multiplicity;
- //A composite is the one whose lifecycle is dependent on the enclosing type and is not just a reference
- public final boolean isComposite;
- public final boolean isUnique;
- public final boolean isIndexable;
-
- /**
- * If this is a reference attribute, then the name of the attribute on the Class
- * that this refers to.
- */
- public final String reverseAttributeName;
-
- public AttributeDefinition(String name, String dataTypeName, Multiplicity multiplicity, boolean isComposite,
- String reverseAttributeName) {
- this(name, dataTypeName, multiplicity, isComposite, false, false, reverseAttributeName);
-
- }
-
- public AttributeDefinition(String name, String dataTypeName, Multiplicity multiplicity, boolean isComposite,
- boolean isUnique, boolean isIndexable, String reverseAttributeName) {
- this.name = ParamChecker.notEmpty(name, "Attribute name");
- this.dataTypeName = ParamChecker.notEmpty(dataTypeName, "Attribute type");
- this.multiplicity = multiplicity;
- this.isComposite = isComposite;
- this.isUnique = isUnique;
- this.isIndexable = isIndexable;
- this.reverseAttributeName = ParamChecker.notEmptyIfNotNull(reverseAttributeName, "Reverse attribute name");
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- AttributeDefinition that = (AttributeDefinition) o;
- return isComposite == that.isComposite &&
- isUnique == that.isUnique &&
- isIndexable == that.isIndexable &&
- Objects.equals(name, that.name) &&
- Objects.equals(dataTypeName, that.dataTypeName) &&
- Objects.equals(multiplicity, that.multiplicity) &&
- Objects.equals(reverseAttributeName, that.reverseAttributeName);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(name, dataTypeName, multiplicity, isComposite, isUnique, isIndexable, reverseAttributeName);
- }
-
- @Override
- public String toString() {
- return name;
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/typesystem/src/main/java/org/apache/atlas/typesystem/types/AttributeInfo.java
----------------------------------------------------------------------
diff --git a/typesystem/src/main/java/org/apache/atlas/typesystem/types/AttributeInfo.java b/typesystem/src/main/java/org/apache/atlas/typesystem/types/AttributeInfo.java
deleted file mode 100755
index c24a55f..0000000
--- a/typesystem/src/main/java/org/apache/atlas/typesystem/types/AttributeInfo.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/**
- * 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.typesystem.types;
-
-import org.apache.atlas.AtlasException;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
-
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-
-public class AttributeInfo {
- public final String name;
- public final Multiplicity multiplicity;
- //A composite is the one whose lifecycle is dependent on the enclosing type and is not just a reference
- public final boolean isComposite;
- public final boolean isUnique;
- public final boolean isIndexable;
- /**
- * If this is a reference attribute, then the name of the attribute on the Class
- * that this refers to.
- */
- public final String reverseAttributeName;
- private IDataType dataType;
-
- public AttributeInfo(TypeSystem t, AttributeDefinition def, Map<String, IDataType> tempTypes) throws AtlasException {
- this.name = def.name;
- this.dataType =
- (tempTypes != null && tempTypes.containsKey(def.dataTypeName)) ? tempTypes.get(def.dataTypeName) :
- t.getDataType(IDataType.class, def.dataTypeName);
- this.multiplicity = def.multiplicity;
- this.isComposite = def.isComposite;
- this.isUnique = def.isUnique;
- this.isIndexable = def.isIndexable;
- this.reverseAttributeName = def.reverseAttributeName;
- }
-
- public IDataType dataType() {
- return dataType;
- }
-
- void setDataType(IDataType dT) {
- dataType = dT;
- }
-
- @Override
- public String toString() {
- StringBuilder buf = new StringBuilder();
- try {
- output(buf, new HashSet<String>());
- } catch (AtlasException e) {
- throw new RuntimeException(e);
- }
- return buf.toString();
- }
-
- public void output(Appendable buf, Set<String> typesInProcess) throws AtlasException {
- try {
- buf.append("{name=").append(name);
- buf.append(", dataType=");
- dataType.output(buf, typesInProcess);
- buf.append(", multiplicity=").append(multiplicity.toString());
- buf.append(", isComposite=").append(Boolean.toString(isComposite));
- buf.append(", isUnique=").append(Boolean.toString(isUnique));
- buf.append(", isIndexable=").append(Boolean.toString(isIndexable));
- buf.append(", reverseAttributeName=").append(reverseAttributeName);
- buf.append('}');
- }
- catch(IOException e) {
- throw new AtlasException(e);
- }
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(name, multiplicity, isComposite, isUnique, isIndexable, reverseAttributeName, dataType);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- AttributeInfo that = (AttributeInfo) o;
- return isComposite == that.isComposite &&
- isUnique == that.isUnique &&
- isIndexable == that.isIndexable &&
- Objects.equals(name, that.name) &&
- Objects.equals(multiplicity, that.multiplicity) &&
- Objects.equals(reverseAttributeName, that.reverseAttributeName) &&
- dataType == null ? that.dataType == null : Objects.equals(dataType.getName(), that.dataType.getName());
- }
-
- public String toJson() throws JSONException {
- JSONObject json = new JSONObject();
- json.put("name", name);
- json.put("multiplicity", multiplicity.toJson());
- json.put("isComposite", isComposite);
- json.put("isUnique", isUnique);
- json.put("isIndexable", isIndexable);
- json.put("dataType", dataType.getName());
- json.put("reverseAttributeName", reverseAttributeName);
- return json.toString();
- }
-
- public static AttributeDefinition fromJson(String jsonStr) throws JSONException {
- JSONObject json = new JSONObject(jsonStr);
- String reverseAttr = null;
- if (json.has("reverseAttributeName")) {
- reverseAttr = json.getString("reverseAttributeName");
- }
- return new AttributeDefinition(json.getString("name"), json.getString("dataType"),
- Multiplicity.fromJson(json.getString("multiplicity")), json.getBoolean("isComposite"),
- json.getBoolean("isUnique"), json.getBoolean("isIndexable"), reverseAttr);
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/typesystem/src/main/java/org/apache/atlas/typesystem/types/ClassType.java
----------------------------------------------------------------------
diff --git a/typesystem/src/main/java/org/apache/atlas/typesystem/types/ClassType.java b/typesystem/src/main/java/org/apache/atlas/typesystem/types/ClassType.java
deleted file mode 100755
index 2f2b090..0000000
--- a/typesystem/src/main/java/org/apache/atlas/typesystem/types/ClassType.java
+++ /dev/null
@@ -1,259 +0,0 @@
-/**
- * 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.typesystem.types;
-
-import com.google.common.collect.ImmutableBiMap;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-
-import org.apache.atlas.AtlasConstants;
-import org.apache.atlas.AtlasException;
-import org.apache.atlas.typesystem.IReferenceableInstance;
-import org.apache.atlas.typesystem.IStruct;
-import org.apache.atlas.typesystem.ITypedReferenceableInstance;
-import org.apache.atlas.typesystem.ITypedStruct;
-import org.apache.atlas.typesystem.Referenceable;
-import org.apache.atlas.typesystem.Struct;
-import org.apache.atlas.typesystem.persistence.AtlasSystemAttributes;
-import org.apache.atlas.typesystem.persistence.Id;
-import org.apache.atlas.typesystem.persistence.ReferenceableInstance;
-import org.apache.atlas.typesystem.persistence.StructInstance;
-import scala.tools.cmd.gen.AnyVals;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.nio.charset.Charset;
-import java.security.MessageDigest;
-import java.util.*;
-
-public class ClassType extends HierarchicalType<ClassType, IReferenceableInstance>
- implements IConstructableType<IReferenceableInstance, ITypedReferenceableInstance> {
-
- public static final String TRAIT_NAME_SEP = "::";
-
- public final Map<AttributeInfo, List<String>> infoToNameMap;
-
- ClassType(TypeSystem typeSystem, String name, String description, ImmutableSet<String> superTypes, int numFields) {
- this(typeSystem, name, description, AtlasConstants.DEFAULT_TYPE_VERSION, superTypes, numFields);
- }
-
- ClassType(TypeSystem typeSystem, String name, String description, String version, ImmutableSet<String> superTypes, int numFields) {
- super(typeSystem, ClassType.class, name, description, version, superTypes, numFields);
- infoToNameMap = null;
- }
-
- ClassType(TypeSystem typeSystem, String name, String description, ImmutableSet<String> superTypes, AttributeInfo... fields)
- throws AtlasException {
- this(typeSystem, name, description, AtlasConstants.DEFAULT_TYPE_VERSION, superTypes, fields);
- }
-
- ClassType(TypeSystem typeSystem, String name, String description, String version, ImmutableSet<String> superTypes, AttributeInfo... fields)
- throws AtlasException {
- super(typeSystem, ClassType.class, name, description, version, superTypes, fields);
- infoToNameMap = TypeUtils.buildAttrInfoToNameMap(fieldMapping);
- }
-
- @Override
- public DataTypes.TypeCategory getTypeCategory() {
- return DataTypes.TypeCategory.CLASS;
- }
-
- public void validateId(Id id) throws AtlasException {
- if (id != null) {
- ClassType cType = typeSystem.getDataType(ClassType.class, id.typeName);
- if (isSubType(cType.getName())) {
- return;
- }
- throw new AtlasException(String.format("Id %s is not valid for class %s", id, getName()));
- }
- }
-
- protected Id getId(Object val) throws AtlasException {
- if (val instanceof Referenceable) {
- return ((Referenceable) val).getId();
- }
- throw new AtlasException(String.format("Cannot get id from class %s", val.getClass()));
- }
-
- @Override
- public ITypedReferenceableInstance convert(Object val, Multiplicity m) throws AtlasException {
-
- if (val != null) {
- if (val instanceof ITypedReferenceableInstance) {
- ITypedReferenceableInstance tr = (ITypedReferenceableInstance) val;
- if (!tr.getTypeName().equals(getName())) {
- /*
- * If val is a subType instance; invoke convert on it.
- */
- ClassType valType = typeSystem.getDataType(superTypeClass, tr.getTypeName());
- if (valType.superTypePaths.containsKey(name)) {
- return valType.convert(val, m);
- }
- throw new ValueConversionException(this, val);
- }
- return tr;
- } else if (val instanceof Struct) {
- Struct s = (Struct) val;
- Referenceable r = null;
- Id id = null;
-
- if (!s.typeName.equals(getName())) {
- /*
- * If val is a subType instance; invoke convert on it.
- */
- ClassType valType = typeSystem.getDataType(superTypeClass, s.typeName);
- if (valType.superTypePaths.containsKey(name)) {
- return valType.convert(s, m);
- }
- throw new ValueConversionException(this, val);
- }
-
- if (val instanceof Referenceable) {
- r = (Referenceable) val;
- id = r.getId();
- }
-
- ITypedReferenceableInstance tr =
- r != null ? createInstanceWithTraits(id, null, r, r.getTraits().toArray(new String[0])) :
- createInstance(id);
-
- if (id != null && id.isAssigned()) {
- return tr;
- }
-
- for (Map.Entry<String, AttributeInfo> e : fieldMapping.fields.entrySet()) {
- String attrKey = e.getKey();
- AttributeInfo i = e.getValue();
- Object aVal = s.get(attrKey);
- if (aVal != null && i.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) {
- if (!i.isComposite) {
- aVal = ((IReferenceableInstance) aVal).getId();
- }
- }
-
- if(!i.multiplicity.nullAllowed() && !s.getValuesMap().containsKey(attrKey)){
- throw new ValueConversionException.NullConversionException(i.multiplicity,
- String.format(" Value expected for required attribute %s", i.name));
- } else {
- try {
- if (s.getValuesMap().containsKey(attrKey)) {
- tr.set(attrKey, aVal);
- }
- } catch (ValueConversionException ve) {
- throw new ValueConversionException(this, val, ve);
- }
- }
- }
-
- return tr;
- } else if (val instanceof ReferenceableInstance) {
- validateId(((ReferenceableInstance) val).getId());
- return (ReferenceableInstance) val;
- } else {
- throw new ValueConversionException(this, val, "value's class is " + val.getClass().getName());
- }
- }
- if (!m.nullAllowed()) {
- throw new ValueConversionException.NullConversionException(m);
- }
- return null;
- }
-
- @Override
- public ITypedReferenceableInstance createInstance() throws AtlasException {
- return createInstance((String[]) null);
- }
-
- public ITypedReferenceableInstance createInstance(String... traitNames) throws AtlasException {
- return createInstance(null, traitNames);
- }
-
- public ITypedReferenceableInstance createInstance(Id id, String... traitNames) throws AtlasException {
- return createInstanceWithTraits(id, null, null, traitNames);
- }
-
- public ITypedReferenceableInstance createInstance(Id id, AtlasSystemAttributes systemAttributes, String... traitNames) throws AtlasException{
- return createInstanceWithTraits(id, systemAttributes, null, traitNames);
- }
-
- public ITypedReferenceableInstance createInstanceWithTraits(Id id, AtlasSystemAttributes systemAttributes, Referenceable r, String... traitNames)
- throws AtlasException {
-
- ImmutableMap.Builder<String, ITypedStruct> b = new ImmutableBiMap.Builder<>();
- if (traitNames != null) {
- for (String t : traitNames) {
- TraitType tType = typeSystem.getDataType(TraitType.class, t);
- IStruct iTraitObject = r == null ? null : r.getTrait(t);
- ITypedStruct trait = iTraitObject == null ? tType.createInstance() :
- tType.convert(iTraitObject, Multiplicity.REQUIRED);
- b.put(t, trait);
- }
- }
-
- return new ReferenceableInstance(id == null ? new Id(getName()) : id, getName(), systemAttributes, fieldMapping,
- new boolean[fieldMapping.fields.size()], new boolean[fieldMapping.fields.size()],
- fieldMapping.numBools == 0 ? null : new boolean[fieldMapping.numBools],
- fieldMapping.numBytes == 0 ? null : new byte[fieldMapping.numBytes],
- fieldMapping.numShorts == 0 ? null : new short[fieldMapping.numShorts],
- fieldMapping.numInts == 0 ? null : new int[fieldMapping.numInts],
- fieldMapping.numLongs == 0 ? null : new long[fieldMapping.numLongs],
- fieldMapping.numFloats == 0 ? null : new float[fieldMapping.numFloats],
- fieldMapping.numDoubles == 0 ? null : new double[fieldMapping.numDoubles],
- fieldMapping.numBigDecimals == 0 ? null : new BigDecimal[fieldMapping.numBigDecimals],
- fieldMapping.numBigInts == 0 ? null : new BigInteger[fieldMapping.numBigInts],
- fieldMapping.numDates == 0 ? null : new Date[fieldMapping.numDates],
- fieldMapping.numStrings == 0 ? null : new String[fieldMapping.numStrings],
- fieldMapping.numArrays == 0 ? null : new ImmutableList[fieldMapping.numArrays],
- fieldMapping.numMaps == 0 ? null : new ImmutableMap[fieldMapping.numMaps],
- fieldMapping.numStructs == 0 ? null : new StructInstance[fieldMapping.numStructs],
- fieldMapping.numReferenceables == 0 ? null : new ReferenceableInstance[fieldMapping.numReferenceables],
- fieldMapping.numReferenceables == 0 ? null : new Id[fieldMapping.numReferenceables], b.build());
- }
-
- @Override
- public void output(IReferenceableInstance s, Appendable buf, String prefix, Set<IReferenceableInstance> inProcess) throws AtlasException {
- fieldMapping.output(s, buf, prefix, inProcess);
- }
-
- @Override
- public List<String> getNames(AttributeInfo info) {
- return infoToNameMap.get(info);
- }
-
- @Override
- public void updateSignatureHash(MessageDigest digester, Object val) throws AtlasException {
- if( !(val instanceof ITypedReferenceableInstance)) {
- throw new IllegalArgumentException("Unexpected value type " + val.getClass().getSimpleName() + ". Expected instance of ITypedStruct");
- }
- digester.update(getName().getBytes(Charset.forName("UTF-8")));
-
- if(fieldMapping.fields != null && val != null) {
- IReferenceableInstance typedValue = (IReferenceableInstance) val;
- if(fieldMapping.fields.values() != null) {
- for (AttributeInfo aInfo : fieldMapping.fields.values()) {
- Object attrVal = typedValue.get(aInfo.name);
- if (attrVal != null) {
- aInfo.dataType().updateSignatureHash(digester, attrVal);
- }
- }
- }
- }
- }
-}
\ No newline at end of file