You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/11/28 12:24:49 UTC
[camel] 02/03: CAMEL-12930 - Fixed CS and sb starter
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit a8ce42321164f2f6e471a9a190012320cbbf9f87
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Nov 28 12:32:51 2018 +0100
CAMEL-12930 - Fixed CS and sb starter
---
.../bigquery/sql/GoogleBigQuerySQLComponent.java | 3 +-
.../sql/GoogleBigQuerySQLConfiguration.java | 9 +-
.../bigquery/sql/GoogleBigQuerySQLEndpoint.java | 28 ++---
.../bigquery/sql/GoogleBigQuerySQLProducer.java | 93 +++++++--------
.../component/google/bigquery/sql/SqlHelper.java | 31 +++--
.../unit/sql/GoogleBigQuerySQLComponentTest.java | 7 +-
.../sql/GoogleBigQuerySQLProducerBaseTest.java | 19 ++-
.../GoogleBigQuerySQLProducerWithParamersTest.java | 6 +-
.../GoogleBigQuerySQLProducerWithPatternTest.java | 4 +-
.../google/bigquery/unit/sql/SqlHelperTest.java | 45 +++----
...oogleBigQuerySQLComponentAutoConfiguration.java | 130 +++++++++++++++++++++
.../GoogleBigQuerySQLComponentConfiguration.java | 93 +++++++++++++++
.../src/main/resources/META-INF/spring.factories | 4 +-
13 files changed, 349 insertions(+), 123 deletions(-)
diff --git a/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLComponent.java b/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLComponent.java
index fcbcf66..a0b2363 100644
--- a/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLComponent.java
+++ b/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLComponent.java
@@ -73,7 +73,8 @@ public class GoogleBigQuerySQLComponent extends DefaultComponent {
}
/**
- * ConnectionFactory to obtain connection to Bigquery Service. If non provided the default one will be used
+ * ConnectionFactory to obtain connection to Bigquery Service. If non
+ * provided the default one will be used
*/
public void setConnectionFactory(GoogleBigQueryConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
diff --git a/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLConfiguration.java b/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLConfiguration.java
index 25ed0dff..5e766a0 100644
--- a/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLConfiguration.java
+++ b/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLConfiguration.java
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -46,7 +46,8 @@ public class GoogleBigQuerySQLConfiguration {
}
/**
- * ConnectionFactory to obtain connection to Bigquery Service. If non provided the default will be used.
+ * ConnectionFactory to obtain connection to Bigquery Service. If non
+ * provided the default will be used.
*/
public GoogleBigQueryConnectionFactory getConnectionFactory() {
return connectionFactory;
diff --git a/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLEndpoint.java b/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLEndpoint.java
index fee9e96..4138faa 100644
--- a/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLEndpoint.java
+++ b/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLEndpoint.java
@@ -25,23 +25,18 @@ import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
/**
- * Google BigQuery data warehouse for analytics.
- *
- * BigQuery Endpoint Definition
- * Represents a table within a BigQuery dataset
- * Contains configuration details for a single table and the utility methods (such as check, create) to ease operations
- * URI Parameters:
- * * Logger ID - To ensure that logging is unified under Route Logger, the logger ID can be passed on
- * via an endpoint URI parameter
- * * Partitioned - to indicate that the table needs to be partitioned - every UTC day to be written into a
- * timestamped separate table
- * side effect: Australian operational day is always split between two UTC days, and, therefore, tables
- *
- * Another consideration is that exceptions are not handled within the class. They are expected to bubble up and be handled
- * by Camel.
+ * Google BigQuery data warehouse for analytics. BigQuery Endpoint Definition
+ * Represents a table within a BigQuery dataset Contains configuration details
+ * for a single table and the utility methods (such as check, create) to ease
+ * operations URI Parameters: * Logger ID - To ensure that logging is unified
+ * under Route Logger, the logger ID can be passed on via an endpoint URI
+ * parameter * Partitioned - to indicate that the table needs to be partitioned
+ * - every UTC day to be written into a timestamped separate table side effect:
+ * Australian operational day is always split between two UTC days, and,
+ * therefore, tables Another consideration is that exceptions are not handled
+ * within the class. They are expected to bubble up and be handled by Camel.
*/
-@UriEndpoint(firstVersion = "2.23.0", scheme = "google-bigquery-sql", title = "Google BigQuery Standard SQL", syntax = "google-bigquery-sql:query",
- label = "cloud,messaging", producerOnly = true)
+@UriEndpoint(firstVersion = "2.23.0", scheme = "google-bigquery-sql", title = "Google BigQuery Standard SQL", syntax = "google-bigquery-sql:query", label = "cloud,messaging", producerOnly = true)
public class GoogleBigQuerySQLEndpoint extends DefaultEndpoint {
@UriParam
@@ -76,5 +71,4 @@ public class GoogleBigQuerySQLEndpoint extends DefaultEndpoint {
return (GoogleBigQuerySQLComponent)super.getComponent();
}
-
}
diff --git a/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLProducer.java b/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLProducer.java
index e9ce93d..eb13666 100644
--- a/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLProducer.java
+++ b/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLProducer.java
@@ -1,29 +1,40 @@
/**
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.apache.camel.component.google.bigquery.sql;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import com.google.api.services.bigquery.Bigquery;
-import com.google.api.services.bigquery.model.*;
+import com.google.api.services.bigquery.model.QueryParameter;
+import com.google.api.services.bigquery.model.QueryParameterType;
+import com.google.api.services.bigquery.model.QueryParameterValue;
+import com.google.api.services.bigquery.model.QueryRequest;
+import com.google.api.services.bigquery.model.QueryResponse;
+
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.RuntimeExchangeException;
import org.apache.camel.component.google.bigquery.GoogleBigQueryConstants;
import org.apache.camel.impl.DefaultProducer;
-import java.util.*;
-
/**
* Generic BigQuery Producer
*/
@@ -34,27 +45,24 @@ public class GoogleBigQuerySQLProducer extends DefaultProducer {
private String query;
private Set<String> queryParameterNames;
- public GoogleBigQuerySQLProducer(Bigquery bigquery, GoogleBigQuerySQLEndpoint endpoint,
- GoogleBigQuerySQLConfiguration configuration) {
+ public GoogleBigQuerySQLProducer(Bigquery bigquery, GoogleBigQuerySQLEndpoint endpoint, GoogleBigQuerySQLConfiguration configuration) {
super(endpoint);
this.bigquery = bigquery;
this.configuration = configuration;
}
/**
- * Process the exchange
- *
- * The incoming exchange can be a grouped exchange in which case all the exchanges will be combined.
- *
- * The incoming can be
+ * Process the exchange The incoming exchange can be a grouped exchange in
+ * which case all the exchanges will be combined. The incoming can be
* <ul>
- * <li>A map where all map keys will map to field records. One map object maps to one bigquery row</li>
- * <li>A list of maps. Each entry in the list will map to one bigquery row</li>
+ * <li>A map where all map keys will map to field records. One map object
+ * maps to one bigquery row</li>
+ * <li>A list of maps. Each entry in the list will map to one bigquery
+ * row</li>
* </ul>
- * The incoming message is expected to be a List of Maps
- * The assumptions:
- * - All incoming records go into the same table
- * - Incoming records sorted by the timestamp
+ * The incoming message is expected to be a List of Maps The assumptions: -
+ * All incoming records go into the same table - Incoming records sorted by
+ * the timestamp
*/
@Override
public void process(Exchange exchange) throws Exception {
@@ -67,19 +75,14 @@ public class GoogleBigQuerySQLProducer extends DefaultProducer {
}
private Long executeSQL(String translatedQuery, Map<String, Object> queryParameters) throws Exception {
- QueryRequest apiQueryRequest = new QueryRequest()
- .setQuery(translatedQuery)
- .setUseLegacySql(false);
+ QueryRequest apiQueryRequest = new QueryRequest().setQuery(translatedQuery).setUseLegacySql(false);
- Bigquery.Jobs.Query apiQuery = bigquery
- .jobs()
- .query(configuration.getProjectId(), apiQueryRequest);
+ Bigquery.Jobs.Query apiQuery = bigquery.jobs().query(configuration.getProjectId(), apiQueryRequest);
setQueryParameters(queryParameters, apiQueryRequest);
if (log.isTraceEnabled()) {
- log.trace("Sending query to bigquery standard sql: {}",
- translatedQuery);
+ log.trace("Sending query to bigquery standard sql: {}", translatedQuery);
}
QueryResponse apiResponse = apiQuery.execute();
@@ -89,15 +92,15 @@ public class GoogleBigQuerySQLProducer extends DefaultProducer {
}
if (log.isTraceEnabled()) {
- log.trace("Result of query {} is {}",
- translatedQuery, apiResponse.toPrettyString());
+ log.trace("Result of query {} is {}", translatedQuery, apiResponse.toPrettyString());
}
return apiResponse.getNumDmlAffectedRows();
}
private Map<String, Object> extractParameters(Exchange exchange) {
- if (queryParameterNames == null || queryParameterNames.size() == 0)
+ if (queryParameterNames == null || queryParameterNames.size() == 0) {
return null;
+ }
Message message = exchange.getMessage();
@@ -124,15 +127,14 @@ public class GoogleBigQuerySQLProducer extends DefaultProducer {
}
private void setQueryParameters(Map<String, Object> params, QueryRequest apiQueryRequest) {
- if (params == null)
+ if (params == null) {
return;
+ }
List<QueryParameter> list = new ArrayList<>();
params.forEach((key, value) -> {
QueryParameter param = new QueryParameter();
- param.setName(key)
- .setParameterType(new QueryParameterType().setType("STRING"))
- .setParameterValue(new QueryParameterValue().setValue(value.toString()));
+ param.setName(key).setParameterType(new QueryParameterType().setType("STRING")).setParameterValue(new QueryParameterValue().setValue(value.toString()));
list.add(param);
});
apiQueryRequest.setQueryParameters(list);
@@ -145,15 +147,14 @@ public class GoogleBigQuerySQLProducer extends DefaultProducer {
@Override
public GoogleBigQuerySQLEndpoint getEndpoint() {
- return (GoogleBigQuerySQLEndpoint) super.getEndpoint();
+ return (GoogleBigQuerySQLEndpoint)super.getEndpoint();
}
@Override
protected void doStart() throws Exception {
super.doStart();
String placeholder = ":#"; // TODO
- query = SqlHelper
- .resolveQuery(getEndpoint().getCamelContext(), configuration.getQuery(), placeholder);
+ query = SqlHelper.resolveQuery(getEndpoint().getCamelContext(), configuration.getQuery(), placeholder);
queryParameterNames = SqlHelper.extractParameterNames(query);
}
}
diff --git a/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/SqlHelper.java b/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/SqlHelper.java
index eb41856..9ecd2e2 100644
--- a/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/SqlHelper.java
+++ b/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/SqlHelper.java
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,9 +16,6 @@
*/
package org.apache.camel.component.google.bigquery.sql;
-import org.apache.camel.*;
-import org.apache.camel.util.ResourceHelper;
-
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
@@ -26,6 +23,13 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.RuntimeExchangeException;
+import org.apache.camel.util.ResourceHelper;
+
public final class SqlHelper {
private static Pattern pattern = Pattern.compile("\\$\\{(\\w+)}");
@@ -35,13 +39,13 @@ public final class SqlHelper {
}
/**
- * Resolve the query by loading the query from the classpath or file resource if needed.
+ * Resolve the query by loading the query from the classpath or file
+ * resource if needed.
*/
public static String resolveQuery(CamelContext camelContext, String query, String placeholder) throws NoTypeConversionAvailableException, IOException {
String answer = query;
if (ResourceHelper.hasScheme(query)) {
- InputStream is = ResourceHelper
- .resolveMandatoryResourceAsInputStream(camelContext, query);
+ InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, query);
answer = camelContext.getTypeConverter().mandatoryConvertTo(String.class, is);
if (placeholder != null) {
answer = answer.replaceAll(placeholder, "@");
@@ -51,8 +55,9 @@ public final class SqlHelper {
}
/**
- * Replaces pattern in query in form of "${param}" with values from message header
- * Raises an error if param value not found in headers
+ * Replaces pattern in query in form of "${param}" with values from message
+ * header Raises an error if param value not found in headers
+ *
* @param exchange
* @return Translated query text
*/
@@ -66,8 +71,9 @@ public final class SqlHelper {
String value = message.getHeader(paramKey, String.class);
if (value == null) {
value = exchange.getProperty(paramKey, String.class);
- if (value == null)
+ if (value == null) {
throw new RuntimeExchangeException("SQL pattern with name '" + paramKey + "' not found in the message headers", exchange);
+ }
}
String replacement = Matcher.quoteReplacement(value);
@@ -79,6 +85,7 @@ public final class SqlHelper {
/**
* Extracts list of parameters in form "@name" from query text
+ *
* @param query
* @return list of parameter names
*/
diff --git a/components/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/GoogleBigQuerySQLComponentTest.java b/components/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/GoogleBigQuerySQLComponentTest.java
index ba24d0d..5cd5d2c 100644
--- a/components/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/GoogleBigQuerySQLComponentTest.java
+++ b/components/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/GoogleBigQuerySQLComponentTest.java
@@ -16,17 +16,14 @@
*/
package org.apache.camel.component.google.bigquery.unit.sql;
-import static org.junit.Assert.assertEquals;
-
import org.apache.camel.CamelContext;
-import org.apache.camel.component.google.bigquery.GoogleBigQueryComponent;
-import org.apache.camel.component.google.bigquery.GoogleBigQueryEndpoint;
import org.apache.camel.component.google.bigquery.sql.GoogleBigQuerySQLComponent;
import org.apache.camel.component.google.bigquery.sql.GoogleBigQuerySQLEndpoint;
-import org.apache.camel.component.google.bigquery.sql.SqlHelper;
import org.junit.Test;
import org.mockito.Mockito;
+import static org.junit.Assert.assertEquals;
+
public class GoogleBigQuerySQLComponentTest {
private CamelContext context = Mockito.mock(CamelContext.class);
diff --git a/components/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/GoogleBigQuerySQLProducerBaseTest.java b/components/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/GoogleBigQuerySQLProducerBaseTest.java
index 244f27c..fa28b70 100644
--- a/components/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/GoogleBigQuerySQLProducerBaseTest.java
+++ b/components/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/GoogleBigQuerySQLProducerBaseTest.java
@@ -1,3 +1,19 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.camel.component.google.bigquery.unit.sql;
import com.google.api.services.bigquery.Bigquery;
@@ -37,8 +53,7 @@ public class GoogleBigQuerySQLProducerBaseTest extends CamelTestSupport {
when(bigquery.jobs()).thenReturn(mockJobs);
when(bigquery.jobs().query(anyString(), any())).thenReturn(mockQuery);
- QueryResponse mockResponse = new QueryResponse()
- .setNumDmlAffectedRows(1L);
+ QueryResponse mockResponse = new QueryResponse().setNumDmlAffectedRows(1L);
when(mockQuery.execute()).thenReturn(mockResponse);
}
}
diff --git a/components/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/GoogleBigQuerySQLProducerWithParamersTest.java b/components/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/GoogleBigQuerySQLProducerWithParamersTest.java
index 6227dfb..5eaa916 100644
--- a/components/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/GoogleBigQuerySQLProducerWithParamersTest.java
+++ b/components/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/GoogleBigQuerySQLProducerWithParamersTest.java
@@ -16,6 +16,9 @@
*/
package org.apache.camel.component.google.bigquery.unit.sql;
+import java.util.HashMap;
+import java.util.Map;
+
import com.google.api.services.bigquery.model.QueryRequest;
import org.apache.camel.Exchange;
import org.apache.camel.RuntimeExchangeException;
@@ -23,9 +26,6 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
-import java.util.HashMap;
-import java.util.Map;
-
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
diff --git a/components/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/GoogleBigQuerySQLProducerWithPatternTest.java b/components/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/GoogleBigQuerySQLProducerWithPatternTest.java
index 11cb050..93ac997 100644
--- a/components/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/GoogleBigQuerySQLProducerWithPatternTest.java
+++ b/components/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/GoogleBigQuerySQLProducerWithPatternTest.java
@@ -16,14 +16,14 @@
*/
package org.apache.camel.component.google.bigquery.unit.sql;
+import java.util.List;
+
import com.google.api.services.bigquery.model.QueryRequest;
import org.apache.camel.Exchange;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
-import java.util.List;
-
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
diff --git a/components/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/SqlHelperTest.java b/components/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/SqlHelperTest.java
index de46355..1ab2b2f 100644
--- a/components/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/SqlHelperTest.java
+++ b/components/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/SqlHelperTest.java
@@ -16,6 +16,8 @@
*/
package org.apache.camel.component.google.bigquery.unit.sql;
+import java.util.Set;
+
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
@@ -25,13 +27,23 @@ import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
-import java.util.Set;
-
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
public class SqlHelperTest {
+
+ String query = "INSERT INTO ${report}.test( -- TODO \n" + " id,\n" + " region\n" + ")\n" + "SELECT\n" + " id,\n" + " region\n" + "FROM\n" + " ${import}.test\n" + "WHERE\n"
+ + " rec_date = @date AND id = @id\n";
+
+ String expected = "INSERT INTO report_data.test( -- TODO \n" + " id,\n" + " region\n" + ")\n" + "SELECT\n" + " id,\n" + " region\n" + "FROM\n" + " import_data.test\n"
+ + "WHERE\n" + " rec_date = @date AND id = @id\n";
+
+ Exchange exchange = Mockito.mock(Exchange.class);
+ Message message = Mockito.mock(Message.class);
+
private CamelContext context = Mockito.mock(CamelContext.class);
@Test
@@ -47,33 +59,6 @@ public class SqlHelperTest {
assertEquals("delete from test.test_sql_table where id = @id", answer);
}
- String query = "INSERT INTO ${report}.test( -- TODO \n" +
- " id,\n" +
- " region\n" +
- ")\n" +
- "SELECT\n" +
- " id,\n" +
- " region\n" +
- "FROM\n" +
- " ${import}.test\n" +
- "WHERE\n" +
- " rec_date = @date AND id = @id\n";
-
- String expected = "INSERT INTO report_data.test( -- TODO \n" +
- " id,\n" +
- " region\n" +
- ")\n" +
- "SELECT\n" +
- " id,\n" +
- " region\n" +
- "FROM\n" +
- " import_data.test\n" +
- "WHERE\n" +
- " rec_date = @date AND id = @id\n";
-
- Exchange exchange = Mockito.mock(Exchange.class);
- Message message = Mockito.mock(Message.class);
-
@Test
public void testTranslateQuery() {
when(exchange.getMessage()).thenReturn(message);
diff --git a/platforms/spring-boot/components-starter/camel-google-bigquery-starter/src/main/java/org/apache/camel/component/google/bigquery/sql/springboot/GoogleBigQuerySQLComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-google-bigquery-starter/src/main/java/org/apache/camel/component/google/bigquery/sql/springboot/GoogleBigQuerySQLComponentAutoConfiguration.java
new file mode 100644
index 0000000..f2028bd
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-google-bigquery-starter/src/main/java/org/apache/camel/component/google/bigquery/sql/springboot/GoogleBigQuerySQLComponentAutoConfiguration.java
@@ -0,0 +1,130 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.google.bigquery.sql.springboot;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Generated;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.google.bigquery.sql.GoogleBigQuerySQLComponent;
+import org.apache.camel.spi.ComponentCustomizer;
+import org.apache.camel.spi.HasId;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.spring.boot.ComponentConfigurationProperties;
+import org.apache.camel.spring.boot.util.CamelPropertiesHelper;
+import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans;
+import org.apache.camel.spring.boot.util.GroupCondition;
+import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator;
+import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+
+/**
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
+@Configuration
+@Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class,
+ GoogleBigQuerySQLComponentAutoConfiguration.GroupConditions.class})
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+@EnableConfigurationProperties({ComponentConfigurationProperties.class,
+ GoogleBigQuerySQLComponentConfiguration.class})
+public class GoogleBigQuerySQLComponentAutoConfiguration {
+
+ private static final Logger LOGGER = LoggerFactory
+ .getLogger(GoogleBigQuerySQLComponentAutoConfiguration.class);
+ @Autowired
+ private ApplicationContext applicationContext;
+ @Autowired
+ private CamelContext camelContext;
+ @Autowired
+ private GoogleBigQuerySQLComponentConfiguration configuration;
+ @Autowired(required = false)
+ private List<ComponentCustomizer<GoogleBigQuerySQLComponent>> customizers;
+
+ static class GroupConditions extends GroupCondition {
+ public GroupConditions() {
+ super("camel.component", "camel.component.google-bigquery-sql");
+ }
+ }
+
+ @Lazy
+ @Bean(name = "google-bigquery-sql-component")
+ @ConditionalOnMissingBean(GoogleBigQuerySQLComponent.class)
+ public GoogleBigQuerySQLComponent configureGoogleBigQuerySQLComponent()
+ throws Exception {
+ GoogleBigQuerySQLComponent component = new GoogleBigQuerySQLComponent();
+ component.setCamelContext(camelContext);
+ Map<String, Object> parameters = new HashMap<>();
+ IntrospectionSupport.getProperties(configuration, parameters, null,
+ false);
+ for (Map.Entry<String, Object> entry : parameters.entrySet()) {
+ Object value = entry.getValue();
+ Class<?> paramClass = value.getClass();
+ if (paramClass.getName().endsWith("NestedConfiguration")) {
+ Class nestedClass = null;
+ try {
+ nestedClass = (Class) paramClass.getDeclaredField(
+ "CAMEL_NESTED_CLASS").get(null);
+ HashMap<String, Object> nestedParameters = new HashMap<>();
+ IntrospectionSupport.getProperties(value, nestedParameters,
+ null, false);
+ Object nestedProperty = nestedClass.newInstance();
+ CamelPropertiesHelper.setCamelProperties(camelContext,
+ nestedProperty, nestedParameters, false);
+ entry.setValue(nestedProperty);
+ } catch (NoSuchFieldException e) {
+ }
+ }
+ }
+ CamelPropertiesHelper.setCamelProperties(camelContext, component,
+ parameters, false);
+ if (ObjectHelper.isNotEmpty(customizers)) {
+ for (ComponentCustomizer<GoogleBigQuerySQLComponent> customizer : customizers) {
+ boolean useCustomizer = (customizer instanceof HasId)
+ ? HierarchicalPropertiesEvaluator
+ .evaluate(
+ applicationContext.getEnvironment(),
+ "camel.component.customizer",
+ "camel.component.google-bigquery-sql.customizer",
+ ((HasId) customizer).getId())
+ : HierarchicalPropertiesEvaluator
+ .evaluate(applicationContext.getEnvironment(),
+ "camel.component.customizer",
+ "camel.component.google-bigquery-sql.customizer");
+ if (useCustomizer) {
+ LOGGER.debug("Configure component {}, with customizer {}",
+ component, customizer);
+ customizer.customize(component);
+ }
+ }
+ }
+ return component;
+ }
+}
\ No newline at end of file
diff --git a/platforms/spring-boot/components-starter/camel-google-bigquery-starter/src/main/java/org/apache/camel/component/google/bigquery/sql/springboot/GoogleBigQuerySQLComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-google-bigquery-starter/src/main/java/org/apache/camel/component/google/bigquery/sql/springboot/GoogleBigQuerySQLComponentConfiguration.java
new file mode 100644
index 0000000..fc08356
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-google-bigquery-starter/src/main/java/org/apache/camel/component/google/bigquery/sql/springboot/GoogleBigQuerySQLComponentConfiguration.java
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.google.bigquery.sql.springboot;
+
+import javax.annotation.Generated;
+import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * Google BigQuery data warehouse for analytics. BigQuery Endpoint Definition
+ * Represents a table within a BigQuery dataset Contains configuration details
+ * for a single table and the utility methods (such as check, create) to ease
+ * operations URI Parameters: Logger ID - To ensure that logging is unified
+ * under Route Logger, the logger ID can be passed on via an endpoint URI
+ * parameter Partitioned - to indicate that the table needs to be partitioned -
+ * every UTC day to be written into a timestamped separate table side effect:
+ * Australian operational day is always split between two UTC days, and,
+ * therefore, tables Another consideration is that exceptions are not handled
+ * within the class. They are expected to bubble up and be handled by Camel.
+ *
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
+@ConfigurationProperties(prefix = "camel.component.google-bigquery-sql")
+public class GoogleBigQuerySQLComponentConfiguration
+ extends
+ ComponentConfigurationPropertiesCommon {
+
+ /**
+ * Whether to enable auto configuration of the google-bigquery-sql
+ * component. This is enabled by default.
+ */
+ private Boolean enabled;
+ /**
+ * Google Cloud Project Id
+ */
+ private String projectId;
+ /**
+ * ConnectionFactory to obtain connection to Bigquery Service. If non
+ * provided the default one will be used
+ */
+ private GoogleBigQueryConnectionFactoryNestedConfiguration connectionFactory;
+ /**
+ * Whether the component should resolve property placeholders on itself when
+ * starting. Only properties which are of String type can use property
+ * placeholders.
+ */
+ private Boolean resolvePropertyPlaceholders = true;
+
+ public String getProjectId() {
+ return projectId;
+ }
+
+ public void setProjectId(String projectId) {
+ this.projectId = projectId;
+ }
+
+ public GoogleBigQueryConnectionFactoryNestedConfiguration getConnectionFactory() {
+ return connectionFactory;
+ }
+
+ public void setConnectionFactory(
+ GoogleBigQueryConnectionFactoryNestedConfiguration connectionFactory) {
+ this.connectionFactory = connectionFactory;
+ }
+
+ public Boolean getResolvePropertyPlaceholders() {
+ return resolvePropertyPlaceholders;
+ }
+
+ public void setResolvePropertyPlaceholders(
+ Boolean resolvePropertyPlaceholders) {
+ this.resolvePropertyPlaceholders = resolvePropertyPlaceholders;
+ }
+
+ public static class GoogleBigQueryConnectionFactoryNestedConfiguration {
+ public static final Class CAMEL_NESTED_CLASS = org.apache.camel.component.google.bigquery.GoogleBigQueryConnectionFactory.class;
+ }
+}
\ No newline at end of file
diff --git a/platforms/spring-boot/components-starter/camel-google-bigquery-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-google-bigquery-starter/src/main/resources/META-INF/spring.factories
index 6f6a9e7..14ead81 100644
--- a/platforms/spring-boot/components-starter/camel-google-bigquery-starter/src/main/resources/META-INF/spring.factories
+++ b/platforms/spring-boot/components-starter/camel-google-bigquery-starter/src/main/resources/META-INF/spring.factories
@@ -16,4 +16,6 @@
## ---------------------------------------------------------------------------
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-org.apache.camel.component.google.bigquery.springboot.GoogleBigQueryComponentAutoConfiguration
+org.apache.camel.component.google.bigquery.springboot.GoogleBigQueryComponentAutoConfiguration,\
+org.apache.camel.component.google.bigquery.sql.springboot.GoogleBigQuerySQLComponentAutoConfiguration
+