|
7 | 7 | import com.orientechnologies.orient.core.command.OCommandContext;
|
8 | 8 | import com.orientechnologies.orient.core.db.record.OIdentifiable;
|
9 | 9 | import com.orientechnologies.orient.core.exception.OCommandExecutionException;
|
| 10 | +import com.orientechnologies.orient.core.metadata.OMetadataInternal; |
| 11 | +import com.orientechnologies.orient.core.metadata.schema.OClass; |
| 12 | +import com.orientechnologies.orient.core.metadata.schema.OImmutableSchema; |
| 13 | +import com.orientechnologies.orient.core.metadata.schema.OProperty; |
10 | 14 | import com.orientechnologies.orient.core.record.OElement;
|
11 | 15 | import com.orientechnologies.orient.core.record.ORecord;
|
12 | 16 | import com.orientechnologies.orient.core.record.impl.ODocument;
|
@@ -411,13 +415,22 @@ public boolean isDefinedFor(OElement currentRecord) {
|
411 | 415 |
|
412 | 416 | public OCollate getCollate(OResult currentRecord, OCommandContext ctx) {
|
413 | 417 | if (identifier != null && currentRecord != null) {
|
414 |
| - return currentRecord |
415 |
| - .getRecord() |
416 |
| - .map(x -> (OElement) x) |
417 |
| - .flatMap(elem -> elem.getSchemaType()) |
418 |
| - .map(clazz -> clazz.getProperty(identifier.getStringValue())) |
419 |
| - .map(prop -> prop.getCollate()) |
420 |
| - .orElse(null); |
| 418 | + String clazz = currentRecord.getProperty("@class"); |
| 419 | + if (clazz != null && ctx.getDatabase() != null) { |
| 420 | + OImmutableSchema schema = |
| 421 | + ((OMetadataInternal) ctx.getDatabase().getMetadata()).getImmutableSchemaSnapshot(); |
| 422 | + OClass cl = schema.getClass(clazz); |
| 423 | + if (cl == null) { |
| 424 | + cl = schema.getView(clazz); |
| 425 | + } |
| 426 | + if (cl == null) { |
| 427 | + return null; |
| 428 | + } |
| 429 | + OProperty prop = cl.getProperty(identifier.getStringValue()); |
| 430 | + if (prop != null) { |
| 431 | + return prop.getCollate(); |
| 432 | + } |
| 433 | + } |
421 | 434 | }
|
422 | 435 | return null;
|
423 | 436 | }
|
|
0 commit comments