org.eclipse.persistence.jpa.jpql.tools.model.query.DateTimeStateObject Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eclipselink Show documentation
Show all versions of eclipselink Show documentation
EclipseLink build based upon Git transaction b7c997804f
/*
* Copyright (c) 2011, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
// Contributors:
// Oracle - initial API and implementation
//
package org.eclipse.persistence.jpa.jpql.tools.model.query;
import org.eclipse.persistence.jpa.jpql.parser.DateTime;
import static org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.*;
import static org.eclipse.persistence.jpa.jpql.parser.Expression.*;
/**
* This {@link DateTimeStateObject} represents a date or time. It supports the following identifiers:
*
* CURRENT_DATE: This function returns the value of current date on the database server.
*
* CURRENT_TIME: This function returns the value of current time on the database server.
*
* CURRENT_TIMESTAMP: This function returns the value of current timestamp on the database
* server.
*
*
BNF: functions_returning_datetime ::= CURRENT_DATE | CURRENT_TIME | CURRENT_TIMESTAMP
*
* The JDBC escape syntax may be used for the specification of date, time, and timestamp literals.
*
*
BNF: expression ::= {d 'yyyy-mm-dd'} | {t 'hh:mm:ss'} | {ts 'yyyy-mm-dd hh:mm:ss.f...'}
*
* @see DateTime
*
* @version 2.4
* @since 2.4
* @author Pascal Filion
*/
@SuppressWarnings("unused") // unused used for the import statement: see bug 330740
public class DateTimeStateObject extends SimpleStateObject {
/**
* Creates a new DateTimeStateObject
.
*
* @param parent The parent of this state object, which cannot be null
* @exception NullPointerException The given parent cannot be null
*/
public DateTimeStateObject(StateObject parent) {
super(parent);
}
/**
* Creates a new DateTimeStateObject
.
*
* @param parent The parent of this state object, which cannot be null
* @param date Either DATE
, TIME
, TIMESTAMP
* or a JDBC date
* @exception NullPointerException The given parent cannot be null
*/
public DateTimeStateObject(StateObject parent, String date) {
super(parent, date);
}
/**
* {@inheritDoc}
*/
public void accept(StateObjectVisitor visitor) {
visitor.visit(this);
}
/**
* {@inheritDoc}
*/
@Override
public DateTime getExpression() {
return (DateTime) super.getExpression();
}
/**
* Determines whether this {@link DateTime} represents the JPQL identifier
* {@link org.eclipse.persistence.jpa.jpql.parser.Expression#CURRENT_DATE CURRENT_DATE}.
*
* @return true
if this {@link org.eclipse.persistence.jpa.jpql.parser.Expression
* Expression} represents {@link org.eclipse.persistence.jpa.jpql.parser.Expression#CURRENT_DATE
* CURRENT_DATE}; false
otherwise
*/
public boolean isCurrentDate() {
return CURRENT_DATE.equalsIgnoreCase(getText());
}
/**
* Determines whether this {@link DateTime} represents the JPQL identifier
* {@link org.eclipse.persistence.jpa.jpql.parser.Expression#CURRENT_TIME CURRENT_TIME}.
*
* @return true
if this {@link org.eclipse.persistence.jpa.jpql.parser.Expression
* Expression} represents {@link org.eclipse.persistence.jpa.jpql.parser.Expression#CURRENT_TIME
* CURRENT_TIME}; false
otherwise
*/
public boolean isCurrentTime() {
return CURRENT_TIME.equalsIgnoreCase(getText());
}
/**
* Determines whether this {@link DateTime} represents the JPQL identifier
* {@link org.eclipse.persistence.jpa.jpql.parser.Expression#CURRENT_TIMESTAMP CURRENT_TIMESTAMP}.
*
* @return true
if this {@link org.eclipse.persistence.jpa.jpql.parser.Expression
* Expression} represents {@link org.eclipse.persistence.jpa.jpql.parser.Expression#CURRENT_TIMESTAMP
* CURRENT_TIMESTAMP}; false
otherwise
*/
public boolean isCurrentTimestamp() {
return CURRENT_TIMESTAMP.equalsIgnoreCase(getText());
}
/**
* Determines whether this {@link DateTime} represents the JDBC escape syntax for date, time,
* timestamp formats.
*
* @return true
if this {@link org.eclipse.persistence.jpa.jpql.parser.Expression
* Expression} represents a JDBC escape syntax; false
otherwise
*/
public boolean isJDBCDate() {
return hasText() ? (getText().charAt(0) == LEFT_CURLY_BRACKET) : false;
}
/**
* Keeps a reference of the {@link DateTime parsed object} object, which should only be
* done when this object is instantiated during the conversion of a parsed JPQL query into
* {@link StateObject StateObjects}.
*
* @param expression The {@link DateTime parsed object} representing a date literal
*/
public void setExpression(DateTime expression) {
super.setExpression(expression);
}
}