Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,6 @@ enum CALLBACK_EVENT {
ExecutionPlanCache getExecutionPlanCache();

int getEdgeListSize(int previousSize);

<RET> RET recordFileChanges(final Callable<Object> callback);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,11 @@ public <RET> RET executeInWriteLock(final Callable<RET> callable) {
}
}

@Override
public <RET> RET recordFileChanges(final Callable<Object> callback) {
return (RET) executeInWriteLock(callback);
}

@Override
public StatementCache getStatementCache() {
return statementCache;
Expand Down
57 changes: 36 additions & 21 deletions engine/src/main/java/com/arcadedb/schema/DocumentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.arcadedb.index.lsm.LSMTreeIndexAbstract;

import java.util.*;
import java.util.concurrent.*;

public class DocumentType {
protected final EmbeddedSchema schema;
Expand Down Expand Up @@ -65,9 +66,11 @@ public DocumentType addParentType(final DocumentType parent) {
if (allProperties.contains(p))
throw new IllegalArgumentException("Property '" + p + "' is already defined in type '" + name + "' or any parent types");

parentTypes.add(parent);
parent.subTypes.add(this);
schema.saveConfiguration();
recordFileChanges(() -> {
parentTypes.add(parent);
parent.subTypes.add(this);
return null;
});
return this;
}

Expand All @@ -76,12 +79,14 @@ public void removeParentType(final String parentName) {
}

public void removeParentType(final DocumentType parent) {
if (!parentTypes.remove(parent))
// ALREADY REMOVED PARENT
return;
recordFileChanges(() -> {
if (!parentTypes.remove(parent))
// ALREADY REMOVED PARENT
return null;

parent.subTypes.remove(this);
schema.saveConfiguration();
parent.subTypes.remove(this);
return null;
});
}

public boolean instanceOf(final String type) {
Expand Down Expand Up @@ -132,10 +137,10 @@ public Property createProperty(final String propertyName, final Type propertyTyp

final Property property = new Property(this, propertyName, propertyType);

properties.put(propertyName, property);

schema.saveConfiguration();

recordFileChanges(() -> {
properties.put(propertyName, property);
return null;
});
return property;
}

Expand All @@ -160,8 +165,10 @@ public Property getOrCreateProperty(final String propertyName, final Type proper
}

public void dropProperty(final String propertyName) {
properties.remove(propertyName);
schema.saveConfiguration();
recordFileChanges(() -> {
properties.remove(propertyName);
return null;
});
}

public Index createTypeIndex(final EmbeddedSchema.INDEX_TYPE indexType, final boolean unique, final String... propertyNames) {
Expand Down Expand Up @@ -211,14 +218,18 @@ public List<Bucket> getBuckets(final boolean polymorphic) {
}

public DocumentType addBucket(final Bucket bucket) {
addBucketInternal(bucket);
schema.saveConfiguration();
recordFileChanges(() -> {
addBucketInternal(bucket);
return null;
});
return this;
}

public DocumentType removeBucket(final Bucket bucket) {
addBucketInternal(bucket);
schema.saveConfiguration();
recordFileChanges(() -> {
addBucketInternal(bucket);
return null;
});
return this;
}

Expand Down Expand Up @@ -468,13 +479,12 @@ public boolean isTheSameAs(final Object o) {
}

@Override
public boolean equals(Object o) {
public boolean equals(final Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
DocumentType that = (DocumentType) o;

final DocumentType that = (DocumentType) o;
return name.equals(that.name);
}

Expand Down Expand Up @@ -583,4 +593,9 @@ public boolean isSubTypeOf(final String type) {
}
return false;
}

protected void recordFileChanges(final Callable<Object> callback) {
schema.recordFileChanges(callback);
schema.saveConfiguration();
}
}
Loading