View Javadoc

1   /*
2    * JBoss DNA (http://www.jboss.org/dna)
3    * See the COPYRIGHT.txt file distributed with this work for information
4    * regarding copyright ownership.  Some portions may be licensed
5    * to Red Hat, Inc. under one or more contributor license agreements.
6    * See the AUTHORS.txt file in the distribution for a full listing of 
7    * individual contributors.
8    *
9    * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
10   * is licensed to you under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation; either version 2.1 of
12   * the License, or (at your option) any later version.
13   * 
14   * JBoss DNA is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this software; if not, write to the Free
21   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23   */
24  package org.modeshape.jcr.query;
25  
26  import java.io.InputStream;
27  import java.math.BigDecimal;
28  import java.util.ArrayList;
29  import java.util.Calendar;
30  import java.util.Collection;
31  import java.util.List;
32  import javax.jcr.Binary;
33  import javax.jcr.Node;
34  import javax.jcr.RepositoryException;
35  import javax.jcr.Value;
36  import javax.jcr.ValueFactory;
37  import javax.jcr.query.Query;
38  import org.modeshape.common.text.TokenStream;
39  import org.modeshape.graph.property.DateTime;
40  import org.modeshape.graph.query.model.ArithmeticOperator;
41  import org.modeshape.graph.query.model.Between;
42  import org.modeshape.graph.query.model.Column;
43  import org.modeshape.graph.query.model.Constraint;
44  import org.modeshape.graph.query.model.DynamicOperand;
45  import org.modeshape.graph.query.model.JoinCondition;
46  import org.modeshape.graph.query.model.JoinType;
47  import org.modeshape.graph.query.model.Length;
48  import org.modeshape.graph.query.model.Limit;
49  import org.modeshape.graph.query.model.Operator;
50  import org.modeshape.graph.query.model.Order;
51  import org.modeshape.graph.query.model.Ordering;
52  import org.modeshape.graph.query.model.PropertyValue;
53  import org.modeshape.graph.query.model.QueryCommand;
54  import org.modeshape.graph.query.model.SelectorName;
55  import org.modeshape.graph.query.model.SetCriteria;
56  import org.modeshape.graph.query.model.SetQuery;
57  import org.modeshape.graph.query.model.Source;
58  import org.modeshape.graph.query.model.StaticOperand;
59  import org.modeshape.graph.query.model.Subquery;
60  import org.modeshape.graph.query.model.TypeSystem;
61  import org.modeshape.graph.query.model.FullTextSearch.Term;
62  import org.modeshape.graph.query.model.SetQuery.Operation;
63  import org.modeshape.graph.query.parse.SqlQueryParser;
64  import org.modeshape.jcr.query.qom.JcrAnd;
65  import org.modeshape.jcr.query.qom.JcrArithmeticOperand;
66  import org.modeshape.jcr.query.qom.JcrBetween;
67  import org.modeshape.jcr.query.qom.JcrBindVariableName;
68  import org.modeshape.jcr.query.qom.JcrChildNode;
69  import org.modeshape.jcr.query.qom.JcrChildNodeJoinCondition;
70  import org.modeshape.jcr.query.qom.JcrColumn;
71  import org.modeshape.jcr.query.qom.JcrComparison;
72  import org.modeshape.jcr.query.qom.JcrConstraint;
73  import org.modeshape.jcr.query.qom.JcrDescendantNode;
74  import org.modeshape.jcr.query.qom.JcrDescendantNodeJoinCondition;
75  import org.modeshape.jcr.query.qom.JcrDynamicOperand;
76  import org.modeshape.jcr.query.qom.JcrEquiJoinCondition;
77  import org.modeshape.jcr.query.qom.JcrFullTextSearch;
78  import org.modeshape.jcr.query.qom.JcrFullTextSearchScore;
79  import org.modeshape.jcr.query.qom.JcrJoin;
80  import org.modeshape.jcr.query.qom.JcrJoinCondition;
81  import org.modeshape.jcr.query.qom.JcrLength;
82  import org.modeshape.jcr.query.qom.JcrLimit;
83  import org.modeshape.jcr.query.qom.JcrLiteral;
84  import org.modeshape.jcr.query.qom.JcrLowerCase;
85  import org.modeshape.jcr.query.qom.JcrNamedSelector;
86  import org.modeshape.jcr.query.qom.JcrNodeDepth;
87  import org.modeshape.jcr.query.qom.JcrNodeLocalName;
88  import org.modeshape.jcr.query.qom.JcrNodeName;
89  import org.modeshape.jcr.query.qom.JcrNodePath;
90  import org.modeshape.jcr.query.qom.JcrNot;
91  import org.modeshape.jcr.query.qom.JcrOr;
92  import org.modeshape.jcr.query.qom.JcrOrdering;
93  import org.modeshape.jcr.query.qom.JcrPropertyExistence;
94  import org.modeshape.jcr.query.qom.JcrPropertyValue;
95  import org.modeshape.jcr.query.qom.JcrQueryCommand;
96  import org.modeshape.jcr.query.qom.JcrReferenceValue;
97  import org.modeshape.jcr.query.qom.JcrSameNode;
98  import org.modeshape.jcr.query.qom.JcrSameNodeJoinCondition;
99  import org.modeshape.jcr.query.qom.JcrSelectQuery;
100 import org.modeshape.jcr.query.qom.JcrSetCriteria;
101 import org.modeshape.jcr.query.qom.JcrSetQuery;
102 import org.modeshape.jcr.query.qom.JcrSource;
103 import org.modeshape.jcr.query.qom.JcrStaticOperand;
104 import org.modeshape.jcr.query.qom.JcrSubquery;
105 import org.modeshape.jcr.query.qom.JcrUpperCase;
106 
107 /**
108  * An specialization of the {@link SqlQueryParser} that uses a different language name that matches the JCR 2.0 specification.
109  */
110 public class JcrSql2QueryParser extends SqlQueryParser {
111 
112     public static final String LANGUAGE = Query.JCR_SQL2;
113 
114     public JcrSql2QueryParser() {
115         super();
116     }
117 
118     /**
119      * {@inheritDoc}
120      * 
121      * @see org.modeshape.graph.query.parse.QueryParser#getLanguage()
122      */
123     @Override
124     public String getLanguage() {
125         return LANGUAGE;
126     }
127 
128     @Override
129     protected JcrNamedSelector parseNamedSelector( TokenStream tokens,
130                                                    TypeSystem typeSystem ) {
131         return new JcrNamedSelector(super.parseNamedSelector(tokens, typeSystem));
132     }
133 
134     /**
135      * {@inheritDoc}
136      * 
137      * @see org.modeshape.graph.query.parse.SqlQueryParser#query(org.modeshape.graph.query.model.Source,
138      *      org.modeshape.graph.query.model.Constraint, java.util.List, java.util.List, org.modeshape.graph.query.model.Limit,
139      *      boolean)
140      */
141     @Override
142     protected JcrSelectQuery query( Source source,
143                                     Constraint constraint,
144                                     List<? extends Ordering> orderings,
145                                     List<? extends Column> columns,
146                                     Limit limit,
147                                     boolean distinct ) {
148         return new JcrSelectQuery((JcrSource)source, (JcrConstraint)constraint, orderings(orderings), columns(columns),
149                                   (JcrLimit)limit, distinct);
150     }
151 
152     /**
153      * {@inheritDoc}
154      * 
155      * @see org.modeshape.graph.query.parse.SqlQueryParser#setQuery(org.modeshape.graph.query.model.QueryCommand,
156      *      org.modeshape.graph.query.model.SetQuery.Operation, org.modeshape.graph.query.model.QueryCommand, boolean)
157      */
158     @Override
159     protected JcrSetQuery setQuery( QueryCommand leftQuery,
160                                     Operation operation,
161                                     QueryCommand rightQuery,
162                                     boolean all ) {
163         return new JcrSetQuery((JcrQueryCommand)leftQuery, operation, (JcrQueryCommand)rightQuery, all);
164     }
165 
166     protected List<JcrColumn> columns( List<? extends Column> columns ) {
167         List<JcrColumn> jcrColumns = new ArrayList<JcrColumn>();
168         for (Column column : columns) {
169             jcrColumns.add((JcrColumn)column);
170         }
171         return jcrColumns;
172     }
173 
174     protected List<JcrOrdering> orderings( List<? extends Ordering> orderings ) {
175         if (orderings == null) return null;
176         List<JcrOrdering> jcrOrderings = new ArrayList<JcrOrdering>();
177         for (Ordering ordering : orderings) {
178             jcrOrderings.add((JcrOrdering)ordering);
179         }
180         return jcrOrderings;
181     }
182 
183     /**
184      * {@inheritDoc}
185      * 
186      * @see org.modeshape.graph.query.parse.SqlQueryParser#parseSetQuery(org.modeshape.common.text.TokenStream,
187      *      org.modeshape.graph.query.model.QueryCommand, org.modeshape.graph.query.model.TypeSystem)
188      */
189     @Override
190     protected SetQuery parseSetQuery( TokenStream tokens,
191                                       QueryCommand leftHandSide,
192                                       TypeSystem typeSystem ) {
193         SetQuery query = super.parseSetQuery(tokens, leftHandSide, typeSystem);
194         JcrQueryCommand left = (JcrQueryCommand)query.left();
195         JcrQueryCommand right = (JcrQueryCommand)query.right();
196         List<JcrOrdering> orderings = orderings(query.orderings());
197         JcrLimit limit = (JcrLimit)query.limits();
198         return new JcrSetQuery(left, query.operation(), right, query.isAll(), orderings, limit);
199     }
200 
201     /**
202      * {@inheritDoc}
203      * 
204      * @see org.modeshape.graph.query.parse.SqlQueryParser#length(org.modeshape.graph.query.model.PropertyValue)
205      */
206     @Override
207     protected Length length( PropertyValue propertyValue ) {
208         return new JcrLength((JcrPropertyValue)propertyValue);
209     }
210 
211     /**
212      * {@inheritDoc}
213      * 
214      * @see org.modeshape.graph.query.parse.SqlQueryParser#lowerCase(org.modeshape.graph.query.model.DynamicOperand)
215      */
216     @Override
217     protected JcrLowerCase lowerCase( DynamicOperand operand ) {
218         return new JcrLowerCase((JcrDynamicOperand)operand);
219     }
220 
221     /**
222      * {@inheritDoc}
223      * 
224      * @see org.modeshape.graph.query.parse.SqlQueryParser#upperCase(org.modeshape.graph.query.model.DynamicOperand)
225      */
226     @Override
227     protected JcrUpperCase upperCase( DynamicOperand operand ) {
228         return new JcrUpperCase((JcrDynamicOperand)operand);
229     }
230 
231     /**
232      * {@inheritDoc}
233      * 
234      * @see org.modeshape.graph.query.parse.SqlQueryParser#nodeName(org.modeshape.graph.query.model.SelectorName)
235      */
236     @Override
237     protected JcrNodeName nodeName( SelectorName selector ) {
238         return new JcrNodeName(selector);
239     }
240 
241     /**
242      * {@inheritDoc}
243      * 
244      * @see org.modeshape.graph.query.parse.SqlQueryParser#nodeLocalName(org.modeshape.graph.query.model.SelectorName)
245      */
246     @Override
247     protected JcrNodeLocalName nodeLocalName( SelectorName selector ) {
248         return new JcrNodeLocalName(selector);
249     }
250 
251     /**
252      * {@inheritDoc}
253      * 
254      * @see org.modeshape.graph.query.parse.SqlQueryParser#nodeDepth(org.modeshape.graph.query.model.SelectorName)
255      */
256     @Override
257     protected JcrNodeDepth nodeDepth( SelectorName selector ) {
258         return new JcrNodeDepth(selector);
259     }
260 
261     /**
262      * {@inheritDoc}
263      * 
264      * @see org.modeshape.graph.query.parse.SqlQueryParser#nodePath(org.modeshape.graph.query.model.SelectorName)
265      */
266     @Override
267     protected JcrNodePath nodePath( SelectorName selector ) {
268         return new JcrNodePath(selector);
269     }
270 
271     /**
272      * {@inheritDoc}
273      * 
274      * @see org.modeshape.graph.query.parse.SqlQueryParser#equiJoinCondition(org.modeshape.graph.query.model.SelectorName,
275      *      java.lang.String, org.modeshape.graph.query.model.SelectorName, java.lang.String)
276      */
277     @Override
278     protected JcrEquiJoinCondition equiJoinCondition( SelectorName selector1,
279                                                       String property1,
280                                                       SelectorName selector2,
281                                                       String property2 ) {
282         return new JcrEquiJoinCondition(selector1, property1, selector2, property2);
283     }
284 
285     /**
286      * {@inheritDoc}
287      * 
288      * @see org.modeshape.graph.query.parse.SqlQueryParser#descendantNodeJoinCondition(org.modeshape.graph.query.model.SelectorName,
289      *      org.modeshape.graph.query.model.SelectorName)
290      */
291     @Override
292     protected JcrDescendantNodeJoinCondition descendantNodeJoinCondition( SelectorName ancestor,
293                                                                           SelectorName descendant ) {
294         return new JcrDescendantNodeJoinCondition(ancestor, descendant);
295     }
296 
297     /**
298      * {@inheritDoc}
299      * 
300      * @see org.modeshape.graph.query.parse.SqlQueryParser#childNodeJoinCondition(org.modeshape.graph.query.model.SelectorName,
301      *      org.modeshape.graph.query.model.SelectorName)
302      */
303     @Override
304     protected JcrChildNodeJoinCondition childNodeJoinCondition( SelectorName parent,
305                                                                 SelectorName child ) {
306         return new JcrChildNodeJoinCondition(parent, child);
307     }
308 
309     /**
310      * {@inheritDoc}
311      * 
312      * @see org.modeshape.graph.query.parse.SqlQueryParser#sameNodeJoinCondition(org.modeshape.graph.query.model.SelectorName,
313      *      org.modeshape.graph.query.model.SelectorName)
314      */
315     @Override
316     protected JcrSameNodeJoinCondition sameNodeJoinCondition( SelectorName selector1,
317                                                               SelectorName selector2 ) {
318         return new JcrSameNodeJoinCondition(selector1, selector2);
319     }
320 
321     /**
322      * {@inheritDoc}
323      * 
324      * @see org.modeshape.graph.query.parse.SqlQueryParser#sameNodeJoinCondition(org.modeshape.graph.query.model.SelectorName,
325      *      org.modeshape.graph.query.model.SelectorName, java.lang.String)
326      */
327     @Override
328     protected JcrSameNodeJoinCondition sameNodeJoinCondition( SelectorName selector1,
329                                                               SelectorName selector2,
330                                                               String path ) {
331         return new JcrSameNodeJoinCondition(selector1, selector2, path);
332     }
333 
334     /**
335      * {@inheritDoc}
336      * 
337      * @see org.modeshape.graph.query.parse.SqlQueryParser#limit(int, int)
338      */
339     @Override
340     protected JcrLimit limit( int rowCount,
341                               int offset ) {
342         return new JcrLimit(rowCount, offset);
343     }
344 
345     @Override
346     protected JcrColumn column( SelectorName selectorName,
347                                 String propertyName,
348                                 String columnName ) {
349         return new JcrColumn(selectorName, propertyName, columnName);
350     }
351 
352     /**
353      * {@inheritDoc}
354      * 
355      * @see org.modeshape.graph.query.parse.SqlQueryParser#join(org.modeshape.graph.query.model.Source,
356      *      org.modeshape.graph.query.model.JoinType, org.modeshape.graph.query.model.Source,
357      *      org.modeshape.graph.query.model.JoinCondition)
358      */
359     @Override
360     protected JcrJoin join( Source left,
361                             JoinType joinType,
362                             Source right,
363                             JoinCondition joinCondition ) {
364         return new JcrJoin((JcrSource)left, joinType, (JcrSource)right, (JcrJoinCondition)joinCondition);
365     }
366 
367     /**
368      * {@inheritDoc}
369      * 
370      * @see org.modeshape.graph.query.parse.SqlQueryParser#not(org.modeshape.graph.query.model.Constraint)
371      */
372     @Override
373     protected JcrNot not( Constraint constraint ) {
374         return new JcrNot((JcrConstraint)constraint);
375     }
376 
377     /**
378      * {@inheritDoc}
379      * 
380      * @see org.modeshape.graph.query.parse.SqlQueryParser#and(org.modeshape.graph.query.model.Constraint,
381      *      org.modeshape.graph.query.model.Constraint)
382      */
383     @Override
384     protected JcrAnd and( Constraint constraint1,
385                           Constraint constraint2 ) {
386         return new JcrAnd((JcrConstraint)constraint1, (JcrConstraint)constraint2);
387     }
388 
389     /**
390      * {@inheritDoc}
391      * 
392      * @see org.modeshape.graph.query.parse.SqlQueryParser#or(org.modeshape.graph.query.model.Constraint,
393      *      org.modeshape.graph.query.model.Constraint)
394      */
395     @Override
396     protected JcrOr or( Constraint constraint1,
397                         Constraint constraint2 ) {
398         return new JcrOr((JcrConstraint)constraint1, (JcrConstraint)constraint2);
399     }
400 
401     /**
402      * {@inheritDoc}
403      * 
404      * @see org.modeshape.graph.query.parse.SqlQueryParser#fullTextSearch(org.modeshape.graph.query.model.SelectorName,
405      *      java.lang.String, java.lang.String, org.modeshape.graph.query.model.FullTextSearch.Term)
406      */
407     @Override
408     protected JcrFullTextSearch fullTextSearch( SelectorName name,
409                                                 String propertyName,
410                                                 String expression,
411                                                 Term term ) {
412         return new JcrFullTextSearch(name, propertyName, expression, term);
413     }
414 
415     /**
416      * {@inheritDoc}
417      * 
418      * @see org.modeshape.graph.query.parse.SqlQueryParser#sameNode(org.modeshape.graph.query.model.SelectorName,
419      *      java.lang.String)
420      */
421     @Override
422     protected JcrSameNode sameNode( SelectorName name,
423                                     String path ) {
424         return new JcrSameNode(name, path);
425     }
426 
427     /**
428      * {@inheritDoc}
429      * 
430      * @see org.modeshape.graph.query.parse.SqlQueryParser#childNode(org.modeshape.graph.query.model.SelectorName,
431      *      java.lang.String)
432      */
433     @Override
434     protected JcrChildNode childNode( SelectorName name,
435                                       String path ) {
436         return new JcrChildNode(name, path);
437     }
438 
439     /**
440      * {@inheritDoc}
441      * 
442      * @see org.modeshape.graph.query.parse.SqlQueryParser#descendantNode(org.modeshape.graph.query.model.SelectorName,
443      *      java.lang.String)
444      */
445     @Override
446     protected JcrDescendantNode descendantNode( SelectorName name,
447                                                 String path ) {
448         return new JcrDescendantNode(name, path);
449     }
450 
451     /**
452      * {@inheritDoc}
453      * 
454      * @see org.modeshape.graph.query.parse.SqlQueryParser#comparison(org.modeshape.graph.query.model.DynamicOperand,
455      *      org.modeshape.graph.query.model.Operator, org.modeshape.graph.query.model.StaticOperand)
456      */
457     @Override
458     protected JcrComparison comparison( DynamicOperand left,
459                                         Operator operator,
460                                         StaticOperand right ) {
461         return new JcrComparison((JcrDynamicOperand)left, operator, (JcrStaticOperand)right);
462     }
463 
464     /**
465      * {@inheritDoc}
466      * 
467      * @see org.modeshape.graph.query.parse.SqlQueryParser#ordering(org.modeshape.graph.query.model.DynamicOperand,
468      *      org.modeshape.graph.query.model.Order)
469      */
470     @Override
471     protected JcrOrdering ordering( DynamicOperand operand,
472                                     Order order ) {
473         return new JcrOrdering((JcrDynamicOperand)operand, order);
474     }
475 
476     /**
477      * {@inheritDoc}
478      * 
479      * @see org.modeshape.graph.query.parse.SqlQueryParser#propertyExistence(org.modeshape.graph.query.model.SelectorName,
480      *      java.lang.String)
481      */
482     @Override
483     protected JcrPropertyExistence propertyExistence( SelectorName selector,
484                                                       String propertyName ) {
485         return new JcrPropertyExistence(selector, propertyName);
486     }
487 
488     /**
489      * {@inheritDoc}
490      * 
491      * @see org.modeshape.graph.query.parse.SqlQueryParser#fullTextSearchScore(org.modeshape.graph.query.model.SelectorName)
492      */
493     @Override
494     protected JcrFullTextSearchScore fullTextSearchScore( SelectorName selector ) {
495         return new JcrFullTextSearchScore(selector);
496     }
497 
498     /**
499      * {@inheritDoc}
500      * 
501      * @see org.modeshape.graph.query.parse.SqlQueryParser#between(org.modeshape.graph.query.model.DynamicOperand,
502      *      org.modeshape.graph.query.model.StaticOperand, org.modeshape.graph.query.model.StaticOperand, boolean, boolean)
503      */
504     @Override
505     protected Between between( DynamicOperand operand,
506                                StaticOperand lowerBound,
507                                StaticOperand upperBound,
508                                boolean lowerInclusive,
509                                boolean upperInclusive ) {
510         return new JcrBetween((JcrDynamicOperand)operand, (JcrStaticOperand)lowerBound, (JcrStaticOperand)upperBound,
511                               lowerInclusive, upperInclusive);
512     }
513 
514     /**
515      * {@inheritDoc}
516      * 
517      * @see org.modeshape.graph.query.parse.SqlQueryParser#setCriteria(org.modeshape.graph.query.model.DynamicOperand,
518      *      java.util.Collection)
519      */
520     @SuppressWarnings( "unchecked" )
521     @Override
522     protected SetCriteria setCriteria( DynamicOperand operand,
523                                        Collection<? extends StaticOperand> values ) {
524         return new JcrSetCriteria((JcrDynamicOperand)operand, (Collection<? extends JcrStaticOperand>)values);
525     }
526 
527     /**
528      * {@inheritDoc}
529      * 
530      * @see org.modeshape.graph.query.parse.SqlQueryParser#arithmeticOperand(org.modeshape.graph.query.model.DynamicOperand,
531      *      org.modeshape.graph.query.model.ArithmeticOperator, org.modeshape.graph.query.model.DynamicOperand)
532      */
533     @Override
534     protected JcrArithmeticOperand arithmeticOperand( DynamicOperand leftOperand,
535                                                       ArithmeticOperator operator,
536                                                       DynamicOperand rightOperand ) {
537         return new JcrArithmeticOperand((JcrDynamicOperand)leftOperand, operator, (JcrDynamicOperand)rightOperand);
538     }
539 
540     /**
541      * {@inheritDoc}
542      * 
543      * @see org.modeshape.graph.query.parse.SqlQueryParser#propertyValue(org.modeshape.graph.query.model.SelectorName,
544      *      java.lang.String)
545      */
546     @Override
547     protected JcrPropertyValue propertyValue( SelectorName selector,
548                                               String propertyName ) {
549         return new JcrPropertyValue(selector, propertyName);
550     }
551 
552     /**
553      * {@inheritDoc}
554      * 
555      * @see org.modeshape.graph.query.parse.SqlQueryParser#referenceValue(org.modeshape.graph.query.model.SelectorName)
556      */
557     @Override
558     protected JcrReferenceValue referenceValue( SelectorName selector ) {
559         return new JcrReferenceValue(selector, null);
560     }
561 
562     /**
563      * {@inheritDoc}
564      * 
565      * @see org.modeshape.graph.query.parse.SqlQueryParser#referenceValue(org.modeshape.graph.query.model.SelectorName,
566      *      java.lang.String)
567      */
568     @Override
569     protected JcrReferenceValue referenceValue( SelectorName selector,
570                                                 String propertyName ) {
571         return new JcrReferenceValue(selector, propertyName);
572     }
573 
574     /**
575      * {@inheritDoc}
576      * 
577      * @see org.modeshape.graph.query.parse.SqlQueryParser#bindVariableName(java.lang.String)
578      */
579     @Override
580     protected JcrBindVariableName bindVariableName( String variableName ) {
581         return new JcrBindVariableName(variableName);
582     }
583 
584     /**
585      * {@inheritDoc}
586      * 
587      * @see org.modeshape.graph.query.parse.SqlQueryParser#subquery(org.modeshape.graph.query.model.QueryCommand)
588      */
589     @Override
590     protected Subquery subquery( QueryCommand queryCommand ) {
591         return new JcrSubquery((JcrQueryCommand)queryCommand);
592     }
593 
594     /**
595      * {@inheritDoc}
596      * 
597      * @see org.modeshape.graph.query.parse.SqlQueryParser#literal(TypeSystem, Object)
598      */
599     @Override
600     protected JcrLiteral literal( TypeSystem typeSystem,
601                                   Object value ) throws org.modeshape.graph.property.ValueFormatException {
602         ValueFactory factory = ((JcrTypeSystem)typeSystem).getValueFactory();
603         Value jcrValue = null;
604         if (value instanceof String) {
605             jcrValue = factory.createValue((String)value);
606         } else if (value instanceof Boolean) {
607             jcrValue = factory.createValue(((Boolean)value).booleanValue());
608         } else if (value instanceof Binary) {
609             jcrValue = factory.createValue((Binary)value);
610         } else if (value instanceof DateTime) {
611             jcrValue = factory.createValue(((DateTime)value).toCalendar());
612         } else if (value instanceof Calendar) {
613             jcrValue = factory.createValue((Calendar)value);
614         } else if (value instanceof BigDecimal) {
615             jcrValue = factory.createValue((BigDecimal)value);
616         } else if (value instanceof Double) {
617             jcrValue = factory.createValue((Double)value);
618         } else if (value instanceof Long) {
619             jcrValue = factory.createValue((Long)value);
620         } else if (value instanceof InputStream) {
621             try {
622                 Binary binary = factory.createBinary((InputStream)value);
623                 jcrValue = factory.createValue(binary);
624             } catch (RepositoryException e) {
625                 throw new org.modeshape.graph.property.ValueFormatException(value,
626                                                                             org.modeshape.graph.property.PropertyType.BINARY,
627                                                                             e.getMessage());
628             }
629         } else if (value instanceof Node) {
630             try {
631                 jcrValue = factory.createValue((Node)value);
632             } catch (RepositoryException e) {
633                 throw new org.modeshape.graph.property.ValueFormatException(value,
634                                                                             org.modeshape.graph.property.PropertyType.REFERENCE,
635                                                                             e.getMessage());
636             }
637         } else {
638             jcrValue = factory.createValue(value.toString());
639         }
640         return new JcrLiteral(jcrValue, value);
641     }
642 
643 }