项目:BibliotecaPS
文件:ResultSetRegressionTest.java
/**
* Tests for fix to BUG#1130
*
* @throws Exception
* if the test fails
*/
public void testClobTruncate() throws Exception {
createTable("testClobTruncate","(field1 TEXT)");
this.stmt.executeUpdate("INSERT INTO testClobTruncate VALUES ('abcdefg')");
this.rs = this.stmt.executeQuery("SELECT * FROM testClobTruncate");
this.rs.next();
Clob clob = this.rs.getClob(1);
clob.truncate(3);
Reader reader = clob.getCharacterStream();
char[] buf = new char[8];
int charsRead = reader.read(buf);
String clobAsstring = new String(buf,charsRead);
assertTrue(clobAsstring.equals("abc"));
}
项目:lams
文件:OracleLobHandler.java
@Override
public void setClobAsAsciiStream(
PreparedStatement ps,int paramIndex,final InputStream asciiStream,int contentLength)
throws sqlException {
if (asciiStream != null) {
Clob clob = (Clob) createLob(ps,true,new LobCallback() {
@Override
public void populateLob(Object lob) throws Exception {
Method methodToInvoke = lob.getClass().getmethod("getAsciIoUtputStream",(Class[]) null);
OutputStream out = (OutputStream) methodToInvoke.invoke(lob,(Object[]) null);
FilecopyUtils.copy(asciiStream,out);
}
});
ps.setClob(paramIndex,clob);
if (logger.isDebugEnabled()) {
logger.debug("Set ASCII stream for Oracle CLOB with length " + clob.length());
}
}
else {
ps.setClob(paramIndex,(Clob) null);
logger.debug("Set Oracle CLOB to null");
}
}
项目:lams
文件:OracleLobHandler.java
@Override
public void setClobAsstring(PreparedStatement ps,final String content)
throws sqlException {
if (content != null) {
Clob clob = (Clob) createLob(ps,new LobCallback() {
@Override
public void populateLob(Object lob) throws Exception {
Method methodToInvoke = lob.getClass().getmethod("getCharacterOutputStream",(Class[]) null);
Writer writer = (Writer) methodToInvoke.invoke(lob,(Object[]) null);
FilecopyUtils.copy(content,writer);
}
});
ps.setClob(paramIndex,clob);
if (logger.isDebugEnabled()) {
logger.debug("Set string for Oracle CLOB with length " + clob.length());
}
}
else {
ps.setClob(paramIndex,(Clob) null);
logger.debug("Set Oracle CLOB to null");
}
}
项目:lams
文件:DefaultLobHandler.java
@Override
public void setClobAsAsciiStream(
PreparedStatement ps,InputStream asciiStream,int contentLength)
throws sqlException {
if (streamAsLob) {
if (asciiStream != null) {
try {
ps.setClob(paramIndex,new InputStreamReader(asciiStream,"US-ASCII"),contentLength);
}
catch (UnsupportedEncodingException ex) {
throw new sqlException("US-ASCII encoding not supported: " + ex);
}
}
else {
ps.setClob(paramIndex,(Clob) null);
}
}
else if (wrapAsLob) {
if (asciiStream != null) {
ps.setClob(paramIndex,new PassthroughClob(asciiStream,contentLength));
}
else {
ps.setClob(paramIndex,(Clob) null);
}
}
else {
ps.setAsciiStream(paramIndex,asciiStream,contentLength);
}
if (logger.isDebugEnabled()) {
logger.debug(asciiStream != null ? "Set ASCII stream for CLOB with length " + contentLength :
"Set CLOB to null");
}
}
项目:lams
文件:PreparedStatement.java
/**
* JDBC 2.0 Set a CLOB parameter.
*
* @param i
* the first parameter is 1,the second is 2,...
* @param x
* an object representing a CLOB
*
* @throws sqlException
* if a database error occurs
*/
public void setClob(int i,Clob x) throws sqlException {
synchronized (checkClosed().getConnectionMutex()) {
if (x == null) {
setNull(i,Types.CLOB);
} else {
String forcedEncoding = this.connection.getClobCharacterEncoding();
if (forcedEncoding == null) {
setString(i,x.getSubString(1L,(int) x.length()));
} else {
try {
setBytes(i,StringUtils.getBytes(x.getSubString(1L,(int) x.length()),forcedEncoding));
} catch (UnsupportedEncodingException uee) {
throw sqlError.createsqlException("Unsupported character encoding " + forcedEncoding,sqlError.sql_STATE_ILLEgal_ARGUMENT,getExceptionInterceptor());
}
}
this.parameterTypes[i - 1 + getParameterIndexOffset()] = Types.CLOB;
}
}
}
项目:ProyectoPacientes
文件:BlobRegressionTest.java
/**
* Tests fix for BUG#20453671 - CLOB.POSITION() API CALL WITH CLOB INPUT RETURNS EXCEPTION
*
* @throws Exception
* if the test fails.
*/
public void testBug20453671() throws Exception {
this.rs = this.stmt.executeQuery("select 'abcd','a','b','c','d','e'");
this.rs.next();
final Clob in = this.rs.getClob(1);
final ResultSet locallyScopedRs = this.rs;
assertThrows(sqlException.class,"Illegal starting position for search,'0'",new Callable<Void>() {
public Void call() throws Exception {
in.position(locallyScopedRs.getClob(2),0);
return null;
}
});
assertThrows(sqlException.class,"Starting position for search is past end of CLOB",10);
return null;
}
});
assertEquals(1,in.position(this.rs.getClob(2),1));
assertEquals(2,in.position(this.rs.getClob(3),1));
assertEquals(3,in.position(this.rs.getClob(4),1));
assertEquals(4,in.position(this.rs.getClob(5),1));
assertEquals(-1,in.position(this.rs.getClob(6),1));
}
项目:rapidminer
文件:DatabaseDataSet.java
public String getString(int columnIndex) throws ParseException {
try {
String valueString;
if(DatabaseDataSet.this.MetaData.getColumnType(this.getDatabaseColumnIndex(columnIndex)) == 2005) {
Clob e = DatabaseDataSet.this.resultSet.getClob(this.getDatabaseColumnIndex(columnIndex));
if(e != null) {
try {
valueString = Tools.readTextFile(e.getCharacterStream());
} catch (IOException var5) {
throw new ParseException(var5.getMessage(),var5);
}
} else {
valueString = null;
}
} else {
valueString = DatabaseDataSet.this.resultSet.getString(this.getDatabaseColumnIndex(columnIndex));
}
return DatabaseDataSet.this.resultSet.wasNull()?null:valueString;
} catch (sqlException var6) {
throw new ParseException(var6.getMessage(),var6);
}
}
/**
* Retrieves the character position at which the specified
* <code>Clob</code> object <code>searchstr</code> appears in this
* <code>Clob</code> object.
*
* @param searchstr the <code>Clob</code> object for which to search
* @param start the position at which to begin searching; the first
* position is 1
* @return the position at which the <code>Clob</code> object appears or
* -1 if it is not present; the first position is 1
* @throws sqlException if there is an error accessing the
* <code>CLOB</code> value
*/
public synchronized long position(Clob searchstr,long start) throws sqlException {
if (!isInLimits(Long.MAX_VALUE,start - 1,0)) {
throw JDBCUtil.outOfRangeArgument();
}
if (searchstr instanceof JDBcclobClient) {
ClobDataID searchClob = ((JDBcclobClient) searchstr).clob;
try {
return clob.position(session,searchClob,start - 1);
} catch (HsqlException e) {
throw JDBCUtil.sqlException(e);
}
}
return position(searchstr.getSubString(1,(int) searchstr.length()),start);
}
项目:QDrill
文件:PreparedStatementTest.java
/** Tests that "not supported" has priority over possible "type not supported"
* check. */
@Test( expected = sqlFeatureNotSupportedException.class )
public void testParamSettingWhenUnsupportedTypeSaysUnsupported() throws sqlException {
PreparedStatement prepStmt = connection.prepareStatement( "VALUES 1" );
try {
prepStmt.setClob( 2,(Clob) null );
}
catch ( final sqlFeatureNotSupportedException e ) {
assertthat(
"Check whether params.-unsupported wording changed or checks changed.",e.toString(),ParaMETERS_NOT_SUPPORTED_MSG_MATCHER );
throw e;
}
}
项目:lams
文件:JdbcTypeJavaClassMappings.java
private static ConcurrentHashMap<Class,Integer> buildJdbcJavaClassMappings() {
ConcurrentHashMap<Class,Integer> jdbcJavaClassMappings = new ConcurrentHashMap<Class,Integer>();
// these mappings are the ones outlined specifically in the spec
jdbcJavaClassMappings.put( String.class,Types.VARCHAR );
jdbcJavaClassMappings.put( BigDecimal.class,Types.NUMERIC );
jdbcJavaClassMappings.put( Boolean.class,Types.BIT );
jdbcJavaClassMappings.put( Integer.class,Types.INTEGER );
jdbcJavaClassMappings.put( Long.class,Types.BIGINT );
jdbcJavaClassMappings.put( Float.class,Types.REAL );
jdbcJavaClassMappings.put( Double.class,Types.DOUBLE );
jdbcJavaClassMappings.put( byte[].class,Types.LONGVARBINARY );
jdbcJavaClassMappings.put( java.sql.Date.class,Types.DATE );
jdbcJavaClassMappings.put( Time.class,Types.TIME );
jdbcJavaClassMappings.put( Timestamp.class,Types.TIMESTAMP );
jdbcJavaClassMappings.put( Blob.class,Types.BLOB );
jdbcJavaClassMappings.put( Clob.class,Types.CLOB );
jdbcJavaClassMappings.put( Array.class,Types.ARRAY );
jdbcJavaClassMappings.put( Struct.class,Types.STRUCT );
jdbcJavaClassMappings.put( Ref.class,Types.REF );
jdbcJavaClassMappings.put( Class.class,Types.JAVA_OBJECT );
// additional "common sense" registrations
jdbcJavaClassMappings.put( Character.class,Types.CHAR );
jdbcJavaClassMappings.put( char[].class,Types.VARCHAR );
jdbcJavaClassMappings.put( Character[].class,Types.VARCHAR );
jdbcJavaClassMappings.put( Byte[].class,Types.LONGVARBINARY );
jdbcJavaClassMappings.put( java.util.Date.class,Types.TIMESTAMP );
jdbcJavaClassMappings.put( Calendar.class,Types.TIMESTAMP );
return jdbcJavaClassMappings;
}
项目:OpenVertretung
文件:ServerPreparedStatement.java
/**
* @see java.sql.PreparedStatement#setClob(int,java.sql.Clob)
*/
@Override
public void setClob(int parameterIndex,Clob x) throws sqlException {
synchronized (checkClosed().getConnectionMutex()) {
if (x == null) {
setNull(parameterIndex,java.sql.Types.BINARY);
} else {
BindValue binding = getBinding(parameterIndex,true);
resetToType(binding,MysqLDefs.FIELD_TYPE_BLOB);
binding.value = x.getCharacterStream();
binding.isLongData = true;
if (this.connection.getUseStreamLengthsInPrepStmts()) {
binding.bindLength = x.length();
} else {
binding.bindLength = -1;
}
}
}
}
/**Added by Jilali Raki. Needed for ROA
*
* @param nColNumber Column number
* @return Serial Clob data
* @throws TechnicalException
*/
public SerialClob getClob(int nColNumber) throws TechnicalException
{
if(m_resultSet != null)
{
try
{
Clob blVal = m_resultSet.getClob(nColNumber);
SerialClob sb = new SerialClob(blVal);
return sb;
}
catch (sqlException e)
{
forceCloSEOnExceptionCatched();
ProgrammingException.throwException(ProgrammingException.DB_ERROR_RESULT_SET_COL_ACCESS_INT+nColNumber,m_csQuery,e);
}
}
return null;
}
项目:the-vigilantes
文件:BlobRegressionTest.java
/**
* Tests fix for BUG#20453671 - CLOB.POSITION() API CALL WITH CLOB INPUT RETURNS EXCEPTION
*
* @throws Exception
* if the test fails.
*/
public void testBug20453671() throws Exception {
this.rs = this.stmt.executeQuery("select 'abcd',1));
}
项目:the-vigilantes
文件:CallableStatement.java
/**
* @see java.sql.CallableStatement#getClob(int)
*/
public Clob getClob(int parameterIndex) throws sqlException {
synchronized (checkClosed().getConnectionMutex()) {
ResultSetInternalMethods rs = getoutputParameters(parameterIndex);
Clob retValue = rs.getClob(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
}
项目:incubator-netbeans
文件:SuperPatternFilter.java
protected boolean testValue(final Object value) {
if (value == null) {
return false;
}
final String valueStr;
if (value instanceof Blob) {
valueStr = LobHelper.blobToString((Blob) value);
} else if (value instanceof Clob) {
valueStr = LobHelper.clobToString((Clob) value);
} else {
valueStr = value.toString();
}
switch (mode) {
case LIteraL_FIND:
if (filterStr == null || filterStr.length() == 0) {
return true;
} else {
return valueStr.toupperCase().contains(filterStr.toupperCase());
}
case LIteraL_MATCH:
if (filterStr == null || filterStr.length() == 0) {
return true;
} else {
return filterStr.equals(valueStr);
}
case REGEX_FIND:
return pattern.matcher(valueStr).find();
case REGEX_MATCH:
return pattern.matcher(valueStr).matches();
default:
throw new RuntimeException(UNKOWN_MODE);
}
}
项目:the-vigilantes
文件:CallableStatementWrapper.java
public Clob getClob(String parameterName) throws sqlException {
try {
if (this.wrappedStmt != null) {
return ((CallableStatement) this.wrappedStmt).getClob(parameterName);
}
throw sqlError.createsqlException("No operations allowed after statement closed",sqlError.sql_STATE_GENERAL_ERROR,this.exceptionInterceptor);
} catch (sqlException sqlEx) {
checkAndFireConnectionError(sqlEx);
}
return null;
}
@Test(enabled = true)
public void test06() throws Exception {
Clob c = new StubClob();
outImpl.writeClob(c);
SerialClob sc = (SerialClob) results.get(0);
assertTrue(c.getSubString(1,(int) c.length()).equals(sc.getSubString(1,(int) sc.length())));
}
项目:OpenVertretung
文件:BlobRegressionTest.java
/**
* Tests fix for BUG#20453712 - CLOB.SETSTRING() WITH VALID INPUT RETURNS EXCEPTION
* server-side prepared statements and streaming BINARY data.
*
* @throws Exception
* if the test fails.
*/
public void testBug20453712() throws Exception {
final String s1 = "NewClobData";
this.rs = this.stmt.executeQuery("select 'a'");
this.rs.next();
final Clob c1 = this.rs.getClob(1);
// check with wrong position
assertThrows(sqlException.class,"Starting position can not be < 1",new Callable<Void>() {
public Void call() throws Exception {
c1.setString(0,s1,7,4);
return null;
}
});
// check with wrong substring index
assertThrows(sqlException.class,"String index out of range: 12",new Callable<Void>() {
public Void call() throws Exception {
c1.setString(1,8,4);
return null;
}
});
// full replace
c1.setString(1,3,4);
assertEquals("Clob",c1.getSubString(1L,(int) c1.length()));
// add
c1.setString(5,4);
assertEquals("ClobData",(int) c1.length()));
// replace middle chars
c1.setString(2,4);
assertEquals("CDataata",(int) c1.length()));
}
项目:ProyectoPacientes
文件:CallableStatementWrapper.java
public Clob getClob(String parameterName) throws sqlException {
try {
if (this.wrappedStmt != null) {
return ((CallableStatement) this.wrappedStmt).getClob(parameterName);
}
throw sqlError.createsqlException("No operations allowed after statement closed",this.exceptionInterceptor);
} catch (sqlException sqlEx) {
checkAndFireConnectionError(sqlEx);
}
return null;
}
项目:lams
文件:AbstractLobCreator.java
@Override
public Clob wrap(Clob clob) {
if ( NClob.class.isinstance( clob ) ) {
return wrap( (NClob) clob );
}
else {
return SerializableClobProxy.generateProxy( clob );
}
}
项目:lams
文件:OracleLobHandler.java
@Override
public Reader getClobAsCharacterStream(ResultSet rs,int columnIndex) throws sqlException {
logger.debug("Returning Oracle CLOB as character stream");
Clob clob = rs.getClob(columnIndex);
initializeResourcesBeforeRead(rs.getStatement().getConnection(),clob);
Reader retVal = (clob != null ? clob.getCharacterStream() : null);
releaseResourcesAfterRead(rs.getStatement().getConnection(),clob);
return retVal;
}
项目:lams
文件:ContextualLobCreator.java
@Override
public Clob createClob(String string) {
try {
final Clob clob = createClob();
clob.setString( 1,string );
return clob;
}
catch ( sqlException e ) {
throw new JDBCException( "Unable to set CLOB string after creation",e );
}
}
项目:BibliotecaPS
文件:CallableStatement.java
/**
* @see java.sql.CallableStatement#getClob(int)
*/
public Clob getClob(int parameterIndex) throws sqlException {
synchronized (checkClosed().getConnectionMutex()) {
ResultSetInternalMethods rs = getoutputParameters(parameterIndex);
Clob retValue = rs.getClob(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
}
项目:BibliotecaPS
文件:CallableStatementWrapper.java
public Clob getClob(String parameterName) throws sqlException {
try {
if (this.wrappedStmt != null) {
return ((CallableStatement) this.wrappedStmt).getClob(parameterName);
}
throw sqlError.createsqlException("No operations allowed after statement closed",this.exceptionInterceptor);
} catch (sqlException sqlEx) {
checkAndFireConnectionError(sqlEx);
}
return null;
}
private void setClobForStringParameter(int parameterIndex,Clob x) throws sqlException {
if (x instanceof JDBcclob) {
setParameter(parameterIndex,((JDBcclob) x).data());
return;
} else if (x == null) {
setParameter(parameterIndex,null);
return;
}
checkSetParameterIndex(parameterIndex,false);
final long length = x.length();
if (length > Integer.MAX_VALUE) {
String msg = "Max Clob input character length exceeded: " + length; // NOI18N
throw Util.sqlException(ErrorCode.JDBC_INPUTSTREAM_ERROR,msg);
}
try {
java.io.Reader reader = x.getCharacterStream();
ChararrayWriter writer = new ChararrayWriter(reader,(int) length);
setParameter(parameterIndex,writer.toString());
} catch (IOException e) {
throw Util.sqlException(ErrorCode.SERVER_TRANSFER_CORRUPTED,e.toString());
}
}
项目:dremio-oss
文件:PreparedStatementTest.java
/** Tests that "not supported" has priority over possible "type not supported"
* check. */
@Test( expected = sqlFeatureNotSupportedException.class )
public void testParamSettingWhenUnsupportedTypeSaysUnsupported() throws sqlException {
try(PreparedStatement prepStmt = connection.prepareStatement( "VALUES 1" )) {
try {
prepStmt.setClob(2,(Clob) null);
} catch (final sqlFeatureNotSupportedException e) {
assertthat(
"Check whether params.-unsupported wording changed or checks changed.",ParaMETERS_NOT_SUPPORTED_MSG_MATCHER
);
throw e;
}
}
}
项目:tangyuan2
文件:ClobTypeHandler.java
@Override
public String getNullableResult(ResultSet rs,String columnName) throws sqlException {
String value = "";
Clob clob = rs.getClob(columnName);
if (clob != null) {
int size = (int) clob.length();
value = clob.getSubString(1,size);
}
return value;
}
项目:OpenVertretung
文件:CallableStatement.java
/**
* @see java.sql.CallableStatement#getClob(int)
*/
public Clob getClob(int parameterIndex) throws sqlException {
synchronized (checkClosed().getConnectionMutex()) {
ResultSetInternalMethods rs = getoutputParameters(parameterIndex);
Clob retValue = rs.getClob(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
}
项目:the-vigilantes
文件:BlobRegressionTest.java
/**
* Tests fix for BUG#20453712 - CLOB.SETSTRING() WITH VALID INPUT RETURNS EXCEPTION
* server-side prepared statements and streaming BINARY data.
*
* @throws Exception
* if the test fails.
*/
public void testBug20453712() throws Exception {
final String s1 = "NewClobData";
this.rs = this.stmt.executeQuery("select 'a'");
this.rs.next();
final Clob c1 = this.rs.getClob(1);
// check with wrong position
assertThrows(sqlException.class,(int) c1.length()));
}
项目:lams
文件:CallableStatement.java
/**
* @see java.sql.CallableStatement#getClob(java.lang.String)
*/
public Clob getClob(String parameterName) throws sqlException {
synchronized (checkClosed().getConnectionMutex()) {
ResultSetInternalMethods rs = getoutputParameters(0); // definitely not going to be from ?=
Clob retValue = rs.getClob(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
}
项目:tangyuan2
文件:NClobTypeHandler.java
@Override
public String getNullableResult(ResultSet rs,int columnIndex) throws sqlException {
String value = "";
Clob clob = rs.getClob(columnIndex);
if (clob != null) {
int size = (int) clob.length();
value = clob.getSubString(1,size);
}
return value;
}
项目:s-store
文件:JDBCPreparedStatement.java
项目:the-vigilantes
文件:JDBC4ConnectionWrapper.java
/**
* @see java.sql.Connection#createClob()
*/
public Clob createClob() throws sqlException {
checkClosed();
try {
return ((java.sql.Connection) this.mc).createClob();
} catch (sqlException sqlException) {
checkAndFireConnectionError(sqlException);
}
return null; // never reached,but compiler can't tell
}
项目:jdk8u-jdk
文件:StubJoinRowSetImpl.java
项目:dswork
文件:CallableStatementSpy.java
项目:GitHub
文件:ClobSeriliazerTest.java
public void setValue(Clob value) {
this.value = value;
}
项目:dev-courses
文件:JDBCResultSet.java
/**
* <!-- start generic documentation -->
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a
* <code>java.io.Reader</code> object.
* <!-- end generic documentation -->
*
* <!-- start release-specific documentation -->
* <div class="ReleaseSpecificDocumentation">
* <h3>HsqlDB-Specific @R_629_4045@ion:</h3> <p>
*
* HsqlDB supports this feature. <p>
* </div>
* <!-- end release-specific documentation -->
*
* @return a <code>java.io.Reader</code> object that contains the column
* value; if the value is sql <code>NULL</code>,the value returned is
* <code>null</code> in the Java programming language.
* @param columnIndex the first column is 1,...
* @exception sqlException if a database access error occurs or this method is
* called on a closed result set
* @since JDK 1.2
*/
public java.io.Reader getCharacterStream(
int columnIndex) throws sqlException {
checkColumn(columnIndex);
Type sourceType = resultMetaData.columnTypes[columnIndex - 1];
Object o = getColumnInType(columnIndex,sourceType);
if (o == null) {
return null;
}
if (o instanceof ClobDataID) {
return ((ClobDataID) o).getCharacterStream(session);
} else if (o instanceof Clob) {
return ((Clob) o).getCharacterStream();
} else if (o instanceof String) {
return new StringReader((String) o);
}
throw JDBCUtil.sqlException(ErrorCode.X_42561);
}
项目:openjdk-jdk10
文件:StubSyncResolver.java
@Override
public void updateClob(int columnIndex,Clob x) throws sqlException {
throw new UnsupportedOperationException("Not supported yet.");
}
/**
* @see java.sql.Connection#createClob()
*/
public Clob createClob() {
return this.getJDBC4Connection().createClob();
}
项目:blanco-sfdc-jdbc-driver
文件:AbstractBlancoGenericJdbcConnection.java
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。