1515 */
1616package com .orientechnologies .orient .core .sql .filter ;
1717
18- import java .util .ArrayList ;
19- import java .util .HashMap ;
20- import java .util .List ;
21- import java .util .Map ;
22-
2318import com .orientechnologies .common .parser .OBaseParser ;
2419import com .orientechnologies .orient .core .command .OCommandContext ;
25- import com .orientechnologies .orient .core .command .OCommandExecutor ;
2620import com .orientechnologies .orient .core .command .OCommandManager ;
2721import com .orientechnologies .orient .core .db .ODatabaseRecordThreadLocal ;
2822import com .orientechnologies .orient .core .db .record .OIdentifiable ;
3226import com .orientechnologies .orient .core .metadata .schema .OClass ;
3327import com .orientechnologies .orient .core .serialization .serializer .OStringSerializerHelper ;
3428import com .orientechnologies .orient .core .sql .OCommandExecutorSQLAbstract ;
29+ import com .orientechnologies .orient .core .sql .OCommandExecutorSQLResultsetDelegate ;
3530import com .orientechnologies .orient .core .sql .OCommandSQL ;
3631import com .orientechnologies .orient .core .sql .OCommandSQLParsingException ;
3732import com .orientechnologies .orient .core .sql .OCommandSQLResultset ;
3833
34+ import java .util .ArrayList ;
35+ import java .util .HashMap ;
36+ import java .util .List ;
37+ import java .util .Map ;
38+
3939/**
4040 * Target parser.
4141 *
4242 * @author Luca Garulli
4343 *
4444 */
4545public class OSQLTarget extends OBaseParser {
46- protected String targetVariable ;
47- protected Iterable <? extends OIdentifiable > targetRecords ;
48- protected Map <String , String > targetClusters ;
49- protected Map <OClass , String > targetClasses ;
50- protected String targetIndex ;
51- protected final boolean empty ;
52- protected final OCommandContext context ;
46+ protected final boolean empty ;
47+ protected final OCommandContext context ;
48+ protected String targetVariable ;
49+ protected OCommandExecutorSQLResultsetDelegate targetQuery ;
50+ protected Iterable <? extends OIdentifiable > targetRecords ;
51+ protected Map <String , String > targetClusters ;
52+ protected Map <OClass , String > targetClasses ;
53+ protected String targetIndex ;
5354
5455 public OSQLTarget (final String iText , final OCommandContext iContext , final String iFilterKeyword ) {
5556 super ();
@@ -71,6 +72,54 @@ public OSQLTarget(final String iText, final OCommandContext iContext, final Stri
7172 }
7273 }
7374
75+ public Map <String , String > getTargetClusters () {
76+ return targetClusters ;
77+ }
78+
79+ public Map <OClass , String > getTargetClasses () {
80+ return targetClasses ;
81+ }
82+
83+ public Iterable <? extends OIdentifiable > getTargetRecords () {
84+ return targetRecords ;
85+ }
86+
87+ public OCommandExecutorSQLResultsetDelegate getTargetQuery () {
88+ return targetQuery ;
89+ }
90+
91+ public String getTargetIndex () {
92+ return targetIndex ;
93+ }
94+
95+ @ Override
96+ public String toString () {
97+ if (targetClasses != null )
98+ return "class " + targetClasses .keySet ();
99+ else if (targetClusters != null )
100+ return "cluster " + targetClusters .keySet ();
101+ if (targetIndex != null )
102+ return "index " + targetIndex ;
103+ if (targetRecords != null )
104+ return "records from " + targetRecords .getClass ().getSimpleName ();
105+ if (targetVariable != null )
106+ return "variable " + targetVariable ;
107+ return "?" ;
108+ }
109+
110+ public String getTargetVariable () {
111+ return targetVariable ;
112+ }
113+
114+ public boolean isEmpty () {
115+ return empty ;
116+ }
117+
118+ @ Override
119+ protected void throwSyntaxErrorException (String iText ) {
120+ throw new OCommandSQLParsingException (iText + ". Use " + getSyntax (), parserText , parserGetPreviousPosition ());
121+ }
122+
74123 @ SuppressWarnings ("unchecked" )
75124 private boolean extractTargets () {
76125 parserSkipWhiteSpaces ();
@@ -94,7 +143,8 @@ private boolean extractTargets() {
94143 parserSetCurrentPosition (OStringSerializerHelper .getEmbedded (parserText , parserGetCurrentPosition (), -1 , subText ) + 1 );
95144 final OCommandSQL subCommand = new OCommandSQLResultset (subText .toString ());
96145
97- final OCommandExecutor executor = OCommandManager .instance ().getExecutor (subCommand );
146+ final OCommandExecutorSQLResultsetDelegate executor = (OCommandExecutorSQLResultsetDelegate ) OCommandManager .instance ()
147+ .getExecutor (subCommand );
98148 executor .setProgressListener (subCommand .getProgressListener ());
99149 executor .parse (subCommand );
100150 context .setChild (executor .getContext ());
@@ -103,6 +153,7 @@ private boolean extractTargets() {
103153 throw new OCommandSQLParsingException ("Sub-query cannot be iterated because doesn't implement the Iterable interface: "
104154 + subCommand );
105155
156+ targetQuery = executor ;
106157 targetRecords = (Iterable <? extends OIdentifiable >) executor ;
107158
108159 } else if (c == OStringSerializerHelper .LIST_BEGIN ) {
@@ -180,48 +231,4 @@ private boolean extractTargets() {
180231
181232 return !parserIsEnded ();
182233 }
183-
184- public Map <String , String > getTargetClusters () {
185- return targetClusters ;
186- }
187-
188- public Map <OClass , String > getTargetClasses () {
189- return targetClasses ;
190- }
191-
192- public Iterable <? extends OIdentifiable > getTargetRecords () {
193- return targetRecords ;
194- }
195-
196- public String getTargetIndex () {
197- return targetIndex ;
198- }
199-
200- @ Override
201- public String toString () {
202- if (targetClasses != null )
203- return "class " + targetClasses .keySet ();
204- else if (targetClusters != null )
205- return "cluster " + targetClusters .keySet ();
206- if (targetIndex != null )
207- return "index " + targetIndex ;
208- if (targetRecords != null )
209- return "records from " + targetRecords .getClass ().getSimpleName ();
210- if (targetVariable != null )
211- return "variable " + targetVariable ;
212- return "?" ;
213- }
214-
215- public String getTargetVariable () {
216- return targetVariable ;
217- }
218-
219- @ Override
220- protected void throwSyntaxErrorException (String iText ) {
221- throw new OCommandSQLParsingException (iText + ". Use " + getSyntax (), parserText , parserGetPreviousPosition ());
222- }
223-
224- public boolean isEmpty () {
225- return empty ;
226- }
227234}
0 commit comments