-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CONJ-1205] permit use of Array parameter
- Loading branch information
Showing
17 changed files
with
430 additions
and
31 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
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
119 changes: 119 additions & 0 deletions
119
src/main/java/org/mariadb/jdbc/plugin/array/FloatArray.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,119 @@ | ||
// SPDX-License-Identifier: LGPL-2.1-or-later | ||
// Copyright (c) 2012-2014 Monty Program Ab | ||
// Copyright (c) 2015-2024 MariaDB Corporation Ab | ||
package org.mariadb.jdbc.plugin.array; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.sql.*; | ||
import java.util.Arrays; | ||
import java.util.Map; | ||
import org.mariadb.jdbc.client.ColumnDecoder; | ||
import org.mariadb.jdbc.client.Context; | ||
import org.mariadb.jdbc.client.DataType; | ||
import org.mariadb.jdbc.client.result.CompleteResult; | ||
import org.mariadb.jdbc.util.constants.ColumnFlags; | ||
|
||
public class FloatArray implements Array { | ||
|
||
private final float[] val; | ||
private Context context; | ||
|
||
public FloatArray(float[] val, Context context) { | ||
this.val = val; | ||
this.context = context; | ||
} | ||
|
||
@Override | ||
public String getBaseTypeName() throws SQLException { | ||
return "float[]"; | ||
} | ||
|
||
@Override | ||
public int getBaseType() throws SQLException { | ||
return Types.FLOAT; | ||
} | ||
|
||
@Override | ||
public Object getArray() throws SQLException { | ||
return this.val; | ||
} | ||
|
||
@Override | ||
public Object getArray(Map<String, Class<?>> map) throws SQLException { | ||
throw new SQLFeatureNotSupportedException( | ||
"getArray(Map<String, Class<?>> map) is not supported"); | ||
} | ||
|
||
@Override | ||
public Object getArray(long index, int count) throws SQLException { | ||
if (index < 1 || index > val.length) { | ||
throw new SQLException( | ||
String.format( | ||
"Wrong index position. Is %s but must be in 1-%s range", index, val.length)); | ||
} | ||
if (count < 0 || (index - 1 + count) > val.length) { | ||
throw new SQLException( | ||
String.format( | ||
"Count value is too big. Count is %s but cannot be > to %s", | ||
count, val.length - (index - 1))); | ||
} | ||
|
||
return Arrays.copyOfRange(val, (int) index - 1, (int) (index - 1) + count); | ||
} | ||
|
||
@Override | ||
public Object getArray(long index, int count, Map<String, Class<?>> map) throws SQLException { | ||
throw new SQLFeatureNotSupportedException( | ||
"getArray(long index, int count, Map<String, Class<?>> map) is not supported"); | ||
} | ||
|
||
@Override | ||
public ResultSet getResultSet() throws SQLException { | ||
return getResultSet(1, this.val.length); | ||
} | ||
|
||
@Override | ||
public ResultSet getResultSet(Map<String, Class<?>> map) throws SQLException { | ||
throw new SQLFeatureNotSupportedException( | ||
"getResultSet(Map<String, Class<?>> map) is not supported"); | ||
} | ||
|
||
@Override | ||
public ResultSet getResultSet(long index, int count) throws SQLException { | ||
byte[][] rows = new byte[count][]; | ||
for (int i = 0; i < count; i++) { | ||
rows[i] = Float.toString(this.val[(int) index - 1 + i]).getBytes(StandardCharsets.US_ASCII); | ||
} | ||
|
||
return new CompleteResult( | ||
new ColumnDecoder[] {ColumnDecoder.create("Array", DataType.FLOAT, ColumnFlags.NOT_NULL)}, | ||
rows, | ||
context, | ||
ResultSet.TYPE_SCROLL_INSENSITIVE); | ||
} | ||
|
||
@Override | ||
public ResultSet getResultSet(long index, int count, Map<String, Class<?>> map) | ||
throws SQLException { | ||
throw new SQLFeatureNotSupportedException( | ||
"getResultSet(long index, int count, Map<String, Class<?>> map) is not supported"); | ||
} | ||
|
||
@Override | ||
public void free() {} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
FloatArray that = (FloatArray) o; | ||
|
||
return Arrays.equals(val, that.val); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Arrays.hashCode(val); | ||
} | ||
} |
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
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
Oops, something went wrong.