file_name
stringlengths
6
86
file_path
stringlengths
45
249
content
stringlengths
47
6.26M
file_size
int64
47
6.26M
language
stringclasses
1 value
extension
stringclasses
1 value
repo_name
stringclasses
767 values
repo_stars
int64
8
14.4k
repo_forks
int64
0
1.17k
repo_open_issues
int64
0
788
repo_created_at
stringclasses
767 values
repo_pushed_at
stringclasses
767 values
PropertyRecordCharValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordCharValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; @PersistentClass("kryo") public class PropertyRecordCharValue implements PropertyRecordValue<Character> { private char value; protected PropertyRecordCharValue(){ // default constructor for kryo } public PropertyRecordCharValue(char value){ this.value = value; } @Override public Character getValue() { return this.value; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordCharValue that = (PropertyRecordCharValue) o; return value == that.value; } @Override public int hashCode() { return value; } @Override public String toString() { return String.valueOf(this.value); } }
984
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordStringSetValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordStringSetValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import com.google.common.collect.Sets; import org.chronos.common.annotation.PersistentClass; import java.util.Collections; import java.util.Objects; import java.util.Set; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordStringSetValue implements PropertyRecordValue<Set<String>> { private Set<String> values; protected PropertyRecordStringSetValue(){ // default constructor for kryo } public PropertyRecordStringSetValue(Set<String> values){ checkNotNull(values, "Precondition violation - argument 'values' must not be NULL!"); this.values = Sets.newHashSet(values); } @Override public Set<String> getValue() { return Collections.unmodifiableSet(this.values); } @Override public Set<String> getSerializationSafeValue() { return Sets.newHashSet(this.values); } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordStringSetValue that = (PropertyRecordStringSetValue) o; return Objects.equals(values, that.values); } @Override public int hashCode() { return values != null ? values.hashCode() : 0; } @Override public String toString() { return this.values.toString(); } }
1,509
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordLongSetValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordLongSetValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import com.google.common.collect.Sets; import org.chronos.common.annotation.PersistentClass; import java.util.Collections; import java.util.Objects; import java.util.Set; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordLongSetValue implements PropertyRecordValue<Set<Long>> { private Set<Long> values; protected PropertyRecordLongSetValue(){ // default constructor for kryo } public PropertyRecordLongSetValue(Set<Long> values){ checkNotNull(values, "Precondition violation - argument 'values' must not be NULL!"); this.values = Sets.newHashSet(values); } @Override public Set<Long> getValue() { return Collections.unmodifiableSet(this.values); } @Override public Set<Long> getSerializationSafeValue() { return Sets.newHashSet(this.values); } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordLongSetValue that = (PropertyRecordLongSetValue) o; return Objects.equals(values, that.values); } @Override public int hashCode() { return values != null ? values.hashCode() : 0; } @Override public String toString() { return this.values.toString(); } }
1,489
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordDateListValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordDateListValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import com.google.common.collect.Lists; import org.chronos.common.annotation.PersistentClass; import org.jetbrains.annotations.NotNull; import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Objects; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordDateListValue implements PropertyRecordValue<List<Date>> { private List<Long> values; protected PropertyRecordDateListValue(){ // default constructor for kryo } public PropertyRecordDateListValue(List<Date> values){ checkNotNull(values, "Precondition violation - argument 'values' must not be NULL!"); this.values = Lists.newArrayListWithExpectedSize(values.size()); for (Date date : values) { if (date == null) { this.values.add(null); } else { this.values.add(date.getTime()); } } } @Override public List<Date> getValue() { return Collections.unmodifiableList(getDates()); } @Override public List<Date> getSerializationSafeValue() { return this.getDates(); } private List<Date> getDates() { List<Date> resultList = Lists.newArrayListWithExpectedSize(this.values.size()); for(Long time : this.values){ if(time == null){ resultList.add(null); }else{ resultList.add(new Date(time)); } } return resultList; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordDateListValue that = (PropertyRecordDateListValue) o; return Objects.equals(values, that.values); } @Override public int hashCode() { return values != null ? values.hashCode() : 0; } @Override public String toString() { return this.values.toString(); } }
2,136
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordByteSetValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordByteSetValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import com.google.common.collect.Sets; import org.chronos.common.annotation.PersistentClass; import java.util.Collections; import java.util.Objects; import java.util.Set; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordByteSetValue implements PropertyRecordValue<Set<Byte>> { private Set<Byte> values; protected PropertyRecordByteSetValue(){ // default constructor for kryo } public PropertyRecordByteSetValue(Set<Byte> values){ checkNotNull(values, "Precondition violation - argument 'values' must not be NULL!"); this.values = Sets.newHashSet(values); } @Override public Set<Byte> getValue() { return Collections.unmodifiableSet(this.values); } @Override public Set<Byte> getSerializationSafeValue() { return Sets.newHashSet(this.values); } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordByteSetValue that = (PropertyRecordByteSetValue) o; return Objects.equals(values, that.values); } @Override public int hashCode() { return values != null ? values.hashCode() : 0; } @Override public String toString() { return this.values.toString(); } }
1,489
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordValueUtil.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordValueUtil.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import java.util.*; import java.util.function.Function; import static com.google.common.base.Preconditions.*; public class PropertyRecordValueUtil { private static final Map<Class<?>, Function<Object, PropertyRecordValue<?>>> PROPERTY_VALUE_CREATORS; private static final Map<Class<?>, Function<Object, PropertyRecordValue<? extends List<?>>>> PROPERTY_LIST_VALUE_CREATORS; private static final Map<Class<?>, Function<Object, PropertyRecordValue<? extends Set<?>>>> PROPERTY_SET_VALUE_CREATORS; static { Map<Class<?>, Function<Object, PropertyRecordValue<?>>> classToValueCreator = Maps.newHashMap(); Map<Class<?>, Function<Object, PropertyRecordValue<? extends List<?>>>> classToListValueCreator = Maps.newHashMap(); Map<Class<?>, Function<Object, PropertyRecordValue<? extends Set<?>>>> classToSetValueCreator = Maps.newHashMap(); // primitives & primitve wrappers classToValueCreator.put(boolean.class, (Object value) -> new PropertyRecordBooleanValue((boolean)value)); classToValueCreator.put(Boolean.class, (Object value) -> new PropertyRecordBooleanValue((boolean)value)); classToValueCreator.put(boolean[].class, (Object value) -> new PropertyRecordBooleanArrayValue((boolean[])value)); classToValueCreator.put(Boolean[].class, (Object value) -> new PropertyRecordBooleanWrapperArrayValue((Boolean[])value)); classToListValueCreator.put(Boolean.class, (Object value) -> new PropertyRecordBooleanListValue((List<Boolean>)value)); classToSetValueCreator.put(Boolean.class, (Object value) -> new PropertyRecordBooleanSetValue((Set<Boolean>)value)); classToValueCreator.put(byte.class, (Object value) -> new PropertyRecordByteValue((byte)value)); classToValueCreator.put(Byte.class, (Object value) -> new PropertyRecordByteValue((byte)value)); classToValueCreator.put(byte[].class, (Object value) -> new PropertyRecordByteArrayValue((byte[])value)); classToValueCreator.put(Byte[].class, (Object value) -> new PropertyRecordByteWrapperArrayValue((Byte[])value)); classToListValueCreator.put(Byte.class, (Object value) -> new PropertyRecordByteListValue((List<Byte>)value)); classToSetValueCreator.put(Byte.class, (Object value) -> new PropertyRecordByteSetValue((Set<Byte>)value)); classToValueCreator.put(short.class, (Object value) -> new PropertyRecordShortValue((short)value)); classToValueCreator.put(Short.class, (Object value) -> new PropertyRecordShortValue((short)value)); classToValueCreator.put(short[].class, (Object value) -> new PropertyRecordShortArrayValue((short[])value)); classToValueCreator.put(Short[].class, (Object value) -> new PropertyRecordShortWrapperArrayValue((Short[])value)); classToListValueCreator.put(Short.class, (Object value) -> new PropertyRecordShortListValue((List<Short>)value)); classToSetValueCreator.put(Short.class, (Object value) -> new PropertyRecordShortSetValue((Set<Short>)value)); classToValueCreator.put(char.class, (Object value) -> new PropertyRecordCharValue((char)value)); classToValueCreator.put(Character.class, (Object value) -> new PropertyRecordCharValue((char)value)); classToValueCreator.put(char[].class, (Object value) -> new PropertyRecordCharArrayValue((char[])value)); classToValueCreator.put(Character[].class, (Object value) -> new PropertyRecordCharWrapperArrayValue((Character[])value)); classToListValueCreator.put(Character.class, (Object value) -> new PropertyRecordCharListValue((List<Character>)value)); classToSetValueCreator.put(Character.class, (Object value) -> new PropertyRecordCharSetValue((Set<Character>)value)); classToValueCreator.put(int.class, (Object value) -> new PropertyRecordIntValue((int)value)); classToValueCreator.put(Integer.class, (Object value) -> new PropertyRecordIntValue((int)value)); classToValueCreator.put(int[].class, (Object value) -> new PropertyRecordIntArrayValue((int[])value)); classToValueCreator.put(Integer[].class, (Object value) -> new PropertyRecordIntWrapperArrayValue((Integer[])value)); classToListValueCreator.put(Integer.class, (Object value) -> new PropertyRecordIntListValue((List<Integer>)value)); classToSetValueCreator.put(Integer.class, (Object value) -> new PropertyRecordIntSetValue((Set<Integer>)value)); classToValueCreator.put(long.class, (Object value) -> new PropertyRecordLongValue((long)value)); classToValueCreator.put(Long.class, (Object value) -> new PropertyRecordLongValue((long)value)); classToValueCreator.put(long[].class, (Object value) -> new PropertyRecordLongArrayValue((long[])value)); classToValueCreator.put(Long[].class, (Object value) -> new PropertyRecordLongWrapperArrayValue((Long[])value)); classToListValueCreator.put(Long.class, (Object value) -> new PropertyRecordLongListValue((List<Long>)value)); classToSetValueCreator.put(Long.class, (Object value) -> new PropertyRecordLongSetValue((Set<Long>)value)); classToValueCreator.put(float.class, (Object value) -> new PropertyRecordFloatValue((float)value)); classToValueCreator.put(Float.class, (Object value) -> new PropertyRecordFloatValue((float)value)); classToValueCreator.put(float[].class, (Object value) -> new PropertyRecordFloatArrayValue((float[])value)); classToValueCreator.put(Float[].class, (Object value) -> new PropertyRecordFloatWrapperArrayValue((Float[])value)); classToListValueCreator.put(Float.class, (Object value) -> new PropertyRecordFloatListValue((List<Float>)value)); classToSetValueCreator.put(Float.class, (Object value) -> new PropertyRecordFloatSetValue((Set<Float>)value)); classToValueCreator.put(double.class, (Object value) -> new PropertyRecordDoubleValue((double)value)); classToValueCreator.put(Double.class, (Object value) -> new PropertyRecordDoubleValue((double)value)); classToValueCreator.put(double[].class, (Object value) -> new PropertyRecordDoubleArrayValue((double[])value)); classToValueCreator.put(Double[].class, (Object value) -> new PropertyRecordDoubleWrapperArrayValue((Double[])value)); classToListValueCreator.put(Double.class, (Object value) -> new PropertyRecordDoubleListValue((List<Double>)value)); classToSetValueCreator.put(Double.class, (Object value) -> new PropertyRecordDoubleSetValue((Set<Double>)value)); // special support, "built-in" classes classToValueCreator.put(String.class, (Object value) -> new PropertyRecordStringValue((String)value)); classToValueCreator.put(String[].class, (Object value) -> new PropertyRecordStringArrayValue((String[])value)); classToListValueCreator.put(String.class, (Object value) -> new PropertyRecordStringListValue((List<String>)value)); classToSetValueCreator.put(String.class, (Object value) -> new PropertyRecordStringSetValue((Set<String>)value)); classToValueCreator.put(Date.class, (Object value) -> new PropertyRecordDateValue((Date)value)); classToValueCreator.put(Date[].class, (Object value) -> new PropertyRecordDateArrayValue((Date[])value)); classToListValueCreator.put(Date.class, (Object value) -> new PropertyRecordDateListValue((List<Date>)value)); classToSetValueCreator.put(Date.class, (Object value) -> new PropertyRecordDateSetValue((Set<Date>)value)); // collection support PROPERTY_VALUE_CREATORS = Collections.unmodifiableMap(classToValueCreator); PROPERTY_LIST_VALUE_CREATORS = Collections.unmodifiableMap(classToListValueCreator); PROPERTY_SET_VALUE_CREATORS = Collections.unmodifiableMap(classToSetValueCreator); } @SuppressWarnings("unchecked") public static <T> PropertyRecordValue<T> createPropertyRecord(T value){ checkNotNull(value, "Precondition violation - argument 'value' must not be NULL!"); if(value instanceof List && value.getClass().getName().startsWith("java.util")){ if(((List<?>)value).isEmpty()){ return (PropertyRecordValue<T>) new PropertyRecordEmptyListValue(); } return createListValue((List)value); }else if(value instanceof Set && value.getClass().getName().startsWith("java.util")){ if(((Set<?>)value).isEmpty()){ return (PropertyRecordValue<T>) new PropertyRecordEmptySetValue(); } return createSetValue((Set)value); } else{ Function<Object, PropertyRecordValue<?>> creator = PROPERTY_VALUE_CREATORS.get(value.getClass()); if(creator == null){ // fall back to generic object creator = PropertyRecordCustomObjectValue::new; } return (PropertyRecordValue<T>) creator.apply(value); } } @SuppressWarnings({"unchecked", "rawtypes"}) public static <T> PropertyRecordValue<List<T>> createListValue(List<T> values) { Class<?> elementClass = null; for(T value : values){ if(value == null) { continue; } if(elementClass == null){ elementClass = value.getClass(); }else if(!elementClass.equals(value.getClass())){ // heterogeneous classes in list -> treat as generic object, but duplicate the list to eliminate unmodifiablelists. PropertyRecordValue result = new PropertyRecordCustomObjectValue(Lists.newArrayList(values)); return (PropertyRecordValue<List<T>>) result; } } if(elementClass == null){ // we have a list of only NULLs... fall back to generic object PropertyRecordValue result = new PropertyRecordCustomObjectValue(values); return (PropertyRecordValue<List<T>>) result; } Function<Object, PropertyRecordValue<? extends List<?>>> creator = PROPERTY_LIST_VALUE_CREATORS.get(elementClass); if(creator == null){ // custom element class -> fall back to generic object, but duplicate the list to eliminate unmodifiablelists. PropertyRecordValue result = new PropertyRecordCustomObjectValue(Lists.newArrayList(values)); return (PropertyRecordValue<List<T>>) result; }else{ return (PropertyRecordValue<List<T>>) creator.apply(values); } } @SuppressWarnings({"unchecked", "rawtypes"}) public static <T> PropertyRecordValue<Set<T>> createSetValue(Set<T> values){ Class<?> elementClass = null; for(T value : values){ if(value == null) { continue; } if(elementClass == null){ elementClass = value.getClass(); }else if(!elementClass.equals(value.getClass())){ // heterogeneous classes in list -> treat as generic object PropertyRecordValue result = new PropertyRecordCustomObjectValue(Sets.newHashSet(values)); return (PropertyRecordValue<Set<T>>) result; } } if(elementClass == null){ // we have a list of only NULLs... fall back to generic object PropertyRecordValue result = new PropertyRecordCustomObjectValue(values); return (PropertyRecordValue<Set<T>>) result; } Function<Object, PropertyRecordValue<? extends Set<?>>> creator = PROPERTY_SET_VALUE_CREATORS.get(elementClass); if(creator == null){ // custom element class -> fall back to generic object PropertyRecordValue result = new PropertyRecordCustomObjectValue(Sets.newHashSet(values)); return (PropertyRecordValue<Set<T>>) result; }else{ return (PropertyRecordValue<Set<T>>) creator.apply(values); } } }
12,149
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordCustomObjectValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordCustomObjectValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; import org.chronos.common.serialization.KryoManager; import java.util.Objects; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordCustomObjectValue implements PropertyRecordValue<Object> { protected byte[] value; protected PropertyRecordCustomObjectValue(){ // default constructor for kryo } public PropertyRecordCustomObjectValue(Object value){ checkNotNull(value, "Precondition violation - argument 'value' must not be NULL!"); this.value = KryoManager.serialize(value); } @Override public Object getValue() { return KryoManager.deserialize(this.value); } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordCustomObjectValue that = (PropertyRecordCustomObjectValue) o; return Objects.equals(this.getValue(), that.getValue()); } @Override public int hashCode() { Object value = this.getValue(); return value != null ? value.hashCode() : 0; } @Override public String toString() { return String.valueOf(this.getValue()); } }
1,404
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordStringArrayValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordStringArrayValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; import java.util.Arrays; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordStringArrayValue implements PropertyRecordValue<String[]> { private String[] array; protected PropertyRecordStringArrayValue(){ // default constructor for kryo } public PropertyRecordStringArrayValue(String[] array){ checkNotNull(array, "Precondition violation - argument 'array' must not be NULL!"); this.array = new String[array.length]; System.arraycopy(array, 0, this.array, 0, array.length); } @Override public String[] getValue() { String[] outArray = new String[this.array.length]; System.arraycopy(this.array, 0, outArray, 0, array.length); return outArray; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordStringArrayValue that = (PropertyRecordStringArrayValue) o; return Arrays.equals(array, that.array); } @Override public int hashCode() { return Arrays.hashCode(array); } @Override public String toString() { return Arrays.toString(this.array); } }
1,443
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordDateArrayValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordDateArrayValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; import java.util.Arrays; import java.util.Date; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordDateArrayValue implements PropertyRecordValue<Date[]> { private Long[] array; protected PropertyRecordDateArrayValue(){ // default constructor for kryo } public PropertyRecordDateArrayValue(Date[] array){ checkNotNull(array, "Precondition violation - argument 'array' must not be NULL!"); this.array = new Long[array.length]; for(int i = 0; i < this.array.length; i++){ Date date = array[i]; if(date == null){ this.array[i] = null; }else{ this.array[i] = date.getTime(); } } } @Override public Date[] getValue() { Date[] outArray = new Date[this.array.length]; for(int i = 0; i < this.array.length; i++){ Long time = this.array[i]; if(time == null){ outArray[i] = null; }else{ outArray[i] = new Date(time); } } return outArray; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordDateArrayValue that = (PropertyRecordDateArrayValue) o; return Arrays.equals(array, that.array); } @Override public int hashCode() { return Arrays.hashCode(array); } @Override public String toString() { return Arrays.toString(this.array); } }
1,800
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordCharWrapperArrayValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordCharWrapperArrayValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; import java.util.Arrays; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordCharWrapperArrayValue implements PropertyRecordValue<Character[]> { private Character[] array; protected PropertyRecordCharWrapperArrayValue(){ // default constructor for kryo } public PropertyRecordCharWrapperArrayValue(Character[] array){ checkNotNull(array, "Precondition violation - argument 'array' must not be NULL!"); this.array = new Character[array.length]; System.arraycopy(array, 0, this.array, 0, array.length); } @Override public Character[] getValue() { Character[] outArray = new Character[this.array.length]; System.arraycopy(this.array, 0, outArray, 0, array.length); return outArray; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordCharWrapperArrayValue that = (PropertyRecordCharWrapperArrayValue) o; // Probably incorrect - comparing Object[] arrays with Arrays.equals return Arrays.equals(array, that.array); } @Override public int hashCode() { return Arrays.hashCode(array); } @Override public String toString() { return Arrays.toString(this.array); } }
1,566
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordShortListValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordShortListValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import com.google.common.collect.Lists; import org.chronos.common.annotation.PersistentClass; import java.util.Collections; import java.util.List; import java.util.Objects; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordShortListValue implements PropertyRecordValue<List<Short>> { private List<Short> values; protected PropertyRecordShortListValue(){ // default constructor for kryo } public PropertyRecordShortListValue(List<Short> values){ checkNotNull(values, "Precondition violation - argument 'values' must not be NULL!"); this.values = Lists.newArrayList(values); } @Override public List<Short> getValue() { return Collections.unmodifiableList(this.values); } @Override public List<Short> getSerializationSafeValue() { return Lists.newArrayList(this.values); } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordShortListValue that = (PropertyRecordShortListValue) o; return Objects.equals(values, that.values); } @Override public int hashCode() { return values != null ? values.hashCode() : 0; } @Override public String toString() { return this.values.toString(); } }
1,518
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordShortSetValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordShortSetValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import com.google.common.collect.Sets; import org.chronos.common.annotation.PersistentClass; import java.util.Collections; import java.util.Objects; import java.util.Set; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordShortSetValue implements PropertyRecordValue<Set<Short>> { private Set<Short> values; protected PropertyRecordShortSetValue(){ // default constructor for kryo } public PropertyRecordShortSetValue(Set<Short> values){ checkNotNull(values, "Precondition violation - argument 'values' must not be NULL!"); this.values = Sets.newHashSet(values); } @Override public Set<Short> getValue() { return Collections.unmodifiableSet(this.values); } @Override public Set<Short> getSerializationSafeValue() { return Sets.newHashSet(this.values); } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordShortSetValue that = (PropertyRecordShortSetValue) o; return Objects.equals(values, that.values); } @Override public int hashCode() { return values != null ? values.hashCode() : 0; } @Override public String toString() { return this.values.toString(); } }
1,499
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordDoubleWrapperArrayValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordDoubleWrapperArrayValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; import java.util.Arrays; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordDoubleWrapperArrayValue implements PropertyRecordValue<Double[]> { private Double[] array; protected PropertyRecordDoubleWrapperArrayValue(){ // default constructor for kryo } public PropertyRecordDoubleWrapperArrayValue(Double[] array){ checkNotNull(array, "Precondition violation - argument 'array' must not be NULL!"); this.array = new Double[array.length]; System.arraycopy(array, 0, this.array, 0, array.length); } @Override public Double[] getValue() { Double[] outArray = new Double[this.array.length]; System.arraycopy(this.array, 0, outArray, 0, array.length); return outArray; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordDoubleWrapperArrayValue that = (PropertyRecordDoubleWrapperArrayValue) o; return Arrays.equals(array, that.array); } @Override public int hashCode() { return Arrays.hashCode(array); } @Override public String toString() { return Arrays.toString(this.array); } }
1,478
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordByteValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordByteValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; @PersistentClass("kryo") public class PropertyRecordByteValue implements PropertyRecordValue<Byte> { private byte value; protected PropertyRecordByteValue(){ // default constructor for kryo } public PropertyRecordByteValue(byte value){ this.value = value; } @Override public Byte getValue() { return this.value; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordByteValue that = (PropertyRecordByteValue) o; return value == that.value; } @Override public int hashCode() { return value; } @Override public String toString() { return String.valueOf(this.value); } }
974
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordCharArrayValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordCharArrayValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; import java.util.Arrays; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordCharArrayValue implements PropertyRecordValue<char[]> { private char[] array; protected PropertyRecordCharArrayValue(){ // default constructor for kryo } public PropertyRecordCharArrayValue(char[] array){ checkNotNull(array, "Precondition violation - argument 'array' must not be NULL!"); this.array = new char[array.length]; System.arraycopy(array, 0, this.array, 0, array.length); } @Override public char[] getValue() { char[] outArray = new char[this.array.length]; System.arraycopy(this.array, 0, outArray, 0, array.length); return outArray; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordCharArrayValue that = (PropertyRecordCharArrayValue) o; return Arrays.equals(array, that.array); } @Override public int hashCode() { return Arrays.hashCode(array); } @Override public String toString() { return Arrays.toString(this.array); } }
1,419
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordLongValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordLongValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; @PersistentClass("kryo") public class PropertyRecordLongValue implements PropertyRecordValue<Long> { private long value; protected PropertyRecordLongValue(){ // default constructor for kryo } public PropertyRecordLongValue(long value){ this.value = value; } @Override public Long getValue() { return this.value; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordLongValue that = (PropertyRecordLongValue) o; return value == that.value; } @Override public int hashCode() { return (int) (value ^ (value >>> 32)); } @Override public String toString() { return String.valueOf(this.value); } }
999
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordFloatArrayValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordFloatArrayValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; import java.util.Arrays; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordFloatArrayValue implements PropertyRecordValue<float[]> { private float[] array; protected PropertyRecordFloatArrayValue(){ // default constructor for kryo } public PropertyRecordFloatArrayValue(float[] array){ checkNotNull(array, "Precondition violation - argument 'array' must not be NULL!"); this.array = new float[array.length]; System.arraycopy(array, 0, this.array, 0, array.length); } @Override public float[] getValue() { float[] outArray = new float[this.array.length]; System.arraycopy(this.array, 0, outArray, 0, array.length); return outArray; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordFloatArrayValue that = (PropertyRecordFloatArrayValue) o; return Arrays.equals(array, that.array); } @Override public int hashCode() { return Arrays.hashCode(array); } @Override public String toString() { return Arrays.toString(this.array); } }
1,431
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordIntValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordIntValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; @PersistentClass("kryo") public class PropertyRecordIntValue implements PropertyRecordValue<Integer> { private int value; protected PropertyRecordIntValue(){ // default constructor for kryo } public PropertyRecordIntValue(int value){ this.value = value; } @Override public Integer getValue() { return this.value; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordIntValue that = (PropertyRecordIntValue) o; return value == that.value; } @Override public int hashCode() { return value; } @Override public String toString() { return String.valueOf(this.value); } }
973
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordShortValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordShortValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; @PersistentClass("kryo") public class PropertyRecordShortValue implements PropertyRecordValue<Short> { private short value; protected PropertyRecordShortValue(){ // default constructor for kryo } public PropertyRecordShortValue(short value){ this.value = value; } @Override public Short getValue() { return this.value; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordShortValue that = (PropertyRecordShortValue) o; return value == that.value; } @Override public int hashCode() { return value; } @Override public String toString() { return String.valueOf(this.value); } }
983
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordDoubleArrayValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordDoubleArrayValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; import java.util.Arrays; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordDoubleArrayValue implements PropertyRecordValue<double[]> { private double[] array; protected PropertyRecordDoubleArrayValue(){ // default constructor for kryo } public PropertyRecordDoubleArrayValue(double[] array){ checkNotNull(array, "Precondition violation - argument 'array' must not be NULL!"); this.array = new double[array.length]; System.arraycopy(array, 0, this.array, 0, array.length); } @Override public double[] getValue() { double[] outArray = new double[this.array.length]; System.arraycopy(this.array, 0, outArray, 0, array.length); return outArray; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordDoubleArrayValue that = (PropertyRecordDoubleArrayValue) o; return Arrays.equals(array, that.array); } @Override public int hashCode() { return Arrays.hashCode(array); } @Override public String toString() { return Arrays.toString(this.array); } }
1,443
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordDoubleSetValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordDoubleSetValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import com.google.common.collect.Sets; import org.chronos.common.annotation.PersistentClass; import java.util.Collections; import java.util.Objects; import java.util.Set; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordDoubleSetValue implements PropertyRecordValue<Set<Double>> { private Set<Double> values; protected PropertyRecordDoubleSetValue(){ // default constructor for kryo } public PropertyRecordDoubleSetValue(Set<Double> values){ checkNotNull(values, "Precondition violation - argument 'values' must not be NULL!"); this.values = Sets.newHashSet(values); } @Override public Set<Double> getValue() { return Collections.unmodifiableSet(this.values); } @Override public Set<Double> getSerializationSafeValue() { return Sets.newHashSet(this.values); } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordDoubleSetValue that = (PropertyRecordDoubleSetValue) o; return Objects.equals(values, that.values); } @Override public int hashCode() { return values != null ? values.hashCode() : 0; } @Override public String toString() { return this.values.toString(); } }
1,509
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordCharListValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordCharListValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import com.google.common.collect.Lists; import org.chronos.common.annotation.PersistentClass; import java.util.Collections; import java.util.List; import java.util.Objects; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordCharListValue implements PropertyRecordValue<List<Character>> { private List<Character> values; protected PropertyRecordCharListValue(){ // default constructor for kryo } public PropertyRecordCharListValue(List<Character> values){ checkNotNull(values, "Precondition violation - argument 'values' must not be NULL!"); this.values = Lists.newArrayList(values); } @Override public List<Character> getValue() { return Collections.unmodifiableList(this.values); } @Override public List<Character> getSerializationSafeValue() { return Lists.newArrayList(this.values); } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordCharListValue that = (PropertyRecordCharListValue) o; return Objects.equals(values, that.values); } @Override public int hashCode() { return values != null ? values.hashCode() : 0; } @Override public String toString() { return this.values.toString(); } }
1,533
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordStringValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordStringValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordStringValue implements PropertyRecordValue<String> { private String value; protected PropertyRecordStringValue(){ // default constructor for kryo } public PropertyRecordStringValue(String value) { checkNotNull(value, "Precondition violation - argument 'value' must not be NULL!"); this.value = value; } @Override public String getValue() { return value; } @Override public String toString() { return this.value; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordStringValue that = (PropertyRecordStringValue) o; return value != null ? value.equals(that.value) : that.value == null; } @Override public int hashCode() { return value != null ? value.hashCode() : 0; } }
1,192
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordByteListValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordByteListValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import com.google.common.collect.Lists; import org.chronos.common.annotation.PersistentClass; import java.util.Collections; import java.util.List; import java.util.Objects; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordByteListValue implements PropertyRecordValue<List<Byte>> { private List<Byte> values; protected PropertyRecordByteListValue(){ // default constructor for kryo } public PropertyRecordByteListValue(List<Byte> values){ checkNotNull(values, "Precondition violation - argument 'values' must not be NULL!"); this.values = Lists.newArrayList(values); } @Override public List<Byte> getValue() { return Collections.unmodifiableList(this.values); } @Override public List<Byte> getSerializationSafeValue() { return Lists.newArrayList(this.values); } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordByteListValue that = (PropertyRecordByteListValue) o; return Objects.equals(values, that.values); } @Override public int hashCode() { return values != null ? values.hashCode() : 0; } @Override public String toString() { return this.values.toString(); } }
1,508
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordLongWrapperArrayValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordLongWrapperArrayValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; import java.util.Arrays; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordLongWrapperArrayValue implements PropertyRecordValue<Long[]> { private Long[] array; protected PropertyRecordLongWrapperArrayValue(){ // default constructor for kryo } public PropertyRecordLongWrapperArrayValue(Long[] array){ checkNotNull(array, "Precondition violation - argument 'array' must not be NULL!"); this.array = new Long[array.length]; System.arraycopy(array, 0, this.array, 0, array.length); } @Override public Long[] getValue() { Long[] outArray = new Long[this.array.length]; System.arraycopy(this.array, 0, outArray, 0, array.length); return outArray; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordLongWrapperArrayValue that = (PropertyRecordLongWrapperArrayValue) o; return Arrays.equals(array, that.array); } @Override public int hashCode() { return Arrays.hashCode(array); } @Override public String toString() { return Arrays.toString(this.array); } }
1,454
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; import java.util.ArrayList; import java.util.HashSet; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public interface PropertyRecordValue<T> { @SuppressWarnings("unchecked") public static <V> PropertyRecordValue<V> of(V value){ checkNotNull(value, "Precondition violation - argument 'value' must not be NULL!"); return PropertyRecordValueUtil.createPropertyRecord(value); } public T getValue(); /** * Returns a variant of this value which is safe for serialization purposes, but may come at additional runtime overhead. * * <p> * For example, collection-type property record values always return unmodifiable collections with {@link #getValue()}. * For this method, they return copies of the original collections which are modifiable (e.g. {@link ArrayList}, {@link HashSet} etc.). * </p> * * @return The serialization-safe value. */ public default T getSerializationSafeValue(){ // to be overridden in subclasses return this.getValue(); } }
1,219
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordBooleanSetValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordBooleanSetValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import com.google.common.collect.Sets; import org.chronos.common.annotation.PersistentClass; import java.util.Collections; import java.util.Objects; import java.util.Set; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordBooleanSetValue implements PropertyRecordValue<Set<Boolean>> { private Set<Boolean> values; protected PropertyRecordBooleanSetValue(){ // default constructor for kryo } public PropertyRecordBooleanSetValue(Set<Boolean> values){ checkNotNull(values, "Precondition violation - argument 'values' must not be NULL!"); this.values = Sets.newHashSet(values); } @Override public Set<Boolean> getValue() { return Collections.unmodifiableSet(this.values); } @Override public Set<Boolean> getSerializationSafeValue() { return Sets.newHashSet(this.values); } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordBooleanSetValue that = (PropertyRecordBooleanSetValue) o; return Objects.equals(values, that.values); } @Override public int hashCode() { return values != null ? values.hashCode() : 0; } @Override public String toString() { return this.values.toString(); } }
1,519
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordIntArrayValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordIntArrayValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; import java.util.Arrays; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordIntArrayValue implements PropertyRecordValue<int[]> { private int[] array; protected PropertyRecordIntArrayValue(){ // default constructor for kryo } public PropertyRecordIntArrayValue(int[] array){ checkNotNull(array, "Precondition violation - argument 'array' must not be NULL!"); this.array = new int[array.length]; System.arraycopy(array, 0, this.array, 0, array.length); } @Override public int[] getValue() { int[] outArray = new int[this.array.length]; System.arraycopy(this.array, 0, outArray, 0, array.length); return outArray; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordIntArrayValue that = (PropertyRecordIntArrayValue) o; return Arrays.equals(array, that.array); } @Override public int hashCode() { return Arrays.hashCode(array); } @Override public String toString() { return Arrays.toString(this.array); } }
1,407
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordShortWrapperArrayValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordShortWrapperArrayValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; import java.util.Arrays; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordShortWrapperArrayValue implements PropertyRecordValue<Short[]> { private Short[] array; protected PropertyRecordShortWrapperArrayValue(){ // default constructor for kryo } public PropertyRecordShortWrapperArrayValue(Short[] array){ checkNotNull(array, "Precondition violation - argument 'array' must not be NULL!"); this.array = new Short[array.length]; System.arraycopy(array, 0, this.array, 0, array.length); } @Override public Short[] getValue() { Short[] outArray = new Short[this.array.length]; System.arraycopy(this.array, 0, outArray, 0, array.length); return outArray; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordShortWrapperArrayValue that = (PropertyRecordShortWrapperArrayValue) o; return Arrays.equals(array, that.array); } @Override public int hashCode() { return Arrays.hashCode(array); } @Override public String toString() { return Arrays.toString(this.array); } }
1,466
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordEmptyListValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordEmptyListValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import com.google.common.collect.Lists; import java.util.Collections; import java.util.List; public class PropertyRecordEmptyListValue implements PropertyRecordValue<List<Object>> { public PropertyRecordEmptyListValue() { // default constructor for kryo } @Override public List<Object> getValue() { return Collections.emptyList(); } @Override public List<Object> getSerializationSafeValue() { return Lists.newArrayList(); } @Override public String toString() { return "[]"; } @Override public int hashCode() { return 0; } @Override public boolean equals(final Object other) { if(other == null){ return false; } return this.getClass().equals(other.getClass()); } }
895
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordEmptySetValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordEmptySetValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import com.google.common.collect.Sets; import java.util.Collections; import java.util.List; import java.util.Set; public class PropertyRecordEmptySetValue implements PropertyRecordValue<Set<Object>> { public PropertyRecordEmptySetValue() { // default constructor for kryo } @Override public Set<Object> getValue() { return Collections.emptySet(); } @Override public Set<Object> getSerializationSafeValue() { return Sets.newHashSet(); } @Override public String toString() { return "[]"; } @Override public int hashCode() { return 0; } @Override public boolean equals(final Object other) { if(other == null){ return false; } return this.getClass().equals(other.getClass()); } }
907
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordIntListValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordIntListValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import com.google.common.collect.Lists; import org.chronos.common.annotation.PersistentClass; import java.util.Collections; import java.util.List; import java.util.Objects; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordIntListValue implements PropertyRecordValue<List<Integer>> { private List<Integer> values; protected PropertyRecordIntListValue(){ // default constructor for kryo } public PropertyRecordIntListValue(List<Integer> values){ checkNotNull(values, "Precondition violation - argument 'values' must not be NULL!"); this.values = Lists.newArrayList(values); } @Override public List<Integer> getValue() { return Collections.unmodifiableList(this.values); } @Override public List<Integer> getSerializationSafeValue() { return Lists.newArrayList(this.values); } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordIntListValue that = (PropertyRecordIntListValue) o; return Objects.equals(values, that.values); } @Override public int hashCode() { return values != null ? values.hashCode() : 0; } @Override public String toString() { return this.values.toString(); } }
1,518
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordIntWrapperArrayValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordIntWrapperArrayValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; import java.util.Arrays; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordIntWrapperArrayValue implements PropertyRecordValue<Integer[]> { private Integer[] array; protected PropertyRecordIntWrapperArrayValue(){ // default constructor for kryo } public PropertyRecordIntWrapperArrayValue(Integer[] array){ checkNotNull(array, "Precondition violation - argument 'array' must not be NULL!"); this.array = new Integer[array.length]; System.arraycopy(array, 0, this.array, 0, array.length); } @Override public Integer[] getValue() { Integer[] outArray = new Integer[this.array.length]; System.arraycopy(this.array, 0, outArray, 0, array.length); return outArray; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordIntWrapperArrayValue that = (PropertyRecordIntWrapperArrayValue) o; return Arrays.equals(array, that.array); } @Override public int hashCode() { return Arrays.hashCode(array); } @Override public String toString() { return Arrays.toString(this.array); } }
1,470
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordBooleanWrapperArrayValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordBooleanWrapperArrayValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; import java.util.Arrays; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordBooleanWrapperArrayValue implements PropertyRecordValue<Boolean[]> { private Boolean[] array; protected PropertyRecordBooleanWrapperArrayValue(){ // default constructor for kryo } public PropertyRecordBooleanWrapperArrayValue(Boolean[] array){ checkNotNull(array, "Precondition violation - argument 'array' must not be NULL!"); this.array = new Boolean[array.length]; System.arraycopy(array, 0, this.array, 0, array.length); } @Override public Boolean[] getValue() { Boolean[] outArray = new Boolean[this.array.length]; System.arraycopy(this.array, 0, outArray, 0, array.length); return outArray; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordBooleanWrapperArrayValue that = (PropertyRecordBooleanWrapperArrayValue) o; return Arrays.equals(array, that.array); } @Override public int hashCode() { return Arrays.hashCode(array); } @Override public String toString() { return Arrays.toString(this.array); } }
1,486
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordByteWrapperArrayValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordByteWrapperArrayValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; import java.util.Arrays; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordByteWrapperArrayValue implements PropertyRecordValue<Byte[]> { private Byte[] array; protected PropertyRecordByteWrapperArrayValue(){ // default constructor for kryo } public PropertyRecordByteWrapperArrayValue(Byte[] array){ checkNotNull(array, "Precondition violation - argument 'array' must not be NULL!"); this.array = new Byte[array.length]; System.arraycopy(array, 0, this.array, 0, array.length); } @Override public Byte[] getValue() { Byte[] outArray = new Byte[this.array.length]; System.arraycopy(this.array, 0, outArray, 0, array.length); return outArray; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordByteWrapperArrayValue that = (PropertyRecordByteWrapperArrayValue) o; return Arrays.equals(array, that.array); } @Override public int hashCode() { return Arrays.hashCode(array); } @Override public String toString() { return Arrays.toString(this.array); } }
1,454
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordFloatWrapperArrayValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordFloatWrapperArrayValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; import java.util.Arrays; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordFloatWrapperArrayValue implements PropertyRecordValue<Float[]> { private Float[] array; protected PropertyRecordFloatWrapperArrayValue(){ // default constructor for kryo } public PropertyRecordFloatWrapperArrayValue(Float[] array){ checkNotNull(array, "Precondition violation - argument 'array' must not be NULL!"); this.array = new Float[array.length]; System.arraycopy(array, 0, this.array, 0, array.length); } @Override public Float[] getValue() { Float[] outArray = new Float[this.array.length]; System.arraycopy(this.array, 0, outArray, 0, array.length); return outArray; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordFloatWrapperArrayValue that = (PropertyRecordFloatWrapperArrayValue) o; return Arrays.equals(array, that.array); } @Override public int hashCode() { return Arrays.hashCode(array); } @Override public String toString() { return Arrays.toString(this.array); } }
1,466
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordByteArrayValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordByteArrayValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; import java.util.Arrays; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordByteArrayValue implements PropertyRecordValue<byte[]> { private byte[] array; protected PropertyRecordByteArrayValue(){ // default constructor for kryo } public PropertyRecordByteArrayValue(byte[] array){ checkNotNull(array, "Precondition violation - argument 'array' must not be NULL!"); this.array = new byte[array.length]; System.arraycopy(array, 0, this.array, 0, array.length); } @Override public byte[] getValue() { byte[] outArray = new byte[this.array.length]; System.arraycopy(this.array, 0, outArray, 0, array.length); return outArray; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordByteArrayValue that = (PropertyRecordByteArrayValue) o; return Arrays.equals(array, that.array); } @Override public int hashCode() { return Arrays.hashCode(array); } @Override public String toString() { return Arrays.toString(this.array); } }
1,419
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordCharSetValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordCharSetValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import com.google.common.collect.Sets; import org.chronos.common.annotation.PersistentClass; import java.util.Collections; import java.util.Objects; import java.util.Set; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordCharSetValue implements PropertyRecordValue<Set<Character>> { private Set<Character> values; protected PropertyRecordCharSetValue(){ // default constructor for kryo } public PropertyRecordCharSetValue(Set<Character> values){ checkNotNull(values, "Precondition violation - argument 'values' must not be NULL!"); this.values = Sets.newHashSet(values); } @Override public Set<Character> getValue() { return Collections.unmodifiableSet(this.values); } @Override public Set<Character> getSerializationSafeValue() { return Sets.newHashSet(this.values); } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordCharSetValue that = (PropertyRecordCharSetValue) o; return Objects.equals(values, that.values); } @Override public int hashCode() { return values != null ? values.hashCode() : 0; } @Override public String toString() { return this.values.toString(); } }
1,514
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordBooleanValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordBooleanValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; @PersistentClass("kryo") public class PropertyRecordBooleanValue implements PropertyRecordValue<Boolean> { private boolean value; protected PropertyRecordBooleanValue(){ // default constructor for kryo } public PropertyRecordBooleanValue(boolean value){ this.value = value; } @Override public Boolean getValue() { return this.value; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordBooleanValue that = (PropertyRecordBooleanValue) o; return value == that.value; } @Override public int hashCode() { return (value ? 1 : 0); } @Override public String toString() { return String.valueOf(this.value); } }
1,011
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordBooleanListValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordBooleanListValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import com.google.common.collect.Lists; import org.chronos.common.annotation.PersistentClass; import java.util.Collections; import java.util.List; import java.util.Objects; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordBooleanListValue implements PropertyRecordValue<List<Boolean>> { private List<Boolean> values; protected PropertyRecordBooleanListValue(){ // default constructor for kryo } public PropertyRecordBooleanListValue(List<Boolean> values){ checkNotNull(values, "Precondition violation - argument 'values' must not be NULL!"); this.values = Lists.newArrayList(values); } @Override public List<Boolean> getValue() { return Collections.unmodifiableList(this.values); } @Override public List<Boolean> getSerializationSafeValue() { return Lists.newArrayList(this.values); } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordBooleanListValue that = (PropertyRecordBooleanListValue) o; return Objects.equals(values, that.values); } @Override public int hashCode() { return values != null ? values.hashCode() : 0; } @Override public String toString() { return this.values.toString(); } }
1,538
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordFloatListValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordFloatListValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import com.google.common.collect.Lists; import org.chronos.common.annotation.PersistentClass; import java.util.Collections; import java.util.List; import java.util.Objects; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordFloatListValue implements PropertyRecordValue<List<Float>> { private List<Float> values; protected PropertyRecordFloatListValue(){ // default constructor for kryo } public PropertyRecordFloatListValue(List<Float> values){ checkNotNull(values, "Precondition violation - argument 'values' must not be NULL!"); this.values = Lists.newArrayList(values); } @Override public List<Float> getValue() { return Collections.unmodifiableList(this.values); } @Override public List<Float> getSerializationSafeValue() { return Lists.newArrayList(this.values); } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordFloatListValue that = (PropertyRecordFloatListValue) o; return Objects.equals(values, that.values); } @Override public int hashCode() { return values != null ? values.hashCode() : 0; } @Override public String toString() { return this.values.toString(); } }
1,518
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordDoubleValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordDoubleValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; @PersistentClass("kryo") public class PropertyRecordDoubleValue implements PropertyRecordValue<Double> { private double value; protected PropertyRecordDoubleValue(){ // default constructor for kryo } public PropertyRecordDoubleValue(double value){ this.value = value; } @Override public Double getValue() { return this.value; } @Override public String toString() { return String.valueOf(this.value); } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordDoubleValue that = (PropertyRecordDoubleValue) o; return Double.compare(that.value, value) == 0; } @Override public int hashCode() { long temp = Double.doubleToLongBits(value); return (int) (temp ^ (temp >>> 32)); } }
1,086
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordDateSetValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordDateSetValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import com.google.common.collect.Sets; import org.chronos.common.annotation.PersistentClass; import org.jetbrains.annotations.NotNull; import java.util.*; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordDateSetValue implements PropertyRecordValue<Set<Date>> { private Set<Long> values; protected PropertyRecordDateSetValue(){ // default constructor for kryo } public PropertyRecordDateSetValue(Set<Date> values){ checkNotNull(values, "Precondition violation - argument 'values' must not be NULL!"); this.values = Sets.newHashSetWithExpectedSize(values.size()); for (Date date : values) { if (date == null) { this.values.add(null); } else { this.values.add(date.getTime()); } } } @Override public Set<Date> getValue() { return Collections.unmodifiableSet(getDates()); } @Override public Set<Date> getSerializationSafeValue() { return getDates(); } @NotNull private Set<Date> getDates() { Set<Date> resultList = Sets.newHashSetWithExpectedSize(this.values.size()); for (Long time : this.values) { if (time == null) { resultList.add(null); } else { resultList.add(new Date(time)); } } return resultList; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordDateSetValue that = (PropertyRecordDateSetValue) o; return Objects.equals(values, that.values); } @Override public int hashCode() { return values != null ? values.hashCode() : 0; } @Override public String toString() { return this.values.toString(); } }
2,047
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordDateValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordDateValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import java.util.Date; public class PropertyRecordDateValue implements PropertyRecordValue<Date> { private long timestamp; protected PropertyRecordDateValue(){ // default constructor for kryo } public PropertyRecordDateValue(Date date){ this.timestamp = date.getTime(); } @Override public Date getValue() { return new Date(this.timestamp); } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordDateValue that = (PropertyRecordDateValue) o; return timestamp == that.timestamp; } @Override public int hashCode() { return (int) (timestamp ^ (timestamp >>> 32)); } @Override public String toString() { return this.getValue().toString(); } }
989
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordLongArrayValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordLongArrayValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; import java.util.Arrays; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordLongArrayValue implements PropertyRecordValue<long[]> { private long[] array; protected PropertyRecordLongArrayValue(){ // default constructor for kryo } public PropertyRecordLongArrayValue(long[] array){ checkNotNull(array, "Precondition violation - argument 'array' must not be NULL!"); this.array = new long[array.length]; System.arraycopy(array, 0, this.array, 0, array.length); } @Override public long[] getValue() { long[] outArray = new long[this.array.length]; System.arraycopy(this.array, 0, outArray, 0, array.length); return outArray; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordLongArrayValue that = (PropertyRecordLongArrayValue) o; return Arrays.equals(array, that.array); } @Override public int hashCode() { return Arrays.hashCode(array); } @Override public String toString() { return Arrays.toString(this.array); } }
1,419
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordBooleanArrayValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordBooleanArrayValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; import java.util.Arrays; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordBooleanArrayValue implements PropertyRecordValue<boolean[]> { private boolean[] array; protected PropertyRecordBooleanArrayValue(){ // default constructor for kryo } public PropertyRecordBooleanArrayValue(boolean[] array){ checkNotNull(array, "Precondition violation - argument 'array' must not be NULL!"); this.array = new boolean[array.length]; System.arraycopy(array, 0, this.array, 0, array.length); } @Override public boolean[] getValue() { boolean[] outArray = new boolean[this.array.length]; System.arraycopy(this.array, 0, outArray, 0, array.length); return outArray; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordBooleanArrayValue that = (PropertyRecordBooleanArrayValue) o; return Arrays.equals(array, that.array); } @Override public int hashCode() { return Arrays.hashCode(array); } @Override public String toString() { return Arrays.toString(this.array); } }
1,451
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordFloatValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordFloatValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import org.chronos.common.annotation.PersistentClass; @PersistentClass("kryo") public class PropertyRecordFloatValue implements PropertyRecordValue<Float> { private float value; protected PropertyRecordFloatValue(){ // default constructor for kryo } public PropertyRecordFloatValue(float value){ this.value = value; } @Override public Float getValue() { return this.value; } @Override public String toString() { return String.valueOf(this.value); } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordFloatValue that = (PropertyRecordFloatValue) o; return Float.compare(that.value, value) == 0; } @Override public int hashCode() { return (value != +0.0f ? Float.floatToIntBits(value) : 0); } }
1,046
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PropertyRecordIntSetValue.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record2/valuerecords/PropertyRecordIntSetValue.java
package org.chronos.chronograph.internal.impl.structure.record2.valuerecords; import com.google.common.collect.Sets; import org.chronos.common.annotation.PersistentClass; import java.util.Collections; import java.util.Objects; import java.util.Set; import static com.google.common.base.Preconditions.*; @PersistentClass("kryo") public class PropertyRecordIntSetValue implements PropertyRecordValue<Set<Integer>> { private Set<Integer> values; protected PropertyRecordIntSetValue(){ // default constructor for kryo } public PropertyRecordIntSetValue(Set<Integer> values){ checkNotNull(values, "Precondition violation - argument 'values' must not be NULL!"); this.values = Sets.newHashSet(values); } @Override public Set<Integer> getValue() { return Collections.unmodifiableSet(this.values); } @Override public Set<Integer> getSerializationSafeValue() { return Sets.newHashSet(this.values); } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyRecordIntSetValue that = (PropertyRecordIntSetValue) o; return Objects.equals(values, that.values); } @Override public int hashCode() { return values != null ? values.hashCode() : 0; } @Override public String toString() { return this.values.toString(); } }
1,499
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoProperty.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/ChronoProperty.java
package org.chronos.chronograph.internal.impl.structure.graph; import org.apache.tinkerpop.gremlin.structure.Property; import org.apache.tinkerpop.gremlin.structure.util.ElementHelper; import org.apache.tinkerpop.gremlin.structure.util.StringFactory; import org.chronos.chronograph.api.structure.record.IPropertyRecord; import org.chronos.chronograph.api.transaction.ChronoGraphTransaction; import org.chronos.chronograph.internal.api.structure.ChronoElementInternal; import org.chronos.chronograph.internal.api.transaction.GraphTransactionContextInternal; import org.chronos.chronograph.internal.impl.structure.record2.PropertyRecord2; import java.util.NoSuchElementException; public class ChronoProperty<V> implements Property<V> { private final ChronoElementInternal owner; private final String key; private V value; private boolean removed; public ChronoProperty(final ChronoElementInternal owner, final String key, final V value) { this(owner, key, value, false); } public ChronoProperty(final ChronoElementInternal owner, final String key, final V value, final boolean silent) { this.owner = owner; this.key = key; this.set(value, silent); } @Override public String key() { return this.key; } @Override public V value() throws NoSuchElementException { if (this.removed) { throw new NoSuchElementException("Property '" + this.key + "' was removed and is no longer present!"); } return this.value; } public void set(final V value) { this.set(value, false); } private void set(final V value, final boolean silent) { if (this.removed) { throw new NoSuchElementException("Property '" + this.key + "' was removed and is no longer present!"); } if (value == null) { this.remove(); } else { this.value = value; if (silent == false) { this.element().notifyPropertyChanged(this); this.getTransactionContext().markPropertyAsModified(this); } } } @Override public boolean isPresent() { return this.removed == false; } @Override public ChronoElementInternal element() { return this.owner; } @Override public void remove() { if (this.removed) { return; } this.getTransactionContext().markPropertyAsDeleted(this); this.removed = true; this.owner.removeProperty(this.key); } public boolean isRemoved() { return this.removed; } public IPropertyRecord toRecord() { return new PropertyRecord2(this.key, this.value); } @Override public int hashCode() { return ElementHelper.hashCode(this); } @Override public boolean equals(final Object obj) { return ElementHelper.areEqual(this, obj); } @Override public String toString() { return StringFactory.propertyString(this); } protected ChronoGraphTransaction getGraphTransaction() { return this.owner.graph().tx().getCurrentTransaction(); } protected GraphTransactionContextInternal getTransactionContext() { return (GraphTransactionContextInternal) this.getGraphTransaction().getContext(); } }
3,363
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoVertexProperty.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/ChronoVertexProperty.java
package org.chronos.chronograph.internal.impl.structure.graph; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import org.apache.tinkerpop.gremlin.structure.Element; import org.apache.tinkerpop.gremlin.structure.Property; import org.apache.tinkerpop.gremlin.structure.VertexProperty; import org.apache.tinkerpop.gremlin.structure.util.ElementHelper; import org.chronos.chronograph.api.structure.ChronoGraph; import org.chronos.chronograph.api.structure.ElementLifecycleStatus; import org.chronos.chronograph.api.structure.PropertyStatus; import org.chronos.chronograph.api.structure.record.IVertexPropertyRecord; import org.chronos.chronograph.api.transaction.ChronoGraphTransaction; import org.chronos.chronograph.internal.api.structure.ChronoElementInternal; import org.chronos.chronograph.internal.impl.structure.record3.SimpleVertexPropertyRecord; import org.chronos.chronograph.internal.impl.structure.record3.VertexPropertyRecord3; import org.chronos.chronograph.internal.impl.util.ChronoGraphElementUtil; import org.chronos.chronograph.internal.impl.util.PredefinedProperty; import java.util.Iterator; import java.util.Map; import java.util.Set; import static com.google.common.base.Preconditions.*; public class ChronoVertexProperty<V> extends ChronoProperty<V> implements VertexProperty<V>, ChronoElementInternal { // ================================================================================================================= // FIELDS // ================================================================================================================= private final Map<String, ChronoProperty<?>> properties; // ================================================================================================================= // CONSTRUCTOR // ================================================================================================================= public ChronoVertexProperty(final ChronoVertexImpl owner, final String key, final V value) { super(owner, key, value, true); this.properties = Maps.newHashMap(); } // ================================================================================================================= // TINKERPOP 3 API // ================================================================================================================= @Override public String id() { return this.element().id() + "->" + this.key(); } @Override public String label() { return this.key(); } @Override public ChronoGraph graph() { return this.element().graph(); } @Override public ChronoVertexImpl element() { return (ChronoVertexImpl) super.element(); } @Override public <T> ChronoProperty<T> property(final String key, final T value) { checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); return this.property(key, value, false); } public <T> ChronoProperty<T> property(final String key, final T value, boolean silent) { checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); ChronoProperty<T> newProperty = new ChronoProperty<>(this, key, value, silent); this.properties.put(key, newProperty); this.updateLifecycleStatus(ElementLifecycleEvent.PROPERTY_CHANGED); return newProperty; } @Override @SuppressWarnings("rawtypes") public <T> Iterator<Property<T>> properties(final String... propertyKeys) { Set<Property> matchingProperties = Sets.newHashSet(); if (propertyKeys == null || propertyKeys.length <= 0) { matchingProperties.addAll(this.properties.values()); } else { for (String key : propertyKeys) { PredefinedProperty<?> predefinedProperty = ChronoGraphElementUtil.asPredefinedProperty(this, key); if (predefinedProperty != null) { matchingProperties.add(predefinedProperty); } Property property = this.properties.get(key); if (property != null) { matchingProperties.add(property); } } } return new PropertiesIterator<>(matchingProperties.iterator()); } @Override public long getLoadedAtRollbackCount() { throw new UnsupportedOperationException("VertexProperties do not support 'loaded at rollback count'!"); } @Override public ChronoGraphTransaction getOwningTransaction() { throw new UnsupportedOperationException("VertexProperties do not support 'getOwningTransaction'!"); } @Override public PropertyStatus getPropertyStatus(final String propertyKey) { throw new UnsupportedOperationException("getPropertyStatus(...) is not supported for meta-properties."); } @Override public boolean isLazy() { // at the point where we have access to a vertex property, // the properties are always loaded. return false; } // ================================================================================================================= // INTERNAL API // ================================================================================================================= @Override public void removeProperty(final String key) { this.properties.remove(key); this.element().notifyPropertyChanged(this); this.updateLifecycleStatus(ElementLifecycleEvent.PROPERTY_CHANGED); } @Override public void notifyPropertyChanged(final ChronoProperty<?> chronoProperty) { // propagate notification to our parent this.element().notifyPropertyChanged(this); } @Override public void validateGraphInvariant() { // nothing to do here } @Override public IVertexPropertyRecord toRecord() { if(this.properties == null || this.properties.isEmpty()){ // no meta-properties present, use a simple property instead return new SimpleVertexPropertyRecord(this.key(), this.value()); }else{ // use full-blown property return new VertexPropertyRecord3(this.key(), this.value(), this.properties()); } } @Override public void updateLifecycleStatus(final ElementLifecycleEvent event) { if (event != ElementLifecycleEvent.SAVED) { this.element().updateLifecycleStatus(ElementLifecycleEvent.PROPERTY_CHANGED); } } @Override public ElementLifecycleStatus getStatus() { if (this.isRemoved()) { return ElementLifecycleStatus.REMOVED; } else { // TODO properties do not separately track their status, using the element status is not entirely correct. return this.element().getStatus(); } } @Override public int hashCode() { return ElementHelper.hashCode((Element) this); } @Override public boolean equals(final Object obj) { return ElementHelper.areEqual(this, obj); } // ================================================================================================================= // INNER CLASSES // ================================================================================================================= private class PropertiesIterator<T> implements Iterator<Property<T>> { @SuppressWarnings("rawtypes") private Iterator<Property> iter; @SuppressWarnings("rawtypes") public PropertiesIterator(final Iterator<Property> iter) { this.iter = iter; } @Override public boolean hasNext() { return this.iter.hasNext(); } @Override @SuppressWarnings("unchecked") public Property<T> next() { Property<T> p = this.iter.next(); return p; } } }
8,001
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoVertexImpl.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/ChronoVertexImpl.java
package org.chronos.chronograph.internal.impl.structure.graph; import com.google.common.base.Objects; import com.google.common.collect.HashMultimap; import com.google.common.collect.Iterators; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.SetMultimap; import com.google.common.collect.Sets; import com.google.common.collect.Streams; import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.structure.VertexProperty; import org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality; import org.apache.tinkerpop.gremlin.structure.util.ElementHelper; import org.apache.tinkerpop.gremlin.structure.util.StringFactory; import org.chronos.chronograph.api.exceptions.GraphInvariantViolationException; import org.chronos.chronograph.api.jmx.ChronoGraphTransactionStatistics; import org.chronos.chronograph.api.structure.ChronoEdge; import org.chronos.chronograph.api.structure.ChronoVertex; import org.chronos.chronograph.api.structure.PropertyStatus; import org.chronos.chronograph.api.structure.record.IEdgeTargetRecord; import org.chronos.chronograph.api.structure.record.IPropertyRecord; import org.chronos.chronograph.api.structure.record.IVertexPropertyRecord; import org.chronos.chronograph.api.structure.record.IVertexRecord; import org.chronos.chronograph.api.transaction.ChronoGraphTransaction; import org.chronos.chronograph.internal.ChronoGraphConstants; import org.chronos.chronograph.internal.api.structure.ChronoGraphInternal; import org.chronos.chronograph.internal.api.transaction.ChronoGraphTransactionInternal; import org.chronos.chronograph.internal.impl.structure.record.EdgeTargetRecordWithLabel; import org.chronos.chronograph.internal.impl.structure.record2.EdgeTargetRecord2; import org.chronos.chronograph.internal.impl.structure.record3.VertexRecord3; import org.chronos.chronograph.internal.impl.util.ChronoGraphElementUtil; import org.chronos.chronograph.internal.impl.util.ChronoGraphLoggingUtil; import org.chronos.chronograph.internal.impl.util.ChronoId; import org.chronos.chronograph.internal.impl.util.ChronoProxyUtil; import org.chronos.chronograph.internal.impl.util.PredefinedVertexProperty; import org.chronos.common.exceptions.UnknownEnumLiteralException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.lang.ref.Reference; import java.lang.ref.WeakReference; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; import static com.google.common.base.Preconditions.*; import static org.chronos.common.logging.ChronosLogMarker.*; public class ChronoVertexImpl extends AbstractChronoElement implements Vertex, ChronoVertex { private static final Logger log = LoggerFactory.getLogger(ChronoVertexImpl.class); // ================================================================================================================= // FIELDS // ================================================================================================================= private SetMultimap<String, ChronoEdge> labelToIncomingEdges = null; private SetMultimap<String, ChronoEdge> labelToOutgoingEdges = null; private Map<String, ChronoVertexProperty<?>> properties = null; protected Reference<IVertexRecord> recordReference; // ================================================================================================================= // CONSTRUCTOR // ================================================================================================================= public ChronoVertexImpl(final String id, final ChronoGraphInternal g, final ChronoGraphTransactionInternal tx, final String label) { this(g, tx, id, label); } public ChronoVertexImpl(final ChronoGraphInternal g, final ChronoGraphTransactionInternal tx, final IVertexRecord record) { super(g, tx, record.getId(), record.getLabel()); this.recordReference = new WeakReference<>(record); this.updateLifecycleStatus(ElementLifecycleEvent.RELOADED_FROM_DB_AND_IN_SYNC); } public ChronoVertexImpl(final ChronoGraphInternal g, final ChronoGraphTransactionInternal tx, final String id, final String label) { super(g, tx, id, label); this.labelToOutgoingEdges = HashMultimap.create(); this.labelToIncomingEdges = HashMultimap.create(); this.properties = Maps.newHashMap(); this.recordReference = null; } // ================================================================================================================= // TINKERPOP 3 API // ================================================================================================================= @Override public String label() { this.checkAccess(); return super.label(); } @Override @SuppressWarnings("unchecked") public <V> VertexProperty<V> property(final String key, final V value) { checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); this.checkAccess(); this.ensureVertexRecordIsLoaded(); if(value == null){ // Since Gremlin 3.5.2: setting a property to value NULL removes it. this.removeProperty(key); return VertexProperty.empty(); } this.logPropertyChange(key, value); if (this.properties == null) { this.properties = Maps.newHashMap(); } ChronoVertexProperty<V> property = (ChronoVertexProperty<V>) this.properties.get(key); if (property == null) { property = new ChronoVertexProperty<>(this, key, value); this.changePropertyStatus(key, PropertyStatus.NEW); this.getTransactionContext().markPropertyAsModified(property); this.properties.put(key, property); } else { property.set(value); this.changePropertyStatus(key, PropertyStatus.MODIFIED); } this.updateLifecycleStatus(ElementLifecycleEvent.PROPERTY_CHANGED); return property; } @Override public ChronoEdge addEdge(final String label, final Vertex inVertex, final Object... keyValues) { this.checkAccess(); ElementHelper.validateLabel(label); ElementHelper.legalPropertyKeyValueArray(keyValues); if (inVertex == null) { throw Graph.Exceptions.argumentCanNotBeNull("inVertex"); } Object id = ElementHelper.getIdValue(keyValues).orElse(null); boolean userProvidedId = true; if (id != null && id instanceof String == false) { throw Edge.Exceptions.userSuppliedIdsOfThisTypeNotSupported(); } this.ensureVertexRecordIsLoaded(); if (id == null) { id = ChronoId.random(); // we generated the ID ourselves, it did not come from the user userProvidedId = false; } String edgeId = (String) id; this.graph.tx().readWrite(); ChronoGraphTransaction graphTx = this.graph.tx().getCurrentTransaction(); this.logAddEdge(inVertex, edgeId, userProvidedId, label); ChronoEdge edge = graphTx.addEdge(this, (ChronoVertex) inVertex, edgeId, userProvidedId, label, keyValues); // add it as an outgoing edge to this vertex if (edge.outVertex().equals(this) == false) { throw new IllegalStateException("Edge is messed up"); } this.labelToOutgoingEdges.put(label, edge); // add it as an incoming edge to the target vertex ChronoVertexImpl inV = ChronoProxyUtil.resolveVertexProxy(inVertex); if (edge.inVertex().equals(inV) == false) { throw new IllegalStateException("Edge is messed up"); } inV.ensureVertexRecordIsLoaded(); inV.labelToIncomingEdges.put(label, edge); this.updateLifecycleStatus(ElementLifecycleEvent.ADJACENT_EDGE_ADDED_OR_REMOVED); inV.updateLifecycleStatus(ElementLifecycleEvent.ADJACENT_EDGE_ADDED_OR_REMOVED); return edge; } @Override public <V> ChronoVertexProperty<V> property(final String key, final V value, final Object... keyValues) { this.checkAccess(); return this.property(Cardinality.list, key, value, keyValues); } @Override public <V> ChronoVertexProperty<V> property(final Cardinality cardinality, final String key, final V value, final Object... keyValues) { ElementHelper.legalPropertyKeyValueArray(keyValues); ElementHelper.validateProperty(key, value); this.checkAccess(); Object id = ElementHelper.getIdValue(keyValues).orElse(null); if (id != null) { // user-supplied ids are not supported throw VertexProperty.Exceptions.userSuppliedIdsNotSupported(); } // // the "stageVertexProperty" helper method checks the cardinality and the given parameters. If the // // cardinality and parameters indicate that an existing property should be returned, the optional is // // non-empty. // Optional<VertexProperty<V>> optionalVertexProperty = ElementHelper.stageVertexProperty(this, cardinality, // key, // value, keyValues); // if (optionalVertexProperty.isPresent()) { // // according to cardinality and other parameters, the property already exists, so return it // return (ChronoVertexProperty<V>) optionalVertexProperty.get(); // } this.ensureVertexRecordIsLoaded(); this.logPropertyChange(key, value); ChronoVertexProperty<V> property = new ChronoVertexProperty<>(this, key, value); ElementHelper.attachProperties(property, keyValues); if (this.property(key).isPresent()) { this.changePropertyStatus(key, PropertyStatus.MODIFIED); } else { this.changePropertyStatus(key, PropertyStatus.NEW); } this.properties.put(key, property); this.getTransactionContext().markPropertyAsModified(property); this.updateLifecycleStatus(ElementLifecycleEvent.PROPERTY_CHANGED); return property; } @Override @SuppressWarnings({"unchecked", "rawtypes"}) public Iterator<Edge> edges(final Direction direction, final String... edgeLabels) { this.checkAccess(); if (this.recordReference != null) { // we're in read-only mode return this.edgesFromLazyVertex(direction, edgeLabels); } else { // we're in read-write mode return this.edgesFromLoadedVertex(direction, edgeLabels); } } private Iterator<Edge> edgesFromLazyVertex(final Direction direction, String... edgeLabels) { IVertexRecord vertexRecord = this.getRecord(); switch (direction) { case BOTH: // note that we do NOT want self-edges (e.g. v1->v1) to appear twice. Therefore, we use // a set to eliminate duplicates. Furthermore, Gremlin wants ot have out-edges before in-edges // in the iterator, so we use concatenated streams to ensure this. Furthermore, // "record.getOutgoingEdges(labels)" and "record.getIncomingEdges(labels)" will return ALL // of their respective edges if the "edgeLabels" parameter is NULL or empty, which is in line // with the gremlin specification. List<EdgeTargetRecordWithLabel> outgoingEdges = vertexRecord.getOutgoingEdges(edgeLabels); List<EdgeTargetRecordWithLabel> incomingEdges = vertexRecord.getIncomingEdges(edgeLabels); return Stream.concat( outgoingEdges.stream().map(this::loadOutgoingEdgeTargetRecord), incomingEdges.stream().map(this::loadIncomingEdgeTargetRecord) ).iterator(); case IN: return Iterators.transform(vertexRecord.getIncomingEdges(edgeLabels).iterator(), this::loadIncomingEdgeTargetRecord); case OUT: return Iterators.transform(vertexRecord.getOutgoingEdges(edgeLabels).iterator(), this::loadOutgoingEdgeTargetRecord); default: throw new UnknownEnumLiteralException(direction); } } private Iterator edgesFromLoadedVertex(final Direction direction, String... edgeLabels) { switch (direction) { case BOTH: if (edgeLabels == null || edgeLabels.length <= 0) { // return all // note that we wrap the internal collections in new hash sets; gremlin specification states // that no concurrent modification excpetions should ever be thrown when iterating over edges // in a single-threaded program. int expectedSize = this.labelToOutgoingEdges.size() + this.labelToIncomingEdges.size(); List<Edge> edges = Lists.newArrayListWithExpectedSize(expectedSize); // Gremlin wants ot have out-edges before in-edges in the iterator. edges.addAll(this.labelToOutgoingEdges.values()); edges.addAll(this.labelToIncomingEdges.values()); return edges.iterator(); } else { // return the ones with matching labels List<Edge> edges = Stream.of(edgeLabels).distinct().flatMap(edgeLabel -> Streams.concat( this.labelToOutgoingEdges.get(edgeLabel).stream(), this.labelToIncomingEdges.get(edgeLabel).stream() ) ).collect(Collectors.toList()); return edges.iterator(); } case IN: if (edgeLabels == null || edgeLabels.length <= 0) { // return all // note that we wrap the internal collections in new hash sets; gremlin specification states // that no concurrent modification exceptions should ever be thrown when iterating over edges // in a single-threaded program. return Lists.newArrayList(this.labelToIncomingEdges.values()).iterator(); } else { // return the ones with matching labels List<Edge> list = Stream.of(edgeLabels) .flatMap(label -> this.labelToIncomingEdges.get(label).stream()) .collect(Collectors.toList()); return list.iterator(); } case OUT: if (edgeLabels == null || edgeLabels.length <= 0) { // return all // note that we wrap the internal collections in new hash sets; gremlin specification states // that no concurrent modification exceptions should ever be thrown when iterating over edges // in a single-threaded program. return Lists.newArrayList(this.labelToOutgoingEdges.values()).iterator(); } else { // return the ones with matching labels List<Edge> list = Stream.of(edgeLabels) .flatMap(label -> this.labelToOutgoingEdges.get(label).stream()) .collect(Collectors.toList()); return list.iterator(); } default: throw new UnknownEnumLiteralException(direction); } } @Override public Iterator<Vertex> vertices(final Direction direction, final String... edgeLabels) { this.checkAccess(); Iterator<Edge> edges = this.edges(direction, edgeLabels); return new OtherEndVertexResolvingEdgeIterator(edges); } @Override public <V> VertexProperty<V> property(final String key) { this.checkAccess(); // note: this code is more efficient than the standard implementation in TinkerPop // because it avoids the creation of an iterator via #properties(key). VertexProperty<V> property = this.getSingleProperty(key); if (property == null) { return VertexProperty.<V>empty(); } return property; } @Override public <V> V value(final String key) { this.checkAccess(); // note: this is more efficient than the standard implementation in TinkerPop // because it avoids the creation of an iterator via #properties(key). return this.<V>property(key).value(); } @Override @SuppressWarnings({"unchecked", "rawtypes"}) public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys) { this.checkAccess(); // Since Gremlin 3.5.2: querying properties(null) is now allowed and returns the empty iterator. if(propertyKeys != null && propertyKeys.length > 0 && Arrays.stream(propertyKeys).allMatch(java.util.Objects::isNull)){ return Collections.emptyIterator(); } if (propertyKeys == null || propertyKeys.length <= 0) { if (this.recordReference == null) { // we are eagerly loaded if (this.properties == null) { // we have no properties return Collections.emptyIterator(); } else { // use all existing properties. Copy the set to prevent concurrent modification exception, // as defined by the gremlin standard. return (Iterator) (Sets.newHashSet(this.properties.values())).iterator(); } } else { // we are lazily loaded; use all the properties prescribed by our record, // and resolve them one by one as needed IVertexRecord vertexRecord = this.getRecord(); return (Iterator) vertexRecord.getProperties().stream().map(IPropertyRecord::getKey).map(this::getSingleProperty).iterator(); } } if (propertyKeys.length == 1) { // special common case: only one key is given. This is an optimization that // avoids creating a new collection and adding elements to it. String propertyKey = propertyKeys[0]; VertexProperty<V> property = this.getSingleProperty(propertyKey); if (property == null) { return Collections.emptyIterator(); } else { return Iterators.singletonIterator(property); } } // general case: more than one key is requested Set<VertexProperty<V>> matchingProperties = Sets.newHashSet(); for (String propertyKey : propertyKeys) { VertexProperty<?> property = this.getSingleProperty(propertyKey); if (property != null) { matchingProperties.add((VertexProperty<V>) property); } } return matchingProperties.iterator(); } @Override public void remove() { this.checkAccess(); this.ensureVertexRecordIsLoaded(); this.logVertexRemove(); // first, remove all incoming and outgoing edges Iterator<Edge> edges = this.edges(Direction.BOTH); while (edges.hasNext()) { Edge edge = edges.next(); edge.remove(); } // then, remove the vertex itself super.remove(); } @Override public String toString() { return StringFactory.vertexString(this); } // ================================================================================================================= // INTERNAL API // ================================================================================================================= protected Edge loadOutgoingEdgeTargetRecord(EdgeTargetRecordWithLabel recordWithLabel) { checkNotNull(recordWithLabel, "Precondition violation - argument 'recordWithLabel' must not be NULL!"); String label = recordWithLabel.getLabel(); IEdgeTargetRecord record; if (recordWithLabel.getRecord() instanceof EdgeTargetRecord2) { // it's an internal object, use it directly record = recordWithLabel.getRecord(); } else { // we got this somehow from the user, copy it record = new EdgeTargetRecord2(recordWithLabel.getRecord().getEdgeId(), recordWithLabel.getRecord().getOtherEndVertexId()); } return this.owningTransaction.loadOutgoingEdgeFromEdgeTargetRecord(this, label, record); } protected Edge loadIncomingEdgeTargetRecord(EdgeTargetRecordWithLabel recordWithLabel) { checkNotNull(recordWithLabel, "Precondition violation - argument 'recordWithLabel' must not be NULL!"); String label = recordWithLabel.getLabel(); IEdgeTargetRecord record; if (recordWithLabel.getRecord() instanceof EdgeTargetRecord2) { // it's an internal object, use it directly record = recordWithLabel.getRecord(); } else { // we got this somehow from the user, copy it record = new EdgeTargetRecord2(recordWithLabel.getRecord().getEdgeId(), recordWithLabel.getRecord().getOtherEndVertexId()); } return this.owningTransaction.loadIncomingEdgeFromEdgeTargetRecord(this, label, record); } protected void loadRecordContents() { if (this.labelToIncomingEdges == null) { this.labelToIncomingEdges = HashMultimap.create(); } if (this.labelToOutgoingEdges == null) { this.labelToOutgoingEdges = HashMultimap.create(); } if (this.properties == null) { this.properties = Maps.newHashMap(); } IVertexRecord vertexRecord = this.getRecord(); this.label = vertexRecord.getLabel(); for (IVertexPropertyRecord pRecord : vertexRecord.getProperties()) { // do not overwrite already loaded properties if (this.properties.containsKey(pRecord.getKey()) == false) { ChronoVertexProperty<?> property = loadPropertyRecord(pRecord); this.properties.put(property.key(), property); } } for (Entry<String, IEdgeTargetRecord> entry : vertexRecord.getIncomingEdgesByLabel().entries()) { String label = entry.getKey(); IEdgeTargetRecord eRecord = entry.getValue(); ChronoEdge edge = this.owningTransaction.loadIncomingEdgeFromEdgeTargetRecord(this, label, eRecord); this.labelToIncomingEdges.put(edge.label(), edge); } for (Entry<String, IEdgeTargetRecord> entry : vertexRecord.getOutgoingEdgesByLabel().entries()) { String label = entry.getKey(); IEdgeTargetRecord eRecord = entry.getValue(); ChronoEdge edge = this.owningTransaction.loadOutgoingEdgeFromEdgeTargetRecord(this, label, eRecord); this.labelToOutgoingEdges.put(edge.label(), edge); } this.recordReference = null; } private ChronoVertexProperty<?> loadPropertyRecord(final IVertexPropertyRecord pRecord) { ChronoVertexProperty<?> property = new ChronoVertexProperty<>(this, pRecord.getKey(), pRecord.getValue()); for (Entry<String, IPropertyRecord> pEntry : pRecord.getProperties().entrySet()) { String metaKey = pEntry.getKey(); IPropertyRecord metaProperty = pEntry.getValue(); property.property(metaKey, metaProperty.getValue(), true); } return property; } @Override public void removeProperty(final String key) { this.checkAccess(); this.logPropertyRemove(key); this.ensureVertexRecordIsLoaded(); this.properties.remove(key); this.changePropertyStatus(key, PropertyStatus.REMOVED); this.updateLifecycleStatus(ElementLifecycleEvent.PROPERTY_CHANGED); } @Override public void notifyPropertyChanged(final ChronoProperty<?> chronoProperty) { if (chronoProperty instanceof ChronoVertexProperty == false) { throw new IllegalArgumentException("Only VertexProperties can reside on a Vertex!"); } if (this.properties == null) { this.properties = Maps.newHashMap(); } this.ensureVertexRecordIsLoaded(); ChronoVertexProperty<?> existingProperty = this.properties.get(chronoProperty.key()); if (existingProperty != null && existingProperty != chronoProperty) { throw new IllegalStateException("Multiple instances of same vertex property detected. Key is '" + chronoProperty.key() + "'."); } this.properties.put(chronoProperty.key(), (ChronoVertexProperty) chronoProperty); this.updateLifecycleStatus(ElementLifecycleEvent.PROPERTY_CHANGED); this.changePropertyStatus(chronoProperty.key(), PropertyStatus.MODIFIED); } public IVertexRecord toRecord() { this.checkAccess(); String id = this.id(); String label = this.label(); return new VertexRecord3( id, label, this.labelToIncomingEdges, this.labelToOutgoingEdges, this.properties); } @Override public void updateLifecycleStatus(final ElementLifecycleEvent event) { super.updateLifecycleStatus(event); if (this.isModificationCheckActive()) { if (this.getStatus().isDirty()) { this.getTransactionContext().markVertexAsModified(this); } } } @Override public void validateGraphInvariant() { this.withoutRemovedCheck(() -> { switch (this.getStatus()) { case PERSISTED: /* fall throuhg*/ case PROPERTY_CHANGED: /* fall through*/ case EDGE_CHANGED: /* fall through*/ case NEW: // the vertex exists, check pointers from/to neighbor edges this.edges(Direction.OUT).forEachRemaining(edge -> { String label = edge.label(); ChronoEdge e = (ChronoEdge) edge; if (e.isRemoved()) { throw new GraphInvariantViolationException("The Vertex '" + this.id() + "' references the OUT Edge '" + e.id() + "' via Label '" + label + "', but this edge was removed!"); } if (!Objects.equal(label, e.label())) { throw new GraphInvariantViolationException("The Vertex '" + this.id() + "' references the OUT Edge '" + e.id() + "' via Label '" + label + "', but this edge has Label '" + e.label() + "'!"); } if (!Objects.equal(e.outVertex(), this)) { throw new GraphInvariantViolationException("The Vertex '" + this.id() + "' references the OUT Edge '" + e.id() + "' via Label '" + label + "', but the OUT Vertex of this Edge is different (v[" + e.outVertex().id() + "])!"); } }); this.edges(Direction.IN).forEachRemaining(edge -> { String label = edge.label(); ChronoEdge e = (ChronoEdge) edge; if (e.isRemoved()) { throw new GraphInvariantViolationException("The Vertex '" + this.id() + "' references the IN Edge '" + e.id() + "' via Label '" + label + "', but this edge was removed!"); } if (!Objects.equal(label, e.label())) { throw new GraphInvariantViolationException("The Vertex '" + this.id() + "' references the IN Edge '" + e.id() + "' via Label '" + label + "', but this edge has Label '" + e.label() + "'!"); } if (!Objects.equal(e.inVertex(), this)) { throw new GraphInvariantViolationException("The Vertex '" + this.id() + "' references the IN Edge '" + e.id() + "' via Label '" + label + "', but the IN Vertex of this Edge is different (v[" + e.outVertex().id() + "])!"); } }); break; case OBSOLETE: /* fall through*/ case REMOVED: // the vertex has been removed, check that neighbors are removed too this.edges(Direction.BOTH).forEachRemaining(e -> { if (!((ChronoEdge) e).isRemoved()) { // neighboring edge is not deleted! throw new GraphInvariantViolationException("The Vertex '" + this.id() + "' was deleted but its adjacent Edge '" + e.id() + "' still exists!"); } }); break; default: throw new UnknownEnumLiteralException(this.getStatus()); } }); } public void removeEdge(final ChronoEdgeImpl chronoEdge) { checkNotNull(chronoEdge, "Precondition violation - argument 'chronoEdge' must not be NULL!"); this.checkAccess(); this.ensureVertexRecordIsLoaded(); boolean changed = false; if (chronoEdge.inVertex().equals(this)) { // incoming edge // remove whatever edge representation has been there with this edge-id boolean removed = this.labelToIncomingEdges.remove(chronoEdge.label(), chronoEdge); if (removed == false) { throw new IllegalStateException("Graph is inconsistent - failed to remove edge from adjacent vertex!"); } changed = true; } // note: this vertex can be in AND out vertex (self-edge!) if (chronoEdge.outVertex().equals(this)) { // outgoing edge // remove whatever edge representation has been there with this edge-id boolean removed = this.labelToOutgoingEdges.remove(chronoEdge.label(), chronoEdge); if (removed == false) { throw new IllegalStateException("Graph is inconsistent - failed to remove edge from adjacent vertex!"); } changed = removed || changed; } if (changed) { this.updateLifecycleStatus(ElementLifecycleEvent.ADJACENT_EDGE_ADDED_OR_REMOVED); } } @Override protected void reloadFromDatabase() { String id = this.id(); ChronoGraphTransaction tx = this.getOwningTransaction(); IVertexRecord vRecord = tx.getBackingDBTransaction().get(ChronoGraphConstants.KEYSPACE_VERTEX, id); this.withoutModificationCheck(() -> { this.clearPropertyStatusCache(); this.labelToIncomingEdges = null; this.labelToOutgoingEdges = null; this.properties = null; if (vRecord != null) { this.recordReference = new WeakReference<>(vRecord); this.updateLifecycleStatus(ElementLifecycleEvent.RELOADED_FROM_DB_AND_IN_SYNC); } else { this.recordReference = null; this.updateLifecycleStatus(ElementLifecycleEvent.RELOADED_FROM_DB_AND_NO_LONGER_EXISTENT); } }); this.updateLifecycleStatus(ElementLifecycleEvent.SAVED); this.getTransactionContext().registerLoadedVertex(this); } @SuppressWarnings({"unchecked"}) private <V> VertexProperty<V> getSingleProperty(final String propertyKey) { PredefinedVertexProperty<V> predefinedProperty = ChronoGraphElementUtil.asPredefinedVertexProperty(this, propertyKey); if (predefinedProperty != null) { return predefinedProperty; } if (this.recordReference == null) { // we're not lazy -> use the regular property access return (VertexProperty<V>) this.properties.get(propertyKey); } else { // we're lazy -> use the record if necessary ChronoVertexProperty<?> chronoVertexProperty = null; if (this.properties != null) { chronoVertexProperty = this.properties.get(propertyKey); } if (chronoVertexProperty == null) { // fall back to creating it from the record IVertexRecord vertexRecord = this.getRecord(); IVertexPropertyRecord record = vertexRecord.getProperty(propertyKey); if (record == null) { // not found return null; } // load this record chronoVertexProperty = this.loadPropertyRecord(record); // cache it if (this.properties == null) { this.properties = Maps.newHashMap(); } this.properties.put(propertyKey, chronoVertexProperty); } return (ChronoVertexProperty<V>) chronoVertexProperty; } } protected IVertexRecord getRecord() { if (this.recordReference == null) { return null; } IVertexRecord record = this.recordReference.get(); if (record == null) { // reload ChronoGraphTransactionStatistics.getInstance().incrementNumberOfVertexRecordRefetches(); record = this.owningTransaction.loadVertexRecord(this.id); this.recordReference = new WeakReference<>(record); } return record; } @Override public boolean isLazy() { if (this.recordReference == null) { // the record is NULL, therefore it has been loaded. return false; } else { // the record is non-NULL, therefore it has yet to // be loaded and this vertex is lazy. return true; } } // ===================================================================================================================== // DEBUG OUTPUT // ===================================================================================================================== private void logPropertyChange(final String key, final Object value) { if (!log.isTraceEnabled(CHRONOS_LOG_MARKER__GRAPH_MODIFICATIONS)) { return; } // prepare some debug output StringBuilder messageBuilder = new StringBuilder(); messageBuilder.append(ChronoGraphLoggingUtil.createLogHeader(this.owningTransaction)); messageBuilder.append("Setting Property '"); messageBuilder.append(key); messageBuilder.append("' "); if (this.property(key).isPresent()) { messageBuilder.append("from '"); messageBuilder.append(this.value(key).toString()); messageBuilder.append("' to '"); messageBuilder.append(value.toString()); messageBuilder.append("' "); } else { messageBuilder.append("to '"); messageBuilder.append(value.toString()); messageBuilder.append("' (new property) "); } messageBuilder.append(" on Vertex "); messageBuilder.append(this.toString()); messageBuilder.append(" (Object ID: "); messageBuilder.append(System.identityHashCode(this)); messageBuilder.append(")"); log.trace(CHRONOS_LOG_MARKER__GRAPH_MODIFICATIONS, messageBuilder.toString()); } private void logVertexRemove() { if (!log.isTraceEnabled(CHRONOS_LOG_MARKER__GRAPH_MODIFICATIONS)) { return; } // prepare some debug output StringBuilder messageBuilder = new StringBuilder(); messageBuilder.append(ChronoGraphLoggingUtil.createLogHeader(this.owningTransaction)); messageBuilder.append("Removing Vertex "); messageBuilder.append(this.toString()); messageBuilder.append(" (Object ID: "); messageBuilder.append(System.identityHashCode(this)); messageBuilder.append(")"); log.trace(CHRONOS_LOG_MARKER__GRAPH_MODIFICATIONS, messageBuilder.toString()); } private void logPropertyRemove(final String key) { if (!log.isTraceEnabled(CHRONOS_LOG_MARKER__GRAPH_MODIFICATIONS)) { return; } // prepare some debug output StringBuilder messageBuilder = new StringBuilder(); messageBuilder.append(ChronoGraphLoggingUtil.createLogHeader(this.owningTransaction)); messageBuilder.append("Removing Property '"); messageBuilder.append(key); messageBuilder.append("' from Vertex "); messageBuilder.append(this.toString()); messageBuilder.append(" (Object ID: "); messageBuilder.append(System.identityHashCode(this)); messageBuilder.append(")"); log.trace(CHRONOS_LOG_MARKER__GRAPH_MODIFICATIONS, messageBuilder.toString()); } private void logAddEdge(final Vertex inVertex, final String edgeId, final boolean userProvidedId, final String label) { if (!log.isTraceEnabled(CHRONOS_LOG_MARKER__GRAPH_MODIFICATIONS)) { return; } // prepare some debug output StringBuilder messageBuilder = new StringBuilder(); messageBuilder.append(ChronoGraphLoggingUtil.createLogHeader(this.owningTransaction)); messageBuilder.append("Adding Edge. From Vertex: '"); messageBuilder.append(this.toString()); messageBuilder.append(" (Object ID: "); messageBuilder.append(System.identityHashCode(this)); messageBuilder.append(") to Vertex '"); messageBuilder.append(inVertex.toString()); messageBuilder.append(" (Object ID: "); messageBuilder.append(System.identityHashCode(inVertex)); messageBuilder.append(") with "); if (userProvidedId) { messageBuilder.append("user-provided "); } else { messageBuilder.append("auto-generated "); } messageBuilder.append("Edge ID '"); messageBuilder.append(edgeId); messageBuilder.append("' and label '"); messageBuilder.append(label); messageBuilder.append("'"); log.trace(CHRONOS_LOG_MARKER__GRAPH_MODIFICATIONS, messageBuilder.toString()); } // ================================================================================================================= // HELPER METHODS // ================================================================================================================= protected void ensureVertexRecordIsLoaded() { if (this.recordReference == null) { // the record is NULL, therefore it has been loaded. return; } // the record isn't NULL, we need to load it this.loadRecordContents(); this.recordReference = null; } // ================================================================================================================= // INNER CLASSES // ================================================================================================================= private class OtherEndVertexResolvingEdgeIterator implements Iterator<Vertex> { private final Iterator<Edge> edgeIterator; private OtherEndVertexResolvingEdgeIterator(final Iterator<Edge> edgeIterator) { this.edgeIterator = edgeIterator; } @Override public boolean hasNext() { return this.edgeIterator.hasNext(); } @Override public Vertex next() { Edge edge = this.edgeIterator.next(); Vertex inV = edge.inVertex(); if (inV.equals(ChronoVertexImpl.this)) { return edge.outVertex(); } else { return edge.inVertex(); } } } private class PropertiesIterator<V> implements Iterator<VertexProperty<V>> { private final Iterator<ChronoVertexProperty<?>> iterator; private PropertiesIterator(final Iterator<ChronoVertexProperty<?>> iterator) { this.iterator = iterator; } @Override public boolean hasNext() { return this.iterator.hasNext(); } @Override @SuppressWarnings("unchecked") public VertexProperty<V> next() { return (VertexProperty<V>) this.iterator.next(); } } }
41,101
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
AbstractChronoElement.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/AbstractChronoElement.java
package org.chronos.chronograph.internal.impl.structure.graph; import com.google.common.collect.Iterators; import com.google.common.collect.Maps; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Property; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.structure.util.ElementHelper; import org.chronos.chronograph.api.structure.ChronoEdge; import org.chronos.chronograph.api.structure.ChronoGraph; import org.chronos.chronograph.api.structure.ChronoVertex; import org.chronos.chronograph.api.structure.ElementLifecycleStatus; import org.chronos.chronograph.api.structure.ElementLifecycleStatus.IllegalStateTransitionException; import org.chronos.chronograph.api.structure.PropertyStatus; import org.chronos.chronograph.internal.api.structure.ChronoElementInternal; import org.chronos.chronograph.internal.api.structure.ChronoGraphInternal; import org.chronos.chronograph.internal.api.transaction.ChronoGraphTransactionInternal; import org.chronos.chronograph.internal.api.transaction.GraphTransactionContextInternal; import org.chronos.chronograph.internal.impl.transaction.ElementLoadMode; import org.chronos.chronograph.internal.impl.transaction.threaded.ChronoThreadedTransactionGraph; import org.chronos.common.exceptions.UnknownEnumLiteralException; import java.util.Iterator; import java.util.Map; import java.util.concurrent.Callable; import static com.google.common.base.Preconditions.*; public abstract class AbstractChronoElement implements ChronoElementInternal { protected final String id; protected String label; protected final ChronoGraphInternal graph; protected final Thread owningThread; protected long loadedAtRollbackCount; protected ChronoGraphTransactionInternal owningTransaction; private int skipRemovedCheck; private int skipModificationCheck; private ElementLifecycleStatus status; private Map<String, PropertyStatus> propertyStatusMap; protected AbstractChronoElement(final ChronoGraphInternal g, final ChronoGraphTransactionInternal tx, final String id, final String label) { checkNotNull(g, "Precondition violation - argument 'g' must not be NULL!"); checkNotNull(tx, "Precondition violation - argument 'tx' must not be NULL!"); checkNotNull(id, "Precondition violation - argument 'id' must not be NULL!"); checkNotNull(label, "Precondition violation - argument 'label' must not be NULL!"); this.graph = g; this.owningTransaction = tx; this.loadedAtRollbackCount = tx.getRollbackCount(); this.id = id; this.status = ElementLifecycleStatus.NEW; this.label = label; this.owningThread = Thread.currentThread(); } @Override public String id() { return this.id; } @Override public String label() { return this.label; } @Override public ChronoGraphInternal graph() { return this.graph; } @Override public void remove() { this.checkAccess(); // removing an element can start a transaction as well this.graph().tx().readWrite(); this.updateLifecycleStatus(ElementLifecycleEvent.DELETED); } @Override public boolean isRemoved() { return this.status.equals(ElementLifecycleStatus.REMOVED) || this.status.equals(ElementLifecycleStatus.OBSOLETE); } @Override public void updateLifecycleStatus(final ElementLifecycleEvent event) { checkNotNull(event, "Precondition violation - argument 'event' must not be NULL!"); if (this.isModificationCheckActive()) { try { this.status = this.status.nextState(event); } catch (IllegalStateTransitionException e) { this.throwIllegalStateSwitchException(event, e); } } } @Override public ElementLifecycleStatus getStatus() { return this.status; } // ================================================================================================================= // HASH CODE & EQUALS // ================================================================================================================= @Override public final int hashCode() { // according to TinkerGraph reference implementation return ElementHelper.hashCode(this); } @Override public final boolean equals(final Object object) { // according to TinkerGraph reference implementation return ElementHelper.areEqual(this, object); } // ================================================================================================================= // INTERNAL API // ================================================================================================================= @Override public ChronoGraphTransactionInternal getOwningTransaction() { return this.owningTransaction; } public Thread getOwningThread() { return this.owningThread; } protected ChronoVertex resolveVertex(final String id) { return (ChronoVertex) this.getOwningTransaction().getVertex(id, ElementLoadMode.LAZY); } protected ChronoEdge resolveEdge(final String id) { Iterator<Edge> iterator = this.graph.edges(id); return (ChronoEdge) Iterators.getOnlyElement(iterator); } protected ChronoGraphTransactionInternal getGraphTransaction() { return (ChronoGraphTransactionInternal) this.graph().tx().getCurrentTransaction(); } protected GraphTransactionContextInternal getTransactionContext() { return (GraphTransactionContextInternal) this.getGraphTransaction().getContext(); } @Override public long getLoadedAtRollbackCount() { return this.loadedAtRollbackCount; } // ===================================================================================================================== // INTERNAL UTILITY METHODS // ===================================================================================================================== protected boolean isModificationCheckActive() { return this.skipModificationCheck <= 0; } protected void assertNotRemoved() { if (this.isRemoved() && this.skipRemovedCheck <= 0) { String elementType; if (this instanceof Vertex) { elementType = "Vertex"; } else if (this instanceof Edge) { elementType = "Edge"; } else { elementType = "Element"; } throw new IllegalStateException("The " + elementType + " '" + this.id + "' has already been removed!"); } } protected void withoutRemovedCheck(final Runnable r) { this.skipRemovedCheck++; try { r.run(); } finally { this.skipRemovedCheck--; } } protected <T> T withoutRemovedCheck(final Callable<T> c) { this.skipRemovedCheck++; try { try { return c.call(); } catch (Exception e) { throw new RuntimeException("Error during method execution", e); } } finally { this.skipRemovedCheck--; } } protected void withoutModificationCheck(final Runnable r) { this.skipModificationCheck++; try { r.run(); } finally { this.skipModificationCheck--; } } protected <T> T withoutModificationCheck(final Callable<T> c) { this.skipModificationCheck++; try { try { return c.call(); } catch (Exception e) { throw new RuntimeException("Error during method execution", e); } } finally { this.skipModificationCheck--; } } public void checkAccess() { this.checkThread(); this.checkTransaction(); this.assertNotRemoved(); } public void checkThread() { if (this.owningTransaction.isThreadedTx()) { // if we are owned by a threaded transaction, any thread has access to the element. return; } Thread currentThread = Thread.currentThread(); if (currentThread.equals(this.getOwningThread()) == false) { throw new IllegalStateException("Graph Elements generated by a thread-bound transaction" + " are not safe for concurrent access! Do not share them among threads! Owning thread is '" + this.getOwningThread().getName() + "', current thread is '" + currentThread.getName() + "'."); } } public void checkTransaction() { if (this.owningTransaction.isThreadedTx()) { // threaded tx this.owningTransaction.assertIsOpen(); } else { // thread-local tx this.graph.tx().readWrite(); ChronoGraphTransactionInternal currentTx = (ChronoGraphTransactionInternal) this.graph.tx() .getCurrentTransaction(); if (currentTx.equals(this.getOwningTransaction())) { // we are still on the same transaction that created this element // Check if a rollback has occurred if (this.loadedAtRollbackCount == currentTx.getRollbackCount()) { // same transaction, same rollback count -> nothing to do. return; } else { // a rollback has occurred; if the element was modified, we need to reload it if (this.status.isDirty()) { this.reloadFromDatabase(); this.updateLifecycleStatus(ElementLifecycleEvent.SAVED); } this.loadedAtRollbackCount = currentTx.getRollbackCount(); } } else { // we are on a different transaction, rebind to the new transaction and reload this.owningTransaction = currentTx; this.loadedAtRollbackCount = this.owningTransaction.getRollbackCount(); this.reloadFromDatabase(); this.updateLifecycleStatus(ElementLifecycleEvent.SAVED); } } } /** * Clears the entire property status cache for all properties of this element. */ protected void clearPropertyStatusCache() { this.propertyStatusMap = null; } /** * Changes the status of the {@link Property} with the given key to the given status. * * @param propertyKey The key of the property to change the status for. Must not be <code>null</code>. * @param status The new status of the property. Must not be <code>null</code>. */ protected void changePropertyStatus(final String propertyKey, final PropertyStatus status) { checkNotNull(propertyKey, "Precondition violation - argument 'propertyKey' must not be NULL!"); checkNotNull(status, "Precondition violation - argument 'status' must not be NULL!"); PropertyStatus currentStatus = this.getPropertyStatus(propertyKey); switch (currentStatus) { case PERSISTED: switch (status) { case MODIFIED: this.assignPropertyStatus(propertyKey, status); break; case NEW: throw new IllegalArgumentException("Cannot switch property state from PERSISTED to NEW!"); case PERSISTED: // no-op break; case REMOVED: this.assignPropertyStatus(propertyKey, status); break; case UNKNOWN: throw new IllegalArgumentException("Cannot switch property state from PERSISTED to UNKNOWN!"); default: throw new UnknownEnumLiteralException(status); } break; case UNKNOWN: switch (status) { case MODIFIED: this.assignPropertyStatus(propertyKey, status); break; case NEW: this.assignPropertyStatus(propertyKey, status); break; case PERSISTED: throw new IllegalArgumentException("Cannot switch property state from UNKNOWN to PERSISTED!"); case REMOVED: this.assignPropertyStatus(propertyKey, status); break; case UNKNOWN: // no-op break; default: throw new UnknownEnumLiteralException(status); } break; case NEW: switch (status) { case MODIFIED: // new remains in new, even when modified again -> no-op break; case NEW: // no-op break; case PERSISTED: if (this.propertyStatusMap != null) { // we mark it as persisted by simply dropping the metadata, the getter will // recreate it on-demand and we save the map entry this.propertyStatusMap.remove(propertyKey); } break; case REMOVED: if (this.propertyStatusMap != null) { // switching from NEW to REMOVED makes the property obsolete, the getter // will recreate it on-demand and we save the map entry this.propertyStatusMap.remove(propertyKey); } break; case UNKNOWN: throw new IllegalArgumentException("Cannot switch property state from NEW to UNKNOWN!"); default: throw new UnknownEnumLiteralException(status); } break; case MODIFIED: switch (status) { case MODIFIED: // no-op break; case NEW: throw new IllegalArgumentException("Cannot switch property state from MODIFIED to NEW!"); case PERSISTED: if (this.propertyStatusMap != null) { // we mark it as persisted by simply dropping the metadata, the getter will // recreate it on-demand and we save the map entry this.propertyStatusMap.remove(propertyKey); } break; case REMOVED: this.assignPropertyStatus(propertyKey, status); break; case UNKNOWN: throw new IllegalArgumentException("Cannot switch property state from MODIFIED to UNKNOWN!"); default: throw new UnknownEnumLiteralException(status); } break; case REMOVED: switch (status) { case MODIFIED: this.assignPropertyStatus(propertyKey, status); break; case NEW: // removal and re-addition = modification this.assignPropertyStatus(propertyKey, PropertyStatus.MODIFIED); break; case PERSISTED: throw new IllegalArgumentException("Cannot switch property state from REMOVED to PERSISTED!"); case REMOVED: // no-op break; case UNKNOWN: if (this.propertyStatusMap != null) { // the property was removed, the vertex was saved and the property is now unknown. this.propertyStatusMap.remove(propertyKey); } break; default: throw new UnknownEnumLiteralException(status); } break; default: throw new UnknownEnumLiteralException(currentStatus); } } private void assignPropertyStatus(final String propertyKey, final PropertyStatus status) { checkNotNull(propertyKey, "Precondition violation - argument 'propertyKey' must not be NULL!"); checkNotNull(status, "Precondition violation - argument 'status' must not be NULL!"); if (this.propertyStatusMap == null) { this.propertyStatusMap = Maps.newHashMap(); } this.propertyStatusMap.put(propertyKey, status); } /** * Returns the current status of the {@link Property} with the given key. * * <p> * The result may be one of the following: * <ul> * <li>{@link PropertyStatus#UNKNOWN}: indicates that a property with the given key has never existed on this vertex. * <li>{@link PropertyStatus#NEW}: the property has been newly added in this transaction. * <li>{@link PropertyStatus#MODIFIED}: the property has existed before, but was modified in this transaction. * <li>{@link PropertyStatus#REMOVED}: the property has existed before, but was removed in this transaction. * <li>{@link PropertyStatus#PERSISTED}: the property exists and is unchanged. * </ul> * * @param propertyKey The property key to search for. Must not be <code>null</code>. * @return The status of the property with the given key, as outlined above. Never <code>null</code>. */ @Override public PropertyStatus getPropertyStatus(final String propertyKey) { checkNotNull(propertyKey, "Precondition violation - argument 'propertyKey' must not be NULL!"); PropertyStatus status = null; if (this.propertyStatusMap != null) { status = this.propertyStatusMap.get(propertyKey); } if (this.propertyStatusMap == null || status == null) { if (this.property(propertyKey).isPresent()) { // the property with the given key exists, but we have no metadata about it -> it's clean return PropertyStatus.PERSISTED; } else { // the property with the given key doesn't exist -> we've never seen this property before return PropertyStatus.UNKNOWN; } } else { return status; } } private void throwIllegalStateSwitchException(final ElementLifecycleEvent event, Exception cause) { throw new IllegalStateException("Element Lifecycle error: element '" + this.getClass().getSimpleName() + "' with id '" + this.id() + "' in status " + this.getStatus() + " cannot accept the change '" + event + "'!", cause); } protected abstract void reloadFromDatabase(); }
19,516
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ElementLifecycleEvent.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/ElementLifecycleEvent.java
package org.chronos.chronograph.internal.impl.structure.graph; public enum ElementLifecycleEvent { /** * The element was created for the first time. It is not yet part of the persistence. */ CREATED, /** * Vertices only: an adjacent edge has been added or removed. */ ADJACENT_EDGE_ADDED_OR_REMOVED, /** * A property on the element has changed. */ PROPERTY_CHANGED, /** * The element has been deleted. */ DELETED, /** * The element has been recreated from the OBSOLETE state. * * <p> * This occurs if the element was created, removed and is now being recreated (within the same transaction). * </p> */ RECREATED_FROM_OBSOLETE, /** * The element has been recreated from the REMOVED state. * * <p> * This occurs if a persistent element is removed and is now being recreated (within the same transaction). * </p> */ RECREATED_FROM_REMOVED, /** * The element has been saved to the persistence mechanism. */ SAVED, /** * The element has been reloaded from the database, and no longer exists */ RELOADED_FROM_DB_AND_NO_LONGER_EXISTENT, /** * The element has been reloaded from the database and is now in sync */ RELOADED_FROM_DB_AND_IN_SYNC }
1,350
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoGraphVariablesImpl.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/ChronoGraphVariablesImpl.java
package org.chronos.chronograph.internal.impl.structure.graph; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import org.apache.tinkerpop.gremlin.structure.util.GraphVariableHelper; import org.apache.tinkerpop.gremlin.structure.util.StringFactory; import org.chronos.chronodb.api.ChronoDBTransaction; import org.chronos.chronograph.api.structure.ChronoGraph; import org.chronos.chronograph.api.transaction.ChronoGraphTransaction; import org.chronos.chronograph.api.transaction.GraphTransactionContext; import org.chronos.chronograph.internal.ChronoGraphConstants; import org.chronos.chronograph.internal.api.transaction.GraphTransactionContextInternal; import java.util.Collections; import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import static com.google.common.base.Preconditions.*; /** * Implementation of the Gremlin {@Link Graph.Variables} interface. * * <p> * This implementation persists the graph variables alongside the actual graph data, i.e. * <code>graph.tx().commit()</code> will also commit the graph variables, and <code>graph.tx().rollback()</code> will * remove any changes. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ public class ChronoGraphVariablesImpl implements org.chronos.chronograph.api.structure.ChronoGraphVariables { private final ChronoGraph graph; // ===================================================================================================================== // CONSTRUCTOR // ===================================================================================================================== public ChronoGraphVariablesImpl(final ChronoGraph graph) { checkNotNull(graph, "Precondition violation - argument 'graph' must not be NULL!"); this.graph = graph; } // ===================================================================================================================== // PUBLIC API // ===================================================================================================================== @Override public Set<String> keys() { return this.keys(ChronoGraphConstants.VARIABLES_DEFAULT_KEYSPACE); } @Override public Set<String> keys(final String keyspace) { checkNotNull(keyspace, "Precondition violation - argument 'keyspace' must not be NULL!"); this.readWrite(); GraphTransactionContext context = this.getContext(); ChronoDBTransaction tx = this.getTransaction().getBackingDBTransaction(); Set<String> keySet = tx.keySet(createChronoDBVariablesKeyspace(keyspace)); keySet.addAll(context.getModifiedVariables(keyspace)); keySet.removeAll(context.getRemovedVariables(keyspace)); return Collections.unmodifiableSet(keySet); } @Override public <R> Optional<R> get(final String key) { checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); return this.getInternal(ChronoGraphConstants.VARIABLES_DEFAULT_KEYSPACE, key); } @Override public <R> Optional<R> get(final String keyspace, final String key) { checkNotNull(keyspace, "Precondition violation - argument 'keyspace' must not be NULL!"); checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); return this.getInternal(keyspace, key); } @SuppressWarnings("unchecked") protected <R> Optional<R> getInternal(final String keyspace, final String key) { checkNotNull(keyspace, "Precondition violation - argument 'keyspace' must not be NULL!"); checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); this.readWrite(); GraphTransactionContext context = this.getContext(); if (context.isVariableModified(keyspace, key)) { // return the modified value return Optional.ofNullable((R) context.getModifiedVariableValue(keyspace, key)); } else { // query the db for the original value ChronoDBTransaction tx = this.getTransaction().getBackingDBTransaction(); return Optional.ofNullable(tx.get(createChronoDBVariablesKeyspace(keyspace), key)); } } @Override public void remove(final String key) { checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); this.remove(ChronoGraphConstants.VARIABLES_DEFAULT_KEYSPACE, key); } @Override public void remove(final String keyspace, final String key) { checkNotNull(keyspace, "Precondition violation - argument 'keyspace' must not be NULL!"); checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); this.readWrite(); GraphTransactionContextInternal context = this.getContext(); context.removeVariable(keyspace, key); } @Override public void set(final String key, final Object value) { this.set(ChronoGraphConstants.VARIABLES_DEFAULT_KEYSPACE, key, value); } @Override public void set(final String keyspace, final String key, final Object value) { checkNotNull(keyspace, "Precondition violation - argument 'keyspace' must not be NULL!"); GraphVariableHelper.validateVariable(key, value); this.readWrite(); GraphTransactionContextInternal context = this.getContext(); context.setVariableValue(keyspace, key, value); } @Override public String toString() { this.readWrite(); // unfortunately we HAVE to adhere to the gremlin defaults here, which means // that only the default variables keyspace is considered. return StringFactory.graphVariablesString(this); } @Override public Map<String, Object> asMap() { return this.asMap(ChronoGraphConstants.VARIABLES_DEFAULT_KEYSPACE); } @Override public Map<String, Object> asMap(final String keyspace) { checkNotNull(keyspace, "Precondition violation - argument 'keyspa' must not be NULL!"); Set<String> keys = this.keys(keyspace); Map<String, Object> resultMap = Maps.newHashMap(); for (String key : keys) { this.get(keyspace, key).ifPresent(value -> resultMap.put(key, value)); } return Collections.unmodifiableMap(resultMap); } @Override public Set<String> keyspaces() { this.readWrite(); Set<String> modifiedKeyspaces = this.getContext().getModifiedVariableKeyspaces(); ChronoDBTransaction chronoDBTransaction = this.getTransaction().getBackingDBTransaction(); Set<String> persistedKeyspaces = chronoDBTransaction.keyspaces().stream() .filter(keyspace -> keyspace.startsWith(ChronoGraphConstants.KEYSPACE_VARIABLES)) .map(ChronoGraphVariablesImpl::createChronoGraphVariablesKeyspace) .collect(Collectors.toSet()); return Collections.unmodifiableSet(Sets.union(modifiedKeyspaces, persistedKeyspaces)); } // ===================================================================================================================== // INTERNAL HELPER METHODS // ===================================================================================================================== protected ChronoGraphTransaction getTransaction() { return this.graph.tx().getCurrentTransaction(); } protected void readWrite() { this.graph.tx().readWrite(); } protected GraphTransactionContextInternal getContext() { return (GraphTransactionContextInternal) this.getTransaction().getContext(); } public static String createChronoDBVariablesKeyspace(String chronoGraphKeyspace) { checkNotNull(chronoGraphKeyspace, "Precondition violation - argument 'chronoGraphKeyspace' must not be NULL!"); if(ChronoGraphConstants.VARIABLES_DEFAULT_KEYSPACE.equals(chronoGraphKeyspace)){ // for backwards compatibility with earlier releases where only the default // chronoGraphKeyspace existed, we do not attach any suffix to it. return ChronoGraphConstants.KEYSPACE_VARIABLES; }else{ return ChronoGraphConstants.KEYSPACE_VARIABLES + "#" + chronoGraphKeyspace; } } public static String createChronoGraphVariablesKeyspace(String chronoDBKeyspace){ checkNotNull(chronoDBKeyspace, "Precondition violation - argument 'chronoDBKeyspace' must not be NULL!"); if(ChronoGraphConstants.KEYSPACE_VARIABLES.equals(chronoDBKeyspace)){ return ChronoGraphConstants.VARIABLES_DEFAULT_KEYSPACE; } String prefix = ChronoGraphConstants.KEYSPACE_VARIABLES + "#"; if(chronoDBKeyspace.startsWith(prefix)){ return chronoDBKeyspace.substring(prefix.length()); }else{ throw new IllegalArgumentException("The given 'chronoDBKeyspace' is not a syntactically valid keyspace identifier: '" + chronoDBKeyspace + "'"); } } }
9,084
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
StandardChronoGraph.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/StandardChronoGraph.java
package org.chronos.chronograph.internal.impl.structure.graph; import com.google.common.collect.Iterators; import com.google.common.collect.Maps; import org.apache.commons.configuration2.Configuration; import org.apache.commons.lang3.tuple.Pair; import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.structure.util.StringFactory; import org.chronos.chronodb.api.ChronoDB; import org.chronos.chronodb.api.ChronoDBConstants; import org.chronos.chronodb.api.ChronoDBTransaction; import org.chronos.chronodb.api.DumpOption; import org.chronos.chronodb.api.Order; import org.chronos.chronodb.internal.impl.dump.DumpOptions; import org.chronos.chronodb.internal.impl.engines.base.ChronosInternalCommitMetadata; import org.chronos.chronodb.internal.util.IteratorUtils; import org.chronos.chronograph.api.branch.ChronoGraphBranchManager; import org.chronos.chronograph.api.history.ChronoGraphHistoryManager; import org.chronos.chronograph.api.index.ChronoGraphIndexManager; import org.chronos.chronograph.api.jmx.ChronoGraphMBeanSupport; import org.chronos.chronograph.api.maintenance.ChronoGraphMaintenanceManager; import org.chronos.chronograph.api.schema.ChronoGraphSchemaManager; import org.chronos.chronograph.api.statistics.ChronoGraphStatisticsManager; import org.chronos.chronograph.api.structure.ChronoGraphVariables; import org.chronos.chronograph.api.transaction.ChronoGraphTransactionManager; import org.chronos.chronograph.internal.ChronoGraphConstants; import org.chronos.chronograph.internal.api.configuration.ChronoGraphConfiguration; import org.chronos.chronograph.internal.api.structure.ChronoGraphInternal; import org.chronos.chronograph.internal.impl.branch.ChronoGraphBranchManagerImpl; import org.chronos.chronograph.internal.impl.configuration.ChronoGraphConfigurationImpl; import org.chronos.chronograph.internal.impl.dumpformat.GraphDumpFormat; import org.chronos.chronograph.internal.impl.history.ChronoGraphHistoryManagerImpl; import org.chronos.chronograph.internal.impl.index.ChronoGraphIndexManagerImpl; import org.chronos.chronograph.internal.impl.maintenance.ChronoGraphMaintenanceManagerImpl; import org.chronos.chronograph.internal.impl.migration.ChronoGraphMigrationChain; import org.chronos.chronograph.internal.impl.optimizer.strategy.ChronoGraphStepStrategy; import org.chronos.chronograph.internal.impl.optimizer.strategy.FetchValuesFromSecondaryIndexStrategy; import org.chronos.chronograph.internal.impl.optimizer.strategy.OrderFiltersStrategy; import org.chronos.chronograph.internal.impl.optimizer.strategy.PredicateNormalizationStrategy; import org.chronos.chronograph.internal.impl.optimizer.strategy.ReplaceGremlinPredicateWithChronosPredicateStrategy; import org.chronos.chronograph.internal.impl.schema.ChronoGraphSchemaManagerImpl; import org.chronos.chronograph.internal.impl.statistics.ChronoGraphStatisticsManagerImpl; import org.chronos.chronograph.internal.impl.structure.graph.features.ChronoGraphFeatures; import org.chronos.chronograph.internal.impl.transaction.ChronoGraphTransactionManagerImpl; import org.chronos.chronograph.internal.impl.transaction.threaded.ChronoThreadedTransactionGraph; import org.chronos.chronograph.internal.impl.transaction.trigger.ChronoGraphTriggerManagerImpl; import org.chronos.chronograph.internal.impl.transaction.trigger.ChronoGraphTriggerManagerInternal; import org.chronos.common.autolock.AutoLock; import org.chronos.common.configuration.ChronosConfigurationUtil; import org.chronos.common.version.ChronosVersion; import org.chronos.common.version.VersionKind; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Optional; import java.util.Set; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.stream.Collectors; import static com.google.common.base.Preconditions.*; public class StandardChronoGraph implements ChronoGraphInternal { private static final Logger log = LoggerFactory.getLogger(StandardChronoGraph.class); static { TraversalStrategies graphStrategies = TraversalStrategies.GlobalCache.getStrategies(Graph.class).clone(); graphStrategies.addStrategies(ChronoGraphStepStrategy.INSTANCE); graphStrategies.addStrategies(PredicateNormalizationStrategy.INSTANCE); graphStrategies.addStrategies(ReplaceGremlinPredicateWithChronosPredicateStrategy.INSTANCE); graphStrategies.addStrategies(FetchValuesFromSecondaryIndexStrategy.INSTANCE); graphStrategies.addStrategies(OrderFiltersStrategy.INSTANCE); // TODO PERFORMANCE GRAPH: Titan has a couple more optimizations. See next line. // Take a look at: AdjacentVertexFilterOptimizerStrategy, TitanLocalQueryOptimizerStrategy // Register with cache TraversalStrategies.GlobalCache.registerStrategies(StandardChronoGraph.class, graphStrategies); TraversalStrategies.GlobalCache.registerStrategies(ChronoThreadedTransactionGraph.class, graphStrategies); // TODO PERFORMANCE GRAPH: Titan has a second graph implementation for transactions. See next line. // TraversalStrategies.GlobalCache.registerStrategies(StandardTitanTx.class, graphStrategies); } private final Configuration rawConfiguration; private final ChronoGraphConfiguration graphConfiguration; private final ChronoDB database; private final ChronoGraphTransactionManager txManager; private final ChronoGraphBranchManager branchManager; private final ChronoGraphTriggerManagerInternal triggerManager; private final ChronoGraphSchemaManager schemaManager; private final ChronoGraphMaintenanceManager maintenanceManager; private final ChronoGraphStatisticsManager statisticsManager; private final ChronoGraphHistoryManager historyManager; private final Object branchLock = new Object(); private final Map<String, ChronoGraphIndexManager> branchNameToIndexManager; private final ChronoGraphFeatures features; private final ChronoGraphVariablesImpl variables; private final Lock commitLock = new ReentrantLock(true); private final ThreadLocal<AutoLock> commitLockHolder = new ThreadLocal<>(); public StandardChronoGraph(final ChronoDB database, final Configuration configuration) { checkNotNull(database, "Precondition violation - argument 'database' must not be NULL!"); checkNotNull(configuration, "Precondition violation - argument 'configuration' must not be NULL!"); this.rawConfiguration = configuration; this.graphConfiguration = ChronosConfigurationUtil.build(configuration, ChronoGraphConfigurationImpl.class); this.database = database; this.txManager = new ChronoGraphTransactionManagerImpl(this); this.branchManager = new ChronoGraphBranchManagerImpl(this); this.schemaManager = new ChronoGraphSchemaManagerImpl(this); this.triggerManager = new ChronoGraphTriggerManagerImpl(this); this.maintenanceManager = new ChronoGraphMaintenanceManagerImpl(this); this.statisticsManager = new ChronoGraphStatisticsManagerImpl(this); this.historyManager = new ChronoGraphHistoryManagerImpl(this); this.branchNameToIndexManager = Maps.newHashMap(); this.features = new ChronoGraphFeatures(this); this.variables = new ChronoGraphVariablesImpl(this); this.writeCurrentChronoGraphVersionIfNecessary(); ChronoGraphMigrationChain.executeMigrationChainOnGraph(this); if (this.database.getConfiguration().isMBeanIntegrationEnabled()) { ChronoGraphMBeanSupport.registerMBeans(this); } } // ================================================================================================================= // GRAPH CLOSING // ================================================================================================================= @Override public void close() { if (this.database.isClosed()) { // already closed return; } this.database.close(); } @Override public boolean isClosed() { return this.database.isClosed(); } // ===================================================================================================================== // VERTEX & EDGE HANDLING // ===================================================================================================================== @Override public Vertex addVertex(final Object... keyValues) { this.tx().readWrite(); return this.tx().getCurrentTransaction().addVertex(keyValues); } @Override public Iterator<Vertex> vertices(final Object... vertexIds) { this.tx().readWrite(); return this.tx().getCurrentTransaction().vertices(vertexIds); } @Override public Iterator<Edge> edges(final Object... edgeIds) { this.tx().readWrite(); return this.tx().getCurrentTransaction().edges(edgeIds); } // ===================================================================================================================== // COMPUTATION API // ===================================================================================================================== @Override public <C extends GraphComputer> C compute(final Class<C> graphComputerClass) throws IllegalArgumentException { // TODO Auto-generated method stub return null; } @Override public GraphComputer compute() throws IllegalArgumentException { // TODO Auto-generated method stub return null; } // ===================================================================================================================== // TRANSACTION API // ===================================================================================================================== @Override public ChronoGraphTransactionManager tx() { this.assertIsOpen(); return this.txManager; } @Override public long getNow() { this.assertIsOpen(); return this.getBackingDB().getBranchManager().getMasterBranch().getNow(); } @Override public long getNow(final String branchName) { checkNotNull(branchName, "Precondition violation - argument 'branchName' must not be NULL!"); this.assertIsOpen(); return this.getBackingDB().getBranchManager().getBranch(branchName).getNow(); } // ===================================================================================================================== // INDEXING // ===================================================================================================================== @Override public ChronoGraphIndexManager getIndexManagerOnMaster() { return this.getIndexManagerOnBranch(ChronoDBConstants.MASTER_BRANCH_IDENTIFIER); } @Override public ChronoGraphIndexManager getIndexManagerOnBranch(final String branchName) { checkNotNull(branchName, "Precondition violation - argument 'branchName' must not be NULL!"); this.assertIsOpen(); synchronized (this.branchLock){ if (this.getBackingDB().getBranchManager().existsBranch(branchName) == false) { throw new IllegalArgumentException("There is no branch named '" + branchName + "'!"); } // try to retrieve a cached copy of the manager ChronoGraphIndexManager indexManager = this.branchNameToIndexManager.get(branchName); if (indexManager == null) { // manager not present in our cache; buildLRU it and add it to the cache indexManager = new ChronoGraphIndexManagerImpl(this.getBackingDB(), branchName); this.branchNameToIndexManager.put(branchName, indexManager); } return indexManager; } } // ===================================================================================================================== // BRANCHING // ===================================================================================================================== @Override public ChronoGraphBranchManager getBranchManager() { this.assertIsOpen(); return this.branchManager; } // ================================================================================================================= // TRIGGERS // ================================================================================================================= @Override public ChronoGraphTriggerManagerInternal getTriggerManager() { this.assertIsOpen(); return this.triggerManager; } // ===================================================================================================================== // VARIABLES & CONFIGURATION // ===================================================================================================================== @Override public ChronoGraphVariables variables() { this.assertIsOpen(); return this.variables; } @Override public Configuration configuration() { return this.rawConfiguration; } @Override public ChronoGraphConfiguration getChronoGraphConfiguration() { return this.graphConfiguration; } // ================================================================================================================= // STORED CHRONOGRAPH VERSION // ================================================================================================================= private void writeCurrentChronoGraphVersionIfNecessary() { Optional<ChronosVersion> storedVersion = this.getStoredChronoGraphVersion(); if (storedVersion.isPresent()) { // stored version already exists, skip return; } // first, check if the graph is empty if (this.isGraphEmpty()) { // the graph is empty, this is a new installation, // set the current Chronos version as ChronoGraph version. if (this.getBackingDB().getConfiguration().isReadOnly()) { throw new IllegalStateException("This ChronoGraph instance is read-only, but graph metadata needs to be written. " + "Please open this graph in read/write mode first, then close it and open it as read-only afterwards."); } this.setStoredChronoGraphVersion(ChronosVersion.getCurrentVersion()); } else { // the graph isn't empty, we assume that the latest chronograph version // which did not support the migration chain is used. if (this.getBackingDB().getConfiguration().isReadOnly()) { throw new IllegalStateException("This ChronoGraph instance is read-only, but graph metadata needs to be written. " + "Please open this graph in read/write mode first, then close it and open it as read-only afterwards."); } this.setStoredChronoGraphVersion(new ChronosVersion(0, 11, 1, VersionKind.RELEASE)); } } private boolean isGraphEmpty() { this.tx().open(); try { // we start the checks with the meta objects since they are cheaper to // query if the graph is indeed non-empty. if (this.getBranchManager().getBranchNames().size() > 1) { // there is more than one branch => graph is not empty. return false; } if (!this.variables().keys().isEmpty()) { // at least one key has been assigned => graph is not empty. return false; } if (!this.getIndexManagerOnMaster().getAllIndicesAtAnyPointInTime().isEmpty()) { // an index has been created => graph is not empty. return false; } if (!this.getSchemaManager().getAllValidatorNames().isEmpty()) { // a schema validator has been created => graph is not empty. return false; } if (!this.getTriggerManager().getAllTriggers().isEmpty()) { // a trigger has been created => graph is not empty. return false; } // no meta objects exist, check if we have any vertices or edges. ChronoDBTransaction tx = this.getBackingDB().tx(); if (!tx.keySet(ChronoGraphConstants.KEYSPACE_VERTEX).isEmpty()) { // there are vertices return false; } if (!tx.keySet(ChronoGraphConstants.KEYSPACE_EDGE).isEmpty()) { // there are edges return false; } // the graph is completely empty return true; } finally { this.tx().rollback(); } } @Override public Optional<ChronosVersion> getStoredChronoGraphVersion() { this.assertIsOpen(); ChronoDBTransaction tx = this.getBackingDB().tx(); String keyspace = ChronoGraphConstants.KEYSPACE_MANAGEMENT; String key = ChronoGraphConstants.KEYSPACE_MANAGEMENT_KEY__CHRONOGRAPH_VERSION; String version = tx.get(keyspace, key); return Optional.ofNullable(version).map(ChronosVersion::parse); } @Override public void setStoredChronoGraphVersion(final ChronosVersion version) { checkNotNull(version, "Precondition violation - argument 'version' must not be NULL!"); this.assertIsOpen(); Optional<ChronosVersion> currentVersion = this.getStoredChronoGraphVersion(); if (currentVersion.isPresent() && version.isSmallerThan(currentVersion.get())) { throw new IllegalArgumentException("Cannot store ChronoGraph version " + version + ": the current version is higher (" + currentVersion + ")!"); } ChronoDBTransaction tx = this.getBackingDB().tx(); String keyspace = ChronoGraphConstants.KEYSPACE_MANAGEMENT; String key = ChronoGraphConstants.KEYSPACE_MANAGEMENT_KEY__CHRONOGRAPH_VERSION; tx.put(keyspace, key, version.toString()); String commitMessage; if (currentVersion.isPresent()) { commitMessage = "Updated stored ChronoGraph version from " + currentVersion.get() + " to " + version + "."; } else { commitMessage = "Updated stored ChronoGraph version from [not set] to " + version + "."; } tx.commit(new ChronosInternalCommitMetadata(commitMessage)); } // ===================================================================================================================== // TEMPORAL ACTIONS // ===================================================================================================================== @Override public Iterator<Long> getVertexHistory(final Object vertexId) { checkNotNull(vertexId, "Precondition violation - argument 'vertexId' must not be NULL!"); this.tx().readWrite(); return this.tx().getCurrentTransaction().getVertexHistory(vertexId); } @Override public Iterator<Long> getVertexHistory(final Object vertexId, final long lowerBound, final long upperBound, final Order order) { checkNotNull(vertexId, "Precondition violation - argument 'vertexId' must not be NULL!"); checkArgument(lowerBound >= 0, "Precondition violation - argument 'lowerBound' must not be negative!"); checkArgument(upperBound >= 0, "Precondition violation - argument 'upperBound' must not be negative!"); checkArgument(lowerBound <= upperBound, "Precondition violation - argument 'lowerBound' must be less than or equal to argument 'upperBound'!"); checkNotNull(order, "Precondition violation - argument 'order' must not be NULL!"); this.tx().readWrite(); return this.tx().getCurrentTransaction().getVertexHistory(vertexId, lowerBound, upperBound, order); } @Override public Iterator<Long> getEdgeHistory(final Object edgeId, final long lowerBound, final long upperBound, final Order order) { checkNotNull(edgeId, "Precondition violation - argument 'edgeId' must not be NULL!"); checkArgument(lowerBound >= 0, "Precondition violation - argument 'lowerBound' must not be negative!"); checkArgument(upperBound >= 0, "Precondition violation - argument 'upperBound' must not be negative!"); checkArgument(lowerBound <= upperBound, "Precondition violation - argument 'lowerBound' must be less than or equal to argument 'upperBound'!"); checkNotNull(order, "Precondition violation - argument 'order' must not be NULL!"); this.tx().readWrite(); return this.tx().getCurrentTransaction().getEdgeHistory(edgeId, lowerBound, upperBound, order); } @Override public Iterator<Long> getEdgeHistory(final Edge edge) { checkNotNull(edge, "Precondition violation - argument 'edge' must not be NULL!"); this.tx().readWrite(); return this.tx().getCurrentTransaction().getEdgeHistory(edge); } @Override public long getLastModificationTimestampOfVertex(final Vertex vertex) { checkNotNull(vertex, "Precondition violation - argument 'vertex' must not be NULL!"); this.tx().readWrite(); return this.tx().getCurrentTransaction().getLastModificationTimestampOfVertex(vertex); } @Override public long getLastModificationTimestampOfVertex(final Object vertexId) { checkNotNull(vertexId, "Precondition violation - argument 'vertexId' must not be NULL!"); this.tx().readWrite(); return this.tx().getCurrentTransaction().getLastModificationTimestampOfVertex(vertexId); } @Override public long getLastModificationTimestampOfEdge(final Edge edge) { checkNotNull(edge, "Precondition violation - argument 'edge' must not be NULL!"); this.tx().readWrite(); return this.tx().getCurrentTransaction().getLastModificationTimestampOfEdge(edge); } @Override public long getLastModificationTimestampOfEdge(final Object edgeId) { checkNotNull(edgeId, "Precondition violation - argument 'edgeId' must not be NULL!"); this.tx().readWrite(); return this.tx().getCurrentTransaction().getLastModificationTimestampOfEdge(edgeId); } @Override public Iterator<Pair<Long, String>> getVertexModificationsBetween(final long timestampLowerBound, final long timestampUpperBound) { checkArgument(timestampLowerBound >= 0, "Precondition violation - argument 'timestampLowerBound' must not be negative!"); checkArgument(timestampUpperBound >= 0, "Precondition violation - argument 'timestampUpperBound' must not be negative!"); checkArgument(timestampLowerBound <= timestampUpperBound, "Precondition violation - argument 'timestampLowerBound' must be less than or equal to 'timestampUpperBound'!"); this.tx().readWrite(); checkArgument(timestampLowerBound <= this.tx().getCurrentTransaction().getTimestamp(), "Precondition violation - argument 'timestampLowerBound' must not exceed the transaction timestamp!"); checkArgument(timestampUpperBound <= this.tx().getCurrentTransaction().getTimestamp(), "Precondition violation - argument 'timestampUpperBound' must not exceed the transaction timestamp!"); return this.tx().getCurrentTransaction().getVertexModificationsBetween(timestampLowerBound, timestampUpperBound); } @Override public Iterator<Pair<Long, String>> getEdgeModificationsBetween(final long timestampLowerBound, final long timestampUpperBound) { checkArgument(timestampLowerBound >= 0, "Precondition violation - argument 'timestampLowerBound' must not be negative!"); checkArgument(timestampUpperBound >= 0, "Precondition violation - argument 'timestampUpperBound' must not be negative!"); checkArgument(timestampLowerBound <= timestampUpperBound, "Precondition violation - argument 'timestampLowerBound' must be less than or equal to 'timestampUpperBound'!"); this.tx().readWrite(); checkArgument(timestampLowerBound <= this.tx().getCurrentTransaction().getTimestamp(), "Precondition violation - argument 'timestampLowerBound' must not exceed the transaction timestamp!"); checkArgument(timestampUpperBound <= this.tx().getCurrentTransaction().getTimestamp(), "Precondition violation - argument 'timestampUpperBound' must not exceed the transaction timestamp!"); return this.tx().getCurrentTransaction().getEdgeModificationsBetween(timestampLowerBound, timestampUpperBound); } @Override public Object getCommitMetadata(final String branch, final long timestamp) { checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); checkArgument(timestamp <= this.getNow(branch), "Precondition violation - argument 'timestamp' must not be larger than the latest commit timestamp!"); return this.getBackingDB().tx(branch).getCommitMetadata(timestamp); } @Override public Iterator<Long> getCommitTimestampsBetween(final String branch, final long from, final long to, final Order order, final boolean includeSystemInternalCommits) { checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); checkArgument(from >= 0, "Precondition violation - argument 'from' must not be negative!"); checkArgument(to >= 0, "Precondition violation - argument 'to' must not be negative!"); checkNotNull(order, "Precondition violation - argument 'order' must not be NULL!"); return this.getBackingDB().tx(branch).getCommitTimestampsBetween(from, to, order, includeSystemInternalCommits); } @Override public Iterator<Entry<Long, Object>> getCommitMetadataBetween(final String branch, final long from, final long to, final Order order, final boolean includeSystemInternalCommits) { checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); checkArgument(from >= 0, "Precondition violation - argument 'from' must not be negative!"); checkArgument(to >= 0, "Precondition violation - argument 'to' must not be negative!"); checkNotNull(order, "Precondition violation - argument 'order' must not be NULL!"); return this.getBackingDB().tx(branch).getCommitMetadataBetween(from, to, order, includeSystemInternalCommits); } @Override public Iterator<Long> getCommitTimestampsPaged(final String branch, final long minTimestamp, final long maxTimestamp, final int pageSize, final int pageIndex, final Order order, final boolean includeSystemInternalCommits) { checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); checkArgument(minTimestamp >= 0, "Precondition violation - argument 'minTimestamp' must not be negative!"); checkArgument(maxTimestamp >= 0, "Precondition violation - argument 'maxTimestamp' must not be negative!"); checkArgument(pageSize > 0, "Precondition violation - argument 'pageSize' must be greater than zero!"); checkArgument(pageIndex >= 0, "Precondition violation - argument 'pageIndex' must not be negative!"); checkNotNull(order, "Precondition violation - argument 'order' must not be NULL!"); return this.getBackingDB().tx(branch).getCommitTimestampsPaged(minTimestamp, maxTimestamp, pageSize, pageIndex, order, includeSystemInternalCommits); } @Override public Iterator<Entry<Long, Object>> getCommitMetadataPaged(final String branch, final long minTimestamp, final long maxTimestamp, final int pageSize, final int pageIndex, final Order order, final boolean includeSystemInternalCommits) { checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); checkArgument(minTimestamp >= 0, "Precondition violation - argument 'minTimestamp' must not be negative!"); checkArgument(maxTimestamp >= 0, "Precondition violation - argument 'maxTimestamp' must not be negative!"); checkArgument(pageSize > 0, "Precondition violation - argument 'pageSize' must be greater than zero!"); checkArgument(pageIndex >= 0, "Precondition violation - argument 'pageIndex' must not be negative!"); checkNotNull(order, "Precondition violation - argument 'order' must not be NULL!"); return this.getBackingDB().tx(branch).getCommitMetadataPaged(minTimestamp, maxTimestamp, pageSize, pageIndex, order, includeSystemInternalCommits); } @Override public List<Entry<Long, Object>> getCommitMetadataAround(final String branch, final long timestamp, final int count, final boolean includeSystemInternalCommits) { checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); checkArgument(count >= 0, "Precondition violation - argument 'count' must not be negative!"); checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); return this.getBackingDB().tx(branch).getCommitMetadataAround(timestamp, count, includeSystemInternalCommits); } @Override public List<Entry<Long, Object>> getCommitMetadataBefore(final String branch, final long timestamp, final int count, final boolean includeSystemInternalCommits) { checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); checkArgument(count >= 0, "Precondition violation - argument 'count' must not be negative!"); checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); return this.getBackingDB().tx(branch).getCommitMetadataBefore(timestamp, count, includeSystemInternalCommits); } @Override public List<Entry<Long, Object>> getCommitMetadataAfter(final String branch, final long timestamp, final int count, final boolean includeSystemInternalCommits) { checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); checkArgument(count >= 0, "Precondition violation - argument 'count' must not be negative!"); checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); return this.getBackingDB().tx(branch).getCommitMetadataAfter(timestamp, count, includeSystemInternalCommits); } @Override public List<Long> getCommitTimestampsAround(final String branch, final long timestamp, final int count, final boolean includeSystemInternalCommits) { checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); checkArgument(count >= 0, "Precondition violation - argument 'count' must not be negative!"); checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); return this.getBackingDB().tx(branch).getCommitTimestampsAround(timestamp, count, includeSystemInternalCommits); } @Override public List<Long> getCommitTimestampsBefore(final String branch, final long timestamp, final int count, final boolean includeSystemInternalCommits) { checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); checkArgument(count >= 0, "Precondition violation - argument 'count' must not be negative!"); checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); return this.getBackingDB().tx(branch).getCommitTimestampsBefore(timestamp, count, includeSystemInternalCommits); } @Override public List<Long> getCommitTimestampsAfter(final String branch, final long timestamp, final int count, final boolean includeSystemInternalCommits) { checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); checkArgument(count >= 0, "Precondition violation - argument 'count' must not be negative!"); checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); return this.getBackingDB().tx(branch).getCommitTimestampsAfter(timestamp, count, includeSystemInternalCommits); } @Override public int countCommitTimestampsBetween(final String branch, final long from, final long to, final boolean includeSystemInternalCommits) { checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); checkArgument(from >= 0, "Precondition violation - argument 'from' must not be negative!"); checkArgument(to >= 0, "Precondition violation - argument 'to' must not be negative!"); return this.getBackingDB().tx(branch).countCommitTimestampsBetween(from, to, includeSystemInternalCommits); } @Override public int countCommitTimestamps(final String branch, final boolean includeSystemInternalCommits) { checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); return this.getBackingDB().tx(branch).countCommitTimestamps(includeSystemInternalCommits); } @Override public Iterator<String> getChangedVerticesAtCommit(final String branch, final long commitTimestamp) { checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); checkArgument(commitTimestamp >= 0, "Precondition violation - argument 'commitTimestamp' must not be negative!"); return Iterators.unmodifiableIterator(this.getBackingDB().tx(branch).getChangedKeysAtCommit(commitTimestamp, ChronoGraphConstants.KEYSPACE_VERTEX)); } @Override public Iterator<String> getChangedEdgesAtCommit(final String branch, final long commitTimestamp) { checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); checkArgument(commitTimestamp >= 0, "Precondition violation - argument 'commitTimestamp' must not be negative!"); return Iterators.unmodifiableIterator(this.getBackingDB().tx(branch).getChangedKeysAtCommit(commitTimestamp, ChronoGraphConstants.KEYSPACE_EDGE)); } @Override public Iterator<Pair<String, String>> getChangedGraphVariablesAtCommit(final long commitTimestamp) { checkArgument(commitTimestamp >= 0, "Precondition violation - argument 'commitTimestamp' must not be negative!"); return this.getChangedGraphVariablesAtCommit(ChronoDBConstants.MASTER_BRANCH_IDENTIFIER, commitTimestamp); } @Override public Iterator<String> getChangedGraphVariablesAtCommitInDefaultKeyspace(final long commitTimestamp) { checkArgument(commitTimestamp >= 0, "Precondition violation - argument 'commitTimestamp' must not be negative!"); return this.getChangedGraphVariablesAtCommitInKeyspace(ChronoDBConstants.MASTER_BRANCH_IDENTIFIER, commitTimestamp, ChronoGraphConstants.VARIABLES_DEFAULT_KEYSPACE); } @Override public Iterator<String> getChangedGraphVariablesAtCommitInKeyspace(final long commitTimestamp, final String keyspace) { checkArgument(commitTimestamp >= 0, "Precondition violation - argument 'commitTimestamp' must not be negative!"); checkNotNull(keyspace, "Precondition violation - argument 'keyspace' must not be NULL!"); return this.getChangedGraphVariablesAtCommitInKeyspace(ChronoDBConstants.MASTER_BRANCH_IDENTIFIER, commitTimestamp, keyspace); } @Override public Iterator<Pair<String, String>> getChangedGraphVariablesAtCommit(final String branch, final long commitTimestamp) { checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); checkArgument(commitTimestamp >= 0, "Precondition violation - argument 'commitTimestamp' must not be negative!"); ChronoDBTransaction tx = this.getBackingDB().tx(branch, commitTimestamp); Set<String> keyspaces = tx.keyspaces().stream().filter(ks -> ks.startsWith(ChronoGraphConstants.KEYSPACE_VARIABLES)).collect(Collectors.toSet()); return Iterators.unmodifiableIterator(keyspaces.stream().flatMap(keyspace -> IteratorUtils.stream(tx.getChangedKeysAtCommit(commitTimestamp, keyspace)) .map(key -> Pair.of(ChronoGraphVariablesImpl.createChronoGraphVariablesKeyspace(keyspace), key)) ).iterator()); } @Override public Iterator<String> getChangedGraphVariablesAtCommitInDefaultKeyspace(final String branch, final long commitTimestamp) { checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); checkArgument(commitTimestamp >= 0, "Precondition violation - argument 'commitTimestamp' must not be negative!"); return this.getChangedGraphVariablesAtCommitInKeyspace(branch, commitTimestamp, ChronoGraphConstants.VARIABLES_DEFAULT_KEYSPACE); } @Override public Iterator<String> getChangedGraphVariablesAtCommitInKeyspace(final String branch, final long commitTimestamp, final String keyspace) { checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); checkArgument(commitTimestamp >= 0, "Precondition violation - argument 'commitTimestamp' must not be negative!"); checkNotNull(keyspace, "Precondition violation - argument 'keyspace' must not be NULL!"); ChronoDBTransaction tx = this.getBackingDB().tx(branch, commitTimestamp); return Iterators.unmodifiableIterator(tx.getChangedKeysAtCommit(commitTimestamp, ChronoGraphVariablesImpl.createChronoDBVariablesKeyspace(keyspace))); } // ================================================================================================================= // SCHEMA MANAGEMENT // ================================================================================================================= @Override public ChronoGraphSchemaManager getSchemaManager() { return this.schemaManager; } // ================================================================================================================= // MAINTENANCE // ================================================================================================================= @Override public ChronoGraphMaintenanceManager getMaintenanceManager() { return this.maintenanceManager; } // ================================================================================================================= // STATISTICS // ================================================================================================================= @Override public ChronoGraphStatisticsManager getStatisticsManager() { return this.statisticsManager; } // ================================================================================================================= // HISTORY // ================================================================================================================= @Override public ChronoGraphHistoryManager getHistoryManager() { return historyManager; } // ===================================================================================================================== // SERIALIZATION & DESERIALIZATION (GraphSon, Gyro, ...) // ===================================================================================================================== // not implemented yet // ===================================================================================================================== // DUMP OPERATIONS // ===================================================================================================================== @Override public void writeDump(final File dumpFile, final DumpOption... dumpOptions) { DumpOptions options = new DumpOptions(dumpOptions); GraphDumpFormat.registerGraphAliases(options); GraphDumpFormat.registerDefaultConvertersForWriting(options); this.getBackingDB().writeDump(dumpFile, options.toArray()); } @Override public void readDump(final File dumpFile, final DumpOption... dumpOptions) { DumpOptions options = new DumpOptions(dumpOptions); GraphDumpFormat.registerGraphAliases(options); GraphDumpFormat.registerDefaultConvertersForReading(options); // we need to perform the ChronoGraph migrations also on the dump file. File migratedDumpFile = ChronoGraphMigrationChain.executeMigrationChainOnDumpFile(dumpFile, options); try { this.getBackingDB().getBackupManager().readDump(migratedDumpFile, options.toArray()); } finally { boolean deleted = migratedDumpFile.delete(); if (!deleted) { log.warn("Failed to delete temporary dump file: '" + migratedDumpFile.getAbsolutePath() + "'!"); } } } // ===================================================================================================================== // STRING REPRESENTATION // ===================================================================================================================== @Override public String toString() { // according to Tinkerpop specification... return StringFactory.graphString(this, ""); } // ================================================================================================================= // INTERNAL API // ================================================================================================================= @Override public ChronoDB getBackingDB() { this.assertIsOpen(); return this.database; } public AutoLock commitLock() { AutoLock autoLock = this.commitLockHolder.get(); if (autoLock == null) { autoLock = AutoLock.createBasicLockHolderFor(this.commitLock); this.commitLockHolder.set(autoLock); } // autoLock.releaseLock() is called on lockHolder.close() autoLock.acquireLock(); return autoLock; } // ===================================================================================================================== // FEATURES DECLARATION // ===================================================================================================================== @Override public ChronoGraphFeatures features() { return this.features; } // ================================================================================================================= // HELPER METHODS // ================================================================================================================= private void assertIsOpen(){ if(this.isClosed()){ throw new IllegalStateException("This ChronoGraph instance has already been closed."); } } }
44,152
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoEdgeImpl.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/ChronoEdgeImpl.java
package org.chronos.chronograph.internal.impl.structure.graph; import com.google.common.collect.Iterators; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Property; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.structure.util.ElementHelper; import org.apache.tinkerpop.gremlin.structure.util.StringFactory; import org.chronos.chronodb.api.ChronoDBTransaction; import org.chronos.chronograph.api.exceptions.GraphInvariantViolationException; import org.chronos.chronograph.api.structure.ChronoEdge; import org.chronos.chronograph.api.structure.ChronoVertex; import org.chronos.chronograph.api.structure.PropertyStatus; import org.chronos.chronograph.api.structure.record.IEdgeRecord; import org.chronos.chronograph.api.structure.record.IEdgeTargetRecord; import org.chronos.chronograph.api.structure.record.IPropertyRecord; import org.chronos.chronograph.api.transaction.ChronoGraphTransaction; import org.chronos.chronograph.internal.ChronoGraphConstants; import org.chronos.chronograph.internal.api.structure.ChronoGraphInternal; import org.chronos.chronograph.internal.api.transaction.ChronoGraphTransactionInternal; import org.chronos.chronograph.internal.impl.structure.record.EdgeRecord; import org.chronos.chronograph.internal.impl.structure.record2.EdgeRecord2; import org.chronos.chronograph.internal.impl.util.ChronoGraphElementUtil; import org.chronos.chronograph.internal.impl.util.ChronoGraphLoggingUtil; import org.chronos.chronograph.internal.impl.util.ChronoProxyUtil; import org.chronos.chronograph.internal.impl.util.PredefinedProperty; import org.chronos.common.exceptions.UnknownEnumLiteralException; import org.chronos.common.logging.ChronosLogMarker; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.lang.ref.WeakReference; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; import java.util.Objects; import java.util.Set; import static com.google.common.base.Preconditions.*; public class ChronoEdgeImpl extends AbstractChronoElement implements Edge, ChronoEdge { private static final Logger log = LoggerFactory.getLogger(ChronoEdgeImpl.class); public static ChronoEdgeImpl create(final ChronoGraphInternal graph, final ChronoGraphTransactionInternal tx, final IEdgeRecord record) { checkNotNull(graph, "Precondition violation - argument 'graph' must not be NULL!"); checkNotNull(tx, "Precondition violation - argument 'tx' must not be NULL!"); checkNotNull(record, "Precondition violation - argument 'record' must not be NULL!"); String id = record.getId(); String outV = record.getOutVertexId(); String label = record.getLabel(); String inV = record.getInVertexId(); Set<? extends IPropertyRecord> properties = record.getProperties(); ChronoEdgeImpl edge = new ChronoEdgeImpl(graph, tx, id, outV, label, inV, properties); edge.updateLifecycleStatus(ElementLifecycleEvent.SAVED); return edge; } public static ChronoEdgeImpl create(final String id, final ChronoVertexImpl outV, final String label, final ChronoVertexImpl inV) { checkNotNull(outV, "Precondition violation - argument 'outV' must not be NULL!"); ElementHelper.validateLabel(label); checkNotNull(inV, "Precondition violation - argument 'inV' must not be NULL!"); ChronoEdgeImpl edge = new ChronoEdgeImpl(id, outV, label, inV); edge.updateLifecycleStatus(ElementLifecycleEvent.CREATED); return edge; } public static ChronoEdgeImpl incomingEdgeFromRecord(final ChronoVertexImpl owner, final String label, final IEdgeTargetRecord record) { checkNotNull(owner, "Precondition violation - argument 'owner' must not be NULL!"); checkNotNull(record, "Precondition violation - argument 'record' must not be NULL!"); checkNotNull(label, "Precondition violation - argument 'label' must not be NULL!"); String id = record.getEdgeId(); String otherEndVertexId = record.getOtherEndVertexId(); ChronoEdgeImpl edge = new ChronoEdgeImpl(id, label, owner, otherEndVertexId, owner.id(), ElementLifecycleEvent.RELOADED_FROM_DB_AND_IN_SYNC); // tell the edge that it's properties must be loaded from the backing data store on first access edge.lazyLoadProperties = true; return edge; } public static ChronoEdgeImpl outgoingEdgeFromRecord(final ChronoVertexImpl owner, final String label, final IEdgeTargetRecord record) { checkNotNull(owner, "Precondition violation - argument 'owner' must not be NULL!"); checkNotNull(record, "Precondition violation - argument 'record' must not be NULL!"); checkNotNull(label, "Precondition violation - argument 'label' must not be NULL!"); String id = record.getEdgeId(); String otherEndVertexId = record.getOtherEndVertexId(); ChronoEdgeImpl edge = new ChronoEdgeImpl(id, label, owner, owner.id(), otherEndVertexId, ElementLifecycleEvent.RELOADED_FROM_DB_AND_IN_SYNC); // tell the edge that it's properties must be loaded from the backing data store on first access edge.lazyLoadProperties = true; return edge; } // ================================================================================================================= // FIELDS // ================================================================================================================= private final String outVid; private final String inVid; protected final Map<String, ChronoProperty<?>> properties; private transient WeakReference<ChronoVertex> outVcache; private transient WeakReference<ChronoVertex> inVcache; private transient boolean lazyLoadProperties; // ================================================================================================================= // CONSTRUCTOR // ================================================================================================================= @SuppressWarnings({"unchecked", "rawtypes"}) protected ChronoEdgeImpl(final ChronoGraphInternal graph, final ChronoGraphTransactionInternal tx, final String id, final String outVid, final String label, final String inVid, final Set<? extends IPropertyRecord> properties) { super(graph, tx, id, label); checkNotNull(outVid, "Precondition violation - argument 'outVid' must not be NULL!"); checkNotNull(inVid, "Precondition violation - argument 'inVid' must not be NULL!"); this.outVid = outVid; this.inVid = inVid; this.properties = Maps.newHashMap(); for (IPropertyRecord pRecord : properties) { String propertyName = pRecord.getKey(); Object propertyValue = pRecord.getValue(); this.properties.put(propertyName, new ChronoProperty(this, propertyName, propertyValue, true)); } } protected ChronoEdgeImpl(final String id, final String label, final ChronoVertexImpl owner, final String outVid, final String inVid, final ElementLifecycleEvent event) { super(owner.graph(), owner.getOwningTransaction(), id, label); checkNotNull(outVid, "Precondition violation - argument 'outVid' must not be NULL!"); checkNotNull(inVid, "Precondition violation - argument 'inVid' must not be NULL!"); checkNotNull(owner, "Precondition violation - argument 'owner' must not be NULL!"); this.outVid = outVid; this.inVid = inVid; this.properties = Maps.newHashMap(); if (owner.id().equals(outVid)) { this.outVcache = new WeakReference<>(owner); } else if (owner.id().equals(inVid)) { this.inVcache = new WeakReference<>(owner); } else { throw new IllegalArgumentException("The given owner is neither the in-vertex nor the out-vertex!"); } this.updateLifecycleStatus(event); } protected ChronoEdgeImpl(final String id, final ChronoVertexImpl outV, final String label, final ChronoVertexImpl inV) { super(inV.graph(), inV.getGraphTransaction(), id, label); checkNotNull(outV, "Precondition violation - argument 'outV' must not be NULL!"); checkNotNull(inV, "Precondition violation - argument 'inV' must not be NULL!"); // we need to check the access on the vertices, as we might have to transition them to another transaction outV.checkAccess(); inV.checkAccess(); if (outV.getOwningTransaction().equals(inV.getOwningTransaction()) == false) { throw new IllegalArgumentException("The given vertices are bound to different transactions!"); } if (outV.getOwningThread().equals(Thread.currentThread()) == false || inV.getOwningThread().equals(Thread.currentThread()) == false) { throw new IllegalStateException("Cannot create edge - neighboring vertices belong to different threads!"); } this.outVid = outV.id(); this.inVid = inV.id(); this.properties = Maps.newHashMap(); this.inVcache = new WeakReference<>(inV); this.outVcache = new WeakReference<>(outV); } // ================================================================================================================= // TINKERPOP 3 API // ================================================================================================================= @Override public Iterator<Vertex> vertices(final Direction direction) { this.checkAccess(); checkNotNull(direction, "Precondition violation - argument 'direction' must not be NULL!"); switch (direction) { case BOTH: // note: according to gremlin specification, the out vertex should be returned first. return Iterators.forArray(this.outVertex(), this.inVertex()); case IN: return Iterators.forArray(this.inVertex()); case OUT: return Iterators.forArray(this.outVertex()); default: throw new IllegalArgumentException("Unkown 'Direction' literal: " + direction); } } @Override public <V> Property<V> property(final String key, final V value) { ElementHelper.validateProperty(key, value); if(value == null){ // Since Gremlin 3.5.2: setting a property to value NULL removes it. this.removeProperty(key); return Property.empty(); } this.checkAccess(); this.loadLazyPropertiesIfRequired(); this.logPropertyChange(key, value); boolean exists = this.property(key).isPresent(); ChronoProperty<V> newProperty = new ChronoProperty<>(this, key, value); if (exists) { this.changePropertyStatus(key, PropertyStatus.MODIFIED); } else { this.changePropertyStatus(key, PropertyStatus.NEW); } this.properties.put(key, newProperty); this.updateLifecycleStatus(ElementLifecycleEvent.PROPERTY_CHANGED); return newProperty; } @Override @SuppressWarnings("rawtypes") public <V> Iterator<Property<V>> properties(final String... propertyKeys) { this.checkAccess(); // Since Gremlin 3.5.2: querying properties(null) is now allowed and returns the empty iterator. if(propertyKeys != null && propertyKeys.length > 0 && Arrays.stream(propertyKeys).allMatch(Objects::isNull)){ return Collections.emptyIterator(); } this.loadLazyPropertiesIfRequired(); Set<Property> matchingProperties = Sets.newHashSet(); if (propertyKeys == null || propertyKeys.length <= 0) { // note: the TinkerPop test suite explicitly demands that predefined property keys, // such as T.id, T.label etc. are EXCLUDED from the iterator in this case. matchingProperties.addAll(this.properties.values()); } else { for (String key : propertyKeys) { PredefinedProperty<?> predefinedProperty = ChronoGraphElementUtil.asPredefinedProperty(this, key); if (predefinedProperty != null) { matchingProperties.add(predefinedProperty); } Property property = this.properties.get(key); if (property != null) { matchingProperties.add(property); } } } return new PropertiesIterator<>(matchingProperties.iterator()); } @Override public ChronoVertex inVertex() { this.checkAccess(); ChronoVertex inVertex = null; if (this.inVcache != null) { // we have loaded this element once before, see if it's cached inVertex = this.inVcache.get(); } if (inVertex == null) { // either we have never loaded this element before, or the garbage collector // decided to remove our cached instance. In this case, we need to reload it. inVertex = this.resolveVertex(this.inVid); // remember it in the cache this.inVcache = new WeakReference<>(inVertex); } return inVertex; } @Override public ChronoVertex outVertex() { this.checkAccess(); ChronoVertex outVertex = null; if (this.outVcache != null) { // we have loaded this element once before, see if it's cached outVertex = this.outVcache.get(); } if (outVertex == null) { // either we have never loaded this element before, or the garbage collector // decided to remove our cached instance. In this case, we need to reload it. outVertex = this.resolveVertex(this.outVid); // remember it in the cache this.outVcache = new WeakReference<>(outVertex); } return outVertex; } @Override public void remove() { this.checkThread(); this.checkTransaction(); if(this.isRemoved()){ // removing an edge twice has no effect (as defined in Gremlin standard) return; } this.logEdgeRemove(); this.withoutRemovedCheck(() -> { super.remove(); if (this.inVertex().equals(this.outVertex())) { // self reference, sufficient to call remove() only on one end ChronoProxyUtil.resolveVertexProxy(this.inVertex()).removeEdge(this); } else { // reference to other vertex, need to remove edge from both ends ChronoProxyUtil.resolveVertexProxy(this.inVertex()).removeEdge(this); ChronoProxyUtil.resolveVertexProxy(this.outVertex()).removeEdge(this); } }); } @Override public String toString() { return StringFactory.edgeString(this); } @Override protected void reloadFromDatabase() { // clear the inV and outV caches (but keep the ids, as the vertices connected to an edge can never change) ElementLifecycleEvent[] lifecycleEvent = new ElementLifecycleEvent[1]; this.withoutRemovedCheck(() -> { this.withoutModificationCheck(() -> { this.inVcache = null; this.outVcache = null; this.properties.clear(); ChronoDBTransaction backendTx = this.getOwningTransaction().getBackingDBTransaction(); EdgeRecord eRecord = backendTx.get(ChronoGraphConstants.KEYSPACE_EDGE, this.id()); if (eRecord == null) { // edge was removed lifecycleEvent[0] = ElementLifecycleEvent.RELOADED_FROM_DB_AND_NO_LONGER_EXISTENT; } else { lifecycleEvent[0] = ElementLifecycleEvent.RELOADED_FROM_DB_AND_IN_SYNC; // load the properties this.lazyLoadProperties = false; for (IPropertyRecord propertyRecord : eRecord.getProperties()) { String key = propertyRecord.getKey(); Object value = propertyRecord.getValue(); this.property(key, value); } } this.getTransactionContext().registerLoadedEdge(this); }); }); this.updateLifecycleStatus(lifecycleEvent[0]); } // ================================================================================================================= // INTERNAL API // ================================================================================================================= @Override public void removeProperty(final String key) { this.checkAccess(); this.loadLazyPropertiesIfRequired(); this.logPropertyRemove(key); this.properties.remove(key); this.changePropertyStatus(key, PropertyStatus.REMOVED); this.updateLifecycleStatus(ElementLifecycleEvent.PROPERTY_CHANGED); } @Override public void notifyPropertyChanged(final ChronoProperty<?> chronoProperty) { // nothing to do for edges so far } public IEdgeRecord toRecord() { String id = this.id(); String label = this.label(); this.loadLazyPropertiesIfRequired(); return new EdgeRecord2(id, this.outVid, label, this.inVid, this.properties); } @Override public void updateLifecycleStatus(final ElementLifecycleEvent event) { super.updateLifecycleStatus(event); if (this.isModificationCheckActive()) { if (event == ElementLifecycleEvent.CREATED || event == ElementLifecycleEvent.DELETED || event == ElementLifecycleEvent.RECREATED_FROM_REMOVED || event == ElementLifecycleEvent.RECREATED_FROM_OBSOLETE) { // need to update adjacency lists of in and out vertex this.inVertex().updateLifecycleStatus(ElementLifecycleEvent.ADJACENT_EDGE_ADDED_OR_REMOVED); this.outVertex().updateLifecycleStatus(ElementLifecycleEvent.ADJACENT_EDGE_ADDED_OR_REMOVED); } if (this.getStatus().isDirty()) { this.getTransactionContext().markEdgeAsModified(this); } } } @Override public void validateGraphInvariant() { this.withoutRemovedCheck(() -> { switch (this.getStatus()) { case PERSISTED: /* fall through */ case PROPERTY_CHANGED: /* fall through */ case EDGE_CHANGED: /* fall through */ case NEW: // the edge exists, check the pointers try { if (this.outVertex().isRemoved()) { throw new GraphInvariantViolationException("The Edge '" + this.id() + "' with Label '" + this.label() + "' references the OUT Vertex '" + this.outVertex().id() + "', but that vertex has been removed!"); } if (Iterators.contains(this.outVertex().edges(Direction.OUT, this.label()), this) == false) { throw new GraphInvariantViolationException("The Edge '" + this.id() + "' with Label '" + this.label() + "' references the OUT Vertex '" + this.outVertex().id() + ", but that vertex does not list this edge as outgoing!"); } } catch (NoSuchElementException e) { throw new GraphInvariantViolationException("The Edge '" + this.id() + "' with Label '" + this.label() + "' references the OUT Vertex '" + this.outVid + "', but that vertex does not exist in the graph!"); } try { if (this.inVertex().isRemoved()) { throw new GraphInvariantViolationException("The Edge '" + this.id() + "' with Label '" + this.label() + "' references the IN Vertex '" + this.inVertex().id() + "', but that vertex has been removed!"); } if (Iterators.contains(this.inVertex().edges(Direction.IN, this.label()), this) == false) { throw new GraphInvariantViolationException("The Edge '" + this.id() + "' with Label '" + this.label() + "' references the IN Vertex '" + this.inVertex().id() + "', but that vertex does not list this edge as incoming!"); } } catch (NoSuchElementException e) { throw new GraphInvariantViolationException("The Edge '" + this.id() + "' with Label '" + this.label() + "' references the IN Vertex '" + this.inVid + "', but that vertex does not exist in the graph!"); } break; case OBSOLETE: /* fall through */ case REMOVED: try { // the edge has been removed, assert that it is no longer referenced by adjacent vertices if (!this.outVertex().isRemoved()) { // out vertex still exists, make sure it does not list this edge as outgoing if (Iterators.contains(this.outVertex().edges(Direction.OUT, this.label()), this)) { throw new GraphInvariantViolationException("The Edge '" + this.id() + "' with Label '" + this.label() + "' has been removed, but is still referenced by its OUT Vertex '" + this.outVertex().id() + "'!"); } } } catch (NoSuchElementException expected) { // in this case, we have been unable to resolve the out-vertex, because it has // been deleted and is not present in our cache. This is okay, because if the // out vertex doesn't exist anymore and this edge doesn't exist either, then // there is no inconsistency here. } try { if (!this.inVertex().isRemoved()) { // in vertex still exists, make sure it does not list this edge as incoming if (Iterators.contains(this.inVertex().edges(Direction.IN, this.label()), this)) { throw new GraphInvariantViolationException("The Edge '" + this.id() + "' with Label '" + this.label() + "' has been removed, but is still referenced by its IN Vertex '" + this.inVertex().id() + "'!"); } } } catch (NoSuchElementException expected) { // in this case, we have been unable to resolve the out-vertex, because it has // been deleted and is not present in our cache. This is okay, because if the // out vertex doesn't exist anymore and this edge doesn't exist either, then // there is no inconsistency here. } break; default: throw new UnknownEnumLiteralException(this.getStatus()); } }); } @Override public boolean isLazy() { return this.lazyLoadProperties; } // ===================================================================================================================== // UTILITY // ===================================================================================================================== @SuppressWarnings({"unchecked", "rawtypes"}) private void loadLazyPropertiesIfRequired() { if (this.lazyLoadProperties == false) { // lazy loading of properties is not required return; } ChronoGraphTransaction graphTx = this.getGraphTransaction(); IEdgeRecord edgeRecord = graphTx.getBackingDBTransaction().get(ChronoGraphConstants.KEYSPACE_EDGE, this.id()); if (edgeRecord == null) { List<Long> history = Lists.newArrayList(Iterators.limit(graphTx.getEdgeHistory(this.id()), 10)); int vertices = graphTx.getBackingDBTransaction().keySet(ChronoGraphConstants.KEYSPACE_VERTEX).size(); int edges = graphTx.getBackingDBTransaction().keySet(ChronoGraphConstants.KEYSPACE_EDGE).size(); throw new IllegalStateException( "Failed to load edge properties - there is no backing Edge Record in the database for ID: '" + this.id() + "' at coordinates [" + graphTx.getBranchName() + "@" + graphTx.getTimestamp() + "]! " + "The graph contains " + vertices + " vertices and " + edges + " edges at the specified coordinates. " + "The last 10 commit timestamps on this edge are: " + history); } // load the properties from the edge record for (IPropertyRecord propertyRecord : edgeRecord.getProperties()) { String key = propertyRecord.getKey(); Object value = propertyRecord.getValue(); ChronoProperty<?> property = new ChronoProperty(this, key, value, true); this.properties.put(key, property); } // remember that properties do not need to be re-loaded this.lazyLoadProperties = false; } // ================================================================================================================= // DEBUG OUTPUT // ================================================================================================================= private void logPropertyChange(final String key, final Object value) { if (!log.isTraceEnabled(ChronosLogMarker.CHRONOS_LOG_MARKER__GRAPH_MODIFICATIONS)) { return; } // prepare some debug output StringBuilder messageBuilder = new StringBuilder(); messageBuilder.append(ChronoGraphLoggingUtil.createLogHeader(this.owningTransaction)); messageBuilder.append("Setting Property '"); messageBuilder.append(key); messageBuilder.append("' "); if (this.property(key).isPresent()) { messageBuilder.append("from '"); messageBuilder.append(this.value(key).toString()); messageBuilder.append("' to '"); messageBuilder.append(value.toString()); messageBuilder.append("' "); } else { messageBuilder.append("to '"); messageBuilder.append(value.toString()); messageBuilder.append("' (new property) "); } messageBuilder.append(" on Edge "); messageBuilder.append(this.toString()); messageBuilder.append(" (Object ID: "); messageBuilder.append(System.identityHashCode(this)); messageBuilder.append(")"); log.trace(ChronosLogMarker.CHRONOS_LOG_MARKER__GRAPH_MODIFICATIONS, messageBuilder.toString()); } private void logEdgeRemove() { if (!log.isTraceEnabled(ChronosLogMarker.CHRONOS_LOG_MARKER__GRAPH_MODIFICATIONS)) { return; } // prepare some debug output StringBuilder messageBuilder = new StringBuilder(); messageBuilder.append(ChronoGraphLoggingUtil.createLogHeader(this.owningTransaction)); messageBuilder.append("Removing Edge "); messageBuilder.append(this); messageBuilder.append(" (Object ID: "); messageBuilder.append(System.identityHashCode(this)); messageBuilder.append(")"); log.trace(ChronosLogMarker.CHRONOS_LOG_MARKER__GRAPH_MODIFICATIONS, messageBuilder.toString()); } private void logPropertyRemove(final String key) { if (!log.isTraceEnabled(ChronosLogMarker.CHRONOS_LOG_MARKER__GRAPH_MODIFICATIONS)) { return; } // prepare some debug output StringBuilder messageBuilder = new StringBuilder(); messageBuilder.append(ChronoGraphLoggingUtil.createLogHeader(this.owningTransaction)); messageBuilder.append("Removing Property '"); messageBuilder.append(key); messageBuilder.append("' from Edge "); messageBuilder.append(this); messageBuilder.append(" (Object ID: "); messageBuilder.append(System.identityHashCode(this)); messageBuilder.append(")"); log.trace(ChronosLogMarker.CHRONOS_LOG_MARKER__GRAPH_MODIFICATIONS, messageBuilder.toString()); } // ================================================================================================================= // INNER CLASSES // ================================================================================================================= private class PropertiesIterator<V> implements Iterator<Property<V>> { @SuppressWarnings("rawtypes") private final Iterator<Property> iter; @SuppressWarnings("rawtypes") public PropertiesIterator(final Iterator<Property> iter) { this.iter = iter; } @Override public boolean hasNext() { return this.iter.hasNext(); } @Override @SuppressWarnings("unchecked") public Property<V> next() { Property<V> p = this.iter.next(); return p; } } }
30,047
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoGraphGraphFeatures.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/features/ChronoGraphGraphFeatures.java
package org.chronos.chronograph.internal.impl.structure.graph.features; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Graph.Features.GraphFeatures; import org.chronos.chronodb.api.ChronoDB; import org.chronos.chronodb.inmemory.InMemoryChronoDB; import org.chronos.chronograph.internal.api.structure.ChronoGraphInternal; public class ChronoGraphGraphFeatures extends AbstractChronoGraphFeature implements Graph.Features.GraphFeatures { protected ChronoGraphGraphFeatures(final ChronoGraphInternal graph) { super(graph); } @Override public boolean supportsComputer() { // TODO Graph feature decision PENDING return Graph.Features.GraphFeatures.super.supportsComputer(); } @Override public boolean supportsConcurrentAccess() { // note: cannot have multiple ChronoDBs on the same data source return false; } @Override public boolean supportsPersistence() { // persistence support depends on the backend. ChronoGraphInternal graph = this.getGraph(); ChronoDB db = graph.getBackingDB(); return db.getFeatures().isPersistent(); } @Override public boolean supportsTransactions() { return true; } @Override public boolean supportsThreadedTransactions() { return true; } public boolean supportsRollover(){ return this.getGraph().getBackingDB().getFeatures().isRolloverSupported(); } @Override public boolean supportsOrderabilitySemantics() { return false; } }
1,460
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoGraphFeatures.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/features/ChronoGraphFeatures.java
package org.chronos.chronograph.internal.impl.structure.graph.features; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.util.StringFactory; import org.chronos.chronograph.internal.api.structure.ChronoGraphInternal; public class ChronoGraphFeatures extends AbstractChronoGraphFeature implements Graph.Features { private final ChronoGraphGraphFeatures graphFeatures; private final ChronoVertexFeatures vertexFeatures; private final ChronoEdgeFeatures edgeFeatures; public ChronoGraphFeatures(final ChronoGraphInternal graph) { super(graph); this.graphFeatures = new ChronoGraphGraphFeatures(graph); this.vertexFeatures = new ChronoVertexFeatures(graph); this.edgeFeatures = new ChronoEdgeFeatures(graph); } @Override public ChronoGraphGraphFeatures graph() { return this.graphFeatures; } @Override public VertexFeatures vertex() { return this.vertexFeatures; } @Override public EdgeFeatures edge() { return this.edgeFeatures; } @Override public String toString() { return StringFactory.featureString(this); } }
1,102
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
AbstractChronoGraphFeature.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/features/AbstractChronoGraphFeature.java
package org.chronos.chronograph.internal.impl.structure.graph.features; import static com.google.common.base.Preconditions.*; import org.chronos.chronograph.internal.api.structure.ChronoGraphInternal; abstract class AbstractChronoGraphFeature { private final ChronoGraphInternal graph; protected AbstractChronoGraphFeature(final ChronoGraphInternal graph) { checkNotNull(graph, "Precondition violation - argument 'graph' must not be NULL!"); this.graph = graph; } protected ChronoGraphInternal getGraph() { return this.graph; } }
546
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoGraphEdgePropertyFeatures.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/features/ChronoGraphEdgePropertyFeatures.java
package org.chronos.chronograph.internal.impl.structure.graph.features; import org.apache.tinkerpop.gremlin.structure.Graph; import org.chronos.chronograph.internal.api.structure.ChronoGraphInternal; class ChronoGraphEdgePropertyFeatures extends AbstractChronoGraphFeature implements Graph.Features.EdgePropertyFeatures { // ===================================================================================== // GENERAL // ===================================================================================== protected ChronoGraphEdgePropertyFeatures(final ChronoGraphInternal graph) { super(graph); } @Override public boolean supportsProperties() { return true; } // ===================================================================================== // SUPPORTED DATA TYPES // ===================================================================================== @Override public boolean supportsBooleanValues() { return true; } @Override public boolean supportsBooleanArrayValues() { return true; } @Override public boolean supportsByteValues() { return true; } @Override public boolean supportsByteArrayValues() { return true; } @Override public boolean supportsDoubleValues() { return true; } @Override public boolean supportsDoubleArrayValues() { return true; } @Override public boolean supportsFloatValues() { return true; } @Override public boolean supportsFloatArrayValues() { return true; } @Override public boolean supportsIntegerValues() { return true; } @Override public boolean supportsIntegerArrayValues() { return true; } @Override public boolean supportsLongValues() { return true; } @Override public boolean supportsLongArrayValues() { return true; } @Override public boolean supportsStringValues() { return true; } @Override public boolean supportsStringArrayValues() { return true; } @Override public boolean supportsMapValues() { return true; } @Override public boolean supportsMixedListValues() { return true; } @Override public boolean supportsUniformListValues() { return true; } @Override public boolean supportsSerializableValues() { return true; } }
2,212
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoVertexPropertyFeatures.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/features/ChronoVertexPropertyFeatures.java
package org.chronos.chronograph.internal.impl.structure.graph.features; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Graph.Features.VertexPropertyFeatures; import org.chronos.chronograph.internal.api.structure.ChronoGraphInternal; class ChronoVertexPropertyFeatures extends AbstractChronoGraphFeature implements Graph.Features.VertexPropertyFeatures { public ChronoVertexPropertyFeatures(final ChronoGraphInternal graph) { super(graph); } // ===================================================================================== // GENERAL // ===================================================================================== @Override public boolean supportsProperties() { return true; } // ===================================================================================== // ID HANDLING // ===================================================================================== @Override public boolean supportsCustomIds() { return false; } @Override public boolean supportsAnyIds() { return false; } @Override public boolean supportsNumericIds() { return false; } @Override public boolean supportsStringIds() { return true; } @Override public boolean supportsUuidIds() { return false; } @Override public boolean supportsUserSuppliedIds() { return false; } @Override public boolean supportsNullPropertyValues() { return false; } @Override public boolean willAllowId(final Object id) { return false; } // ===================================================================================== // ADD / REMOVE // ===================================================================================== @Override public boolean supportsRemoveProperty() { return true; } // ===================================================================================== // SUPPORTED DATA TYPES // ===================================================================================== @Override public boolean supportsBooleanValues() { return true; } @Override public boolean supportsBooleanArrayValues() { return true; } @Override public boolean supportsByteValues() { return true; } @Override public boolean supportsByteArrayValues() { return true; } @Override public boolean supportsDoubleValues() { return true; } @Override public boolean supportsDoubleArrayValues() { return true; } @Override public boolean supportsFloatValues() { return true; } @Override public boolean supportsFloatArrayValues() { return true; } @Override public boolean supportsIntegerValues() { return true; } @Override public boolean supportsIntegerArrayValues() { return true; } @Override public boolean supportsLongValues() { return true; } @Override public boolean supportsLongArrayValues() { return true; } @Override public boolean supportsStringValues() { return true; } @Override public boolean supportsStringArrayValues() { return true; } @Override public boolean supportsMapValues() { return true; } @Override public boolean supportsMixedListValues() { return true; } @Override public boolean supportsUniformListValues() { return true; } @Override public boolean supportsSerializableValues() { return true; } }
3,327
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoVertexFeatures.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/features/ChronoVertexFeatures.java
package org.chronos.chronograph.internal.impl.structure.graph.features; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Graph.Features.VertexFeatures; import org.apache.tinkerpop.gremlin.structure.Graph.Features.VertexPropertyFeatures; import org.chronos.chronograph.internal.api.structure.ChronoGraphInternal; class ChronoVertexFeatures extends AbstractChronoGraphFeature implements Graph.Features.VertexFeatures { private final ChronoVertexPropertyFeatures propertyFeatures; public ChronoVertexFeatures(final ChronoGraphInternal graph) { super(graph); this.propertyFeatures = new ChronoVertexPropertyFeatures(graph); } // ===================================================================================== // ID HANDLING // ===================================================================================== @Override public boolean supportsCustomIds() { return false; } @Override public boolean supportsUserSuppliedIds() { return true; } @Override public boolean supportsStringIds() { return true; } @Override public boolean supportsAnyIds() { return false; } @Override public boolean supportsUuidIds() { return false; } @Override public boolean supportsNumericIds() { return false; } @Override public boolean supportsNullPropertyValues() { return false; } @Override public boolean willAllowId(final Object id) { return id != null && id instanceof String; } // ===================================================================================== // ADD PROPERTY / REMOVE PROPERTY // ===================================================================================== @Override public boolean supportsAddProperty() { return true; } @Override public boolean supportsRemoveProperty() { return true; } // ===================================================================================== // ADD VERTEX / REMOVE VERTEX // ===================================================================================== @Override public boolean supportsAddVertices() { return true; } @Override public boolean supportsRemoveVertices() { return true; } // ===================================================================================== // META- & MULTI-PROPERTIES // ===================================================================================== @Override public boolean supportsMetaProperties() { return true; } @Override public boolean supportsMultiProperties() { return false; } @Override public VertexPropertyFeatures properties() { return this.propertyFeatures; } }
2,646
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoEdgeFeatures.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/features/ChronoEdgeFeatures.java
package org.chronos.chronograph.internal.impl.structure.graph.features; import static com.google.common.base.Preconditions.*; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Graph.Features.EdgeFeatures; import org.apache.tinkerpop.gremlin.structure.Graph.Features.EdgePropertyFeatures; import org.chronos.chronograph.internal.api.structure.ChronoGraphInternal; class ChronoEdgeFeatures implements Graph.Features.EdgeFeatures { private final ChronoGraphEdgePropertyFeatures propertyFeatures; public ChronoEdgeFeatures(final ChronoGraphInternal graph) { checkNotNull(graph, "Precondition violation - argument 'graph' must not be NULL!"); this.propertyFeatures = new ChronoGraphEdgePropertyFeatures(graph); } // ===================================================================================== // ID HANDLING // ===================================================================================== @Override public boolean supportsCustomIds() { return false; } @Override public boolean supportsAnyIds() { return false; } @Override public boolean supportsUserSuppliedIds() { return true; } @Override public boolean supportsNumericIds() { return false; } @Override public boolean supportsStringIds() { return true; } @Override public boolean supportsUuidIds() { return false; } @Override public boolean supportsNullPropertyValues() { return false; } @Override public boolean willAllowId(final Object id) { return id != null && id instanceof String; } // ===================================================================================== // ADD EDGE / REMOVE EDGE // ===================================================================================== @Override public boolean supportsAddEdges() { return true; } @Override public boolean supportsRemoveEdges() { return true; } // ===================================================================================== // EDGE PROPERTIES // ===================================================================================== @Override public boolean supportsAddProperty() { return true; } @Override public boolean supportsRemoveProperty() { return true; } @Override public EdgePropertyFeatures properties() { return this.propertyFeatures; } }
2,347
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ReadOnlyChronoGraphIndexManager.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/ReadOnlyChronoGraphIndexManager.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import org.apache.tinkerpop.gremlin.structure.Element; import org.chronos.chronograph.api.builder.index.IndexBuilderStarter; import org.chronos.chronograph.api.index.ChronoGraphIndex; import org.chronos.chronograph.api.index.ChronoGraphIndexManager; import java.util.Set; import static com.google.common.base.Preconditions.*; public class ReadOnlyChronoGraphIndexManager implements ChronoGraphIndexManager { private final ChronoGraphIndexManager manager; public ReadOnlyChronoGraphIndexManager(ChronoGraphIndexManager manager) { checkNotNull(manager, "Precondition violation - argument 'manager' must not be NULL!"); this.manager = manager; } @Override public IndexBuilderStarter create() { return this.unsupportedOperation(); } @Override public Set<ChronoGraphIndex> getIndexedPropertiesAtTimestamp(final Class<? extends Element> clazz, final long timestamp) { return this.manager.getIndexedPropertiesAtTimestamp(clazz, timestamp); } @Override public Set<ChronoGraphIndex> getIndexedPropertiesAtAnyPointInTime(final Class<? extends Element> clazz) { return this.manager.getIndexedPropertiesAtAnyPointInTime(clazz); } @Override public Set<ChronoGraphIndex> getAllIndicesAtAnyPointInTime() { return this.manager.getAllIndicesAtAnyPointInTime(); } @Override public Set<ChronoGraphIndex> getAllIndicesAtTimestamp(final long timestamp) { return this.manager.getAllIndicesAtTimestamp(timestamp); } @Override public ChronoGraphIndex getVertexIndexAtTimestamp(final String indexedPropertyName, final long timestamp) { return this.manager.getVertexIndexAtTimestamp(indexedPropertyName, timestamp); } @Override public Set<ChronoGraphIndex> getVertexIndicesAtAnyPointInTime(final String indexedPropertyName) { return this.manager.getVertexIndicesAtAnyPointInTime(indexedPropertyName); } @Override public ChronoGraphIndex getEdgeIndexAtTimestamp(final String indexedPropertyName, final long timestamp) { return this.manager.getEdgeIndexAtTimestamp(indexedPropertyName, timestamp); } @Override public Set<ChronoGraphIndex> getEdgeIndicesAtAnyPointInTime(final String indexedPropertyName) { return this.manager.getEdgeIndicesAtAnyPointInTime(indexedPropertyName); } @Override public void reindexAll(boolean force) { this.unsupportedOperation(); } @Override public void dropIndex(final ChronoGraphIndex index) { this.unsupportedOperation(); } @Override public void dropAllIndices() { this.unsupportedOperation(); } @Override public void dropAllIndices(Object commitMetadata) { this.unsupportedOperation(); } @Override public ChronoGraphIndex terminateIndex(final ChronoGraphIndex index, final long timestamp) { return this.unsupportedOperation(); } @Override public boolean isReindexingRequired() { return this.manager.isReindexingRequired(); } private <T> T unsupportedOperation() { throw new UnsupportedOperationException("This operation is not supported in a read-only graph!"); } }
3,310
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ReadOnlyGraphTransactionContext.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/ReadOnlyGraphTransactionContext.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import com.google.common.collect.Sets; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.chronos.chronograph.api.structure.ChronoEdge; import org.chronos.chronograph.api.structure.ChronoElement; import org.chronos.chronograph.api.structure.ChronoVertex; import org.chronos.chronograph.api.transaction.GraphTransactionContext; import java.util.Collections; import java.util.Set; import java.util.stream.Collectors; import static com.google.common.base.Preconditions.*; public class ReadOnlyGraphTransactionContext implements GraphTransactionContext { private final GraphTransactionContext context; public ReadOnlyGraphTransactionContext(GraphTransactionContext context) { checkNotNull(context, "Precondition violation - argument 'context' must not be NULL!"); this.context = context; } @Override public Set<ChronoVertex> getModifiedVertices() { Set<ChronoVertex> vertices = this.context.getModifiedVertices(); Set<ChronoVertex> result = vertices.stream().map(ReadOnlyChronoVertex::new).collect(Collectors.toSet()); return Collections.unmodifiableSet(result); } @Override public Set<ChronoEdge> getModifiedEdges() { Set<ChronoEdge> edges = this.context.getModifiedEdges(); Set<ChronoEdge> result = edges.stream().map(ReadOnlyChronoEdge::new).collect(Collectors.toSet()); return Collections.unmodifiableSet(result); } @Override public Set<String> getModifiedVariables(String keyspace) { return Collections.unmodifiableSet(this.context.getModifiedVariables(keyspace)); } @Override public Set<ChronoElement> getModifiedElements() { Set<ChronoElement> allElements = Sets.newHashSet(); allElements.addAll(this.getModifiedVertices()); allElements.addAll(this.getModifiedEdges()); return Collections.unmodifiableSet(allElements); } @Override public boolean isDirty() { return this.context.isDirty(); } @Override public boolean isVertexModified(final Vertex vertex) { return this.context.isVertexModified(vertex); } @Override public boolean isVertexModified(final String vertexId) { return this.context.isVertexModified(vertexId); } @Override public boolean isEdgeModified(final Edge edge) { return this.context.isEdgeModified(edge); } @Override public boolean isEdgeModified(final String edgeId) { return this.context.isEdgeModified(edgeId); } @Override public boolean isVariableModified(final String keyspace, final String variableName) { return this.context.isVariableModified(keyspace, variableName); } @Override public boolean isVariableRemoved(final String keyspace, final String variableName) { return this.context.isVariableRemoved(keyspace, variableName); } @Override public Object getModifiedVariableValue(final String keyspace, final String variableName) { return this.context.getModifiedVariableValue(keyspace, variableName); } @Override public Set<String> getModifiedVariableKeyspaces() { return Collections.unmodifiableSet(this.context.getModifiedVariableKeyspaces()); } @Override public Set<String> getRemovedVariables(String keyspace) { return Collections.unmodifiableSet(this.context.getRemovedVariables(keyspace)); } @Override public void clear() { throw new UnsupportedOperationException("This operation is not supported in a read-only graph!"); } @Override public ChronoVertex getModifiedVertex(final String id) { ChronoVertex vertex = this.context.getModifiedVertex(id); if (vertex == null) { return null; } return new ReadOnlyChronoVertex(vertex); } @Override public ChronoEdge getModifiedEdge(final String id) { ChronoEdge edge = this.context.getModifiedEdge(id); if (edge == null) { return null; } return new ReadOnlyChronoEdge(edge); } }
4,212
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ReadOnlyVariables.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/ReadOnlyVariables.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import org.chronos.chronograph.api.structure.ChronoGraphVariables; import java.util.Collections; import java.util.Map; import java.util.Optional; import java.util.Set; import static com.google.common.base.Preconditions.*; public class ReadOnlyVariables implements ChronoGraphVariables { private final ChronoGraphVariables variables; public ReadOnlyVariables(final ChronoGraphVariables variables) { checkNotNull(variables, "Precondition violation - argument 'variables' must not be NULL!"); this.variables = variables; } @Override public Set<String> keys() { return Collections.unmodifiableSet(this.variables.keys()); } @Override public Set<String> keys(final String keyspace) { return Collections.unmodifiableSet(this.variables.keys(keyspace)); } @Override public <R> Optional<R> get(final String key) { return this.variables.get(key); } @Override public <R> Optional<R> get(final String keyspace, final String key) { return this.variables.get(keyspace, key); } @Override public void set(final String key, final Object value) { this.unsupportedOperation(); } @Override public void set(final String keyspace, final String key, final Object value) { this.unsupportedOperation(); } @Override public void remove(final String key) { this.unsupportedOperation(); } @Override public void remove(final String keyspace, final String key) { this.unsupportedOperation(); } @Override public Map<String, Object> asMap() { return Collections.unmodifiableMap(this.variables.asMap()); } @Override public Map<String, Object> asMap(final String keyspace) { return Collections.unmodifiableMap(this.variables.asMap(keyspace)); } @Override public Set<String> keyspaces() { return Collections.unmodifiableSet(this.variables.keyspaces()); } private void unsupportedOperation() { throw new UnsupportedOperationException("This operation is not supported for readOnly graph!"); } }
2,210
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ReadOnlyChronoElement.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/ReadOnlyChronoElement.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import org.chronos.chronograph.api.structure.ChronoElement; import org.chronos.chronograph.api.structure.ChronoGraph; import org.chronos.chronograph.api.structure.ElementLifecycleStatus; import org.chronos.chronograph.api.structure.PropertyStatus; import org.chronos.chronograph.api.transaction.ChronoGraphTransaction; import org.chronos.chronograph.internal.api.structure.ChronoElementInternal; import org.chronos.chronograph.internal.impl.structure.graph.ChronoProperty; import org.chronos.chronograph.internal.impl.structure.graph.ElementLifecycleEvent; import static com.google.common.base.Preconditions.*; public abstract class ReadOnlyChronoElement implements ChronoElementInternal { protected ChronoElement element; public ReadOnlyChronoElement(ChronoElement element) { checkNotNull(element, "Precondition violation - argument 'element' must not be NULL!"); this.element = element; } @Override public String id() { return this.element.id(); } @Override public String label() { return this.element.label(); } @Override public ChronoGraph graph() { return new ReadOnlyChronoGraph(this.element.graph()); } @Override public void remove() { this.unsupportedOperation(); } @Override public void removeProperty(final String key) { this.unsupportedOperation(); } @Override public boolean isRemoved() { return this.element.isRemoved(); } @Override public ChronoGraphTransaction getOwningTransaction() { return new ReadOnlyChronoGraphTransaction(this.element.getOwningTransaction()); } @Override public long getLoadedAtRollbackCount() { return this.element.getLoadedAtRollbackCount(); } @Override public void updateLifecycleStatus(final ElementLifecycleEvent status) { this.unsupportedOperation(); } @Override public ElementLifecycleStatus getStatus() { return this.element.getStatus(); } @Override public PropertyStatus getPropertyStatus(final String propertyKey) { return this.element.getPropertyStatus(propertyKey); } @Override public boolean isLazy() { return this.element.isLazy(); } protected <T> T unsupportedOperation() { throw new UnsupportedOperationException("Unsupported operation for readOnly graph!"); } @Override public void notifyPropertyChanged(final ChronoProperty<?> chronoProperty) { throw new UnsupportedOperationException("Properties must not change in a readOnly graph!"); } }
2,693
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ReadOnlyChronoGraphTransactionManager.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/ReadOnlyChronoGraphTransactionManager.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource; import org.apache.tinkerpop.gremlin.structure.Transaction; import org.chronos.chronograph.api.structure.ChronoGraph; import org.chronos.chronograph.api.transaction.ChronoGraphTransaction; import org.chronos.chronograph.api.transaction.ChronoGraphTransactionManager; import java.util.Date; import java.util.function.Consumer; import static com.google.common.base.Preconditions.*; public class ReadOnlyChronoGraphTransactionManager implements ChronoGraphTransactionManager { private ChronoGraphTransactionManager manager; public ReadOnlyChronoGraphTransactionManager(ChronoGraphTransactionManager manager){ checkNotNull(manager, "Precondition violation - argument 'manager' must not be NULL!"); this.manager = manager; } @Override public void open(final long timestamp) { this.unsupportedOperation(); } @Override public void open(final Date date) { this.unsupportedOperation(); } @Override public void open(final String branch) { this.unsupportedOperation(); } @Override public void open(final String branch, final long timestamp) { this.unsupportedOperation(); } @Override public void open(final String branch, final Date date) { this.unsupportedOperation(); } @Override public void reset() { this.unsupportedOperation(); } @Override public void reset(final long timestamp) { this.unsupportedOperation(); } @Override public void reset(final Date date) { this.unsupportedOperation(); } @Override public void reset(final String branch, final long timestamp) { this.unsupportedOperation(); } @Override public void reset(final String branch, final Date date) { this.unsupportedOperation(); } @Override public ChronoGraph createThreadedTx() { return this.unsupportedOperation(); } @Override public ChronoGraph createThreadedTx(final long timestamp) { return this.unsupportedOperation(); } @Override public ChronoGraph createThreadedTx(final Date date) { return this.unsupportedOperation(); } @Override public ChronoGraph createThreadedTx(final String branchName) { return this.unsupportedOperation(); } @Override public ChronoGraph createThreadedTx(final String branchName, final long timestamp) { return this.unsupportedOperation(); } @Override public ChronoGraph createThreadedTx(final String branchName, final Date date) { return this.unsupportedOperation(); } @Override public void commitIncremental() { this.unsupportedOperation(); } @Override public void commit(final Object metadata) { this.unsupportedOperation(); } @Override public long commitAndReturnTimestamp() { return this.unsupportedOperation(); } @Override public long commitAndReturnTimestamp(final Object metadata) { return this.unsupportedOperation(); } @Override public ChronoGraphTransaction getCurrentTransaction() { return new ReadOnlyChronoGraphTransaction(this.manager.getCurrentTransaction()); } @Override public void open() { this.unsupportedOperation(); } @Override public void commit() { this.unsupportedOperation(); } @Override public void rollback() { // transaction was read-only to begin with; nothing to do! } @Override public <T extends TraversalSource> T begin(final Class<T> traversalSourceClass) { return this.manager.begin(traversalSourceClass); } @Override public boolean isOpen() { return this.manager.isOpen(); } @Override public void readWrite() { this.unsupportedOperation(); } @Override public void close() { this.unsupportedOperation(); } @Override public Transaction onReadWrite(final Consumer<Transaction> consumer) { return this.unsupportedOperation(); } @Override public Transaction onClose(final Consumer<Transaction> consumer) { return this.unsupportedOperation(); } @Override public void addTransactionListener(final Consumer<Status> listener) { this.unsupportedOperation(); } @Override public void removeTransactionListener(final Consumer<Status> listener) { this.unsupportedOperation(); } @Override public void clearTransactionListeners() { this.unsupportedOperation(); } private <T> T unsupportedOperation(){ throw new UnsupportedOperationException("This operation is not supported on a read-only graph!"); } }
4,899
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ReadOnlyConfiguration.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/ReadOnlyConfiguration.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import com.google.common.collect.Iterators; import org.apache.commons.configuration2.Configuration; import org.apache.commons.configuration2.ConfigurationDecoder; import org.apache.commons.configuration2.ImmutableConfiguration; import org.apache.commons.configuration2.interpol.ConfigurationInterpolator; import org.apache.commons.configuration2.interpol.Lookup; import org.apache.commons.configuration2.sync.LockMode; import org.apache.commons.configuration2.sync.Synchronizer; import java.math.BigDecimal; import java.math.BigInteger; import java.util.*; import static com.google.common.base.Preconditions.*; public class ReadOnlyConfiguration implements Configuration { private final Configuration configuration; public ReadOnlyConfiguration(final Configuration configuration) { checkNotNull(configuration, "Precondition violation - argument 'configuration' must not be NULL!"); this.configuration = configuration; } @Override public ConfigurationInterpolator getInterpolator() { // the interpolator is mutable so we hide it completely. return null; } @Override public void setInterpolator(final ConfigurationInterpolator ci) { this.unsupportedOperation(); } @Override public void installInterpolator(final Map<String, ? extends Lookup> prefixLookups, final Collection<? extends Lookup> defLookups) { this.unsupportedOperation(); } @Override public int size() { return this.configuration.size(); } @Override public String getEncodedString(final String key) { return this.configuration.getEncodedString(key); } @Override public String getEncodedString(final String key, final ConfigurationDecoder decoder) { return this.configuration.getEncodedString(key, decoder); } @Override public Configuration subset(final String prefix) { return new ReadOnlyConfiguration(this.configuration.subset(prefix)); } @Override public boolean isEmpty() { return this.configuration.isEmpty(); } @Override public boolean containsKey(final String key) { return this.configuration.containsKey(key); } @Override public void addProperty(final String key, final Object value) { this.unsupportedOperation(); } @Override public void setProperty(final String key, final Object value) { this.unsupportedOperation(); } @Override public void clearProperty(final String key) { this.unsupportedOperation(); } @Override public void clear() { this.unsupportedOperation(); } @Override public Object getProperty(final String key) { return this.configuration.getProperty(key); } @Override public Iterator<String> getKeys(final String prefix) { return Iterators.unmodifiableIterator(this.configuration.getKeys(prefix)); } @Override public Iterator<String> getKeys() { return Iterators.unmodifiableIterator(this.configuration.getKeys()); } @Override public Properties getProperties(final String key) { return new Properties(this.configuration.getProperties(key)); } @Override public boolean getBoolean(final String key) { return this.configuration.getBoolean(key); } @Override public boolean getBoolean(final String key, final boolean defaultValue) { return this.configuration.getBoolean(key, defaultValue); } @Override public Boolean getBoolean(final String key, final Boolean defaultValue) { return this.configuration.getBoolean(key, defaultValue); } @Override public byte getByte(final String key) { return this.configuration.getByte(key); } @Override public byte getByte(final String key, final byte defaultValue) { return this.configuration.getByte(key, defaultValue); } @Override public Byte getByte(final String key, final Byte defaultValue) { return this.configuration.getByte(key, defaultValue); } @Override public double getDouble(final String key) { return this.configuration.getDouble(key); } @Override public double getDouble(final String key, final double defaultValue) { return this.configuration.getDouble(key, defaultValue); } @Override public Double getDouble(final String key, final Double defaultValue) { return this.configuration.getDouble(key, defaultValue); } @Override public float getFloat(final String key) { return this.configuration.getFloat(key); } @Override public float getFloat(final String key, final float defaultValue) { return this.configuration.getFloat(key, defaultValue); } @Override public Float getFloat(final String key, final Float defaultValue) { return this.configuration.getFloat(key, defaultValue); } @Override public int getInt(final String key) { return this.configuration.getInt(key); } @Override public int getInt(final String key, final int defaultValue) { return this.configuration.getInt(key, defaultValue); } @Override public Integer getInteger(final String key, final Integer defaultValue) { return this.configuration.getInteger(key, defaultValue); } @Override public long getLong(final String key) { return this.configuration.getLong(key); } @Override public long getLong(final String key, final long defaultValue) { return this.configuration.getLong(key, defaultValue); } @Override public Long getLong(final String key, final Long defaultValue) { return this.configuration.getLong(key, defaultValue); } @Override public short getShort(final String key) { return this.configuration.getShort(key); } @Override public short getShort(final String key, final short defaultValue) { return this.configuration.getShort(key, defaultValue); } @Override public Short getShort(final String key, final Short defaultValue) { return this.configuration.getShort(key, defaultValue); } @Override public BigDecimal getBigDecimal(final String key) { return this.configuration.getBigDecimal(key); } @Override public BigDecimal getBigDecimal(final String key, final BigDecimal defaultValue) { return this.configuration.getBigDecimal(key, defaultValue); } @Override public BigInteger getBigInteger(final String key) { return this.configuration.getBigInteger(key); } @Override public BigInteger getBigInteger(final String key, final BigInteger defaultValue) { return this.configuration.getBigInteger(key, defaultValue); } @Override public String getString(final String key) { return this.configuration.getString(key); } @Override public String getString(final String key, final String defaultValue) { return this.configuration.getString(key, defaultValue); } @Override public String[] getStringArray(final String key) { String[] array = this.configuration.getStringArray(key); return Arrays.copyOf(array, array.length); } @Override public List<Object> getList(final String key) { return Collections.unmodifiableList(this.configuration.getList(key)); } @Override public List<Object> getList(final String key, final List<?> defaultValue) { return Collections.unmodifiableList(this.configuration.getList(key, defaultValue)); } @Override public <T> T get(final Class<T> cls, final String key) { return this.configuration.get(cls, key); } @Override public <T> T get(final Class<T> cls, final String key, final T defaultValue) { return this.configuration.get(cls, key, defaultValue); } @Override public Object getArray(final Class<?> cls, final String key) { return this.configuration.getArray(cls, key); } @Override @SuppressWarnings("deprecation") public Object getArray(final Class<?> cls, final String key, final Object defaultValue) { return this.configuration.getArray(cls, key, defaultValue); } @Override public <T> List<T> getList(final Class<T> cls, final String key) { return Collections.unmodifiableList(this.configuration.getList(cls, key)); } @Override public <T> List<T> getList(final Class<T> cls, final String key, final List<T> defaultValue) { return Collections.unmodifiableList(this.configuration.getList(cls, key, defaultValue)); } @Override public <T> Collection<T> getCollection(final Class<T> cls, final String key, final Collection<T> target) { return Collections.unmodifiableCollection(this.configuration.getCollection(cls, key, target)); } @Override public <T> Collection<T> getCollection(final Class<T> cls, final String key, final Collection<T> target, final Collection<T> defaultValue) { return Collections.unmodifiableCollection(this.configuration.getCollection(cls, key, target, defaultValue)); } @Override public ImmutableConfiguration immutableSubset(final String prefix) { return this.configuration.immutableSubset(prefix); } private void unsupportedOperation() { throw new UnsupportedOperationException("Unsupported method for readOnly graph!"); } @Override public Synchronizer getSynchronizer() { return this.configuration.getSynchronizer(); } @Override public void setSynchronizer(final Synchronizer sync) { this.unsupportedOperation(); } @Override public void lock(final LockMode mode) { this.configuration.lock(mode); } @Override public void unlock(final LockMode mode) { this.configuration.unlock(mode); } }
10,041
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
NoTransactionControlChronoGraph.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/NoTransactionControlChronoGraph.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import org.apache.commons.configuration2.Configuration; import org.apache.commons.lang3.tuple.Pair; import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.chronos.chronodb.api.DumpOption; import org.chronos.chronodb.api.Order; import org.chronos.chronograph.api.branch.ChronoGraphBranchManager; import org.chronos.chronograph.api.history.ChronoGraphHistoryManager; import org.chronos.chronograph.api.index.ChronoGraphIndexManager; import org.chronos.chronograph.api.maintenance.ChronoGraphMaintenanceManager; import org.chronos.chronograph.api.schema.ChronoGraphSchemaManager; import org.chronos.chronograph.api.statistics.ChronoGraphStatisticsManager; import org.chronos.chronograph.api.structure.ChronoGraph; import org.chronos.chronograph.api.structure.ChronoGraphVariables; import org.chronos.chronograph.api.transaction.ChronoGraphTransactionManager; import org.chronos.chronograph.api.transaction.trigger.ChronoGraphTriggerManager; import org.chronos.chronograph.internal.api.configuration.ChronoGraphConfiguration; import java.io.File; import java.util.Iterator; import java.util.List; import java.util.Map.Entry; import static com.google.common.base.Preconditions.*; public class NoTransactionControlChronoGraph implements ChronoGraph { private final ChronoGraph graph; public NoTransactionControlChronoGraph(ChronoGraph graph) { this.graph = graph; } @Override public ChronoGraphTransactionManager tx() { return new NoTransactionControlTransactionManager(this.graph.tx()); } @Override public ChronoGraphConfiguration getChronoGraphConfiguration() { return this.graph.getChronoGraphConfiguration(); } @Override public void close() { this.graph.close(); } @Override public ChronoGraphVariables variables() { return this.graph.variables(); } @Override public Configuration configuration() { return this.graph.configuration(); } @Override public boolean isClosed() { return this.graph.isClosed(); } @Override public long getNow() { return this.graph.getNow(); } @Override public long getNow(final String branchName) { return this.graph.getNow(branchName); } @Override public Vertex addVertex(final Object... keyValues) { return this.graph.addVertex(keyValues); } @Override public <C extends GraphComputer> C compute(final Class<C> graphComputerClass) throws IllegalArgumentException { return this.graph.compute(graphComputerClass); } @Override public GraphComputer compute() throws IllegalArgumentException { return this.graph.compute(); } @Override public Iterator<Vertex> vertices(final Object... vertexIds) { return this.graph.vertices(vertexIds); } @Override public Iterator<Edge> edges(final Object... edgeIds) { return this.graph.edges(edgeIds); } @Override public Iterator<Long> getVertexHistory(final Object vertexId, final long lowerBound, final long upperBound, final Order order) { return this.graph.getVertexHistory(vertexId, lowerBound, upperBound, order); } @Override public Iterator<Long> getEdgeHistory(final Object edgeId, final long lowerBound, final long upperBound, final Order order) { return this.graph.getEdgeHistory(edgeId, lowerBound, upperBound, order); } @Override public Iterator<Long> getEdgeHistory(final Edge edge) { return this.graph.getEdgeHistory(edge); } @Override public long getLastModificationTimestampOfVertex(final Vertex vertex) { checkNotNull(vertex, "Precondition violation - argument 'vertex' must not be NULL!"); return this.graph.getLastModificationTimestampOfVertex(vertex); } @Override public long getLastModificationTimestampOfVertex(final Object vertexId) { checkNotNull(vertexId, "Precondition violation - argument 'vertexId' must not be NULL!"); return this.graph.getLastModificationTimestampOfVertex(vertexId); } @Override public long getLastModificationTimestampOfEdge(final Edge edge) { checkNotNull(edge, "Precondition violation - argument 'edge' must not be NULL!"); return this.graph.getLastModificationTimestampOfEdge(edge); } @Override public long getLastModificationTimestampOfEdge(final Object edgeId) { checkNotNull(edgeId, "Precondition violation - argument 'edgeId' must not be NULL!"); return this.graph.getLastModificationTimestampOfEdge(edgeId); } @Override public Iterator<Pair<Long, String>> getVertexModificationsBetween(final long timestampLowerBound, final long timestampUpperBound) { return this.graph.getVertexModificationsBetween(timestampLowerBound, timestampUpperBound); } @Override public Iterator<Pair<Long, String>> getEdgeModificationsBetween(final long timestampLowerBound, final long timestampUpperBound) { return this.graph.getEdgeModificationsBetween(timestampLowerBound, timestampUpperBound); } @Override public Object getCommitMetadata(final String branch, final long timestamp) { return this.graph.getCommitMetadata(branch, timestamp); } @Override public Iterator<Long> getCommitTimestampsBetween(final String branch, final long from, final long to, final Order order, final boolean includeSystemInternalCommits) { return this.graph.getCommitTimestampsBetween(branch, from, to, order, includeSystemInternalCommits); } @Override public Iterator<Entry<Long, Object>> getCommitMetadataBetween(final String branch, final long from, final long to, final Order order, final boolean includeSystemInternalCommits) { return this.graph.getCommitMetadataBetween(branch, from, to, order, includeSystemInternalCommits); } @Override public Iterator<Long> getCommitTimestampsPaged(final String branch, final long minTimestamp, final long maxTimestamp, final int pageSize, final int pageIndex, final Order order, final boolean includeSystemInternalCommits) { return this.graph.getCommitTimestampsPaged(branch, minTimestamp, maxTimestamp, pageSize, pageIndex, order, includeSystemInternalCommits); } @Override public Iterator<Entry<Long, Object>> getCommitMetadataPaged(final String branch, final long minTimestamp, final long maxTimestamp, final int pageSize, final int pageIndex, final Order order, final boolean includeSystemInternalCommits) { return this.graph.getCommitMetadataPaged(branch, minTimestamp, maxTimestamp, pageSize, pageIndex, order, includeSystemInternalCommits); } @Override public List<Entry<Long, Object>> getCommitMetadataAround(final String branch, final long timestamp, final int count, final boolean includeSystemInternalCommits) { return this.graph.getCommitMetadataAround(branch, timestamp, count, includeSystemInternalCommits); } @Override public List<Entry<Long, Object>> getCommitMetadataBefore(final String branch, final long timestamp, final int count, final boolean includeSystemInternalCommits) { return this.graph.getCommitMetadataBefore(branch, timestamp, count, includeSystemInternalCommits); } @Override public List<Entry<Long, Object>> getCommitMetadataAfter(final String branch, final long timestamp, final int count, final boolean includeSystemInternalCommits) { return this.graph.getCommitMetadataAfter(branch, timestamp, count, includeSystemInternalCommits); } @Override public List<Long> getCommitTimestampsAround(final String branch, final long timestamp, final int count, final boolean includeSystemInternalCommits) { return this.graph.getCommitTimestampsAround(branch, timestamp, count, includeSystemInternalCommits); } @Override public List<Long> getCommitTimestampsBefore(final String branch, final long timestamp, final int count, final boolean includeSystemInternalCommits) { return this.graph.getCommitTimestampsBefore(branch, timestamp, count, includeSystemInternalCommits); } @Override public List<Long> getCommitTimestampsAfter(final String branch, final long timestamp, final int count, final boolean includeSystemInternalCommits) { return this.graph.getCommitTimestampsAfter(branch, timestamp, count, includeSystemInternalCommits); } @Override public int countCommitTimestampsBetween(final String branch, final long from, final long to, final boolean includeSystemInternalCommits) { return this.graph.countCommitTimestampsBetween(branch, from, to, includeSystemInternalCommits); } @Override public int countCommitTimestamps(final String branch, boolean includeSystemInternalCommits) { return this.graph.countCommitTimestamps(branch, includeSystemInternalCommits); } @Override public Iterator<String> getChangedVerticesAtCommit(final String branch, final long commitTimestamp) { return this.graph.getChangedVerticesAtCommit(branch, commitTimestamp); } @Override public Iterator<String> getChangedEdgesAtCommit(final String branch, final long commitTimestamp) { return this.graph.getChangedEdgesAtCommit(branch, commitTimestamp); } @Override public Iterator<Pair<String, String>> getChangedGraphVariablesAtCommit(final long commitTimestamp) { return this.graph.getChangedGraphVariablesAtCommit(commitTimestamp); } @Override public Iterator<String> getChangedGraphVariablesAtCommitInDefaultKeyspace(final long commitTimestamp) { return this.graph.getChangedGraphVariablesAtCommitInDefaultKeyspace(commitTimestamp); } @Override public Iterator<String> getChangedGraphVariablesAtCommitInKeyspace(final long commitTimestamp, final String keyspace) { return this.graph.getChangedGraphVariablesAtCommitInKeyspace(commitTimestamp, keyspace); } @Override public Iterator<Pair<String, String>> getChangedGraphVariablesAtCommit(final String branch, final long commitTimestamp) { return this.graph.getChangedGraphVariablesAtCommit(branch, commitTimestamp); } @Override public Iterator<String> getChangedGraphVariablesAtCommitInDefaultKeyspace(final String branch, final long commitTimestamp) { return this.graph.getChangedGraphVariablesAtCommitInDefaultKeyspace(branch, commitTimestamp); } @Override public Iterator<String> getChangedGraphVariablesAtCommitInKeyspace(final String branch, final long commitTimestamp, final String keyspace) { return this.graph.getChangedGraphVariablesAtCommitInKeyspace(branch, commitTimestamp, keyspace); } @Override public ChronoGraphIndexManager getIndexManagerOnMaster() { return this.graph.getIndexManagerOnMaster(); } @Override public ChronoGraphIndexManager getIndexManagerOnBranch(final String branchName) { return this.graph.getIndexManagerOnBranch(branchName); } @Override public ChronoGraphBranchManager getBranchManager() { return this.graph.getBranchManager(); } @Override public ChronoGraphTriggerManager getTriggerManager() { return this.graph.getTriggerManager(); } @Override public ChronoGraphSchemaManager getSchemaManager() { return this.graph.getSchemaManager(); } @Override public ChronoGraphStatisticsManager getStatisticsManager(){ return this.graph.getStatisticsManager(); } @Override public ChronoGraphMaintenanceManager getMaintenanceManager(){ return this.graph.getMaintenanceManager(); } @Override public ChronoGraphHistoryManager getHistoryManager() { return this.graph.getHistoryManager(); } @Override public void writeDump(final File dumpFile, final DumpOption... dumpOptions) { this.graph.writeDump(dumpFile, dumpOptions); } @Override public void readDump(final File dumpFile, final DumpOption... options) { this.graph.readDump(dumpFile, options); } }
12,312
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ReadOnlyHistoryManager.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/ReadOnlyHistoryManager.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import org.chronos.chronograph.api.history.ChronoGraphHistoryManager; import org.chronos.chronograph.api.history.RestoreResult; import java.util.Set; import static com.google.common.base.Preconditions.*; public class ReadOnlyHistoryManager implements ChronoGraphHistoryManager { private final ChronoGraphHistoryManager manager; public ReadOnlyHistoryManager(ChronoGraphHistoryManager manager){ checkNotNull(manager, "Precondition violation - argument 'manager' must not be NULL!"); this.manager = manager; } @Override public RestoreResult restoreGraphElementsAsOf(final long timestamp, final Set<String> vertexIds, final Set<String> edgeIds) { throw new UnsupportedOperationException("This operation is not supported in a read-only graph!"); } @Override public RestoreResult restoreGraphStateAsOf(final long timestamp) { throw new UnsupportedOperationException("This operation is not supported in a read-only graph!"); } }
1,072
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ReadOnlyChronoGraph.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/ReadOnlyChronoGraph.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import com.google.common.collect.Iterators; import org.apache.commons.configuration2.Configuration; import org.apache.commons.lang3.tuple.Pair; import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.chronos.chronodb.api.DumpOption; import org.chronos.chronodb.api.Order; import org.chronos.chronograph.api.branch.ChronoGraphBranchManager; import org.chronos.chronograph.api.history.ChronoGraphHistoryManager; import org.chronos.chronograph.api.index.ChronoGraphIndexManager; import org.chronos.chronograph.api.maintenance.ChronoGraphMaintenanceManager; import org.chronos.chronograph.api.schema.ChronoGraphSchemaManager; import org.chronos.chronograph.api.statistics.ChronoGraphStatisticsManager; import org.chronos.chronograph.api.structure.ChronoEdge; import org.chronos.chronograph.api.structure.ChronoGraph; import org.chronos.chronograph.api.structure.ChronoGraphVariables; import org.chronos.chronograph.api.structure.ChronoVertex; import org.chronos.chronograph.api.transaction.ChronoGraphTransactionManager; import org.chronos.chronograph.api.transaction.trigger.ChronoGraphTriggerManager; import org.chronos.chronograph.internal.api.configuration.ChronoGraphConfiguration; import java.io.File; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import static com.google.common.base.Preconditions.*; public class ReadOnlyChronoGraph implements ChronoGraph { private ChronoGraph graph; public ReadOnlyChronoGraph(ChronoGraph graph) { checkNotNull(graph, "Precondition violation - argument 'graph' must not be NULL!"); this.graph = graph; } @Override public ChronoGraphConfiguration getChronoGraphConfiguration() { return this.graph.getChronoGraphConfiguration(); } @Override public void close() { this.unsupportedOperation(); } @Override public ChronoGraphVariables variables() { return new ReadOnlyVariables(this.graph.variables()); } @Override public Configuration configuration() { return new ReadOnlyConfiguration(this.graph.configuration()); } @Override public boolean isClosed() { return this.graph.isClosed(); } @Override public long getNow() { return this.graph.getNow(); } @Override public long getNow(final String branchName) { return this.graph.getNow(branchName); } @Override public Vertex addVertex(final Object... keyValues) { return this.unsupportedOperation(); } @Override public <C extends GraphComputer> C compute(final Class<C> graphComputerClass) throws IllegalArgumentException { return this.graph.compute(graphComputerClass); } @Override public GraphComputer compute() throws IllegalArgumentException { return this.graph.compute(); } @Override @SuppressWarnings({"unchecked", "rawtypes"}) public Iterator<Vertex> vertices(final Object... vertexIds) { Iterator<ChronoVertex> vertices = (Iterator) this.graph.vertices(vertexIds); return Iterators.transform(vertices, ReadOnlyChronoVertex::new); } @Override @SuppressWarnings({"unchecked", "rawtypes"}) public Iterator<Edge> edges(final Object... edgeIds) { Iterator<ChronoEdge> edges = (Iterator) this.graph.edges(edgeIds); return Iterators.transform(edges, ReadOnlyChronoEdge::new); } @Override public ChronoGraphTransactionManager tx() { return new ReadOnlyChronoGraphTransactionManager(this.graph.tx()); } @Override public Iterator<Long> getVertexHistory(final Object vertexId, final long lowerBound, final long upperBound, final Order order) { Iterator<Long> history = this.graph.getVertexHistory(vertexId, lowerBound, upperBound, order); return Iterators.unmodifiableIterator(history); } @Override public Iterator<Long> getEdgeHistory(final Object edgeId) { Iterator<Long> history = this.graph.getEdgeHistory(edgeId); return Iterators.unmodifiableIterator(history); } @Override public Iterator<Long> getEdgeHistory(final Object edgeId, final long lowerBound, final long upperBound, final Order order) { Iterator<Long> history = this.graph.getEdgeHistory(edgeId, lowerBound, upperBound,order); return Iterators.unmodifiableIterator(history); } @Override public long getLastModificationTimestampOfVertex(final Vertex vertex) { checkNotNull(vertex, "Precondition violation - argument 'vertex' must not be NULL!"); return this.graph.getLastModificationTimestampOfVertex(vertex); } @Override public long getLastModificationTimestampOfVertex(final Object vertexId) { checkNotNull(vertexId, "Precondition violation - argument 'vertexId' must not be NULL!"); return this.graph.getLastModificationTimestampOfVertex(vertexId); } @Override public long getLastModificationTimestampOfEdge(final Edge edge) { checkNotNull(edge, "Precondition violation - argument 'edge' must not be NULL!"); return this.graph.getLastModificationTimestampOfEdge(edge); } @Override public long getLastModificationTimestampOfEdge(final Object edgeId) { checkNotNull(edgeId, "Precondition violation - argument 'edgeId' must not be NULL!"); return this.graph.getLastModificationTimestampOfEdge(edgeId); } @Override public Iterator<Pair<Long, String>> getVertexModificationsBetween(final long timestampLowerBound, final long timestampUpperBound) { Iterator<Pair<Long, String>> modifications = this.graph.getVertexModificationsBetween(timestampLowerBound, timestampUpperBound); return Iterators.unmodifiableIterator(modifications); } @Override public Iterator<Pair<Long, String>> getEdgeModificationsBetween(final long timestampLowerBound, final long timestampUpperBound) { Iterator<Pair<Long, String>> modifications = this.graph.getEdgeModificationsBetween(timestampLowerBound, timestampUpperBound); return Iterators.unmodifiableIterator(modifications); } @Override public Object getCommitMetadata(final String branch, final long timestamp) { return this.graph.getCommitMetadata(branch, timestamp); } @Override public Iterator<Long> getCommitTimestampsBetween(final String branch, final long from, final long to, final Order order, final boolean includeSystemInternalCommits) { Iterator<Long> timestamps = this.graph.getCommitTimestampsBetween(branch, from, to, order, includeSystemInternalCommits); return Iterators.unmodifiableIterator(timestamps); } @Override public Iterator<Map.Entry<Long, Object>> getCommitMetadataBetween(final String branch, final long from, final long to, final Order order, final boolean includeSystemInternalCommits) { Iterator<Entry<Long, Object>> metadata = this.graph.getCommitMetadataBetween(branch, from, to, order, includeSystemInternalCommits); return Iterators.unmodifiableIterator(metadata); } @Override public Iterator<Long> getCommitTimestampsPaged(final String branch, final long minTimestamp, final long maxTimestamp, final int pageSize, final int pageIndex, final Order order, final boolean includeSystemInternalCommits) { Iterator<Long> timestamps = this.graph.getCommitTimestampsPaged(branch, minTimestamp, maxTimestamp, pageSize, pageIndex, order, includeSystemInternalCommits); return Iterators.unmodifiableIterator(timestamps); } @Override public Iterator<Map.Entry<Long, Object>> getCommitMetadataPaged(final String branch, final long minTimestamp, final long maxTimestamp, final int pageSize, final int pageIndex, final Order order, final boolean includeSystemInternalCommits) { Iterator<Entry<Long, Object>> metadata = this.graph.getCommitMetadataPaged(branch, minTimestamp, maxTimestamp, pageSize, pageIndex, order, includeSystemInternalCommits); return Iterators.unmodifiableIterator(metadata); } @Override public List<Map.Entry<Long, Object>> getCommitMetadataAround(final String branch, final long timestamp, final int count, final boolean includeSystemInternalCommits) { List<Entry<Long, Object>> metadata = this.graph.getCommitMetadataAround(branch, timestamp, count, includeSystemInternalCommits); return Collections.unmodifiableList(metadata); } @Override public List<Map.Entry<Long, Object>> getCommitMetadataBefore(final String branch, final long timestamp, final int count, final boolean includeSystemInternalCommits) { List<Entry<Long, Object>> metadata = this.graph.getCommitMetadataBefore(branch, timestamp, count, includeSystemInternalCommits); return Collections.unmodifiableList(metadata); } @Override public List<Map.Entry<Long, Object>> getCommitMetadataAfter(final String branch, final long timestamp, final int count, final boolean includeSystemInternalCommits) { List<Entry<Long, Object>> metadata = this.graph.getCommitMetadataAfter(branch, timestamp, count, includeSystemInternalCommits); return Collections.unmodifiableList(metadata); } @Override public List<Long> getCommitTimestampsAround(final String branch, final long timestamp, final int count, final boolean includeSystemInternalCommits) { List<Long> timestamps = this.graph.getCommitTimestampsAround(branch, timestamp, count, includeSystemInternalCommits); return Collections.unmodifiableList(timestamps); } @Override public List<Long> getCommitTimestampsBefore(final String branch, final long timestamp, final int count, final boolean includeSystemInternalCommits) { List<Long> timestamps = this.graph.getCommitTimestampsBefore(branch, timestamp, count, includeSystemInternalCommits); return Collections.unmodifiableList(timestamps); } @Override public List<Long> getCommitTimestampsAfter(final String branch, final long timestamp, final int count, final boolean includeSystemInternalCommits) { List<Long> timestamps = this.graph.getCommitTimestampsAfter(branch, timestamp, count, includeSystemInternalCommits); return Collections.unmodifiableList(timestamps); } @Override public int countCommitTimestampsBetween(final String branch, final long from, final long to, final boolean includeSystemInternalCommits) { return this.graph.countCommitTimestampsBetween(branch, from, to, includeSystemInternalCommits); } @Override public int countCommitTimestamps(final String branch, final boolean includeSystemInternalCommits) { return this.graph.countCommitTimestamps(branch, includeSystemInternalCommits); } @Override public Iterator<String> getChangedVerticesAtCommit(final String branch, final long commitTimestamp) { Iterator<String> vertexIds = this.graph.getChangedVerticesAtCommit(branch, commitTimestamp); return Iterators.unmodifiableIterator(vertexIds); } @Override public Iterator<String> getChangedEdgesAtCommit(final String branch, final long commitTimestamp) { Iterator<String> edgeIds = this.graph.getChangedEdgesAtCommit(branch, commitTimestamp); return Iterators.unmodifiableIterator(edgeIds); } @Override public Iterator<Pair<String, String>> getChangedGraphVariablesAtCommit(final long commitTimestamp) { return Iterators.unmodifiableIterator(this.graph.getChangedGraphVariablesAtCommit(commitTimestamp)); } @Override public Iterator<String> getChangedGraphVariablesAtCommitInDefaultKeyspace(final long commitTimestamp) { return Iterators.unmodifiableIterator(this.graph.getChangedGraphVariablesAtCommitInDefaultKeyspace(commitTimestamp)); } @Override public Iterator<String> getChangedGraphVariablesAtCommitInKeyspace(final long commitTimestamp, final String keyspace) { return Iterators.unmodifiableIterator(this.graph.getChangedGraphVariablesAtCommitInKeyspace(commitTimestamp, keyspace)); } @Override public Iterator<Pair<String, String>> getChangedGraphVariablesAtCommit(final String branch, final long commitTimestamp) { return Iterators.unmodifiableIterator(this.graph.getChangedGraphVariablesAtCommit(branch, commitTimestamp)); } @Override public Iterator<String> getChangedGraphVariablesAtCommitInDefaultKeyspace(final String branch, final long commitTimestamp) { return Iterators.unmodifiableIterator(this.graph.getChangedGraphVariablesAtCommitInDefaultKeyspace(branch, commitTimestamp)); } @Override public Iterator<String> getChangedGraphVariablesAtCommitInKeyspace(final String branch, final long commitTimestamp, final String keyspace) { return Iterators.unmodifiableIterator(this.graph.getChangedGraphVariablesAtCommitInKeyspace(branch, commitTimestamp, keyspace)); } @Override public ChronoGraphIndexManager getIndexManagerOnMaster() { return new ReadOnlyChronoGraphIndexManager(this.graph.getIndexManagerOnMaster()); } @Override public ChronoGraphIndexManager getIndexManagerOnBranch(final String branchName) { return new ReadOnlyChronoGraphIndexManager(this.graph.getIndexManagerOnBranch(branchName)); } @Override public ChronoGraphBranchManager getBranchManager() { return new ReadOnlyChronoGraphBranchManager(this.graph.getBranchManager()); } @Override public ChronoGraphTriggerManager getTriggerManager() { return new ReadOnlyChronoGraphTriggerManager(this.graph.getTriggerManager()); } @Override public ChronoGraphSchemaManager getSchemaManager() { return new ReadOnlyChronoGraphSchemaManager(this.graph.getSchemaManager()); } @Override public ChronoGraphMaintenanceManager getMaintenanceManager() { return new ReadOnlyChronoGraphMaintenanceManager(this.graph.getMaintenanceManager()); } @Override public ChronoGraphStatisticsManager getStatisticsManager() { return new ReadOnlyChronoGraphStatisticsManager(this.graph.getStatisticsManager()); } @Override public ChronoGraphHistoryManager getHistoryManager() { return new ReadOnlyHistoryManager(this.graph.getHistoryManager()); } @Override public void writeDump(final File dumpFile, final DumpOption... dumpOptions) { this.unsupportedOperation(); } @Override public void readDump(final File dumpFile, final DumpOption... options) { this.unsupportedOperation(); } private <T> T unsupportedOperation() { throw new UnsupportedOperationException("This operation is not supported on a readOnly graph!"); } }
15,002
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ReadOnlyChronoVertex.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/ReadOnlyChronoVertex.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import com.google.common.collect.Iterators; import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.structure.VertexProperty; import org.chronos.chronograph.api.structure.ChronoEdge; import org.chronos.chronograph.api.structure.ChronoVertex; import org.chronos.chronograph.internal.api.structure.ChronoElementInternal; import java.util.Iterator; import java.util.NoSuchElementException; public class ReadOnlyChronoVertex extends ReadOnlyChronoElement implements ChronoVertex { public ReadOnlyChronoVertex(Vertex vertex) { this((ChronoVertex) vertex); } public ReadOnlyChronoVertex(final ChronoVertex vertex) { super(vertex); } @Override public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) { return this.unsupportedOperation(); } @Override public <V> VertexProperty<V> property(final String key) { return new ReadOnlyVertexProperty<>(this.vertex().property(key)); } @Override public <V> VertexProperty<V> property(final String key, final V value) { return this.unsupportedOperation(); } @Override @SuppressWarnings("unchecked") public <V> V value(final String key) throws NoSuchElementException { return (V) this.vertex().value(key); } @Override public <V> Iterator<V> values(final String... propertyKeys) { Iterator<V> values = this.vertex().values(propertyKeys); return Iterators.unmodifiableIterator(values); } @Override public <V> VertexProperty<V> property(final String key, final V value, final Object... keyValues) { return this.unsupportedOperation(); } @Override public <V> VertexProperty<V> property(final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues) { return this.unsupportedOperation(); } @Override public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys) { Iterator<VertexProperty<V>> iterator = this.vertex().properties(propertyKeys); return Iterators.transform(iterator, ReadOnlyVertexProperty::new); } @Override @SuppressWarnings({"rawtypes", "unchecked"}) public Iterator<Edge> edges(final Direction direction, final String... edgeLabels) { Iterator<ChronoEdge> edges = (Iterator) this.vertex().edges(direction, edgeLabels); return Iterators.transform(edges, ReadOnlyChronoEdge::new); } @Override @SuppressWarnings({"rawtypes", "unchecked"}) public Iterator<Vertex> vertices(final Direction direction, final String... edgeLabels) { Iterator<ChronoVertex> vertices = (Iterator) this.vertex().vertices(direction, edgeLabels); return Iterators.transform(vertices, ReadOnlyChronoVertex::new); } @Override public void validateGraphInvariant() { ((ChronoElementInternal)this.vertex()).validateGraphInvariant(); } protected ChronoVertex vertex() { return (ChronoVertex) super.element; } }
3,258
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ReadOnlyProperty.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/ReadOnlyProperty.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Element; import org.apache.tinkerpop.gremlin.structure.Property; import org.apache.tinkerpop.gremlin.structure.Vertex; import java.util.NoSuchElementException; import static com.google.common.base.Preconditions.*; public class ReadOnlyProperty<V> implements Property<V> { protected final Property<V> property; public ReadOnlyProperty(Property<V> property) { checkNotNull(property, "Precondition violation - argument 'property' must not be NULL!"); this.property = property; } @Override public String key() { return this.property.key(); } @Override public V value() throws NoSuchElementException { return this.property.value(); } @Override public boolean isPresent() { return this.property.isPresent(); } @Override public Element element() { Element element = this.property.element(); if (element instanceof Vertex) { return new ReadOnlyChronoVertex((Vertex) element); } else if (element instanceof Edge) { return new ReadOnlyChronoEdge((Edge) element); } else { throw new RuntimeException("Encountered unknown subclass of " + Element.class.getName() + ": " + this.element().getClass().getName()); } } @Override public void remove() { throw new UnsupportedOperationException("This operation is not supported in a read-only graph!"); } }
1,613
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ReadOnlyChronoGraphTransaction.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/ReadOnlyChronoGraphTransaction.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import com.google.common.collect.Iterators; import org.apache.commons.lang3.tuple.Pair; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.chronos.chronodb.api.ChronoDBTransaction; import org.chronos.chronodb.api.Order; import org.chronos.chronodb.internal.api.query.ChronoDBQuery; import org.chronos.chronograph.api.structure.ChronoEdge; import org.chronos.chronograph.api.structure.ChronoGraph; import org.chronos.chronograph.api.structure.ChronoVertex; import org.chronos.chronograph.api.transaction.ChronoGraphTransaction; import org.chronos.chronograph.api.transaction.GraphTransactionContext; import org.chronos.chronograph.internal.impl.transaction.ElementLoadMode; import java.util.Collections; import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import static com.google.common.base.Preconditions.*; public class ReadOnlyChronoGraphTransaction implements ChronoGraphTransaction { private final ChronoGraphTransaction currentTransaction; public ReadOnlyChronoGraphTransaction(final ChronoGraphTransaction currentTransaction) { checkNotNull(currentTransaction, "Precondition violation - argument 'currentTransaction' must not be NULL!"); this.currentTransaction = currentTransaction; } @Override public ChronoGraph getGraph() { return new ReadOnlyChronoGraph(this.currentTransaction.getGraph()); } @Override public long getTimestamp() { // this operation is allowed even in read-only mode; // this override circumvents the public call to "getBackingDBTransaction" (which is not permitted) return this.currentTransaction.getTimestamp(); } @Override public String getBranchName() { // this operation is allowed even in read-only mode; // this override circumvents the public call to "getBackingDBTransaction" (which is not permitted) return this.currentTransaction.getBranchName(); } @Override public String getTransactionId() { return this.currentTransaction.getTransactionId(); } @Override public long getRollbackCount() { return this.currentTransaction.getRollbackCount(); } @Override public boolean isThreadedTx() { return this.currentTransaction.isThreadedTx(); } @Override public boolean isThreadLocalTx() { return this.currentTransaction.isThreadLocalTx(); } @Override public boolean isOpen() { return this.currentTransaction.isOpen(); } @Override public ChronoVertex addVertex(final Object... keyValues) { return this.unsupportedOperation(); } @Override public ChronoEdge addEdge(final ChronoVertex outVertex, final ChronoVertex inVertex, final String id, final boolean isUserProvidedId, final String label, final Object... keyValues) { return this.unsupportedOperation(); } @Override @SuppressWarnings({"rawtypes", "unchecked"}) public Iterator<Vertex> vertices(final Object... vertexIds) { return this.unmodifiableVertices(this.currentTransaction.vertices(vertexIds)); } @Override @SuppressWarnings({"rawtypes", "unchecked"}) public Iterator<Vertex> getAllVerticesIterator() { return this.unmodifiableVertices(this.currentTransaction.getAllVerticesIterator()); } @Override public Iterator<Vertex> getVerticesIterator(final Iterable<String> chronoVertexIds, final ElementLoadMode loadMode) { return this.unmodifiableVertices(this.currentTransaction.getVerticesIterator(chronoVertexIds, loadMode)); } @Override public Iterator<Edge> edges(final Object... edgeIds) { return this.unmodifiableEdges(this.currentTransaction.edges(edgeIds)); } @Override public Iterator<Edge> getAllEdgesIterator() { return this.unmodifiableEdges(this.currentTransaction.getAllEdgesIterator()); } @Override public Iterator<Edge> getEdgesIterator(final Iterable<String> chronoEdgeIds, ElementLoadMode loadMode) { return this.unmodifiableEdges(this.currentTransaction.getEdgesIterator(chronoEdgeIds, loadMode)); } @Override public Iterator<Long> getVertexHistory(final Object vertexId, final long lowerBound, final long upperBound, final Order order) { return Iterators.unmodifiableIterator(this.currentTransaction.getVertexHistory(vertexId, lowerBound, upperBound, order)); } @Override public Iterator<Long> getEdgeHistory(final Object vertexId, final long lowerBound, final long upperBound, final Order order) { return Iterators.unmodifiableIterator(this.currentTransaction.getEdgeHistory(vertexId, lowerBound, upperBound, order)); } @Override public Iterator<Long> getEdgeHistory(final Edge edge) { return Iterators.unmodifiableIterator(this.currentTransaction.getEdgeHistory(edge)); } @Override public long getLastModificationTimestampOfVertex(final Vertex vertex) { checkNotNull(vertex, "Precondition violation - argument 'vertex' must not be NULL!"); return this.currentTransaction.getLastModificationTimestampOfVertex(vertex); } @Override public long getLastModificationTimestampOfVertex(final Object vertexId) { checkNotNull(vertexId, "Precondition violation - argument 'vertexId' must not be NULL!"); return this.currentTransaction.getLastModificationTimestampOfVertex(vertexId); } @Override public long getLastModificationTimestampOfEdge(final Edge edge) { checkNotNull(edge, "Precondition violation - argument 'edge' must not be NULL!"); return this.currentTransaction.getLastModificationTimestampOfEdge(edge); } @Override public long getLastModificationTimestampOfEdge(final Object edgeId) { checkNotNull(edgeId, "Precondition violation - argument 'edgeId' must not be NULL!"); return this.currentTransaction.getLastModificationTimestampOfEdge(edgeId); } @Override public Iterator<Pair<Long, String>> getVertexModificationsBetween(final long timestampLowerBound, final long timestampUpperBound) { return Iterators.unmodifiableIterator(this.currentTransaction.getVertexModificationsBetween(timestampLowerBound, timestampUpperBound)); } @Override public Iterator<Pair<Long, String>> getEdgeModificationsBetween(final long timestampLowerBound, final long timestampUpperBound) { return Iterators.unmodifiableIterator(this.currentTransaction.getEdgeModificationsBetween(timestampLowerBound, timestampUpperBound)); } @Override public Object getCommitMetadata(final long commitTimestamp) { return this.currentTransaction.getCommitMetadata(commitTimestamp); } @Override public long commit() { return this.unsupportedOperation(); } @Override public long commit(final Object metadata) { return this.unsupportedOperation(); } @Override public void commitIncremental() { this.unsupportedOperation(); } @Override public void rollback() { // transaction was read-only to begin with; nothing to do! } @Override public ChronoDBTransaction getBackingDBTransaction() { return this.unsupportedOperation(); } @Override public GraphTransactionContext getContext() { return new ReadOnlyGraphTransactionContext(this.currentTransaction.getContext()); } private <T> T unsupportedOperation() { throw new UnsupportedOperationException("This operation is not supported on a read-only graph!"); } private Iterator<Vertex> unmodifiableVertices(Iterator<Vertex> vertices) { Iterator<Vertex> unmodifiableIterator = Iterators.unmodifiableIterator(vertices); return Iterators.transform(unmodifiableIterator, ReadOnlyChronoVertex::new); } private Iterator<Edge> unmodifiableEdges(Iterator<Edge> edges) { Iterator<Edge> unmodifiableIterator = Iterators.unmodifiableIterator(edges); return Iterators.transform(unmodifiableIterator, ReadOnlyChronoEdge::new); } }
8,265
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ReadOnlyChronoGraphStatisticsManager.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/ReadOnlyChronoGraphStatisticsManager.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import org.chronos.chronodb.api.BranchHeadStatistics; import org.chronos.chronograph.api.statistics.ChronoGraphStatisticsManager; import static com.google.common.base.Preconditions.*; public class ReadOnlyChronoGraphStatisticsManager implements ChronoGraphStatisticsManager { private final ChronoGraphStatisticsManager manager; public ReadOnlyChronoGraphStatisticsManager(final ChronoGraphStatisticsManager statisticsManager) { checkNotNull(statisticsManager, "Precondition violation - argument 'statisticsManager' must not be NULL!"); this.manager = statisticsManager; } @Override public BranchHeadStatistics getBranchHeadStatistics(final String branchName) { checkNotNull(branchName, "Precondition violation - argument 'branchName' must not be NULL!"); return this.manager.getBranchHeadStatistics(branchName); } }
951
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ReadOnlyVertexProperty.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/ReadOnlyVertexProperty.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import com.google.common.collect.Iterators; import org.apache.tinkerpop.gremlin.structure.*; import org.chronos.chronograph.api.structure.ChronoGraph; import org.chronos.chronograph.api.structure.ChronoVertex; import java.util.Collections; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Set; import java.util.function.Consumer; import java.util.function.Supplier; public class ReadOnlyVertexProperty<V> extends ReadOnlyProperty<V> implements VertexProperty<V> { public ReadOnlyVertexProperty(final VertexProperty<V> property) { super(property); } @Override public Object id() { return this.vertexProperty().id(); } @Override public <V> Property<V> property(final String key, final V value) { throw new UnsupportedOperationException("This operation is not supported in a read-only graph!"); } @Override public <V> V value(final String key) throws NoSuchElementException { return null; } @Override public <V> Iterator<V> values(final String... propertyKeys) { return null; } @Override public Graph graph() { return new ReadOnlyChronoGraph((ChronoGraph) this.vertexProperty().graph()); } @Override public Vertex element() { return new ReadOnlyChronoVertex((ChronoVertex)this.vertexProperty().element()); } @Override public Set<String> keys() { return Collections.unmodifiableSet(this.vertexProperty().keys()); } @Override public <V> Property<V> property(final String key) { return new ReadOnlyProperty<>(this.vertexProperty().property(key)); } @Override public String label() { return this.vertexProperty().label(); } @Override public <U> Iterator<Property<U>> properties(final String... propertyKeys) { Iterator<Property<U>> properties = this.vertexProperty().properties(propertyKeys); return Iterators.transform(properties, ReadOnlyProperty::new); } private VertexProperty<V> vertexProperty(){ return (VertexProperty<V>)this.property; } @Override public void ifPresent(final Consumer<? super V> consumer) { this.vertexProperty().ifPresent(consumer); } @Override public V orElse(final V otherValue) { return this.vertexProperty().orElse(otherValue); } @Override public V orElseGet(final Supplier<? extends V> valueSupplier) { return this.vertexProperty().orElseGet(valueSupplier); } @Override public <E extends Throwable> V orElseThrow(final Supplier<? extends E> exceptionSupplier) throws E { return this.vertexProperty().orElseThrow(exceptionSupplier); } }
2,807
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
NoTransactionControlChronoGraphTransaction.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/NoTransactionControlChronoGraphTransaction.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import org.apache.commons.lang3.tuple.Pair; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.chronos.chronodb.api.ChronoDBTransaction; import org.chronos.chronodb.api.Order; import org.chronos.chronodb.internal.api.query.ChronoDBQuery; import org.chronos.chronodb.internal.api.query.searchspec.SearchSpecification; import org.chronos.chronograph.api.structure.ChronoEdge; import org.chronos.chronograph.api.structure.ChronoGraph; import org.chronos.chronograph.api.structure.ChronoVertex; import org.chronos.chronograph.api.structure.record.IEdgeRecord; import org.chronos.chronograph.api.structure.record.IVertexRecord; import org.chronos.chronograph.api.transaction.GraphTransactionContext; import org.chronos.chronograph.internal.api.transaction.ChronoGraphTransactionInternal; import org.chronos.chronograph.internal.impl.structure.graph.ChronoVertexImpl; import org.chronos.chronograph.api.structure.record.IEdgeTargetRecord; import org.chronos.chronograph.internal.impl.transaction.ElementLoadMode; import java.util.Collection; import java.util.Iterator; import java.util.Map; import java.util.Set; import static com.google.common.base.Preconditions.*; public class NoTransactionControlChronoGraphTransaction implements ChronoGraphTransactionInternal { private final ChronoGraphTransactionInternal tx; public NoTransactionControlChronoGraphTransaction(ChronoGraphTransactionInternal tx){ checkNotNull(tx, "Precondition violation - argument 'tx' must not be NULL!"); this.tx = tx; } @Override public ChronoEdge loadIncomingEdgeFromEdgeTargetRecord(final ChronoVertexImpl targetVertex, final String label, final IEdgeTargetRecord record) { return this.tx.loadIncomingEdgeFromEdgeTargetRecord(targetVertex, label, record); } @Override public ChronoEdge loadOutgoingEdgeFromEdgeTargetRecord(final ChronoVertexImpl sourceVertex, final String label, final IEdgeTargetRecord record) { return this.tx.loadOutgoingEdgeFromEdgeTargetRecord(sourceVertex, label, record); } @Override public IVertexRecord loadVertexRecord(final String recordId) { return this.tx.loadVertexRecord(recordId); } @Override public IEdgeRecord loadEdgeRecord(final String recordId) { return this.tx.loadEdgeRecord(recordId); } @Override public ChronoGraph getGraph() { return new NoTransactionControlChronoGraph(this.tx.getGraph()); } @Override public long getTimestamp() { // this operation is allowed even in read-only mode; // this override circumvents the public call to "getBackingDBTransaction" (which is not permitted) return this.tx.getTimestamp(); } @Override public String getBranchName() { // this operation is allowed even in read-only mode; // this override circumvents the public call to "getBackingDBTransaction" (which is not permitted) return this.tx.getBranchName(); } @Override public String getTransactionId() { return this.tx.getTransactionId(); } @Override public long getRollbackCount() { return this.tx.getRollbackCount(); } @Override public boolean isThreadedTx() { return this.tx.isThreadedTx(); } @Override public boolean isThreadLocalTx() { return this.tx.isThreadLocalTx(); } @Override public boolean isOpen() { return this.tx.isOpen(); } @Override public ChronoVertex addVertex(final Object... keyValues) { return this.tx.addVertex(keyValues); } @Override public ChronoEdge addEdge(final ChronoVertex outVertex, final ChronoVertex inVertex, final String id, final boolean isUserProvidedId, final String label, final Object... keyValues) { return this.tx.addEdge(outVertex, inVertex, id, isUserProvidedId, label, keyValues); } @Override public Iterator<Vertex> vertices(final Object... vertexIds) { return this.tx.vertices(vertexIds); } @Override public Iterator<Vertex> getAllVerticesIterator() { return this.tx.getAllVerticesIterator(); } @Override public Iterator<Vertex> getVerticesIterator(final Iterable<String> chronoVertexIds, final ElementLoadMode loadMode) { return this.tx.getVerticesIterator(chronoVertexIds, loadMode); } @Override public Iterator<Edge> edges(final Object... edgeIds) { return this.tx.edges(edgeIds); } @Override public Iterator<Edge> getAllEdgesIterator() { return this.tx.getAllEdgesIterator(); } @Override public Iterator<Edge> getEdgesIterator(final Iterable<String> chronoEdgeIds, final ElementLoadMode loadMode) { return this.tx.getEdgesIterator(chronoEdgeIds, loadMode); } @Override public Iterator<Long> getVertexHistory(final Object vertexId, final long lowerBound, final long upperBound, final Order order) { return this.tx.getVertexHistory(vertexId, lowerBound, upperBound, order); } @Override public Iterator<Long> getEdgeHistory(final Object vertexId, final long lowerBound, final long upperBound, final Order order) { return this.tx.getEdgeHistory(vertexId, lowerBound, upperBound, order); } @Override public long getLastModificationTimestampOfVertex(final Vertex vertex) { return this.tx.getLastModificationTimestampOfVertex(vertex); } @Override public long getLastModificationTimestampOfVertex(final Object vertexId) { return this.tx.getLastModificationTimestampOfVertex(vertexId); } @Override public long getLastModificationTimestampOfEdge(final Edge edge) { return this.tx.getLastModificationTimestampOfEdge(edge); } @Override public long getLastModificationTimestampOfEdge(final Object edgeId) { return this.tx.getLastModificationTimestampOfEdge(edgeId); } @Override public Iterator<Pair<Long, String>> getVertexModificationsBetween(final long timestampLowerBound, final long timestampUpperBound) { return this.tx.getVertexModificationsBetween(timestampLowerBound, timestampUpperBound); } @Override public Iterator<Pair<Long, String>> getEdgeModificationsBetween(final long timestampLowerBound, final long timestampUpperBound) { return this.tx.getEdgeModificationsBetween(timestampLowerBound, timestampUpperBound); } @Override public Object getCommitMetadata(final long commitTimestamp) { return this.tx.getCommitMetadata(commitTimestamp); } @Override public long commit() { return this.unsupportedOperation(); } @Override public long commit(final Object metadata) { return this.unsupportedOperation(); } @Override public void commitIncremental() { this.unsupportedOperation(); } @Override public void rollback() { this.unsupportedOperation(); } @Override public ChronoDBTransaction getBackingDBTransaction() { return this.unsupportedOperation(); } @Override public GraphTransactionContext getContext() { return this.tx.getContext(); } private <T> T unsupportedOperation() { throw new UnsupportedOperationException("Opening and closing transactions is not supported on this graph instance."); } }
7,504
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ReadOnlyChronoGraphMaintenanceManager.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/ReadOnlyChronoGraphMaintenanceManager.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import org.chronos.chronograph.api.maintenance.ChronoGraphMaintenanceManager; import java.util.function.Predicate; import static com.google.common.base.Preconditions.*; public class ReadOnlyChronoGraphMaintenanceManager implements ChronoGraphMaintenanceManager { private final ChronoGraphMaintenanceManager manager; public ReadOnlyChronoGraphMaintenanceManager(ChronoGraphMaintenanceManager manager){ checkNotNull(manager, "Precondition violation - argument 'manager' must not be NULL!"); this.manager = manager; } @Override public void performRolloverOnBranch(final String branchName, boolean updateIndices) { this.unsupportedOperation(); } @Override public void performRolloverOnAllBranches(boolean updateIndices) { this.unsupportedOperation(); } @Override public void performRolloverOnAllBranchesWhere(final Predicate<String> branchPredicate, boolean updateIndices) { this.unsupportedOperation(); } private <T> T unsupportedOperation(){ throw new UnsupportedOperationException("This operation is not supported on a read-only graph!"); } }
1,228
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ReadOnlyChronoGraphBranchManager.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/ReadOnlyChronoGraphBranchManager.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import org.chronos.chronograph.api.branch.ChronoGraphBranchManager; import org.chronos.chronograph.api.branch.GraphBranch; import java.util.Collections; import java.util.List; import java.util.Set; import static com.google.common.base.Preconditions.*; public class ReadOnlyChronoGraphBranchManager implements ChronoGraphBranchManager { private final ChronoGraphBranchManager manager; public ReadOnlyChronoGraphBranchManager(ChronoGraphBranchManager manager){ checkNotNull(manager, "Precondition violation - argument 'manager' must not be NULL!"); this.manager = manager; } @Override public GraphBranch createBranch(final String branchName) { return this.unsupportedOperation(); } @Override public GraphBranch createBranch(final String branchName, final long branchingTimestamp) { return this.unsupportedOperation(); } @Override public GraphBranch createBranch(final String parentName, final String newBranchName) { return this.unsupportedOperation(); } @Override public GraphBranch createBranch(final String parentName, final String newBranchName, final long branchingTimestamp) { return this.unsupportedOperation(); } @Override public boolean existsBranch(final String branchName) { return this.manager.existsBranch(branchName); } @Override public GraphBranch getBranch(final String branchName) { return this.manager.getBranch(branchName); } @Override public Set<String> getBranchNames() { return Collections.unmodifiableSet(this.manager.getBranchNames()); } @Override public Set<GraphBranch> getBranches() { return Collections.unmodifiableSet(this.manager.getBranches()); } @Override public List<String> deleteBranchRecursively(final String branchName) { return this.unsupportedOperation(); } @Override public GraphBranch getActualBranchForQuerying(final String branchName, final long timestamp) { return this.manager.getActualBranchForQuerying(branchName, timestamp); } private <T> T unsupportedOperation() { throw new UnsupportedOperationException("This operation is not supported on a readOnly graph!"); } }
2,346
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
NoTransactionControlTransactionManager.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/NoTransactionControlTransactionManager.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource; import org.apache.tinkerpop.gremlin.structure.Transaction; import org.chronos.chronograph.api.structure.ChronoGraph; import org.chronos.chronograph.api.transaction.ChronoGraphTransaction; import org.chronos.chronograph.api.transaction.ChronoGraphTransactionManager; import org.chronos.chronograph.internal.api.transaction.ChronoGraphTransactionInternal; import java.util.Date; import java.util.function.Consumer; import static com.google.common.base.Preconditions.*; public class NoTransactionControlTransactionManager implements ChronoGraphTransactionManager { private final ChronoGraphTransactionManager txManager; public NoTransactionControlTransactionManager(ChronoGraphTransactionManager txManager) { checkNotNull(txManager, "Precondition violation - argument 'txManager' must not be NULL!"); this.txManager = txManager; } @Override public void open(final long timestamp) { this.unsupportedOperation(); } @Override public void open(final Date date) { this.unsupportedOperation(); } @Override public void open(final String branch) { this.unsupportedOperation(); } @Override public void open(final String branch, final long timestamp) { this.unsupportedOperation(); } @Override public void open(final String branch, final Date date) { this.unsupportedOperation(); } @Override public void reset() { this.unsupportedOperation(); } @Override public void reset(final long timestamp) { this.unsupportedOperation(); } @Override public void reset(final Date date) { this.unsupportedOperation(); } @Override public void reset(final String branch, final long timestamp) { this.unsupportedOperation(); } @Override public void reset(final String branch, final Date date) { this.unsupportedOperation(); } @Override public ChronoGraph createThreadedTx() { return this.unsupportedOperation(); } @Override public ChronoGraph createThreadedTx(final long timestamp) { return this.unsupportedOperation(); } @Override public ChronoGraph createThreadedTx(final Date date) { return this.unsupportedOperation(); } @Override public ChronoGraph createThreadedTx(final String branchName) { return this.unsupportedOperation(); } @Override public ChronoGraph createThreadedTx(final String branchName, final long timestamp) { return this.unsupportedOperation(); } @Override public ChronoGraph createThreadedTx(final String branchName, final Date date) { return this.unsupportedOperation(); } @Override public void commitIncremental() { this.unsupportedOperation(); } @Override public void commit(final Object metadata) { this.unsupportedOperation(); } @Override public long commitAndReturnTimestamp() { return this.unsupportedOperation(); } @Override public long commitAndReturnTimestamp(final Object metadata) { return this.unsupportedOperation(); } @Override public ChronoGraphTransaction getCurrentTransaction() { return new NoTransactionControlChronoGraphTransaction((ChronoGraphTransactionInternal) this.txManager.getCurrentTransaction()); } @Override public void open() { this.unsupportedOperation(); } @Override public void commit() { this.unsupportedOperation(); } @Override public void rollback() { this.unsupportedOperation(); } @Override public <T extends TraversalSource> T begin(final Class<T> traversalSourceClass) { return this.unsupportedOperation(); } @Override public boolean isOpen() { return this.txManager.isOpen(); } @Override public void readWrite() { this.txManager.readWrite(); } @Override public void close() { this.unsupportedOperation(); } @Override public Transaction onReadWrite(final Consumer<Transaction> consumer) { return this.txManager.onReadWrite(consumer); } @Override public Transaction onClose(final Consumer<Transaction> consumer) { return this.unsupportedOperation(); } @Override public void addTransactionListener(final Consumer<Status> listener) { this.unsupportedOperation(); } @Override public void removeTransactionListener(final Consumer<Status> listener) { this.unsupportedOperation(); } @Override public void clearTransactionListeners() { this.unsupportedOperation(); } private <T> T unsupportedOperation() { throw new UnsupportedOperationException("Opening and closing transactions is not supported on this graph instance."); } }
5,044
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ReadOnlyChronoEdge.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/ReadOnlyChronoEdge.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import com.google.common.collect.Iterators; import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Property; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.chronos.chronograph.api.structure.ChronoEdge; import org.chronos.chronograph.api.structure.ChronoVertex; import org.chronos.chronograph.internal.api.structure.ChronoElementInternal; import java.util.Collections; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Set; public class ReadOnlyChronoEdge extends ReadOnlyChronoElement implements ChronoEdge { public ReadOnlyChronoEdge(Edge edge) { this((ChronoEdge) edge); } public ReadOnlyChronoEdge(ChronoEdge edge) { super(edge); } @Override @SuppressWarnings({"rawtypes", "unchecked"}) public Iterator<Vertex> vertices(final Direction direction) { Iterator<ChronoVertex> iterator = (Iterator) this.edge().vertices(direction); return Iterators.transform(iterator, ReadOnlyChronoVertex::new); } @Override public Vertex outVertex() { return new ReadOnlyChronoVertex((ChronoVertex) this.edge().outVertex()); } @Override public Vertex inVertex() { return new ReadOnlyChronoVertex((ChronoVertex) this.edge().inVertex()); } @Override @SuppressWarnings({"rawtypes", "unchecked"}) public Iterator<Vertex> bothVertices() { Iterator<ChronoVertex> iterator = (Iterator) this.edge().bothVertices(); return Iterators.transform(iterator, ReadOnlyChronoVertex::new); } @Override public Set<String> keys() { return Collections.unmodifiableSet(this.edge().keys()); } @Override public <V> Property<V> property(final String key) { return new ReadOnlyProperty<>(this.edge().property(key)); } @Override public <V> Property<V> property(final String key, final V value) { return this.unsupportedOperation(); } @Override public <V> V value(final String key) throws NoSuchElementException { return this.edge().value(key); } @Override public <V> Iterator<V> values(final String... propertyKeys) { Iterator<V> iterator = this.edge().values(propertyKeys); return Iterators.unmodifiableIterator(iterator); } @Override public <V> Iterator<Property<V>> properties(final String... propertyKeys) { Iterator<Property<V>> properties = this.edge().properties(propertyKeys); return Iterators.transform(properties, ReadOnlyProperty::new); } @Override public void validateGraphInvariant() { ((ChronoElementInternal)this.edge()).validateGraphInvariant(); } protected ChronoEdge edge() { return (ChronoEdge) this.element; } }
2,939
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ReadOnlyChronoGraphTriggerManager.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/ReadOnlyChronoGraphTriggerManager.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import org.chronos.chronograph.api.exceptions.TriggerAlreadyExistsException; import org.chronos.chronograph.api.transaction.trigger.ChronoGraphTrigger; import org.chronos.chronograph.api.transaction.trigger.ChronoGraphTriggerManager; import org.chronos.chronograph.api.transaction.trigger.GraphTriggerMetadata; import java.util.Collections; import java.util.List; import java.util.Set; import java.util.function.Supplier; import static com.google.common.base.Preconditions.*; public class ReadOnlyChronoGraphTriggerManager implements ChronoGraphTriggerManager { // ================================================================================================================= // FIELDS // ================================================================================================================= private final ChronoGraphTriggerManager manager; // ================================================================================================================= // CONSTRUCTOR // ================================================================================================================= public ReadOnlyChronoGraphTriggerManager(ChronoGraphTriggerManager manager) { checkNotNull(manager, "Precondition violation - argument 'manager' must not be NULL!"); this.manager = manager; } // ================================================================================================================= // PUBLIC API // ================================================================================================================= @Override public boolean existsTrigger(final String triggerName) { return this.manager.existsTrigger(triggerName); } @Override public boolean createTriggerIfNotPresent(final String triggerName, final Supplier<ChronoGraphTrigger> triggerSupplier) { return this.unsupportedOperation(); } @Override public boolean createTriggerIfNotPresent(final String triggerName, final Supplier<ChronoGraphTrigger> triggerSupplier, Object commitMetadata) { return this.unsupportedOperation(); } @Override public boolean createTriggerAndOverwrite(final String triggerName, final ChronoGraphTrigger trigger) { return this.unsupportedOperation(); } @Override public boolean createTriggerAndOverwrite(final String triggerName, final ChronoGraphTrigger trigger, Object commitMetadata) { return this.unsupportedOperation(); } @Override public void createTrigger(final String triggerName, final ChronoGraphTrigger trigger) throws TriggerAlreadyExistsException { this.unsupportedOperation(); } @Override public void createTrigger(final String triggerName, final ChronoGraphTrigger trigger, Object commitMetadata) throws TriggerAlreadyExistsException { this.unsupportedOperation(); } @Override public boolean dropTrigger(final String triggerName) { return this.unsupportedOperation(); } @Override public boolean dropTrigger(final String triggerName, Object commitMetadata) { return this.unsupportedOperation(); } @Override public Set<String> getTriggerNames() { return Collections.unmodifiableSet(this.manager.getTriggerNames()); } @Override public List<GraphTriggerMetadata> getTriggers() { return this.manager.getTriggers(); } @Override public GraphTriggerMetadata getTrigger(final String triggerName) { return this.manager.getTrigger(triggerName); } // ================================================================================================================= // HELPER METHODS // ================================================================================================================= private <T> T unsupportedOperation() { throw new UnsupportedOperationException("This operation is not supported in read-only mode!"); } }
4,089
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ReadOnlyChronoGraphSchemaManager.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/readonly/ReadOnlyChronoGraphSchemaManager.java
package org.chronos.chronograph.internal.impl.structure.graph.readonly; import org.chronos.chronograph.api.schema.ChronoGraphSchemaManager; import org.chronos.chronograph.api.schema.SchemaValidationResult; import org.chronos.chronograph.api.structure.ChronoElement; import java.util.Set; import static com.google.common.base.Preconditions.*; public class ReadOnlyChronoGraphSchemaManager implements ChronoGraphSchemaManager { private ChronoGraphSchemaManager manager; public ReadOnlyChronoGraphSchemaManager(ChronoGraphSchemaManager manager) { checkNotNull(manager, "Precondition violation - argument 'manager' must not be NULL!"); this.manager = manager; } @Override public boolean addOrOverrideValidator(final String validatorName, final String scriptContent) { return this.unsupportedOperation(); } @Override public boolean addOrOverrideValidator(final String validatorName, final String scriptContent, final Object commitMetadata) { return this.unsupportedOperation(); } @Override public boolean removeValidator(final String validatorName) { return this.unsupportedOperation(); } @Override public boolean removeValidator(final String validatorName, final Object commitMetadata) { return this.unsupportedOperation(); } @Override public String getValidatorScript(final String validatorName) { return this.manager.getValidatorScript(validatorName); } @Override public Set<String> getAllValidatorNames() { return this.manager.getAllValidatorNames(); } @Override public SchemaValidationResult validate(final String branch, final Iterable<? extends ChronoElement> elements) { return this.manager.validate(branch, elements); } private <T> T unsupportedOperation() { throw new UnsupportedOperationException("This operation is not supported on a read-only graph!"); } }
1,964
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoEdgeProxy.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/proxy/ChronoEdgeProxy.java
package org.chronos.chronograph.internal.impl.structure.graph.proxy; import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Property; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.structure.util.StringFactory; import org.chronos.chronograph.api.structure.ChronoEdge; import org.chronos.chronograph.api.structure.ChronoGraph; import org.chronos.chronograph.api.transaction.ChronoGraphTransaction; import org.chronos.chronograph.internal.api.transaction.GraphTransactionContextInternal; import org.chronos.chronograph.internal.impl.structure.graph.ChronoEdgeImpl; import org.chronos.chronograph.internal.impl.structure.graph.ChronoProperty; import org.chronos.chronograph.internal.impl.transaction.ElementLoadMode; import org.chronos.chronograph.internal.impl.util.ChronoProxyUtil; import java.util.Iterator; public class ChronoEdgeProxy extends AbstractElementProxy<ChronoEdgeImpl> implements ChronoEdge { public ChronoEdgeProxy(final ChronoGraph graph, final String id) { super(graph, id); } public ChronoEdgeProxy(final ChronoEdgeImpl edge) { super(edge.graph(), edge.id()); this.element = edge; } // ================================================================================================================= // TINKERPOP API // ================================================================================================================= @Override public Iterator<Vertex> vertices(final Direction direction) { return this.getElement().vertices(direction); } @Override public <V> Property<V> property(final String key, final V value) { return this.getElement().property(key, value); } @Override public <V> Iterator<Property<V>> properties(final String... propertyKeys) { return this.getElement().properties(propertyKeys); } @Override public void validateGraphInvariant() { this.getElement().validateGraphInvariant(); } @Override public String toString() { return StringFactory.edgeString(this); } // ================================================================================================================= // INTERNAL API // ================================================================================================================= @Override protected ChronoEdgeImpl loadElement(final ChronoGraphTransaction tx, final String id) { ChronoEdge edge = (ChronoEdge) tx.getEdge(id); return ChronoProxyUtil.resolveEdgeProxy(edge); } @Override protected void registerProxyAtTransaction(final ChronoGraphTransaction transaction) { ((GraphTransactionContextInternal) transaction.getContext()).registerEdgeProxyInCache(this); } @Override public void notifyPropertyChanged(final ChronoProperty<?> chronoProperty) { this.getElement().notifyPropertyChanged(chronoProperty); } }
3,031
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
AbstractElementProxy.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/proxy/AbstractElementProxy.java
package org.chronos.chronograph.internal.impl.structure.graph.proxy; import com.google.common.base.Objects; import org.apache.tinkerpop.gremlin.structure.Property; import org.apache.tinkerpop.gremlin.structure.util.ElementHelper; import org.chronos.chronograph.api.structure.ChronoGraph; import org.chronos.chronograph.api.structure.ElementLifecycleStatus; import org.chronos.chronograph.api.structure.PropertyStatus; import org.chronos.chronograph.api.transaction.ChronoGraphTransaction; import org.chronos.chronograph.internal.api.structure.ChronoElementInternal; import org.chronos.chronograph.internal.impl.structure.graph.AbstractChronoElement; import org.chronos.chronograph.internal.impl.structure.graph.ElementLifecycleEvent; import java.util.Iterator; import static com.google.common.base.Preconditions.*; public abstract class AbstractElementProxy<T extends AbstractChronoElement> implements ChronoElementInternal { protected final String id; protected final ChronoGraph graph; protected T element; // ================================================================================================================= // CONSTRUCTOR // ================================================================================================================= protected AbstractElementProxy(final ChronoGraph graph, final String id) { checkNotNull(graph, "Precondition violation - argument 'graph' must not be NULL!"); checkNotNull(id, "Precondition violation - argument 'id' must not be NULL!"); this.graph = graph; this.id = id; } // ================================================================================================================= // TINKERPOP API // ================================================================================================================= @Override public String label() { return this.getElement().label(); } @Override public void remove() { this.getElement().remove(); } @Override public <V> Iterator<? extends Property<V>> properties(final String... propertyKeys) { return this.getElement().properties(propertyKeys); } @Override public String id() { return this.id; } @Override public ChronoGraph graph() { return this.graph; } @Override public void removeProperty(final String key) { this.getElement().removeProperty(key); } @Override public boolean isRemoved() { return this.getElement().isRemoved(); } @Override public void updateLifecycleStatus(final ElementLifecycleEvent event) { this.getElement().updateLifecycleStatus(event); } @Override public ElementLifecycleStatus getStatus() { return this.getElement().getStatus(); } @Override public PropertyStatus getPropertyStatus(final String propertyKey) { return this.getElement().getPropertyStatus(propertyKey); } @Override public ChronoGraphTransaction getOwningTransaction() { return this.getElement().getOwningTransaction(); } @Override public long getLoadedAtRollbackCount() { return this.getElement().getLoadedAtRollbackCount(); } @Override public int hashCode() { return ElementHelper.hashCode(this); } @Override public boolean equals(final Object obj) { return ElementHelper.areEqual(this, obj); } @Override public boolean isLazy() { if(this.element == null){ return true; } return this.getElement().isLazy(); } public void rebindTo(T newElement) { checkNotNull(newElement, "Precondition violation - argument 'newElement' must not be NULL!"); if (!Objects.equal(this.id, newElement.id())) { throw new IllegalArgumentException("Cannot rebind " + this.getClass().getSimpleName() + ": the current element has ID '" + this.id + "', but the provided new element has the different ID '" + newElement.id() + "'!"); } this.element = newElement; } // ================================================================================================================= // INTERNAL UTILITY METHODS // ================================================================================================================= public T getElement() { this.assertElementLoaded(); return this.element; } public boolean isLoaded(){ return this.element != null; } protected void assertElementLoaded() { this.graph.tx().readWrite(); if (this.element != null) { // make sure that no other thread tries to access this element this.element.checkThread(); // check that the element belongs to the current transaction ChronoGraphTransaction currentTx = this.graph.tx().getCurrentTransaction(); ChronoGraphTransaction owningTx = this.element.getOwningTransaction(); if (currentTx.equals(owningTx)) { // check if the rollback count is still the same if (this.element.getLoadedAtRollbackCount() == currentTx.getRollbackCount()) { // still same transaction, same rollback count, keep the element as-is. return; } else { // a rollback has occurred, set the element to NULL and re-load this.element = null; } } else { // the transaction that created our element has been closed; set the element to NULL and re-load this.element = null; } } this.graph.tx().readWrite(); ChronoGraphTransaction tx = this.graph.tx().getCurrentTransaction(); this.element = this.loadElement(tx, this.id); this.registerProxyAtTransaction(tx); } // ================================================================================================================= // ABSTRACT METHOD DECLARATIONS // ================================================================================================================= protected abstract T loadElement(final ChronoGraphTransaction tx, final String id); protected abstract void registerProxyAtTransaction(ChronoGraphTransaction transaction); }
6,423
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoVertexProxy.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/graph/proxy/ChronoVertexProxy.java
package org.chronos.chronograph.internal.impl.structure.graph.proxy; import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.structure.VertexProperty; import org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality; import org.apache.tinkerpop.gremlin.structure.util.StringFactory; import org.chronos.chronograph.api.structure.ChronoGraph; import org.chronos.chronograph.api.structure.ChronoVertex; import org.chronos.chronograph.api.transaction.ChronoGraphTransaction; import org.chronos.chronograph.internal.api.transaction.GraphTransactionContextInternal; import org.chronos.chronograph.internal.impl.structure.graph.ChronoProperty; import org.chronos.chronograph.internal.impl.structure.graph.ChronoVertexImpl; import org.chronos.chronograph.internal.impl.util.ChronoProxyUtil; import java.util.Iterator; import java.util.NoSuchElementException; public class ChronoVertexProxy extends AbstractElementProxy<ChronoVertexImpl> implements ChronoVertex { public ChronoVertexProxy(final ChronoGraph graph, final String id) { super(graph, id); } public ChronoVertexProxy(final ChronoVertexImpl vertex) { super(vertex.graph(), vertex.id()); this.element = vertex; } // ================================================================================================================= // TINKERPOP API // ================================================================================================================= @Override public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) { return this.getElement().addEdge(label, inVertex, keyValues); } @Override public <V> VertexProperty<V> property(final String key) { return this.getElement().property(key); } @Override public <V> V value(final String key) throws NoSuchElementException { return this.getElement().value(key); } @Override public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys) { return this.getElement().properties(propertyKeys); } @Override public <V> VertexProperty<V> property(final Cardinality cardinality, final String key, final V value, final Object... keyValues) { return this.getElement().property(cardinality, key, value, keyValues); } @Override public <V> VertexProperty<V> property(final String key, final V value) { return this.getElement().property(key, value); } @Override public <V> VertexProperty<V> property(final String key, final V value, final Object... keyValues) { return this.getElement().property(key, value, keyValues); } @Override public Iterator<Edge> edges(final Direction direction, final String... edgeLabels) { return this.getElement().edges(direction, edgeLabels); } @Override public Iterator<Vertex> vertices(final Direction direction, final String... edgeLabels) { return this.getElement().vertices(direction, edgeLabels); } @Override public void validateGraphInvariant() { this.getElement().validateGraphInvariant(); } @Override public String toString() { return StringFactory.vertexString(this); } // ================================================================================================================= // INTERNAL API // ================================================================================================================= @Override protected ChronoVertexImpl loadElement(final ChronoGraphTransaction tx, final String id) { ChronoVertex vertex = (ChronoVertex) tx.getVertex(id); return ChronoProxyUtil.resolveVertexProxy(vertex); } @Override protected void registerProxyAtTransaction(final ChronoGraphTransaction transaction) { ((GraphTransactionContextInternal) transaction.getContext()).registerVertexProxyInCache(this); } @Override public void notifyPropertyChanged(final ChronoProperty<?> chronoProperty) { this.getElement().notifyPropertyChanged(chronoProperty); } }
4,279
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
SimpleVertexPropertyRecord.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record3/SimpleVertexPropertyRecord.java
package org.chronos.chronograph.internal.impl.structure.record3; import org.chronos.chronograph.api.structure.record.IPropertyRecord; import org.chronos.chronograph.api.structure.record.IVertexPropertyRecord; import org.chronos.chronograph.internal.impl.structure.record2.PropertyRecord2; import org.chronos.common.annotation.PersistentClass; import java.util.Collections; import java.util.Map; /** * A {@link SimpleVertexPropertyRecord} is a {@link IVertexPropertyRecord} which has no {@link #getProperties()} meta-properties}. * * The reason this class exists is that meta-properties are rarely used in practice. This class * has no field to hold them (it just returns an empty map on {@link #getProperties()}), which makes * this class smaller on disk and in memory. * * @author martin.haeusler@txture.io -- Initial contribution and API */ @PersistentClass("kryo") public class SimpleVertexPropertyRecord extends PropertyRecord2 implements IVertexPropertyRecord { protected SimpleVertexPropertyRecord(){ // default constructor for (de-)serialization } public SimpleVertexPropertyRecord(final String key, final Object value){ super(key, value); } @Override public Map<String, IPropertyRecord> getProperties() { // simple vertex property records have no meta-properties. return Collections.emptyMap(); } }
1,381
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
VertexPropertyRecord3.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record3/VertexPropertyRecord3.java
package org.chronos.chronograph.internal.impl.structure.record3; import com.google.common.collect.Maps; import org.apache.tinkerpop.gremlin.structure.Property; import org.apache.tinkerpop.gremlin.structure.VertexProperty; import org.chronos.chronograph.api.structure.record.IPropertyRecord; import org.chronos.chronograph.api.structure.record.IVertexPropertyRecord; import org.chronos.chronograph.internal.impl.structure.record2.PropertyRecord2; import org.chronos.common.annotation.PersistentClass; import java.util.Collections; import java.util.Iterator; import java.util.Map; import static com.google.common.base.Preconditions.*; /** * Represents the persistent state of a {@link VertexProperty}. * * <p> * If a {@link VertexProperty} has no {@linkplain VertexProperty#properties(String...) meta-properties}, then * {@link SimpleVertexPropertyRecord} should be used instead of this class. * </p> * * @author martin.haeusler@txture.io -- Initial contribution and API. */ @PersistentClass("kryo") public class VertexPropertyRecord3 extends PropertyRecord2 implements IVertexPropertyRecord { // ===================================================================================================================== // FIELDS // ===================================================================================================================== private Map<String, PropertyRecord2> properties; // ===================================================================================================================== // CONSTRUCTORS // ===================================================================================================================== protected VertexPropertyRecord3() { // default constructor for serialization } public VertexPropertyRecord3(final String key, final Object value, final Iterator<Property<Object>> properties) { super(key, value); checkNotNull(properties, "Precondition violation - argument 'properties' must not be NULL!"); if (properties.hasNext()) { this.properties = Maps.newHashMap(); while (properties.hasNext()) { Property<?> property = properties.next(); String pKey = property.key(); Object pValue = property.value(); PropertyRecord2 pRecord = new PropertyRecord2(pKey, pValue); this.properties.put(pKey, pRecord); } } } public VertexPropertyRecord3(final String key, final Object value, final Map<String, PropertyRecord2> properties) { super(key, value); checkNotNull(properties, "Precondition violation - argument 'properties' must not be NULL!"); if (properties.isEmpty() == false) { this.properties = Maps.newHashMap(); this.properties.putAll(properties); } } // ===================================================================================================================== // PUBLIC API // ===================================================================================================================== @Override public Map<String, IPropertyRecord> getProperties() { if (this.properties == null) { return Collections.emptyMap(); } return Collections.unmodifiableMap(this.properties); } }
3,392
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
VertexRecord3.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/structure/record3/VertexRecord3.java
package org.chronos.chronograph.internal.impl.structure.record3; import com.google.common.collect.*; import org.chronos.chronodb.api.ChronoDBTransaction; import org.chronos.chronodb.api.dump.annotations.ChronosExternalizable; import org.chronos.chronograph.api.structure.ChronoEdge; import org.chronos.chronograph.api.structure.record.IEdgeTargetRecord; import org.chronos.chronograph.api.structure.record.IVertexPropertyRecord; import org.chronos.chronograph.api.structure.record.IVertexRecord; import org.chronos.chronograph.api.transaction.ChronoGraphTransaction; import org.chronos.chronograph.internal.impl.dumpformat.converter.VertexRecordConverter; import org.chronos.chronograph.internal.impl.structure.graph.ChronoEdgeImpl; import org.chronos.chronograph.internal.impl.structure.graph.ChronoVertexImpl; import org.chronos.chronograph.internal.impl.structure.graph.ChronoVertexProperty; import org.chronos.chronograph.internal.impl.structure.record.EdgeTargetRecordWithLabel; import org.chronos.chronograph.internal.impl.structure.record2.EdgeTargetRecord2; import org.chronos.chronograph.internal.impl.util.ChronoProxyUtil; import org.chronos.common.annotation.PersistentClass; import java.util.*; import java.util.Map.Entry; import static com.google.common.base.Preconditions.*; /** * A {@link VertexRecord3} is the immutable data core of a vertex that has been persisted to the database. * * <p> * This is the class that will actually get serialized as the <code>value</code> in {@link ChronoDBTransaction#put(String, Object)}. * * <p> * It is crucial that all instances of this class are to be treated as immutable after their creation, as these instances are potentially shared among threads due to caching mechanisms. * * <p> * The {@link ChronoVertexImpl} implementation which typically wraps a {@link VertexRecord3} is mutable and contains the transient (i.e. not yet persisted) state of the vertex that is specific for the transaction at hand. Upon calling {@link ChronoGraphTransaction#commit()}, the transient state in {@link ChronoVertexImpl} will be written into a new {@link VertexRecord3} and persisted to the database with a new timestamp (but the same vertex id), provided that the vertex has indeed been modified by the user. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ @PersistentClass("kryo") @ChronosExternalizable(converterClass = VertexRecordConverter.class) public final class VertexRecord3 implements IVertexRecord { // ===================================================================================================================== // FIELDS // ===================================================================================================================== // note: the only reason why the fields in this class are not declared as "final" is because // serialization mechanisms struggle with final fields. All fields are effectively final, and // all of their contents are effectively immutable. /** The id of this record. */ private String recordId; /** The label of the vertex stored in this record. */ private String label; /** Mapping of edge labels to incoming edges, i.e. edges which specify this vertex as their in-vertex. */ private Map<String, Set<EdgeTargetRecord2>> incomingEdges; /** Mapping of edge labels to outgoing edges, i.e. edges which specify this vertex as their out-vertex. */ private Map<String, Set<EdgeTargetRecord2>> outgoingEdges; /** The set of vertex properties known on this vertex. */ private Set<IVertexPropertyRecord> properties; // ===================================================================================================================== // CONSTRUCTORS // ===================================================================================================================== protected VertexRecord3() { // default constructor for serialization mechanism } public VertexRecord3(final String recordId, final String label, final SetMultimap<String, ChronoEdge> inE, final SetMultimap<String, ChronoEdge> outE, final Map<String, ChronoVertexProperty<?>> properties) { checkNotNull(recordId, "Precondition violation - argument 'recordId' must not be NULL!"); checkNotNull(label, "Precondition violation - argument 'label' must not be NULL!"); checkNotNull(properties, "Precondition violation - argument 'properties' must not be NULL!"); this.recordId = recordId; this.label = label; if (inE != null && inE.isEmpty() == false) { this.incomingEdges = Maps.newHashMap(); Iterator<ChronoEdge> inEIterator = Sets.newHashSet(inE.values()).iterator(); while (inEIterator.hasNext()) { ChronoEdgeImpl edge = ChronoProxyUtil.resolveEdgeProxy(inEIterator.next()); // create the minimal "edge target" representation for this edge to store in this vertex EdgeTargetRecord2 edgeTargetRecord = new EdgeTargetRecord2(edge.id(), edge.outVertex().id()); // retrieve the set of edge target records with the label in question Set<EdgeTargetRecord2> edgeRecordsByLabel = this.incomingEdges.get(edge.label()); if (edgeRecordsByLabel == null) { // this is the first edge with that label; add a new set to the map edgeRecordsByLabel = Sets.newHashSet(); this.incomingEdges.put(edge.label(), edgeRecordsByLabel); } // store the edge target record by labels edgeRecordsByLabel.add(edgeTargetRecord); } } if (outE != null && outE.isEmpty() == false) { this.outgoingEdges = Maps.newHashMap(); Iterator<ChronoEdge> outEIterator = Sets.newHashSet(outE.values()).iterator(); while (outEIterator.hasNext()) { ChronoEdgeImpl edge = ChronoProxyUtil.resolveEdgeProxy(outEIterator.next()); // create the minimal "edge target" representation for this edge to store in this vertex EdgeTargetRecord2 edgeTargetRecord = new EdgeTargetRecord2(edge.id(), edge.inVertex().id()); // retrieve the set of edge target records with the label in question Set<EdgeTargetRecord2> edgeRecordsByLabel = this.outgoingEdges.get(edge.label()); if (edgeRecordsByLabel == null) { // this is the first edge with that label; add a new set to the map edgeRecordsByLabel = Sets.newHashSet(); this.outgoingEdges.put(edge.label(), edgeRecordsByLabel); } // store the edge target record by labels edgeRecordsByLabel.add(edgeTargetRecord); } } // create an immutable copy of the vertex properties Collection<ChronoVertexProperty<?>> props = properties.values(); if (props.isEmpty() == false) { // we have at least one property this.properties = Sets.newHashSet(); for (ChronoVertexProperty<?> property : props) { IVertexPropertyRecord pRecord = property.toRecord(); this.properties.add(pRecord); } } } public VertexRecord3(final String recordId, final String label, final SetMultimap<String, EdgeTargetRecord2> inE, final SetMultimap<String, EdgeTargetRecord2> outE, final Set<IVertexPropertyRecord> properties) { checkNotNull(recordId, "Precondition violation - argument 'recordId' must not be NULL!"); checkNotNull(label, "Precondition violation - argument 'label' must not be NULL!"); checkNotNull(inE, "Precondition violation - argument 'inE' must not be NULL!"); checkNotNull(outE, "Precondition violation - argument 'outE' must not be NULL!"); checkNotNull(properties, "Precondition violation - argument 'properties' must not be NULL!"); this.recordId = recordId; this.label = label; // convert incoming edges if (inE.isEmpty() == false) { this.incomingEdges = Maps.newHashMap(); for (Entry<String, Collection<EdgeTargetRecord2>> entry : inE.asMap().entrySet()) { String edgeLabel = entry.getKey(); Collection<EdgeTargetRecord2> edgeRecords = entry.getValue(); if (edgeRecords.isEmpty()) { continue; } Set<EdgeTargetRecord2> edgeRecordsByLabel = this.incomingEdges.get(edgeLabel); if (edgeRecordsByLabel == null) { // this is the first edge with that label; add a new set to the map edgeRecordsByLabel = Sets.newHashSet(); this.incomingEdges.put(edgeLabel, edgeRecordsByLabel); } edgeRecordsByLabel.addAll(edgeRecords); } } // convert outgoing edges if (outE.isEmpty() == false) { this.outgoingEdges = Maps.newHashMap(); for (Entry<String, Collection<EdgeTargetRecord2>> entry : outE.asMap().entrySet()) { String edgeLabel = entry.getKey(); Collection<EdgeTargetRecord2> edgeRecords = entry.getValue(); if (edgeRecords.isEmpty()) { continue; } Set<EdgeTargetRecord2> edgeRecordsByLabel = this.outgoingEdges.get(edgeLabel); if (edgeRecordsByLabel == null) { // this is the first edge with that label; add a new set to the map edgeRecordsByLabel = Sets.newHashSet(); this.outgoingEdges.put(edgeLabel, edgeRecordsByLabel); } edgeRecordsByLabel.addAll(edgeRecords); } } // convert vertex properties if (properties.isEmpty() == false) { this.properties = Sets.newHashSet(); this.properties.addAll(properties); } } @Override public String getId() { return this.recordId; } @Override public String getLabel() { return this.label; } @Override public List<EdgeTargetRecordWithLabel> getIncomingEdges() { if (this.incomingEdges == null || this.incomingEdges.isEmpty()) { return Collections.emptyList(); } List<EdgeTargetRecordWithLabel> resultList = new ArrayList<>(); for(Entry<String, Set<EdgeTargetRecord2>> entry : this.incomingEdges.entrySet()){ String label = entry.getKey(); Set<EdgeTargetRecord2> edgeTargetRecords = entry.getValue(); for(EdgeTargetRecord2 record : edgeTargetRecords){ resultList.add(new EdgeTargetRecordWithLabel(record, label)); } } return resultList; } @Override public List<EdgeTargetRecordWithLabel> getIncomingEdges(String... labels){ if(labels == null || labels.length <= 0){ return getIncomingEdges(); } if(this.incomingEdges == null || this.incomingEdges.isEmpty()){ return Collections.emptyList(); } List<EdgeTargetRecordWithLabel> resultList = new ArrayList<>(); for(String label : labels){ Set<EdgeTargetRecord2> labelRecords = this.incomingEdges.get(label); if(labelRecords == null){ continue; } for(EdgeTargetRecord2 record : labelRecords){ resultList.add(new EdgeTargetRecordWithLabel(record, label)); } } return resultList; } @Override public SetMultimap<String, IEdgeTargetRecord> getIncomingEdgesByLabel() { if (this.incomingEdges == null || this.incomingEdges.isEmpty()) { // return the empty multimap return Multimaps.unmodifiableSetMultimap(HashMultimap.create()); } // transform the internal data structure into a set multimap SetMultimap<String, IEdgeTargetRecord> multimap = HashMultimap.create(); for (Entry<String, Set<EdgeTargetRecord2>> entry : this.incomingEdges.entrySet()) { String label = entry.getKey(); Set<EdgeTargetRecord2> edges = entry.getValue(); for (EdgeTargetRecord2 edge : edges) { multimap.put(label, edge); } } return Multimaps.unmodifiableSetMultimap(multimap); } @Override public List<EdgeTargetRecordWithLabel> getOutgoingEdges() { if (this.outgoingEdges == null || this.outgoingEdges.isEmpty()) { return Collections.emptyList(); } List<EdgeTargetRecordWithLabel> resultList = new ArrayList<>(); for(Entry<String, Set<EdgeTargetRecord2>> entry : this.outgoingEdges.entrySet()){ String label = entry.getKey(); Set<EdgeTargetRecord2> edgeTargetRecords = entry.getValue(); for(EdgeTargetRecord2 record : edgeTargetRecords){ resultList.add(new EdgeTargetRecordWithLabel(record, label)); } } return resultList; } @Override public List<EdgeTargetRecordWithLabel> getOutgoingEdges(String... labels){ if(labels == null || labels.length <= 0){ return getOutgoingEdges(); } if(this.outgoingEdges == null || this.outgoingEdges.isEmpty()){ return Collections.emptyList(); } List<EdgeTargetRecordWithLabel> resultList = new ArrayList<>(); for(String label : labels){ Set<EdgeTargetRecord2> labelRecords = this.outgoingEdges.get(label); if(labelRecords == null){ continue; } for(EdgeTargetRecord2 record : labelRecords){ resultList.add(new EdgeTargetRecordWithLabel(record, label)); } } return resultList; } @Override public SetMultimap<String, IEdgeTargetRecord> getOutgoingEdgesByLabel() { if (this.outgoingEdges == null || this.outgoingEdges.isEmpty()) { // return the empty multimap return Multimaps.unmodifiableSetMultimap(HashMultimap.create()); } // transform the internal data structure into a set multimap SetMultimap<String, IEdgeTargetRecord> multimap = HashMultimap.create(); for (Entry<String, Set<EdgeTargetRecord2>> entry : this.outgoingEdges.entrySet()) { String label = entry.getKey(); Set<EdgeTargetRecord2> edges = entry.getValue(); for (EdgeTargetRecord2 edge : edges) { multimap.put(label, edge); } } return Multimaps.unmodifiableSetMultimap(multimap); } @Override public Set<IVertexPropertyRecord> getProperties() { if (this.properties == null || this.properties.isEmpty()) { return Collections.emptySet(); } return Collections.unmodifiableSet(this.properties); } @Override public IVertexPropertyRecord getProperty(final String propertyKey) { if(propertyKey == null || this.properties == null || this.properties.isEmpty()){ return null; } for(IVertexPropertyRecord record : this.properties){ if(Objects.equals(record.getKey(), propertyKey)){ return record; } } return null; } }
13,642
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoGraphBranchIteratorBuilderImpl.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/iterators/builder/ChronoGraphBranchIteratorBuilderImpl.java
package org.chronos.chronograph.internal.impl.iterators.builder; import org.chronos.chronograph.api.iterators.ChronoGraphBranchIteratorBuilder; import org.chronos.chronograph.api.iterators.ChronoGraphTimestampIteratorBuilder; import org.chronos.chronograph.api.iterators.callbacks.TimestampChangeCallback; import java.util.Iterator; import java.util.function.Function; public class ChronoGraphBranchIteratorBuilderImpl extends AbstractChronoGraphIteratorBuilder implements ChronoGraphBranchIteratorBuilder { public ChronoGraphBranchIteratorBuilderImpl(final BuilderConfig config) { super(config); } @Override public ChronoGraphTimestampIteratorBuilder overTimestamps(final Function<String, Iterator<Long>> branchToTimestampsFunction, final TimestampChangeCallback callback) { BuilderConfig config = new BuilderConfig(this.getConfig()); config.setBranchToTimestampsFunction(branchToTimestampsFunction); config.setTimestampChangeCallback(callback); return new ChronoGraphTimestampIteratorBuilderImpl(config); } }
1,076
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoGraphTimestampIteratorBuilderImpl.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/iterators/builder/ChronoGraphTimestampIteratorBuilderImpl.java
package org.chronos.chronograph.internal.impl.iterators.builder; import com.google.common.collect.Iterators; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Element; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.chronos.chronograph.api.iterators.states.AllChangedEdgeIdsAndTheirPreviousNeighborhoodState; import org.chronos.chronograph.api.iterators.states.AllChangedEdgeIdsState; import org.chronos.chronograph.api.iterators.states.AllChangedElementIdsAndTheirNeighborhoodState; import org.chronos.chronograph.api.iterators.states.AllChangedElementIdsState; import org.chronos.chronograph.api.iterators.states.AllChangedVertexIdsAndTheirPreviousNeighborhoodState; import org.chronos.chronograph.api.iterators.states.AllChangedVertexIdsState; import org.chronos.chronograph.api.iterators.states.AllEdgesState; import org.chronos.chronograph.api.iterators.states.AllElementsState; import org.chronos.chronograph.api.iterators.states.AllVerticesState; import org.chronos.chronograph.api.iterators.states.GraphIteratorState; import org.chronos.chronograph.api.structure.ChronoGraph; import org.chronos.chronograph.internal.impl.iterators.builder.states.AllChangedEdgeIdsAndTheirPreviousNeighborhoodStateImpl; import org.chronos.chronograph.internal.impl.iterators.builder.states.AllChangedEdgeIdsStateImpl; import org.chronos.chronograph.internal.impl.iterators.builder.states.AllChangedElementIdsAndTheirPreviousNeighborhoodStateImpl; import org.chronos.chronograph.internal.impl.iterators.builder.states.AllChangedElementIdsStateImpl; import org.chronos.chronograph.internal.impl.iterators.builder.states.AllChangedVertexIdsAndTheirPreviousNeighborhoodStateImpl; import org.chronos.chronograph.internal.impl.iterators.builder.states.AllChangedVertexIdsStateImpl; import org.chronos.chronograph.internal.impl.iterators.builder.states.AllEdgesStateImpl; import org.chronos.chronograph.internal.impl.iterators.builder.states.AllElementsStateImpl; import org.chronos.chronograph.internal.impl.iterators.builder.states.AllVerticesStateImpl; import org.chronos.chronograph.internal.impl.iterators.builder.states.GraphIteratorStateImpl; import java.util.Iterator; import java.util.function.Consumer; import java.util.function.Function; public class ChronoGraphTimestampIteratorBuilderImpl extends AbstractChronoGraphIteratorBuilder implements org.chronos.chronograph.api.iterators.ChronoGraphTimestampIteratorBuilder { protected ChronoGraphTimestampIteratorBuilderImpl(BuilderConfig config) { super(config); } @Override public void visitCoordinates(final Consumer<GraphIteratorState> consumer) { this.iterate(this::createVisitCoordinatesStates, consumer); } private Iterator<GraphIteratorState> createVisitCoordinatesStates(final ChronoGraph graph) { return Iterators.singletonIterator(new GraphIteratorStateImpl(graph)); } @Override public void overAllVertices(final Consumer<AllVerticesState> consumer) { this.iterate(this::createAllVerticesStates, consumer); } private Iterator<AllVerticesState> createAllVerticesStates(final ChronoGraph graph) { Iterator<Vertex> vertexIterator = graph.vertices(); return Iterators.transform(vertexIterator, v -> new AllVerticesStateImpl(graph, v)); } @Override public void overAllEdges(final Consumer<AllEdgesState> consumer) { this.iterate(this::createAllEdgesStates, consumer); } private Iterator<AllEdgesState> createAllEdgesStates(final ChronoGraph graph) { Iterator<Edge> edgeIterator = graph.edges(); return Iterators.transform(edgeIterator, e -> new AllEdgesStateImpl(graph, e)); } @Override public void overAllElements(final Consumer<AllElementsState> consumer) { this.iterate(this::createAllElementsStates, consumer); } private Iterator<AllElementsState> createAllElementsStates(final ChronoGraph graph) { Iterator<Vertex> vertexIterator = this.getGraph().vertices(); Iterator<Edge> edgeIterator = this.getGraph().edges(); Iterator<Element> elementIterator = Iterators.concat(vertexIterator, edgeIterator); return Iterators.transform(elementIterator, e -> new AllElementsStateImpl(graph, e)); } @Override public void overAllChangedVertexIds(final Consumer<AllChangedVertexIdsState> consumer) { this.iterate(this::createAllChangedVertexIdsStates, consumer); } private Iterator<AllChangedVertexIdsState> createAllChangedVertexIdsStates(final ChronoGraph graph) { String branch = graph.tx().getCurrentTransaction().getBranchName(); long timestamp = graph.tx().getCurrentTransaction().getTimestamp(); Iterator<String> changedVertexIds = this.getGraph().getChangedVerticesAtCommit(branch, timestamp); return Iterators.transform(changedVertexIds, vId -> new AllChangedVertexIdsStateImpl(graph, vId)); } @Override public void overAllChangedEdgeIds(final Consumer<AllChangedEdgeIdsState> consumer) { this.iterate(this::createAllChangedEdgeIdsStates, consumer); } private Iterator<AllChangedEdgeIdsState> createAllChangedEdgeIdsStates(final ChronoGraph graph) { String branch = graph.tx().getCurrentTransaction().getBranchName(); long timestamp = graph.tx().getCurrentTransaction().getTimestamp(); Iterator<String> changedEdgeIds = this.getGraph().getChangedEdgesAtCommit(branch, timestamp); return Iterators.transform(changedEdgeIds, eId -> new AllChangedEdgeIdsStateImpl(graph, eId)); } @Override public void overAllChangedElementIds(final Consumer<AllChangedElementIdsState> consumer) { this.iterate(this::createAllChangedElementIdsStates, consumer); } private Iterator<AllChangedElementIdsState> createAllChangedElementIdsStates(final ChronoGraph graph) { String branch = graph.tx().getCurrentTransaction().getBranchName(); long timestamp = graph.tx().getCurrentTransaction().getTimestamp(); Iterator<String> changedVertexIds = this.getGraph().getChangedVerticesAtCommit(branch, timestamp); Iterator<String> changedEdgeIds = this.getGraph().getChangedEdgesAtCommit(branch, timestamp); Iterator<AllChangedElementIdsState> vertexStateIterator = Iterators.transform(changedVertexIds, vId -> new AllChangedElementIdsStateImpl(graph, vId, Vertex.class)); Iterator<AllChangedElementIdsState> edgeStateIterator = Iterators.transform(changedEdgeIds, eId -> new AllChangedElementIdsStateImpl(graph, eId, Edge.class)); return Iterators.concat(vertexStateIterator, edgeStateIterator); } @Override public void overAllChangedVertexIdsAndTheirPreviousNeighborhood(final Consumer<AllChangedVertexIdsAndTheirPreviousNeighborhoodState> consumer) { this.iterate(this::createAllChangedVertexIdsAndTheirPreviousNeighborhoodStates, consumer); } private Iterator<AllChangedVertexIdsAndTheirPreviousNeighborhoodState> createAllChangedVertexIdsAndTheirPreviousNeighborhoodStates(final ChronoGraph graph) { String branch = graph.tx().getCurrentTransaction().getBranchName(); long timestamp = graph.tx().getCurrentTransaction().getTimestamp(); Iterator<String> vertexIdIterator = graph.getChangedVerticesAtCommit(branch, timestamp); return Iterators.transform(vertexIdIterator, vId -> new AllChangedVertexIdsAndTheirPreviousNeighborhoodStateImpl(graph, vId)); } @Override public void overAllChangedEdgeIdsAndTheirPreviousNeighborhood(final Consumer<AllChangedEdgeIdsAndTheirPreviousNeighborhoodState> consumer) { this.iterate(this::createAllChangedEdgeIdsAndTheirPreviousNeighborhoodStates, consumer); } private Iterator<AllChangedEdgeIdsAndTheirPreviousNeighborhoodState> createAllChangedEdgeIdsAndTheirPreviousNeighborhoodStates(final ChronoGraph graph) { String branch = graph.tx().getCurrentTransaction().getBranchName(); long timestamp = graph.tx().getCurrentTransaction().getTimestamp(); Iterator<String> edgeIdIterator = graph.getChangedEdgesAtCommit(branch, timestamp); return Iterators.transform(edgeIdIterator, vId -> new AllChangedEdgeIdsAndTheirPreviousNeighborhoodStateImpl(graph, vId)); } @Override public void overAllChangedElementIdsAndTheirPreviousNeighborhood(final Consumer<AllChangedElementIdsAndTheirNeighborhoodState> consumer) { this.iterate(this::createAllChangedElementIdsAndTheirPreviousNeighborhoodStates, consumer); } private Iterator<AllChangedElementIdsAndTheirNeighborhoodState> createAllChangedElementIdsAndTheirPreviousNeighborhoodStates(final ChronoGraph graph) { String branch = graph.tx().getCurrentTransaction().getBranchName(); long timestamp = graph.tx().getCurrentTransaction().getTimestamp(); Iterator<String> changedVertexIds = this.getGraph().getChangedVerticesAtCommit(branch, timestamp); Iterator<String> changedEdgeIds = this.getGraph().getChangedEdgesAtCommit(branch, timestamp); Iterator<AllChangedElementIdsAndTheirNeighborhoodState> vertexStatesIterator = Iterators.transform(changedVertexIds, vId -> new AllChangedElementIdsAndTheirPreviousNeighborhoodStateImpl(graph, vId, Vertex.class)); Iterator<AllChangedElementIdsAndTheirNeighborhoodState> edgeStatesIterator = Iterators.transform(changedEdgeIds, eId -> new AllChangedElementIdsAndTheirPreviousNeighborhoodStateImpl(graph, eId, Edge.class)); return Iterators.concat(vertexStatesIterator, edgeStatesIterator); } private <T> void iterate(Function<ChronoGraph, Iterator<T>> stateProducer, Consumer<T> stateConsumer) { BuilderConfig c = this.getConfig(); Iterator<String> branchIterator = c.getBranchNames().iterator(); // apply the branch change side effect branchIterator = SideEffectIterator.create(branchIterator, c.getBranchChangeCallback()::handleBranchChanged); while (branchIterator.hasNext()) { String branch = branchIterator.next(); Iterator<Long> timestampsIterator = c.getBranchToTimestampsFunction().apply(branch); // apply the timestamp change side effect timestampsIterator = SideEffectIterator.create(timestampsIterator, c.getTimestampChangeCallback()::handleTimestampChange); while (timestampsIterator.hasNext()) { Long timestamp = timestampsIterator.next(); ChronoGraph graph = c.getGraph(); ChronoGraph txGraph = graph.tx().createThreadedTx(branch, timestamp); try { Iterator<T> stateIterator = stateProducer.apply(txGraph); while (stateIterator.hasNext()) { T state = stateIterator.next(); stateConsumer.accept(state); } } finally { txGraph.close(); } } } } }
11,047
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoGraphRootIteratorBuilderImpl.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/iterators/builder/ChronoGraphRootIteratorBuilderImpl.java
package org.chronos.chronograph.internal.impl.iterators.builder; import org.chronos.chronograph.api.iterators.ChronoGraphBranchIteratorBuilder; import org.chronos.chronograph.api.iterators.ChronoGraphRootIteratorBuilder; import org.chronos.chronograph.api.iterators.callbacks.BranchChangeCallback; import org.chronos.chronograph.api.structure.ChronoGraph; public class ChronoGraphRootIteratorBuilderImpl extends AbstractChronoGraphIteratorBuilder implements ChronoGraphRootIteratorBuilder { public ChronoGraphRootIteratorBuilderImpl(final ChronoGraph graph) { super(new BuilderConfig(graph)); } @Override public ChronoGraphBranchIteratorBuilder overBranches(final Iterable<String> branchNames, final BranchChangeCallback callback) { BuilderConfig config = new BuilderConfig(this.getConfig()); config.setBranchNames(branchNames); config.setBranchChangeCallback(callback); return new ChronoGraphBranchIteratorBuilderImpl(config); } }
996
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
SideEffectIterator.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/iterators/builder/SideEffectIterator.java
package org.chronos.chronograph.internal.impl.iterators.builder; import java.util.Iterator; import java.util.function.BiConsumer; import static com.google.common.base.Preconditions.*; public class SideEffectIterator<T> implements Iterator<T> { public static <T> Iterator<T> create(Iterator<T> iterator, BiConsumer<T, T> sideEffect) { return new SideEffectIterator<>(iterator, sideEffect); } private final Iterator<T> iterator; private final BiConsumer<T, T> sideEffect; private T current = null; public SideEffectIterator(Iterator<T> iterator, BiConsumer<T, T> sideEffect) { checkNotNull(iterator, "Precondition violation - argument 'iterator' must not be NULL!"); checkNotNull(sideEffect, "Precondition violation - argument 'sideEffect' must not be NULL!"); this.iterator = iterator; this.sideEffect = sideEffect; } @Override public boolean hasNext() { return this.iterator.hasNext(); } @Override public T next() { T next = this.iterator.next(); this.sideEffect.accept(this.current, next); this.current = next; return next; } }
1,171
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
BuilderConfig.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/iterators/builder/BuilderConfig.java
package org.chronos.chronograph.internal.impl.iterators.builder; import org.chronos.chronograph.api.iterators.callbacks.BranchChangeCallback; import org.chronos.chronograph.api.iterators.callbacks.TimestampChangeCallback; import org.chronos.chronograph.api.structure.ChronoGraph; import java.util.Iterator; import java.util.function.Function; import static com.google.common.base.Preconditions.*; public class BuilderConfig { private ChronoGraph graph; private Iterable<String> branchNames; private BranchChangeCallback branchChangeCallback; private Function<String, Iterator<Long>> branchToTimestampsFunction; private TimestampChangeCallback timestampChangeCallback; public BuilderConfig(ChronoGraph graph) { checkNotNull(graph, "Precondition violation - argument 'graph' must not be NULL!"); this.graph = graph; } public BuilderConfig(BuilderConfig other) { checkNotNull(other, "Precondition violation - argument 'other' must not be NULL!"); this.graph = other.getGraph(); this.branchNames = other.getBranchNames(); this.branchChangeCallback = other.getBranchChangeCallback(); this.branchToTimestampsFunction = other.getBranchToTimestampsFunction(); this.timestampChangeCallback = other.getTimestampChangeCallback(); } public ChronoGraph getGraph() { return this.graph; } public void setGraph(final ChronoGraph graph) { this.graph = graph; } public Iterable<String> getBranchNames() { return this.branchNames; } public void setBranchNames(final Iterable<String> branchNames) { this.branchNames = branchNames; } public BranchChangeCallback getBranchChangeCallback() { return this.branchChangeCallback; } public void setBranchChangeCallback(final BranchChangeCallback branchChangeCallback) { this.branchChangeCallback = branchChangeCallback; } public Function<String, Iterator<Long>> getBranchToTimestampsFunction() { return this.branchToTimestampsFunction; } public void setBranchToTimestampsFunction(final Function<String, Iterator<Long>> branchToTimestampsFunction) { this.branchToTimestampsFunction = branchToTimestampsFunction; } public TimestampChangeCallback getTimestampChangeCallback() { return this.timestampChangeCallback; } public void setTimestampChangeCallback(final TimestampChangeCallback timestampChangeCallback) { this.timestampChangeCallback = timestampChangeCallback; } }
2,569
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
AbstractChronoGraphIteratorBuilder.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/iterators/builder/AbstractChronoGraphIteratorBuilder.java
package org.chronos.chronograph.internal.impl.iterators.builder; import org.chronos.chronograph.api.iterators.ChronoGraphIteratorBuilder; import org.chronos.chronograph.api.structure.ChronoGraph; import static com.google.common.base.Preconditions.*; public abstract class AbstractChronoGraphIteratorBuilder implements ChronoGraphIteratorBuilder { private final BuilderConfig config; protected AbstractChronoGraphIteratorBuilder(BuilderConfig config) { checkNotNull(config, "Precondition violation - argument 'config' must not be NULL!"); this.config = config; } @Override public ChronoGraph getGraph() { return this.config.getGraph(); } protected BuilderConfig getConfig() { return this.config; } }
770
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
AllChangedElementIdsStateImpl.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/iterators/builder/states/AllChangedElementIdsStateImpl.java
package org.chronos.chronograph.internal.impl.iterators.builder.states; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Element; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.chronos.chronograph.api.iterators.states.AllChangedElementIdsState; import org.chronos.chronograph.api.structure.ChronoGraph; import static com.google.common.base.Preconditions.*; public class AllChangedElementIdsStateImpl extends GraphIteratorStateImpl implements AllChangedElementIdsState { private final String elementId; private final Class<? extends Element> elementType; public AllChangedElementIdsStateImpl(final ChronoGraph txGraph, String elementId, Class<? extends Element> elementType) { super(txGraph); checkNotNull(elementId, "Precondition violation - argument 'elementId' must not be NULL!"); checkNotNull(elementType, "Precondition violation - argument 'elementType' must not be NULL!"); if (!Vertex.class.isAssignableFrom(elementType) && !Edge.class.isAssignableFrom(elementType)) { throw new IllegalArgumentException("Precondition violation - argument 'elementType' is neither Vertex nor Edge!"); } this.elementId = elementId; this.elementType = elementType; } @Override public String getCurrentElementId() { return this.elementId; } @Override public Class<? extends Element> getCurrentElementClass() { return this.elementType; } @Override public boolean isCurrentElementRemoved() { if (this.isCurrentElementAVertex()) { return !this.getVertexById(this.elementId).isPresent(); } else { return !this.getEdgeById(this.elementId).isPresent(); } } }
1,799
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
AllEdgesStateImpl.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/iterators/builder/states/AllEdgesStateImpl.java
package org.chronos.chronograph.internal.impl.iterators.builder.states; import org.apache.tinkerpop.gremlin.structure.Edge; import org.chronos.chronograph.api.iterators.states.AllEdgesState; import org.chronos.chronograph.api.structure.ChronoGraph; import static com.google.common.base.Preconditions.*; public class AllEdgesStateImpl extends GraphIteratorStateImpl implements AllEdgesState { private final Edge edge; public AllEdgesStateImpl(final ChronoGraph txGraph, Edge edge) { super(txGraph); checkNotNull(edge, "Precondition violation - argument 'edge' must not be NULL!"); this.edge = edge; } @Override public Edge getCurrentEdge() { return this.edge; } }
726
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
AllChangedEdgeIdsAndTheirPreviousNeighborhoodStateImpl.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/iterators/builder/states/AllChangedEdgeIdsAndTheirPreviousNeighborhoodStateImpl.java
package org.chronos.chronograph.internal.impl.iterators.builder.states; import com.google.common.collect.Iterators; import com.google.common.collect.Sets; import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Edge; import org.chronos.chronograph.api.iterators.states.AllChangedEdgeIdsAndTheirPreviousNeighborhoodState; import org.chronos.chronograph.api.structure.ChronoGraph; import org.chronos.chronograph.internal.impl.transaction.threaded.ChronoThreadedTransactionGraph; import java.util.Collections; import java.util.Iterator; import java.util.Set; public class AllChangedEdgeIdsAndTheirPreviousNeighborhoodStateImpl extends GraphIteratorStateImpl implements AllChangedEdgeIdsAndTheirPreviousNeighborhoodState { private final String edgeId; private Set<String> neighborhoodVertexIds = null; public AllChangedEdgeIdsAndTheirPreviousNeighborhoodStateImpl(final ChronoGraph txGraph, String edgeId) { super(txGraph); this.edgeId = edgeId; } @Override public String getCurrentEdgeId() { return this.edgeId; } @Override public boolean isCurrentEdgeRemoved() { return !this.getEdgeById(this.edgeId).isPresent(); } @Override public Set<String> getNeighborhoodVertexIds() { if (this.neighborhoodVertexIds == null) { this.neighborhoodVertexIds = this.calculatePreviousNeighborhoodIds(); } return Collections.unmodifiableSet(this.neighborhoodVertexIds); } private Set<String> calculatePreviousNeighborhoodIds() { Set<String> resultSet = Sets.newHashSet(); // add the previous neighborhood (if any) String branch = this.getTransactionGraph().tx().getCurrentTransaction().getBranchName(); Long previousCommit = this.getPreviousCommitOnEdge(this.getTransactionGraph(), this.edgeId); if (previousCommit != null) { try(ChronoGraph txGraph = this.getTransactionGraph().tx().createThreadedTx(branch, previousCommit)){ Iterator<Edge> previousEdges = txGraph.edges(this.edgeId); if (previousEdges.hasNext()) { Edge previousEdge = Iterators.getOnlyElement(previousEdges); previousEdge.vertices(Direction.BOTH).forEachRemaining(v -> resultSet.add((String) v.id())); } } } return resultSet; } private Long getPreviousCommitOnEdge(ChronoGraph graph, String edgeId) { long txTimestamp = graph.tx().getCurrentTransaction().getTimestamp(); Iterator<Long> historyIterator = graph.getEdgeHistory(edgeId); while (historyIterator.hasNext()) { long timestamp = historyIterator.next(); if (timestamp < txTimestamp) { return timestamp; } } return null; } }
2,886
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
AllChangedVertexIdsStateImpl.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronograph/src/main/java/org/chronos/chronograph/internal/impl/iterators/builder/states/AllChangedVertexIdsStateImpl.java
package org.chronos.chronograph.internal.impl.iterators.builder.states; import org.chronos.chronograph.api.iterators.states.AllChangedVertexIdsState; import org.chronos.chronograph.api.structure.ChronoGraph; import static com.google.common.base.Preconditions.*; public class AllChangedVertexIdsStateImpl extends GraphIteratorStateImpl implements AllChangedVertexIdsState { private final String vertexId; public AllChangedVertexIdsStateImpl(final ChronoGraph txGraph, String vertexId) { super(txGraph); checkNotNull(vertexId, "Precondition violation - argument 'vertexId' must not be NULL!"); this.vertexId = vertexId; } @Override public String getCurrentVertexId() { return this.vertexId; } @Override public boolean isCurrentVertexRemoved() { return !this.getVertexById(this.vertexId).isPresent(); } }
885
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z