org.datanucleus.api.jdo.query.NumericExpressionImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datanucleus-api-jdo Show documentation
Show all versions of datanucleus-api-jdo Show documentation
Plugin providing DataNucleus implementation of the JDO API.
/**********************************************************************
Copyright (c) 2010 Andy Jefferson and others. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Contributors:
...
**********************************************************************/
package org.datanucleus.api.jdo.query;
import java.util.ArrayList;
import java.util.List;
import javax.jdo.query.Expression;
import javax.jdo.query.NumericExpression;
import javax.jdo.query.PersistableExpression;
import org.datanucleus.query.expression.DyadicExpression;
import org.datanucleus.query.expression.InvokeExpression;
import org.datanucleus.query.expression.Literal;
/**
* Implementation of a NumericExpression.
*/
public class NumericExpressionImpl extends ComparableExpressionImpl implements NumericExpression
{
public NumericExpressionImpl(PersistableExpression parent, String name)
{
super(parent, name);
}
public NumericExpressionImpl(org.datanucleus.query.expression.Expression queryExpr)
{
super(queryExpr);
}
public NumericExpressionImpl(Class cls, String name, ExpressionType type)
{
super(cls, name, type);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.Expression#add(org.datanucleus.query.typesafe.Expression)
*/
public NumericExpression add(Expression expr)
{
org.datanucleus.query.expression.Expression leftQueryExpr = queryExpr;
org.datanucleus.query.expression.Expression rightQueryExpr = ((ExpressionImpl)expr).getQueryExpression();
org.datanucleus.query.expression.Expression queryExpr =
new DyadicExpression(leftQueryExpr, org.datanucleus.query.expression.Expression.OP_ADD, rightQueryExpr);
return new NumericExpressionImpl(queryExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.NumericExpression#add(java.lang.Number)
*/
public NumericExpression add(Number num)
{
org.datanucleus.query.expression.Expression leftQueryExpr = queryExpr;
org.datanucleus.query.expression.Expression rightQueryExpr = new Literal(num);
org.datanucleus.query.expression.Expression queryExpr =
new DyadicExpression(leftQueryExpr, org.datanucleus.query.expression.Expression.OP_ADD, rightQueryExpr);
return new NumericExpressionImpl(queryExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.Expression#mul(org.datanucleus.query.typesafe.Expression)
*/
public NumericExpression mul(Expression expr)
{
org.datanucleus.query.expression.Expression leftQueryExpr = queryExpr;
org.datanucleus.query.expression.Expression rightQueryExpr = ((ExpressionImpl)expr).getQueryExpression();
org.datanucleus.query.expression.Expression queryExpr =
new DyadicExpression(leftQueryExpr, org.datanucleus.query.expression.Expression.OP_MUL, rightQueryExpr);
return new NumericExpressionImpl(queryExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.NumericExpression#mul(java.lang.Number)
*/
public NumericExpression mul(Number num)
{
org.datanucleus.query.expression.Expression leftQueryExpr = queryExpr;
org.datanucleus.query.expression.Expression rightQueryExpr = new Literal(num);
org.datanucleus.query.expression.Expression queryExpr =
new DyadicExpression(leftQueryExpr, org.datanucleus.query.expression.Expression.OP_MUL, rightQueryExpr);
return new NumericExpressionImpl(queryExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.Expression#sub(org.datanucleus.query.typesafe.Expression)
*/
public NumericExpression sub(Expression expr)
{
org.datanucleus.query.expression.Expression leftQueryExpr = queryExpr;
org.datanucleus.query.expression.Expression rightQueryExpr = ((ExpressionImpl)expr).getQueryExpression();
org.datanucleus.query.expression.Expression queryExpr =
new DyadicExpression(leftQueryExpr, org.datanucleus.query.expression.Expression.OP_SUB, rightQueryExpr);
return new NumericExpressionImpl(queryExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.NumericExpression#sub(java.lang.Number)
*/
public NumericExpression sub(Number num)
{
org.datanucleus.query.expression.Expression leftQueryExpr = queryExpr;
org.datanucleus.query.expression.Expression rightQueryExpr = new Literal(num);
org.datanucleus.query.expression.Expression queryExpr =
new DyadicExpression(leftQueryExpr, org.datanucleus.query.expression.Expression.OP_SUB, rightQueryExpr);
return new NumericExpressionImpl(queryExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.Expression#div(org.datanucleus.query.typesafe.Expression)
*/
public NumericExpression div(Expression expr)
{
org.datanucleus.query.expression.Expression leftQueryExpr = queryExpr;
org.datanucleus.query.expression.Expression rightQueryExpr = ((ExpressionImpl)expr).getQueryExpression();
org.datanucleus.query.expression.Expression queryExpr =
new DyadicExpression(leftQueryExpr, org.datanucleus.query.expression.Expression.OP_DIV, rightQueryExpr);
return new NumericExpressionImpl(queryExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.NumericExpression#div(java.lang.Number)
*/
public NumericExpression div(Number num)
{
org.datanucleus.query.expression.Expression leftQueryExpr = queryExpr;
org.datanucleus.query.expression.Expression rightQueryExpr = new Literal(num);
org.datanucleus.query.expression.Expression queryExpr =
new DyadicExpression(leftQueryExpr, org.datanucleus.query.expression.Expression.OP_DIV, rightQueryExpr);
return new NumericExpressionImpl(queryExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.Expression#mod(org.datanucleus.query.typesafe.Expression)
*/
public NumericExpression mod(Expression expr)
{
org.datanucleus.query.expression.Expression leftQueryExpr = queryExpr;
org.datanucleus.query.expression.Expression rightQueryExpr = ((ExpressionImpl)expr).getQueryExpression();
org.datanucleus.query.expression.Expression queryExpr =
new DyadicExpression(leftQueryExpr, org.datanucleus.query.expression.Expression.OP_MOD, rightQueryExpr);
return new NumericExpressionImpl(queryExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.NumericExpression#mod(java.lang.Number)
*/
public NumericExpression mod(Number num)
{
org.datanucleus.query.expression.Expression leftQueryExpr = queryExpr;
org.datanucleus.query.expression.Expression rightQueryExpr = new Literal(num);
org.datanucleus.query.expression.Expression queryExpr =
new DyadicExpression(leftQueryExpr, org.datanucleus.query.expression.Expression.OP_MOD, rightQueryExpr);
return new NumericExpressionImpl(queryExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.Expression#avg()
*/
public NumericExpression avg()
{
List args = new ArrayList();
args.add(queryExpr);
org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(null, "avg", args);
return new NumericExpressionImpl(invokeExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.Expression#sum()
*/
public NumericExpression sum()
{
List args = new ArrayList();
args.add(queryExpr);
org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(null, "sum", args);
return new NumericExpressionImpl(invokeExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.NumericExpression#abs()
*/
public NumericExpression abs()
{
List args = new ArrayList();
args.add(queryExpr);
org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(null, "abs", args);
return new NumericExpressionImpl(invokeExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.NumericExpression#sqrt()
*/
public NumericExpression sqrt()
{
List args = new ArrayList();
args.add(queryExpr);
org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(null, "sqrt", args);
return new NumericExpressionImpl(invokeExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.NumericExpression#acos()
*/
public NumericExpression acos()
{
List args = new ArrayList();
args.add(queryExpr);
org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(null, "acos", args);
return new NumericExpressionImpl(invokeExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.NumericExpression#asin()
*/
public NumericExpression asin()
{
List args = new ArrayList();
args.add(queryExpr);
org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(null, "asin", args);
return new NumericExpressionImpl(invokeExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.NumericExpression#atan()
*/
public NumericExpression atan()
{
List args = new ArrayList();
args.add(queryExpr);
org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(null, "atan", args);
return new NumericExpressionImpl(invokeExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.NumericExpression#cos()
*/
public NumericExpression cos()
{
List args = new ArrayList();
args.add(queryExpr);
org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(null, "cos", args);
return new NumericExpressionImpl(invokeExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.NumericExpression#sin()
*/
public NumericExpression sin()
{
List args = new ArrayList();
args.add(queryExpr);
org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(null, "sin", args);
return new NumericExpressionImpl(invokeExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.NumericExpression#tan()
*/
public NumericExpression tan()
{
List args = new ArrayList();
args.add(queryExpr);
org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(null, "tan", args);
return new NumericExpressionImpl(invokeExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.NumericExpression#exp()
*/
public NumericExpression exp()
{
List args = new ArrayList();
args.add(queryExpr);
org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(null, "exp", args);
return new NumericExpressionImpl(invokeExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.NumericExpression#log()
*/
public NumericExpression log()
{
List args = new ArrayList();
args.add(queryExpr);
org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(null, "log", args);
return new NumericExpressionImpl(invokeExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.NumericExpression#ceil()
*/
public NumericExpression ceil()
{
List args = new ArrayList();
args.add(queryExpr);
org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(null, "ceil", args);
return new NumericExpressionImpl(invokeExpr);
}
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.NumericExpression#floor()
*/
public NumericExpression floor()
{
List args = new ArrayList();
args.add(queryExpr);
org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(null, "floor", args);
return new NumericExpressionImpl(invokeExpr);
}
/* (non-Javadoc)
* @see javax.jdo.query.NumericExpression#neg()
*/
@Override
public NumericExpression neg()
{
org.datanucleus.query.expression.Expression queryExpr = new DyadicExpression(org.datanucleus.query.expression.Expression.OP_NEG, this.queryExpr);
return new NumericExpressionImpl(queryExpr);
}
/* (non-Javadoc)
* @see javax.jdo.query.NumericExpression#com()
*/
@Override
public NumericExpression com()
{
org.datanucleus.query.expression.Expression queryExpr = new DyadicExpression(org.datanucleus.query.expression.Expression.OP_COM, this.queryExpr);
return new NumericExpressionImpl(queryExpr);
}
/* (non-Javadoc)
* @see javax.jdo.query.NumericExpression#bAnd(javax.jdo.query.NumericExpression)
*/
@Override
public NumericExpression bAnd(NumericExpression bitExpr)
{
org.datanucleus.query.expression.Expression leftQueryExpr = queryExpr;
org.datanucleus.query.expression.Expression rightQueryExpr = ((ExpressionImpl)bitExpr).getQueryExpression();
org.datanucleus.query.expression.Expression queryExpr =
new DyadicExpression(leftQueryExpr, org.datanucleus.query.expression.Expression.OP_BIT_AND, rightQueryExpr);
return new NumericExpressionImpl(queryExpr);
}
/* (non-Javadoc)
* @see javax.jdo.query.NumericExpression#bOr(javax.jdo.query.NumericExpression)
*/
@Override
public NumericExpression bOr(NumericExpression bitExpr)
{
org.datanucleus.query.expression.Expression leftQueryExpr = queryExpr;
org.datanucleus.query.expression.Expression rightQueryExpr = ((ExpressionImpl)bitExpr).getQueryExpression();
org.datanucleus.query.expression.Expression queryExpr =
new DyadicExpression(leftQueryExpr, org.datanucleus.query.expression.Expression.OP_BIT_OR, rightQueryExpr);
return new NumericExpressionImpl(queryExpr);
}
/* (non-Javadoc)
* @see javax.jdo.query.NumericExpression#bXor(javax.jdo.query.NumericExpression)
*/
@Override
public NumericExpression bXor(NumericExpression bitExpr)
{
org.datanucleus.query.expression.Expression leftQueryExpr = queryExpr;
org.datanucleus.query.expression.Expression rightQueryExpr = ((ExpressionImpl)bitExpr).getQueryExpression();
org.datanucleus.query.expression.Expression queryExpr =
new DyadicExpression(leftQueryExpr, org.datanucleus.query.expression.Expression.OP_BIT_XOR, rightQueryExpr);
return new NumericExpressionImpl(queryExpr);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy