|
| 1 | +// --------------------------------------------------------------------------------------------------------------------------------- |
| 2 | +// File: SqlBinary.java |
| 3 | +// |
| 4 | +// |
| 5 | +// Microsoft JDBC Driver for SQL Server |
| 6 | +// Copyright(c) Microsoft Corporation |
| 7 | +// All rights reserved. |
| 8 | +// MIT License |
| 9 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 10 | +// of this software and associated documentation files(the "Software"), |
| 11 | +// to deal in the Software without restriction, including without limitation the |
| 12 | +// rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 13 | +// and / or sell copies of the Software, and to permit persons to whom the |
| 14 | +// Software is furnished to do so, subject to the following conditions : |
| 15 | +// The above copyright notice and this permission notice shall be included in |
| 16 | +// all copies or substantial portions of the Software. |
| 17 | +// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE |
| 20 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 23 | +// IN THE SOFTWARE. |
| 24 | +// --------------------------------------------------------------------------------------------------------------------------------- |
| 25 | + |
| 26 | +package com.microsoft.sqlserver.testframework.sqlType; |
| 27 | + |
| 28 | +import java.sql.JDBCType; |
| 29 | +import java.util.concurrent.ThreadLocalRandom; |
| 30 | + |
| 31 | +/** |
| 32 | + * Contains name, jdbctype, precision, scale for binary data type |
| 33 | + */ |
| 34 | +public class SqlBinary extends SqlType { |
| 35 | + |
| 36 | + /** |
| 37 | + * set JDBCType and precision for SqlBinary |
| 38 | + */ |
| 39 | + public SqlBinary() { |
| 40 | + this("binary", JDBCType.BINARY, 2000); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * |
| 45 | + * @param name binary or varbinary |
| 46 | + * @param jdbctype |
| 47 | + * @param precision |
| 48 | + */ |
| 49 | + SqlBinary(String name, JDBCType jdbctype, int precision) { |
| 50 | + super(name, jdbctype, precision, 0, SqlTypeValue.BINARY.minValue, SqlTypeValue.BINARY.maxValue, SqlTypeValue.BINARY.nullValue, |
| 51 | + VariableLengthType.Precision); |
| 52 | + generatePrecision(); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * create random data for binary and varbinary column |
| 57 | + */ |
| 58 | + public Object createdata() { |
| 59 | + int dataLength = ThreadLocalRandom.current().nextInt(precision); |
| 60 | + byte[] bytes = new byte[dataLength]; |
| 61 | + ThreadLocalRandom.current().nextBytes(bytes); |
| 62 | + return bytes; |
| 63 | + } |
| 64 | +} |
0 commit comments