Path: blob/master/test/jdk/javax/sql/testng/util/TestSQLDataImpl.java
41153 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22package util;2324import java.math.BigDecimal;25import java.sql.Date;26import java.sql.SQLData;27import java.sql.SQLException;28import java.sql.SQLInput;29import java.sql.SQLOutput;30import java.sql.Time;31import java.sql.Timestamp;32import java.time.LocalDate;33import java.time.LocalDateTime;34import java.time.LocalTime;35import java.util.Arrays;3637public class TestSQLDataImpl implements SQLData {3839private final int stringPos = 0;40private final int datePos = 1;41private final int timePos = 2;42private final int timestampPos = 3;43private final int intPos = 4;44private final int longPos = 5;45private final int shortPos = 6;46private final int bigDecimalPos = 7;47private final int doublePos = 8;48private final int booleanPos = 9;49private final int floatPos = 10;50private final int bytePos = 11;51private final int bytesPos = 12;52private final int MAX_TYPES = bytesPos + 1;53private final Object[] types = new Object[MAX_TYPES];5455private final static byte[] b = {1, 2, 3};5657// attributes entries must line up with the ordering of the reading and58// writing of the fields in readSQL and writeSQL59public final static Object[] attributes = {"The Dark Knight",60Date.valueOf(LocalDate.now()), Time.valueOf(LocalTime.now()),61Timestamp.valueOf(LocalDateTime.now()), Integer.MAX_VALUE,62Long.MAX_VALUE, Short.MIN_VALUE, BigDecimal.ONE,63Double.MAX_VALUE, true, 1.5f, Byte.MAX_VALUE, b};6465private String sqlType;6667public TestSQLDataImpl(String type) {68sqlType = type;69}7071@Override72public String getSQLTypeName() throws SQLException {73return sqlType;74}7576@Override77public void readSQL(SQLInput stream, String typeName) throws SQLException {7879sqlType = typeName;80types[stringPos] = stream.readString();81types[datePos] = stream.readDate();82types[timePos] = stream.readTime();83types[timestampPos] = stream.readTimestamp();84types[intPos] = stream.readInt();85types[longPos] = stream.readLong();86types[shortPos] = stream.readShort();87types[bigDecimalPos] = stream.readBigDecimal();88types[doublePos] = stream.readDouble();89types[booleanPos] = stream.readBoolean();90types[floatPos] = stream.readFloat();91types[bytePos] = stream.readByte();92types[bytesPos] = stream.readBytes();93}9495@Override96public void writeSQL(SQLOutput stream) throws SQLException {9798stream.writeString((String) types[stringPos]);99stream.writeDate((Date) types[datePos]);100stream.writeTime((Time) types[timePos]);101stream.writeTimestamp((Timestamp) types[timestampPos]);102stream.writeInt((Integer) types[intPos]);103stream.writeLong((Long) types[longPos]);104stream.writeShort((Short) types[shortPos]);105stream.writeBigDecimal((BigDecimal) types[bigDecimalPos]);106stream.writeDouble((Double) types[doublePos]);107stream.writeBoolean((Boolean) types[booleanPos]);108stream.writeFloat((Float) types[floatPos]);109stream.writeByte((Byte) types[bytePos]);110stream.writeBytes((byte[]) types[bytesPos]);111}112113public Object[] toArray() {114115Object[] result = Arrays.copyOf(types, types.length);116return result;117}118119@Override120public String toString() {121return "[" + sqlType + " " + types + "]";122}123124}125126127