4343import com .google .cloud .bigquery .TableId ;
4444import com .google .cloud .bigquery .exception .BigQueryJdbcException ;
4545import com .google .cloud .bigquery .jdbc .BigQueryJdbcTypeMappings .ColumnTypeInfo ;
46+ import com .google .cloud .bigquery .jdbc .utils .BigQueryJdbcVersionUtility ;
4647import java .io .BufferedReader ;
47- import java .io .IOException ;
4848import java .io .InputStream ;
4949import java .io .InputStreamReader ;
5050import java .sql .Connection ;
6060import java .util .Comparator ;
6161import java .util .HashSet ;
6262import java .util .List ;
63- import java .util .Properties ;
6463import java .util .Scanner ;
6564import java .util .Set ;
6665import java .util .concurrent .BlockingQueue ;
7372import java .util .concurrent .LinkedBlockingQueue ;
7473import java .util .concurrent .TimeUnit ;
7574import java .util .concurrent .TimeoutException ;
76- import java .util .concurrent .atomic .AtomicReference ;
7775import java .util .function .Function ;
7876import java .util .function .Supplier ;
7977import java .util .regex .Pattern ;
@@ -92,7 +90,7 @@ class BigQueryDatabaseMetaData implements DatabaseMetaData {
9290 private static final String DATABASE_PRODUCT_NAME = "Google BigQuery" ;
9391 private static final String DATABASE_PRODUCT_VERSION = "2.0" ;
9492 private static final String DRIVER_NAME = "GoogleJDBCDriverForGoogleBigQuery" ;
95- private static final String DRIVER_DEFAULT_VERSION = "0.0.0" ;
93+
9694 private static final String SCHEMA_TERM = "Dataset" ;
9795 private static final String CATALOG_TERM = "Project" ;
9896 private static final String PROCEDURE_TERM = "Procedure" ;
@@ -143,18 +141,12 @@ class BigQueryDatabaseMetaData implements DatabaseMetaData {
143141 BigQueryConnection connection ;
144142 private final BigQuery bigquery ;
145143 private final int metadataFetchThreadCount ;
146- private static final AtomicReference <String > parsedDriverVersion = new AtomicReference <>(null );
147- private static final AtomicReference <Integer > parsedDriverMajorVersion =
148- new AtomicReference <>(null );
149- private static final AtomicReference <Integer > parsedDriverMinorVersion =
150- new AtomicReference <>(null );
151144
152145 BigQueryDatabaseMetaData (BigQueryConnection connection ) {
153146 this .URL = connection .getConnectionUrl ();
154147 this .connection = connection ;
155148 this .bigquery = connection .getBigQuery ();
156149 this .metadataFetchThreadCount = connection .getMetadataFetchThreadCount ();
157- loadDriverVersionProperties ();
158150 }
159151
160152 @ Override
@@ -223,17 +215,17 @@ public String getDriverName() {
223215
224216 @ Override
225217 public String getDriverVersion () {
226- return parsedDriverVersion . get () != null ? parsedDriverVersion . get () : DRIVER_DEFAULT_VERSION ;
218+ return BigQueryJdbcVersionUtility . getDriverVersion () ;
227219 }
228220
229221 @ Override
230222 public int getDriverMajorVersion () {
231- return parsedDriverMajorVersion . get () != null ? parsedDriverMajorVersion . get () : 0 ;
223+ return BigQueryJdbcVersionUtility . getDriverMajorVersion () ;
232224 }
233225
234226 @ Override
235227 public int getDriverMinorVersion () {
236- return parsedDriverMinorVersion . get () != null ? parsedDriverMinorVersion . get () : 0 ;
228+ return BigQueryJdbcVersionUtility . getDriverMinorVersion () ;
237229 }
238230
239231 @ Override
@@ -5233,51 +5225,6 @@ String replaceSqlParameters(String sql, String... params) throws SQLException {
52335225 return String .format (sql , (Object []) params );
52345226 }
52355227
5236- private void loadDriverVersionProperties () {
5237- if (parsedDriverVersion .get () != null ) {
5238- return ;
5239- }
5240- Properties props = new Properties ();
5241- try (InputStream input =
5242- getClass ().getResourceAsStream ("/com/google/cloud/bigquery/jdbc/dependencies.properties" )) {
5243- if (input == null ) {
5244- String errorMessage =
5245- "Could not find dependencies.properties. Driver version information is unavailable." ;
5246- IllegalStateException ex = new IllegalStateException (errorMessage );
5247- LOG .severe (errorMessage , ex );
5248- throw ex ;
5249- }
5250- props .load (input );
5251- String versionString = props .getProperty ("version.jdbc" );
5252- if (versionString == null || versionString .trim ().isEmpty ()) {
5253- String errorMessage =
5254- "The property version.jdbc not found or empty in dependencies.properties." ;
5255- IllegalStateException ex = new IllegalStateException (errorMessage );
5256- LOG .severe (errorMessage , ex );
5257- throw ex ;
5258- }
5259- parsedDriverVersion .compareAndSet (null , versionString .trim ());
5260- String [] parts = versionString .split ("\\ ." );
5261- if (parts .length < 2 ) {
5262- return ;
5263- }
5264- parsedDriverMajorVersion .compareAndSet (null , Integer .parseInt (parts [0 ]));
5265- String minorPart = parts [1 ];
5266- String numericMinor = minorPart .replaceAll ("[^0-9].*" , "" );
5267- if (!numericMinor .isEmpty ()) {
5268- parsedDriverMinorVersion .compareAndSet (null , Integer .parseInt (numericMinor ));
5269- }
5270- } catch (IOException | NumberFormatException e ) {
5271- String errorMessage =
5272- "Error reading dependencies.properties. Driver version information is"
5273- + " unavailable. Error: "
5274- + e .getMessage ();
5275- IllegalStateException ex = new IllegalStateException (errorMessage , e );
5276- LOG .severe (errorMessage , ex );
5277- throw ex ;
5278- }
5279- }
5280-
52815228 // TODO(keshav): This is a temporary compatibility bridge to wrap raw Threads into Futures.
52825229 // This should be removed when BigQueryDatabaseMetaData is refactored to use the ExecutorService
52835230 // directly.
0 commit comments