4
4
5
5
import com .orientechnologies .orient .core .command .OCommandContext ;
6
6
import com .orientechnologies .orient .core .db .record .OIdentifiable ;
7
+ import com .orientechnologies .orient .core .record .OElement ;
7
8
import com .orientechnologies .orient .core .sql .executor .OResult ;
8
9
import com .orientechnologies .orient .core .sql .executor .OResultSet ;
9
10
import java .util .HashSet ;
@@ -49,21 +50,25 @@ public boolean refersToParent() {
49
50
return false ;
50
51
}
51
52
52
- private Object handleStar (OResult iCurrentRecord , OCommandContext ctx ) {
53
+ private Set < Object > handleStar (OResult iCurrentRecord , OCommandContext ctx ) {
53
54
Set <Object > result = new HashSet <>();
54
55
for (String prop : iCurrentRecord .getPropertyNames ()) {
55
56
Object val = iCurrentRecord .getProperty (prop );
56
- if (isOResult (val ) || isValidIdentifiable (val )) {
57
+ if (isPersistentOResult (val ) || isValidIdentifiable (val )) {
57
58
result .add (val );
58
59
60
+ } else if (val instanceof OResult ) {
61
+ result .addAll (handleStar ((OResult ) val , ctx ));
62
+ } else if (val instanceof OElement ) {
63
+ handleDocument (result , (OElement ) val );
59
64
} else {
60
65
if (val instanceof Iterable ) {
61
66
val = ((Iterable ) val ).iterator ();
62
67
}
63
68
if (val instanceof Iterator ) {
64
69
while (((Iterator ) val ).hasNext ()) {
65
70
Object sub = ((Iterator ) val ).next ();
66
- if (isOResult (sub ) || isValidIdentifiable (sub )) {
71
+ if (isPersistentOResult (sub ) || isValidIdentifiable (sub )) {
67
72
result .add (sub );
68
73
}
69
74
}
@@ -77,15 +82,45 @@ private Object handleStar(OResult iCurrentRecord, OCommandContext ctx) {
77
82
return result ;
78
83
}
79
84
85
+ private void handleDocument (Set <Object > result , OElement record ) {
86
+ for (String prop : record .getPropertyNames ()) {
87
+ Object val = record .getProperty (prop );
88
+ if (isPersistentOResult (val ) || isValidIdentifiable (val )) {
89
+ result .add (val );
90
+ } else if (val instanceof OElement ) {
91
+ handleDocument (result , (OElement ) val );
92
+ } else {
93
+ if (val instanceof Iterable ) {
94
+ val = ((Iterable ) val ).iterator ();
95
+ }
96
+ if (val instanceof Iterator ) {
97
+ while (((Iterator ) val ).hasNext ()) {
98
+ Object sub = ((Iterator ) val ).next ();
99
+ if (isPersistentOResult (sub ) || isValidIdentifiable (sub )) {
100
+ result .add (sub );
101
+ }
102
+ }
103
+ } else if (val instanceof OResultSet ) {
104
+ while (((OResultSet ) val ).hasNext ()) {
105
+ result .add (((OResultSet ) val ).next ());
106
+ }
107
+ }
108
+ }
109
+ }
110
+ }
111
+
80
112
private boolean isValidIdentifiable (Object val ) {
81
113
if (!(val instanceof OIdentifiable )) {
82
114
return false ;
83
115
}
84
116
return ((OIdentifiable ) val ).getIdentity ().isPersistent ();
85
117
}
86
118
87
- private boolean isOResult (Object val ) {
88
- return val instanceof OResult ;
119
+ private boolean isPersistentOResult (Object val ) {
120
+ if (val instanceof OResult ) {
121
+ return ((OResult ) val ).getIdentity ().map ((x ) -> x .getIdentity ().isPersistent ()).orElse (false );
122
+ }
123
+ return false ;
89
124
}
90
125
91
126
public void toString (Map <Object , Object > params , StringBuilder builder ) {
0 commit comments