/** * Copyright (C) 2009-2013 FoundationDB, LLC * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.foundationdb.server.types.mcompat.mcasts; import com.foundationdb.server.types.TCastBase; import com.foundationdb.server.types.TCast; import com.foundationdb.server.types.TExecutionContext; import com.foundationdb.server.types.mcompat.mtypes.MDateAndTime; import com.foundationdb.server.types.mcompat.mtypes.MApproximateNumber; import com.foundationdb.server.types.mcompat.mtypes.MNumeric; import com.foundationdb.server.types.value.ValueSource; import com.foundationdb.server.types.value.ValueTarget; import com.foundationdb.server.types.texpressions.Constantness; import static com.foundationdb.server.types.mcompat.mcasts.MNumericCastBase.*; public class Cast_From_Timestamp { public static final TCast TO_TINYINT = new FromInt32ToInt8(MDateAndTime.TIMESTAMP, MNumeric.TINYINT, false, Constantness.UNKNOWN); public static final TCast TO_UNSIGNED_TINYINT = new FromInt32ToUnsignedInt8(MDateAndTime.TIMESTAMP, MNumeric.TINYINT_UNSIGNED, false, Constantness.UNKNOWN); public static final TCast TO_SMALLINT = new FromInt32ToInt16(MDateAndTime.TIMESTAMP, MNumeric.SMALLINT, false, Constantness.UNKNOWN); public static final TCast TO_UNSIGNED_SMALINT = new FromInt32ToUnsignedInt16(MDateAndTime.TIMESTAMP, MNumeric.SMALLINT_UNSIGNED, false, Constantness.UNKNOWN); public static final TCast TO_MEDIUMINT = new FromInt32ToInt32(MDateAndTime.TIMESTAMP, MNumeric.MEDIUMINT, false, Constantness.UNKNOWN); public static final TCast TO_UNSIGNED_MEDIUMINT = new FromInt32ToUnsignedInt32(MDateAndTime.TIMESTAMP, MNumeric.MEDIUMINT_UNSIGNED, false, Constantness.UNKNOWN); public static final TCast TO_INT = new FromInt32ToInt32(MDateAndTime.TIMESTAMP, MNumeric.INT, false, Constantness.UNKNOWN); public static final TCast TO_UNSIGNED_INT = new FromInt32ToUnsignedInt32(MDateAndTime.TIMESTAMP, MNumeric.INT_UNSIGNED, false, Constantness.UNKNOWN); public static final TCast TO_BIGINT = new FromInt32ToInt64(MDateAndTime.TIMESTAMP, MNumeric.BIGINT, false, Constantness.UNKNOWN); public static final TCast TO_UNSIGNED_BIGINT = new FromInt32ToInt64(MDateAndTime.TIMESTAMP, MNumeric.BIGINT_UNSIGNED, false, Constantness.UNKNOWN); public static final TCast TO_DOUBLE = new FromInt32ToDouble(MDateAndTime.TIMESTAMP, MApproximateNumber.DOUBLE, false, Constantness.UNKNOWN); public static final TCast TO_DECIMAL = new FromInt32ToDecimal(MDateAndTime.TIMESTAMP, MNumeric.DECIMAL, false, Constantness.UNKNOWN); public static final TCast TO_DATE = new TCastBase(MDateAndTime.TIMESTAMP, MDateAndTime.DATE, Constantness.UNKNOWN) { @Override public void doEvaluate(TExecutionContext context, ValueSource source, ValueTarget target) { target.putInt32(MDateAndTime.encodeDate(MDateAndTime.decodeTimestamp(source.getInt32(), context.getCurrentTimezone()))); } }; public static final TCast TO_TIME = new TCastBase(MDateAndTime.TIMESTAMP, MDateAndTime.TIME, Constantness.UNKNOWN) { @Override public void doEvaluate(TExecutionContext context, ValueSource source, ValueTarget target) { target.putInt32(MDateAndTime.encodeTime(MDateAndTime.decodeTimestamp(source.getInt32(), context.getCurrentTimezone()), context)); } }; public static final TCast TO_DATETIME = new TCastBase(MDateAndTime.TIMESTAMP, MDateAndTime.DATETIME, Constantness.UNKNOWN) { @Override public void doEvaluate(TExecutionContext context, ValueSource source, ValueTarget target) { target.putInt64(MDateAndTime.encodeDateTime(MDateAndTime.decodeTimestamp(source.getInt32(), context.getCurrentTimezone()))); } }; }