Skip to content
This repository was archived by the owner on Dec 30, 2020. It is now read-only.

Commit bc9c178

Browse files
committed
Merge branch 'release/3.0.3'
2 parents 89655cf + 96c0251 commit bc9c178

File tree

5 files changed

+67
-53
lines changed

5 files changed

+67
-53
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ it in your application using the following Maven dependency::
5252
<dependency>
5353
<groupId>com.github.adejanovski</groupId>
5454
<artifactId>cassandra-jdbc-wrapper</artifactId>
55-
<version>3.0.0</version>
55+
<version>3.0.3</version>
5656
</dependency>
5757

5858
Or get the `fat jar with all dependencies included <https://drive.google.com/folderview?id=0B7fwX0DqcWSTNzZianJrWDI2bHc&usp=sharing#list>`_.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.github.adejanovski</groupId>
77
<artifactId>cassandra-jdbc-wrapper</artifactId>
8-
<version>3.0.2</version>
8+
<version>3.0.3</version>
99

1010
<packaging>jar</packaging>
1111
<name>Cassandra JDBC Wrapper</name>

src/main/java/com/github/adejanovski/cassandra/jdbc/CassandraDatabaseMetaData.java

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,13 @@
1414
*/
1515
package com.github.adejanovski.cassandra.jdbc;
1616

17+
import com.datastax.driver.core.Metadata;
18+
19+
import java.sql.*;
20+
1721
import static com.github.adejanovski.cassandra.jdbc.Utils.NOT_SUPPORTED;
1822
import static com.github.adejanovski.cassandra.jdbc.Utils.NO_INTERFACE;
1923

20-
import java.sql.Connection;
21-
import java.sql.DatabaseMetaData;
22-
import java.sql.ResultSet;
23-
import java.sql.RowIdLifetime;
24-
import java.sql.SQLException;
25-
import java.sql.SQLFeatureNotSupportedException;
26-
import java.sql.SQLSyntaxErrorException;
27-
import java.util.List;
28-
29-
import com.datastax.driver.core.ColumnMetadata;
30-
import com.datastax.driver.core.KeyspaceMetadata;
31-
import com.datastax.driver.core.Metadata;
32-
import com.datastax.driver.core.TableMetadata;
33-
3424
class CassandraDatabaseMetaData implements DatabaseMetaData
3525
{
3626
private CassandraConnection connection;
@@ -40,7 +30,7 @@ class CassandraDatabaseMetaData implements DatabaseMetaData
4030
public CassandraDatabaseMetaData(CassandraConnection connection) throws SQLException
4131
{
4232
this.connection = connection;
43-
this.statement = new CassandraStatement(connection);
33+
this.statement = new CassandraStatement(this.connection);
4434
this.metadata = this.connection.getClusterMetadata();
4535
}
4636

@@ -112,7 +102,10 @@ public String getCatalogTerm() throws SQLException
112102

113103
public ResultSet getCatalogs() throws SQLException
114104
{
115-
ResultSet rs = MetadataResultSets.instance.makeCatalogs(statement);
105+
if(statement.isClosed()){
106+
statement = new CassandraStatement(this.connection);
107+
}
108+
ResultSet rs = MetadataResultSets.instance.makeCatalogs(statement);
116109
return rs;
117110

118111
}
@@ -129,13 +122,17 @@ public ResultSet getColumnPrivileges(String arg0, String arg1, String arg2, Stri
129122

130123
public ResultSet getColumns(String catalog,String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException
131124
{
125+
if(statement.isClosed()){
126+
statement = new CassandraStatement(this.connection);
127+
}
132128
if (catalog == null || connection.getCatalog().equals(catalog))
133129
{
130+
statement.connection = connection;
134131
if (schemaPattern == null) schemaPattern = connection.getSchema(); //limit to current schema if set
135132
ResultSet rs = MetadataResultSets.instance.makeColumns(statement, schemaPattern, tableNamePattern,columnNamePattern);
136133
return rs;
137134
}
138-
return new CassandraResultSet();
135+
return new CassandraResultSet();
139136
}
140137

141138
public Connection getConnection() throws SQLException
@@ -225,13 +222,16 @@ public ResultSet getImportedKeys(String arg0, String arg1, String arg2) throws S
225222

226223
public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException
227224
{
225+
if(statement.isClosed()){
226+
statement = new CassandraStatement(this.connection);
227+
}
228228
if (catalog == null || connection.getCatalog().equals(catalog))
229229
{
230230
if (schema == null) schema = connection.getSchema(); //limit to current schema if set
231231
ResultSet rs = MetadataResultSets.instance.makeIndexes(statement, schema, table,unique,approximate);
232232
return rs;
233233
}
234-
return new CassandraResultSet();
234+
return new CassandraResultSet();
235235
}
236236

237237
public int getJDBCMajorVersion() throws SQLException
@@ -352,13 +352,16 @@ public String getNumericFunctions() throws SQLException
352352

353353
public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException
354354
{
355+
if(statement.isClosed()){
356+
statement = new CassandraStatement(this.connection);
357+
}
355358
if (catalog == null || connection.getCatalog().equals(catalog))
356359
{
357360
if (schema == null) schema = connection.getSchema(); //limit to current schema if set
358361
ResultSet rs = MetadataResultSets.instance.makePrimaryKeys(statement, schema, table);
359362
return rs;
360363
}
361-
return new CassandraResultSet();
364+
return new CassandraResultSet();
362365
}
363366

364367
public ResultSet getProcedureColumns(String arg0, String arg1, String arg2, String arg3) throws SQLException
@@ -403,18 +406,26 @@ public String getSchemaTerm() throws SQLException
403406

404407
public ResultSet getSchemas() throws SQLException
405408
{
406-
ResultSet rs = MetadataResultSets.instance.makeSchemas(statement, null);
407-
return rs;
409+
if(statement.isClosed()){
410+
statement = new CassandraStatement(this.connection);
411+
}
412+
ResultSet rs = MetadataResultSets.instance.makeSchemas(statement, null);
413+
return rs;
408414

409415

410416
}
411417

412418
public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException
413419
{
414-
if (!(catalog == null || catalog.equals(statement.connection.getCatalog()) ))
415-
throw new SQLSyntaxErrorException("catalog name must exactly match or be null");
420+
if(statement.isClosed()){
421+
statement = new CassandraStatement(this.connection);
422+
}
423+
if (!(catalog == null || catalog.equals(statement.connection.getCatalog()) )){
424+
throw new SQLSyntaxErrorException("catalog name must exactly match or be null");
425+
}
416426

417427
ResultSet rs = MetadataResultSets.instance.makeSchemas(statement, schemaPattern);
428+
418429
return rs;
419430

420431
//return new CassandraResultSet();
@@ -452,7 +463,10 @@ public ResultSet getTablePrivileges(String arg0, String arg1, String arg2) throw
452463

453464
public ResultSet getTableTypes() throws SQLException
454465
{
455-
ResultSet result = MetadataResultSets.instance.makeTableTypes(statement);
466+
if(statement.isClosed()){
467+
statement = new CassandraStatement(this.connection);
468+
}
469+
ResultSet result = MetadataResultSets.instance.makeTableTypes(statement);
456470
return result;
457471
}
458472

@@ -473,6 +487,9 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam
473487
}
474488
if ((catalog == null || connection.getCatalog().equals(catalog)) && askingForTable)
475489
{
490+
if(statement.isClosed()){
491+
statement = new CassandraStatement(this.connection);
492+
}
476493
//if (schemaPattern == null) schemaPattern = connection.getSchema(); //limit to current schema if set
477494
ResultSet rs = MetadataResultSets.instance.makeTables(statement, schemaPattern, tableNamePattern);
478495
return rs;

src/main/java/com/github/adejanovski/cassandra/jdbc/CassandraMetadataResultSet.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ public int getColumnCount() throws SQLException
10161016
if(currentRow!=null){
10171017
return currentRow.getColumnDefinitions().size();
10181018
}
1019-
return driverResultSet.getColumnDefinitions().size();
1019+
return driverResultSet!=null && driverResultSet.getColumnDefinitions()!=null?driverResultSet.getColumnDefinitions().size():0;
10201020
}
10211021

10221022
@SuppressWarnings("rawtypes")
@@ -1093,13 +1093,17 @@ public String getColumnTypeName(int column) throws SQLException
10931093

10941094
//checkIndex(column);
10951095
DataType type = null;
1096-
if(currentRow!=null){
1097-
type = currentRow.getColumnDefinitions().getType(column-1);
1098-
}else{
1099-
type = driverResultSet.getColumnDefinitions().getType(column-1);
1100-
}
1101-
1102-
return type.toString();
1096+
try {
1097+
if(currentRow!=null){
1098+
type = currentRow.getColumnDefinitions().getType(column-1);
1099+
}else{
1100+
type = driverResultSet.getColumnDefinitions().getType(column-1);
1101+
}
1102+
1103+
return type.toString();
1104+
} catch (Exception e) {
1105+
return DataType.varchar().toString();
1106+
}
11031107
}
11041108

11051109
public int getPrecision(int column) throws SQLException

src/main/java/com/github/adejanovski/cassandra/jdbc/MetadataResultSets.java

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,18 @@
1414
*/
1515
package com.github.adejanovski.cassandra.jdbc;
1616

17-
import java.nio.ByteBuffer;
18-
import java.nio.charset.CharacterCodingException;
17+
import com.datastax.driver.core.ColumnMetadata;
18+
import com.datastax.driver.core.IndexMetadata;
19+
import com.datastax.driver.core.KeyspaceMetadata;
20+
import com.datastax.driver.core.TableMetadata;
21+
import com.google.common.collect.Lists;
22+
1923
import java.sql.DatabaseMetaData;
20-
import java.sql.ResultSet;
2124
import java.sql.SQLException;
22-
import java.sql.SQLTransientException;
2325
import java.sql.Types;
2426
import java.util.ArrayList;
2527
import java.util.Collection;
26-
import java.util.HashMap;
27-
import java.util.Iterator;
28-
import java.util.LinkedList;
2928
import java.util.List;
30-
import java.util.Map;
31-
32-
33-
34-
import com.datastax.driver.core.ColumnMetadata;
35-
import com.datastax.driver.core.IndexMetadata;
36-
import com.datastax.driver.core.KeyspaceMetadata;
37-
import com.datastax.driver.core.Row;
38-
import com.datastax.driver.core.TableMetadata;
39-
import com.google.common.collect.Lists;
4029

4130
public class MetadataResultSets
4231
{
@@ -178,6 +167,7 @@ public CassandraMetadataResultSet makeColumns(CassandraStatement statement, Stri
178167
// COLUMN_SIZE
179168
int length = -1;
180169
AbstractJdbcType jtype = TypesMap.getTypeForComparator(column.getType().toString());
170+
181171
if (jtype instanceof JdbcBytes) length = Integer.MAX_VALUE / 2;
182172
if (jtype instanceof JdbcAscii || jtype instanceof JdbcUTF8) length = Integer.MAX_VALUE;
183173
if (jtype instanceof JdbcUUID) length = 36;
@@ -189,8 +179,11 @@ public CassandraMetadataResultSet makeColumns(CassandraStatement statement, Stri
189179
if (jtype != null && (jtype.getJdbcType() == Types.DECIMAL || jtype.getJdbcType() == Types.NUMERIC)) npr = 10;
190180

191181
//CHAR_OCTET_LENGTH
192-
Integer charol = null;
193-
if (jtype instanceof JdbcAscii || jtype instanceof JdbcUTF8) charol = Integer.MAX_VALUE;
182+
Integer charol = Integer.MAX_VALUE;
183+
184+
// if (jtype instanceof JdbcAscii || jtype instanceof JdbcUTF8 || jtype instanceof JdbcDate) {
185+
// charol = Integer.MAX_VALUE;
186+
// }
194187

195188
System.out.println("Type : " + column.getType().toString());
196189
System.out.println("Name : " + column.getName());

0 commit comments

Comments
 (0)