4242import com .google .cloud .bigquery .TableDefinition ;
4343import com .google .cloud .bigquery .TableId ;
4444import com .google .cloud .bigquery .exception .BigQueryJdbcException ;
45+ import com .google .cloud .bigquery .jdbc .utils .BigQueryJdbcVersionUtility ;
4546import com .google .common .collect .ImmutableMap ;
4647import java .io .BufferedReader ;
4748import java .io .IOException ;
6162import java .util .HashSet ;
6263import java .util .List ;
6364import java .util .Map ;
64- import java . util . Properties ;
65+
6566import java .util .Scanner ;
6667import java .util .Set ;
6768import java .util .concurrent .BlockingQueue ;
7374import java .util .concurrent .Future ;
7475import java .util .concurrent .LinkedBlockingQueue ;
7576import java .util .concurrent .TimeUnit ;
76- import java . util . concurrent . atomic . AtomicReference ;
77+
7778import java .util .function .Function ;
7879import java .util .function .Supplier ;
7980import java .util .regex .Pattern ;
@@ -92,7 +93,7 @@ class BigQueryDatabaseMetaData implements DatabaseMetaData {
9293 private static final String DATABASE_PRODUCT_NAME = "Google BigQuery" ;
9394 private static final String DATABASE_PRODUCT_VERSION = "2.0" ;
9495 private static final String DRIVER_NAME = "GoogleJDBCDriverForGoogleBigQuery" ;
95- private static final String DRIVER_DEFAULT_VERSION = "0.0.0" ;
96+
9697 private static final String SCHEMA_TERM = "Dataset" ;
9798 private static final String CATALOG_TERM = "Project" ;
9899 private static final String PROCEDURE_TERM = "Procedure" ;
@@ -143,18 +144,11 @@ class BigQueryDatabaseMetaData implements DatabaseMetaData {
143144 BigQueryConnection connection ;
144145 private final BigQuery bigquery ;
145146 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 );
151-
152147 BigQueryDatabaseMetaData (BigQueryConnection connection ) {
153148 this .URL = connection .getConnectionUrl ();
154149 this .connection = connection ;
155150 this .bigquery = connection .getBigQuery ();
156151 this .metadataFetchThreadCount = connection .getMetadataFetchThreadCount ();
157- loadDriverVersionProperties ();
158152 }
159153
160154 @ Override
@@ -223,17 +217,17 @@ public String getDriverName() {
223217
224218 @ Override
225219 public String getDriverVersion () {
226- return parsedDriverVersion . get () != null ? parsedDriverVersion . get () : DRIVER_DEFAULT_VERSION ;
220+ return BigQueryJdbcVersionUtility . getDriverVersion () ;
227221 }
228222
229223 @ Override
230224 public int getDriverMajorVersion () {
231- return parsedDriverMajorVersion . get () != null ? parsedDriverMajorVersion . get () : 0 ;
225+ return BigQueryJdbcVersionUtility . getDriverMajorVersion () ;
232226 }
233227
234228 @ Override
235229 public int getDriverMinorVersion () {
236- return parsedDriverMinorVersion . get () != null ? parsedDriverMinorVersion . get () : 0 ;
230+ return BigQueryJdbcVersionUtility . getDriverMinorVersion () ;
237231 }
238232
239233 @ Override
@@ -5288,48 +5282,4 @@ String replaceSqlParameters(String sql, String... params) throws SQLException {
52885282 return String .format (sql , (Object []) params );
52895283 }
52905284
5291- private void loadDriverVersionProperties () {
5292- if (parsedDriverVersion .get () != null ) {
5293- return ;
5294- }
5295- Properties props = new Properties ();
5296- try (InputStream input =
5297- getClass ().getResourceAsStream ("/com/google/cloud/bigquery/jdbc/dependencies.properties" )) {
5298- if (input == null ) {
5299- String errorMessage =
5300- "Could not find dependencies.properties. Driver version information is unavailable." ;
5301- IllegalStateException ex = new IllegalStateException (errorMessage );
5302- LOG .severe (errorMessage , ex );
5303- throw ex ;
5304- }
5305- props .load (input );
5306- String versionString = props .getProperty ("version.jdbc" );
5307- if (versionString == null || versionString .trim ().isEmpty ()) {
5308- String errorMessage =
5309- "The property version.jdbc not found or empty in dependencies.properties." ;
5310- IllegalStateException ex = new IllegalStateException (errorMessage );
5311- LOG .severe (errorMessage , ex );
5312- throw ex ;
5313- }
5314- parsedDriverVersion .compareAndSet (null , versionString .trim ());
5315- String [] parts = versionString .split ("\\ ." );
5316- if (parts .length < 2 ) {
5317- return ;
5318- }
5319- parsedDriverMajorVersion .compareAndSet (null , Integer .parseInt (parts [0 ]));
5320- String minorPart = parts [1 ];
5321- String numericMinor = minorPart .replaceAll ("[^0-9].*" , "" );
5322- if (!numericMinor .isEmpty ()) {
5323- parsedDriverMinorVersion .compareAndSet (null , Integer .parseInt (numericMinor ));
5324- }
5325- } catch (IOException | NumberFormatException e ) {
5326- String errorMessage =
5327- "Error reading dependencies.properties. Driver version information is"
5328- + " unavailable. Error: "
5329- + e .getMessage ();
5330- IllegalStateException ex = new IllegalStateException (errorMessage , e );
5331- LOG .severe (errorMessage , ex );
5332- throw ex ;
5333- }
5334- }
53355285}
0 commit comments