Skip to content

Commit d71bd78

Browse files
committed
MLH-1226 Optimize
1 parent 4aa11fb commit d71bd78

File tree

1 file changed

+29
-43
lines changed

1 file changed

+29
-43
lines changed

graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusElement.java

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -129,33 +129,42 @@ public void removeProperty(String propertyName) {
129129
public void removePropertyValue(String propertyName, Object propertyValue) {
130130
RequestContext context = RequestContext.get();
131131
Iterator<? extends Property<Object>> it = getWrappedElement().properties(propertyName);
132-
// we create a map of properties that are only internal
133-
fillInternalPropertiesIfApplicable(propertyName, propertyValue, it, context);
134-
it = getWrappedElement().properties(propertyName);
132+
List<Object> finalValues = new ArrayList<>();
133+
boolean removedFirst = false;
134+
135135
while (it.hasNext()) {
136136
Property currentProperty = it.next();
137137
Object currentPropertyValue = currentProperty.value();
138138

139-
if (Objects.equals(currentPropertyValue, propertyValue)) {
139+
if (Objects.equals(currentPropertyValue, propertyValue) && !removedFirst) {
140140
currentProperty.remove();
141-
break;
141+
removedFirst = true;
142+
} else {
143+
finalValues.add(currentPropertyValue);
142144
}
143145
}
146+
147+
recordInternalAttribute(propertyName, finalValues);
144148
}
145149

146150
@Override
147151
public void removeAllPropertyValue(String propertyName, Object propertyValue) {
148152
Iterator<? extends Property<Object>> it = getWrappedElement().properties(propertyName);
149-
RequestContext context = RequestContext.get();
150-
fillInternalPropertiesIfApplicable(propertyName, propertyValue, it, context);
153+
List<Object> finalValues = new ArrayList<>();
154+
155+
151156
while (it.hasNext()) {
152157
Property currentProperty = it.next();
153158
Object currentPropertyValue = currentProperty.value();
154159

155160
if (Objects.equals(currentPropertyValue, propertyValue)) {
156161
currentProperty.remove();
162+
} else {
163+
finalValues.add(currentPropertyValue);
157164
}
158165
}
166+
167+
recordInternalAttribute(propertyName, finalValues);
159168
}
160169

161170
@Override
@@ -169,19 +178,7 @@ public void setProperty(String propertyName, Object value) {
169178
}
170179
} else {
171180
getWrappedElement().property(propertyName, value);
172-
//fill all internal properties for the entityGuid
173-
if (propertyName.startsWith(INTERNAL_PROPERTY_KEY_PREFIX)) {
174-
String entityGuid = this.getProperty(GUID_PROPERTY_KEY, String.class);
175-
if (StringUtils.isNotEmpty(entityGuid)) {
176-
if (context.getAllInternalAttributesMap().get(entityGuid) != null) {
177-
context.getAllInternalAttributesMap().get(entityGuid).put(propertyName, value);
178-
} else {
179-
Map<String, Object> map = new HashMap<>();
180-
map.put(propertyName, value);
181-
context.getAllInternalAttributesMap().put(entityGuid, map);
182-
}
183-
}
184-
}
181+
recordInternalAttribute(propertyName, value);
185182
}
186183
} catch(SchemaViolationException e) {
187184
throw new AtlasSchemaViolationException(e);
@@ -348,29 +345,18 @@ public boolean isIdAssigned() {
348345
return true;
349346
}
350347

351-
352-
private void fillInternalPropertiesIfApplicable(String propertyName, Object propertyValue, Iterator<? extends Property<Object>> it, RequestContext context) {
353-
while (it.hasNext()) {
354-
Property currentProperty = it.next();
355-
Object currentPropertyValue = currentProperty.value();
356-
357-
if (!Objects.equals(currentPropertyValue, propertyValue)) {
358-
//fill the map with all iterartor values for the entityGuid
359-
if (propertyName.startsWith(INTERNAL_PROPERTY_KEY_PREFIX)) {
360-
String entityGuid = this.getProperty(GUID_PROPERTY_KEY, String.class);
361-
if (StringUtils.isNotEmpty(entityGuid)) {
362-
if (context.getAllInternalAttributesMap().get(entityGuid) != null) {
363-
Object value = context.getAllInternalAttributesMap().get(entityGuid);
364-
List<Object> values = new ArrayList<>();
365-
values.add(value);
366-
values.add(currentPropertyValue);
367-
context.getAllInternalAttributesMap().get(entityGuid).put(propertyName, values);
368-
} else {
369-
Map<String, Object> map = new HashMap<>();
370-
map.put(propertyName, currentPropertyValue);
371-
context.getAllInternalAttributesMap().put(entityGuid, map);
372-
}
373-
}
348+
private void recordInternalAttribute(String propertyName, Object finalValue) {
349+
if (propertyName.startsWith(INTERNAL_PROPERTY_KEY_PREFIX)) {
350+
RequestContext context = RequestContext.get();
351+
String entityGuid = this.getProperty(GUID_PROPERTY_KEY, String.class);
352+
353+
if (StringUtils.isNotEmpty(entityGuid)) {
354+
if (context.getAllInternalAttributesMap().get(entityGuid) != null) {
355+
context.getAllInternalAttributesMap().get(entityGuid).put(propertyName, finalValue);
356+
} else {
357+
Map<String, Object> map = new HashMap<>();
358+
map.put(propertyName, finalValue);
359+
context.getAllInternalAttributesMap().put(entityGuid, map);
374360
}
375361
}
376362
}

0 commit comments

Comments
 (0)