-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
723 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
215 changes: 215 additions & 0 deletions
215
src/main/java/org/mariadb/jdbc/client/column/UuidColumn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
// SPDX-License-Identifier: LGPL-2.1-or-later | ||
// Copyright (c) 2012-2014 Monty Program Ab | ||
// Copyright (c) 2015-2021 MariaDB Corporation Ab | ||
|
||
package org.mariadb.jdbc.client.column; | ||
|
||
import java.sql.*; | ||
import java.util.Calendar; | ||
import java.util.UUID; | ||
import org.mariadb.jdbc.Configuration; | ||
import org.mariadb.jdbc.client.ColumnDecoder; | ||
import org.mariadb.jdbc.client.DataType; | ||
import org.mariadb.jdbc.client.ReadableByteBuf; | ||
import org.mariadb.jdbc.message.server.ColumnDefinitionPacket; | ||
import org.mariadb.jdbc.util.CharsetEncodingLength; | ||
|
||
/** Column metadata definition */ | ||
public class UuidColumn extends ColumnDefinitionPacket implements ColumnDecoder { | ||
|
||
/** | ||
* UUID metadata type decoder | ||
* | ||
* @param buf buffer | ||
* @param charset charset | ||
* @param length maximum data length | ||
* @param dataType data type. see https://mariadb.com/kb/en/result-set-packets/#field-types | ||
* @param decimals decimal length | ||
* @param flags flags. see https://mariadb.com/kb/en/result-set-packets/#field-details-flag | ||
* @param stringPos string offset position in buffer | ||
* @param extTypeName extended type name | ||
* @param extTypeFormat extended type format | ||
*/ | ||
public UuidColumn( | ||
ReadableByteBuf buf, | ||
int charset, | ||
long length, | ||
DataType dataType, | ||
byte decimals, | ||
int flags, | ||
int[] stringPos, | ||
String extTypeName, | ||
String extTypeFormat) { | ||
super(buf, charset, length, dataType, decimals, flags, stringPos, extTypeName, extTypeFormat); | ||
} | ||
|
||
public String defaultClassname(Configuration conf) { | ||
return conf.uuidAsString() ? String.class.getName() : UUID.class.getName(); | ||
} | ||
|
||
public int getColumnType(Configuration conf) { | ||
return conf.uuidAsString() ? Types.CHAR : Types.OTHER; | ||
} | ||
|
||
public String getColumnTypeName(Configuration conf) { | ||
return "uuid"; | ||
} | ||
|
||
public int getPrecision() { | ||
Integer maxWidth = CharsetEncodingLength.maxCharlen.get(charset); | ||
if (maxWidth == null) { | ||
return (int) columnLength; | ||
} | ||
return (int) (columnLength / maxWidth); | ||
} | ||
|
||
@Override | ||
public Object getDefaultText(final Configuration conf, ReadableByteBuf buf, int length) | ||
throws SQLDataException { | ||
return conf.uuidAsString() ? buf.readString(length) : UUID.fromString(buf.readAscii(length)); | ||
} | ||
|
||
@Override | ||
public Object getDefaultBinary(final Configuration conf, ReadableByteBuf buf, int length) | ||
throws SQLDataException { | ||
return conf.uuidAsString() ? buf.readString(length) : UUID.fromString(buf.readAscii(length)); | ||
} | ||
|
||
@Override | ||
public boolean decodeBooleanText(ReadableByteBuf buf, int length) throws SQLDataException { | ||
buf.skip(length); | ||
throw new SQLDataException("Data type UUID cannot be decoded as Boolean"); | ||
} | ||
|
||
@Override | ||
public boolean decodeBooleanBinary(ReadableByteBuf buf, int length) throws SQLDataException { | ||
buf.skip(length); | ||
throw new SQLDataException("Data type UUID cannot be decoded as Boolean"); | ||
} | ||
|
||
@Override | ||
public byte decodeByteText(ReadableByteBuf buf, int length) throws SQLDataException { | ||
buf.skip(length); | ||
throw new SQLDataException("Data type UUID cannot be decoded as byte"); | ||
} | ||
|
||
@Override | ||
public byte decodeByteBinary(ReadableByteBuf buf, int length) throws SQLDataException { | ||
buf.skip(length); | ||
throw new SQLDataException("Data type UUID cannot be decoded as byte"); | ||
} | ||
|
||
@Override | ||
public String decodeStringText(ReadableByteBuf buf, int length, Calendar cal) | ||
throws SQLDataException { | ||
return buf.readString(length); | ||
} | ||
|
||
@Override | ||
public String decodeStringBinary(ReadableByteBuf buf, int length, Calendar cal) | ||
throws SQLDataException { | ||
return buf.readString(length); | ||
} | ||
|
||
@Override | ||
public short decodeShortText(ReadableByteBuf buf, int length) throws SQLDataException { | ||
buf.skip(length); | ||
throw new SQLDataException("Data type UUID cannot be decoded as Short"); | ||
} | ||
|
||
@Override | ||
public short decodeShortBinary(ReadableByteBuf buf, int length) throws SQLDataException { | ||
buf.skip(length); | ||
throw new SQLDataException("Data type UUID cannot be decoded as Short"); | ||
} | ||
|
||
@Override | ||
public int decodeIntText(ReadableByteBuf buf, int length) throws SQLDataException { | ||
buf.skip(length); | ||
throw new SQLDataException("Data type UUID cannot be decoded as Integer"); | ||
} | ||
|
||
@Override | ||
public int decodeIntBinary(ReadableByteBuf buf, int length) throws SQLDataException { | ||
buf.skip(length); | ||
throw new SQLDataException("Data type UUID cannot be decoded as Integer"); | ||
} | ||
|
||
@Override | ||
public long decodeLongText(ReadableByteBuf buf, int length) throws SQLDataException { | ||
buf.skip(length); | ||
throw new SQLDataException("Data type UUID cannot be decoded as Long"); | ||
} | ||
|
||
@Override | ||
public long decodeLongBinary(ReadableByteBuf buf, int length) throws SQLDataException { | ||
buf.skip(length); | ||
throw new SQLDataException("Data type UUID cannot be decoded as Long"); | ||
} | ||
|
||
@Override | ||
public float decodeFloatText(ReadableByteBuf buf, int length) throws SQLDataException { | ||
buf.skip(length); | ||
throw new SQLDataException("Data type UUID cannot be decoded as Float"); | ||
} | ||
|
||
@Override | ||
public float decodeFloatBinary(ReadableByteBuf buf, int length) throws SQLDataException { | ||
buf.skip(length); | ||
throw new SQLDataException("Data type UUID cannot be decoded as Float"); | ||
} | ||
|
||
@Override | ||
public double decodeDoubleText(ReadableByteBuf buf, int length) throws SQLDataException { | ||
buf.skip(length); | ||
throw new SQLDataException("Data type UUID cannot be decoded as Double"); | ||
} | ||
|
||
@Override | ||
public double decodeDoubleBinary(ReadableByteBuf buf, int length) throws SQLDataException { | ||
buf.skip(length); | ||
throw new SQLDataException("Data type UUID cannot be decoded as Double"); | ||
} | ||
|
||
@Override | ||
public Date decodeDateText(ReadableByteBuf buf, int length, Calendar cal) | ||
throws SQLDataException { | ||
buf.skip(length); | ||
throw new SQLDataException("Data type UUID cannot be decoded as Date"); | ||
} | ||
|
||
@Override | ||
public Date decodeDateBinary(ReadableByteBuf buf, int length, Calendar cal) | ||
throws SQLDataException { | ||
buf.skip(length); | ||
throw new SQLDataException("Data type UUID cannot be decoded as Date"); | ||
} | ||
|
||
@Override | ||
public Time decodeTimeText(ReadableByteBuf buf, int length, Calendar cal) | ||
throws SQLDataException { | ||
buf.skip(length); | ||
throw new SQLDataException("Data type UUID cannot be decoded as Time"); | ||
} | ||
|
||
@Override | ||
public Time decodeTimeBinary(ReadableByteBuf buf, int length, Calendar calParam) | ||
throws SQLDataException { | ||
buf.skip(length); | ||
throw new SQLDataException("Data type UUID cannot be decoded as Time"); | ||
} | ||
|
||
@Override | ||
public Timestamp decodeTimestampText(ReadableByteBuf buf, int length, Calendar calParam) | ||
throws SQLDataException { | ||
buf.skip(length); | ||
throw new SQLDataException("Data type UUID cannot be decoded as Timestamp"); | ||
} | ||
|
||
@Override | ||
public Timestamp decodeTimestampBinary(ReadableByteBuf buf, int length, Calendar calParam) | ||
throws SQLDataException { | ||
buf.skip(length); | ||
throw new SQLDataException("Data type UUID cannot be decoded as Timestamp"); | ||
} | ||
} |
Oops, something went wrong.