-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
1cd9cf4
commit cc48926
Showing
11 changed files
with
873 additions
and
42 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
83 changes: 83 additions & 0 deletions
83
src/main/java/com/firebolt/jdbc/type/lob/FireboltBlob.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,83 @@ | ||
package com.firebolt.jdbc.type.lob; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.lang.reflect.Array; | ||
import java.sql.Blob; | ||
import java.sql.SQLException; | ||
import java.util.Arrays; | ||
import java.util.LinkedList; | ||
|
||
public class FireboltBlob extends FireboltLob<byte[], Byte> implements Blob { | ||
public FireboltBlob() { | ||
this(new byte[0]); | ||
} | ||
|
||
public FireboltBlob(byte[] buf) { | ||
super(buf, (a, i) -> a[i], Integer::byteValue, n -> (byte[])Array.newInstance(byte.class, n)); | ||
} | ||
|
||
@Override | ||
public byte[] getBytes(long pos, int length) throws SQLException { | ||
isValid(buf); | ||
validateGetRange(pos, length, buf.length); | ||
int from = (int)pos - 1; | ||
byte[] bytes = new byte[length]; | ||
System.arraycopy(buf, from, bytes, 0, bytes.length); | ||
return bytes; | ||
} | ||
|
||
@Override | ||
public InputStream getBinaryStream() throws SQLException { | ||
isValid(buf); | ||
return new ByteArrayInputStream(buf); | ||
} | ||
|
||
@Override | ||
public long position(byte[] pattern, long start) throws SQLException { | ||
return super.position(pattern, start); | ||
} | ||
|
||
@Override | ||
public long position(Blob pattern, long start) throws SQLException { | ||
return position(pattern.getBytes(1, (int)(pattern.length())), start); | ||
} | ||
|
||
@Override | ||
public int setBytes(long pos, byte[] bytes) throws SQLException { | ||
return setBytes(pos, bytes, 0, bytes.length); | ||
} | ||
|
||
@Override | ||
public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException { | ||
return setData(pos, bytes, offset, len); | ||
} | ||
|
||
@Override | ||
public OutputStream setBinaryStream(long pos) throws SQLException { | ||
return setStream(pos, new LinkedList<>()); | ||
} | ||
|
||
@Override | ||
public void truncate(long length) throws SQLException { | ||
isValid(buf); | ||
buf = length == 0 ? new byte[0] : getBytes(1, (int)length); | ||
} | ||
|
||
@Override | ||
public InputStream getBinaryStream(long pos, long length) throws SQLException { | ||
return new ByteArrayInputStream(getBytes(pos, (int)length)); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("java:S6201") // Pattern Matching for "instanceof" was introduced in java 16 while we still try to be compliant with java 11 | ||
public boolean equals(Object obj) { | ||
return this == obj || (obj instanceof FireboltBlob && Arrays.equals(buf, ((FireboltBlob)obj).buf)); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return 31 * FireboltBlob.class.hashCode() + Arrays.hashCode(buf); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
src/main/java/com/firebolt/jdbc/type/lob/FireboltClob.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,101 @@ | ||
package com.firebolt.jdbc.type.lob; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.io.OutputStreamWriter; | ||
import java.io.Reader; | ||
import java.io.StringReader; | ||
import java.io.Writer; | ||
import java.lang.reflect.Array; | ||
import java.sql.Clob; | ||
import java.sql.NClob; | ||
import java.sql.SQLException; | ||
import java.util.Arrays; | ||
import java.util.LinkedList; | ||
|
||
public class FireboltClob extends FireboltLob<char[], Character> implements NClob { | ||
public FireboltClob() { | ||
this(new char[0]); | ||
} | ||
|
||
public FireboltClob(char[] buf) { | ||
super(buf, (a, i) -> a[i], i -> (char)i.intValue(), n -> (char[])Array.newInstance(char.class, n)); | ||
} | ||
|
||
@Override | ||
public String getSubString(long pos, int length) throws SQLException { | ||
isValid(buf); | ||
validateGetRange(pos, length, buf.length); | ||
int from = (int)(pos - 1); | ||
return new String(buf, from, Math.min(buf.length - from, length)); | ||
} | ||
|
||
@Override | ||
public Reader getCharacterStream() throws SQLException { | ||
isValid(buf); | ||
return new StringReader(new String(buf)); | ||
} | ||
|
||
@Override | ||
public InputStream getAsciiStream() throws SQLException { | ||
isValid(buf); | ||
return new ByteArrayInputStream(new String(buf).getBytes()); | ||
} | ||
|
||
@Override | ||
public long position(String searchStr, long start) throws SQLException { | ||
return position(searchStr.toCharArray(), start); | ||
} | ||
|
||
@Override | ||
public long position(Clob searchStr, long start) throws SQLException { | ||
return position(searchStr.getSubString(1, (int)searchStr.length()), start); | ||
} | ||
|
||
@Override | ||
public int setString(long pos, String str) throws SQLException { | ||
return setString(pos, str, 0, str.length()); | ||
} | ||
|
||
@Override | ||
public int setString(long pos, String str, int offset, int len) throws SQLException { | ||
return setChars(pos, str.toCharArray(), offset, len); | ||
} | ||
|
||
private int setChars(long pos, char[] chars, int offset, int len) throws SQLException { | ||
return setData(pos, chars, offset, len); | ||
} | ||
|
||
@Override | ||
public OutputStream setAsciiStream(long pos) throws SQLException { | ||
return setStream(pos, new LinkedList<>()); | ||
} | ||
|
||
@Override | ||
public Writer setCharacterStream(long pos) throws SQLException { | ||
return new OutputStreamWriter(setAsciiStream(pos)); | ||
} | ||
|
||
@Override | ||
public void truncate(long length) throws SQLException { | ||
isValid(buf); | ||
buf = length == 0 ? new char[0] : getSubString(1, (int)length).toCharArray(); | ||
} | ||
|
||
@Override | ||
public Reader getCharacterStream(long pos, long length) throws SQLException { | ||
return new StringReader(getSubString(pos, (int)length)); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("java:S6201") // Pattern Matching for "instanceof" was introduced in java 16 while we still try to be compliant with java 11 | ||
public boolean equals(Object obj) { | ||
return this == obj || (obj instanceof FireboltClob && Arrays.equals(buf, ((FireboltClob)obj).buf)); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return 31 * FireboltClob.class.hashCode() + Arrays.hashCode(buf); | ||
} | ||
} |
Oops, something went wrong.