org.eclipse.persistence.history.AsOfSCNClause Maven / Gradle / Ivy
Show all versions of eclipselink Show documentation
/*
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022 IBM Corporation. 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 from Oracle TopLink
package org.eclipse.persistence.history;
import org.eclipse.persistence.expressions.Expression;
import org.eclipse.persistence.internal.expressions.ConstantExpression;
import org.eclipse.persistence.internal.expressions.ExpressionSQLPrinter;
import org.eclipse.persistence.internal.helper.ClassConstants;
import org.eclipse.persistence.internal.helper.ConversionManager;
/**
* Purpose:Wraps an immutable value for a past time, represented as a
* database system change number.
*
* This should be specified with an Oracle platform supporting flashback,
* and the value will be written to the SQL FROM clause:
*
* SELECT ... FROM EMPLOYEE AS OF SCN (value) t0, ...
* @since OracleAS TopLink 10g (10.0.3)
* @author Stephen McRitchie
* @see AsOfClause
* @see org.eclipse.persistence.platform.database.OraclePlatform#getSystemChangeNumberQuery
*/
public class AsOfSCNClause extends AsOfClause {
public AsOfSCNClause(Number systemChangeNumber) {
super(systemChangeNumber);
}
public AsOfSCNClause(Long systemChangeNumber) {
super(systemChangeNumber);
}
public AsOfSCNClause(long systemChangeNumber) {
super(Long.valueOf(systemChangeNumber));
}
public AsOfSCNClause(Expression expression) {
super(expression);
}
/**
* INTERNAL:
* Prints the as of clause for an expression inside of the FROM clause.
*/
@Override
public void printSQL(ExpressionSQLPrinter printer) {
printer.printString("AS OF SCN (");
Object value = getValue();
if (value instanceof Expression expression) {
// Sort of an implementation of native sql.
// Print AS OF SCN (1000L - 45L) not AS OF ('1000L - 45L').
if ((value instanceof ConstantExpression ce) && (ce.getValue() instanceof String s)) {
printer.printString(s);
} else {
printer.printExpression(expression);
}
} else {
ConversionManager converter = ConversionManager.getDefaultManager();
value = converter.convertObject(value, ClassConstants.LONG);
printer.printPrimitive(value, true);
}
printer.printString(")");
}
/**
* PUBLIC:
*/
@Override
public boolean isAsOfSCNClause() {
return true;
}
}