3604 |
26 Jul 07 |
nicklas |
1 |
/** |
3604 |
26 Jul 07 |
nicklas |
$Id$ |
3604 |
26 Jul 07 |
nicklas |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2007 Nicklas Nordborg |
3604 |
26 Jul 07 |
nicklas |
5 |
|
3604 |
26 Jul 07 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
3604 |
26 Jul 07 |
nicklas |
Available at http://base.thep.lu.se/ |
3604 |
26 Jul 07 |
nicklas |
8 |
|
3604 |
26 Jul 07 |
nicklas |
BASE is free software; you can redistribute it and/or |
3604 |
26 Jul 07 |
nicklas |
modify it under the terms of the GNU General Public License |
4479 |
05 Sep 08 |
jari |
as published by the Free Software Foundation; either version 3 |
3604 |
26 Jul 07 |
nicklas |
of the License, or (at your option) any later version. |
3604 |
26 Jul 07 |
nicklas |
13 |
|
3604 |
26 Jul 07 |
nicklas |
BASE is distributed in the hope that it will be useful, |
3604 |
26 Jul 07 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
3604 |
26 Jul 07 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3604 |
26 Jul 07 |
nicklas |
GNU General Public License for more details. |
3604 |
26 Jul 07 |
nicklas |
18 |
|
3604 |
26 Jul 07 |
nicklas |
You should have received a copy of the GNU General Public License |
4515 |
11 Sep 08 |
jari |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
3604 |
26 Jul 07 |
nicklas |
21 |
*/ |
3604 |
26 Jul 07 |
nicklas |
22 |
package net.sf.basedb.util.jep.convert; |
3604 |
26 Jul 07 |
nicklas |
23 |
|
3604 |
26 Jul 07 |
nicklas |
24 |
import net.sf.basedb.core.query.Expression; |
3604 |
26 Jul 07 |
nicklas |
25 |
import net.sf.basedb.core.query.Expressions; |
3604 |
26 Jul 07 |
nicklas |
26 |
|
3604 |
26 Jul 07 |
nicklas |
27 |
import org.nfunk.jep.ASTVarNode; |
3604 |
26 Jul 07 |
nicklas |
28 |
|
3604 |
26 Jul 07 |
nicklas |
29 |
/** |
3604 |
26 Jul 07 |
nicklas |
Converts a variable node to a parameter expression or null. |
3604 |
26 Jul 07 |
nicklas |
31 |
|
3604 |
26 Jul 07 |
nicklas |
@author nicklas |
3604 |
26 Jul 07 |
nicklas |
@version 2.4 |
3604 |
26 Jul 07 |
nicklas |
@base.modified $Date$ |
3604 |
26 Jul 07 |
nicklas |
35 |
*/ |
3604 |
26 Jul 07 |
nicklas |
36 |
public class ASTVarNodeConverter |
3604 |
26 Jul 07 |
nicklas |
37 |
extends AbstractJepConversionFunction<ASTVarNode> |
3604 |
26 Jul 07 |
nicklas |
38 |
{ |
3604 |
26 Jul 07 |
nicklas |
39 |
|
3604 |
26 Jul 07 |
nicklas |
40 |
public ASTVarNodeConverter() |
3604 |
26 Jul 07 |
nicklas |
41 |
{} |
3604 |
26 Jul 07 |
nicklas |
42 |
|
3604 |
26 Jul 07 |
nicklas |
43 |
/* |
3604 |
26 Jul 07 |
nicklas |
From the JepConversionFunction interface |
3604 |
26 Jul 07 |
nicklas |
45 |
------------------------------------------- |
3604 |
26 Jul 07 |
nicklas |
46 |
*/ |
3604 |
26 Jul 07 |
nicklas |
47 |
/** |
3604 |
26 Jul 07 |
nicklas |
Converts a JEP variable to a parameter. A value for the parameter |
3604 |
26 Jul 07 |
nicklas |
must be set on the query before executing it. The special variable |
3604 |
26 Jul 07 |
nicklas |
<code>NULL</code> (ignoring case) is converted to Java null. |
3604 |
26 Jul 07 |
nicklas |
@return An {@link Expression} representing a parameter or null |
3616 |
01 Aug 07 |
nicklas |
@see net.sf.basedb.core.query.Query#setParameter(String, Object, net.sf.basedb.core.Type) |
3604 |
26 Jul 07 |
nicklas |
53 |
*/ |
3604 |
26 Jul 07 |
nicklas |
54 |
@Override |
3604 |
26 Jul 07 |
nicklas |
55 |
public Expression toExpression(ASTVarNode node) |
3604 |
26 Jul 07 |
nicklas |
56 |
{ |
3604 |
26 Jul 07 |
nicklas |
57 |
Expression e = null; |
3604 |
26 Jul 07 |
nicklas |
58 |
String name = node.getName(); |
3604 |
26 Jul 07 |
nicklas |
59 |
if ("NULL".equalsIgnoreCase(name)) name = null; |
3604 |
26 Jul 07 |
nicklas |
60 |
return name == null ? null : Expressions.parameter(name); |
3604 |
26 Jul 07 |
nicklas |
61 |
} |
3604 |
26 Jul 07 |
nicklas |
62 |
// ------------------------------------------- |
3604 |
26 Jul 07 |
nicklas |
63 |
|
3604 |
26 Jul 07 |
nicklas |
64 |
} |