Skip to content

Commit

Permalink
fix: corrected insert content to respect default values
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Jan 5, 2024
1 parent 0996fa3 commit d51a333
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,19 @@ private boolean handleContent(OElement record, OCommandContext ctx) {
.getImmutableSchemaSnapshot()
.getClass(OSecurity.RESTRICTED_CLASSNAME);

if (restricted != null && restricted.isSuperClassOf(record.getSchemaType().orElse(null))) {
OClass clazz = record.getSchemaType().orElse(null);
if (restricted != null && restricted.isSuperClassOf(clazz)) {
for (OProperty prop : restricted.properties()) {
fieldsToPreserve.field(prop.getName(), record.<Object>getProperty(prop.getName()));
}
}
if (clazz != null) {
for (OProperty prop : clazz.properties()) {
if (prop.getDefaultValue() != null) {
fieldsToPreserve.field(prop.getName(), record.<Object>getProperty(prop.getName()));
}
}
}

OClass recordClass =
ODocumentInternal.getImmutableSchemaClass(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
import static org.junit.Assert.assertTrue;

import com.orientechnologies.BaseMemoryDatabase;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OProperty;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.core.util.ODateHelper;
import java.util.Date;
import org.junit.Test;
Expand Down Expand Up @@ -51,8 +50,8 @@ public void testDefaultValueDate() {
assertTrue(saved.field("date") instanceof Date);
assertNotNull(saved.field("id"));

OIdentifiable id = db.command(new OCommandSQL("insert into ClassA content {}")).execute();
ODocument seved1 = db.load(id.getIdentity());
OResult inserted = db.command("insert into ClassA content {}").next();
ODocument seved1 = db.load(inserted.getIdentity().get());
assertNotNull(seved1.field("date"));
assertNotNull(seved1.field("id"));
assertTrue(seved1.field("date") instanceof Date);
Expand Down

0 comments on commit d51a333

Please # to comment.