http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/common/src/test/java/org/apache/sqoop/json/TestConnectionBean.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/json/TestConnectionBean.java b/common/src/test/java/org/apache/sqoop/json/TestConnectionBean.java deleted file mode 100644 index 19f81a8..0000000 --- a/common/src/test/java/org/apache/sqoop/json/TestConnectionBean.java +++ /dev/null @@ -1,138 +0,0 @@ -/** - * 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.sqoop.json; - -import org.apache.sqoop.model.MConnection; -import org.apache.sqoop.model.MStringInput; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.JSONArray; -import org.json.simple.JSONValue; -import org.junit.Test; - -import java.util.Date; - -import static junit.framework.Assert.*; -import static org.apache.sqoop.json.TestUtil.*; - -/** - * - */ -public class TestConnectionBean { - @Test - public void testSerialization() { - Date created = new Date(); - Date updated = new Date(); - MConnection connection = getConnection("ahoj"); - connection.setName("Connection"); - connection.setPersistenceId(666); - connection.setCreationUser("admin"); - connection.setCreationDate(created); - connection.setLastUpdateUser("user"); - connection.setLastUpdateDate(updated); - connection.setEnabled(false); - - // Fill some data at the beginning - MStringInput input = (MStringInput) connection.getConnectorPart().getForms() - .get(0).getInputs().get(0); - input.setValue("Hi there!"); - - // Serialize it to JSON object - ConnectionBean bean = new ConnectionBean(connection); - JSONObject json = bean.extract(false); - - // Check for sensitivity - JSONArray all = (JSONArray)json.get("all"); - JSONObject allItem = (JSONObject)all.get(0); - JSONArray connectors = (JSONArray)allItem.get("connector"); - JSONObject connector = (JSONObject)connectors.get(0); - JSONArray inputs = (JSONArray)connector.get("inputs"); - for (Object input1 : inputs) { - assertTrue(((JSONObject)input1).containsKey("sensitive")); - } - - // "Move" it across network in text form - String string = json.toJSONString(); - - // Retrieved transferred object - JSONObject retrievedJson = (JSONObject) JSONValue.parse(string); - ConnectionBean retrievedBean = new ConnectionBean(); - retrievedBean.restore(retrievedJson); - MConnection target = retrievedBean.getConnections().get(0); - - // Check id and name - assertEquals(666, target.getPersistenceId()); - assertEquals("Connection", target.getName()); - assertEquals("admin", target.getCreationUser()); - assertEquals(created, target.getCreationDate()); - assertEquals("user", target.getLastUpdateUser()); - assertEquals(updated, target.getLastUpdateDate()); - assertEquals(false, target.getEnabled()); - - // Test that value was correctly moved - MStringInput targetInput = (MStringInput) target.getConnectorPart() - .getForms().get(0).getInputs().get(0); - assertEquals("Hi there!", targetInput.getValue()); - } - - @Test - public void testSensitivityFilter() { - Date created = new Date(); - Date updated = new Date(); - MConnection connection = getConnection("ahoj"); - connection.setName("Connection"); - connection.setPersistenceId(666); - connection.setCreationUser("admin"); - connection.setCreationDate(created); - connection.setLastUpdateUser("user"); - connection.setLastUpdateDate(updated); - connection.setEnabled(true); - - // Fill some data at the beginning - MStringInput input = (MStringInput) connection.getConnectorPart().getForms() - .get(0).getInputs().get(0); - input.setValue("Hi there!"); - - // Serialize it to JSON object - ConnectionBean bean = new ConnectionBean(connection); - JSONObject json = bean.extract(false); - JSONObject jsonFiltered = bean.extract(true); - - // Sensitive values should exist - JSONArray all = (JSONArray)json.get("all"); - JSONObject allItem = (JSONObject)all.get(0); - JSONArray connectors = (JSONArray)allItem.get("connector"); - JSONObject connector = (JSONObject)connectors.get(0); - JSONArray inputs = (JSONArray)connector.get("inputs"); - assertEquals(3, inputs.size()); - // Inputs are ordered when creating connection - JSONObject password = (JSONObject)inputs.get(2); - assertTrue(password.containsKey("value")); - - // Sensitive values should not exist - all = (JSONArray)jsonFiltered.get("all"); - allItem = (JSONObject)all.get(0); - connectors = (JSONArray)allItem.get("connector"); - connector = (JSONObject)connectors.get(0); - inputs = (JSONArray)connector.get("inputs"); - assertEquals(3, inputs.size()); - // Inputs are ordered when creating connection - password = (JSONObject)inputs.get(2); - assertFalse(password.containsKey("value")); - } -}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/common/src/test/java/org/apache/sqoop/json/TestDriverConfigBean.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/json/TestDriverConfigBean.java b/common/src/test/java/org/apache/sqoop/json/TestDriverConfigBean.java new file mode 100644 index 0000000..4309f10 --- /dev/null +++ b/common/src/test/java/org/apache/sqoop/json/TestDriverConfigBean.java @@ -0,0 +1,64 @@ +/** + * 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.sqoop.json; + +import org.apache.sqoop.model.MDriverConfig; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; +import org.junit.Test; + +import java.util.ResourceBundle; + +import static org.apache.sqoop.json.TestUtil.*; + + +import static org.junit.Assert.*; + +/** + * + */ +public class TestDriverConfigBean { + + /** + * Test that by JSON serialization followed by deserialization we will get + * equal framework object. + */ + @Test + public void testSerialization() { + MDriverConfig driverConfig = getDriverConfig(); + + // Serialize it to JSON object + DriverConfigBean bean = new DriverConfigBean(driverConfig, getResourceBundle()); + JSONObject json = bean.extract(false); + + // "Move" it across network in text form + String string = json.toJSONString(); + + // Retrieved transferred object + JSONObject retrievedJson = (JSONObject) JSONValue.parse(string); + DriverConfigBean retrievedBean = new DriverConfigBean(); + retrievedBean.restore(retrievedJson); + + assertEquals(driverConfig, retrievedBean.getDriverConfig()); + + ResourceBundle retrievedBundle = retrievedBean.getResourceBundle(); + assertEquals("a", retrievedBundle.getString("a")); + assertEquals("b", retrievedBundle.getString("b")); + } + +} http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/common/src/test/java/org/apache/sqoop/json/TestFrameworkBean.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/json/TestFrameworkBean.java b/common/src/test/java/org/apache/sqoop/json/TestFrameworkBean.java deleted file mode 100644 index 5cc110a..0000000 --- a/common/src/test/java/org/apache/sqoop/json/TestFrameworkBean.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * 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.sqoop.json; - -import org.apache.sqoop.model.MFramework; -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; -import org.junit.Test; - -import java.util.ResourceBundle; - -import static org.apache.sqoop.json.TestUtil.*; - - -import static org.junit.Assert.*; - -/** - * - */ -public class TestFrameworkBean { - - /** - * Test that by JSON serialization followed by deserialization we will get - * equal framework object. - */ - @Test - public void testSerialization() { - MFramework framework = getFramework(); - - // Serialize it to JSON object - FrameworkBean bean = new FrameworkBean(framework, getResourceBundle()); - JSONObject json = bean.extract(false); - - // "Move" it across network in text form - String string = json.toJSONString(); - - // Retrieved transferred object - JSONObject retrievedJson = (JSONObject) JSONValue.parse(string); - FrameworkBean retrievedBean = new FrameworkBean(); - retrievedBean.restore(retrievedJson); - - assertEquals(framework, retrievedBean.getFramework()); - - ResourceBundle retrievedBundle = retrievedBean.getResourceBundle(); - assertEquals("a", retrievedBundle.getString("a")); - assertEquals("b", retrievedBundle.getString("b")); - } - -} http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/common/src/test/java/org/apache/sqoop/json/TestJobBean.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/json/TestJobBean.java b/common/src/test/java/org/apache/sqoop/json/TestJobBean.java index 3106d39..c6461bf 100644 --- a/common/src/test/java/org/apache/sqoop/json/TestJobBean.java +++ b/common/src/test/java/org/apache/sqoop/json/TestJobBean.java @@ -68,8 +68,8 @@ public class TestJobBean { // Check id and name assertEquals(666, target.getPersistenceId()); - assertEquals(target.getConnectionId(Direction.FROM), 1); - assertEquals(target.getConnectionId(Direction.TO), 2); + assertEquals(target.getLinkId(Direction.FROM), 1); + assertEquals(target.getLinkId(Direction.TO), 2); assertEquals(target.getConnectorId(Direction.FROM), 1); assertEquals(target.getConnectorId(Direction.TO), 2); assertEquals("The big job", target.getName()); http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/common/src/test/java/org/apache/sqoop/json/TestLinkBean.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/json/TestLinkBean.java b/common/src/test/java/org/apache/sqoop/json/TestLinkBean.java new file mode 100644 index 0000000..8235275 --- /dev/null +++ b/common/src/test/java/org/apache/sqoop/json/TestLinkBean.java @@ -0,0 +1,138 @@ +/** + * 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.sqoop.json; + +import org.apache.sqoop.model.MLink; +import org.apache.sqoop.model.MStringInput; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.JSONArray; +import org.json.simple.JSONValue; +import org.junit.Test; + +import java.util.Date; + +import static junit.framework.Assert.*; +import static org.apache.sqoop.json.TestUtil.*; + +/** + * + */ +public class TestLinkBean { + @Test + public void testSerialization() { + Date created = new Date(); + Date updated = new Date(); + MLink link = getLink("ahoj"); + link.setName("Connection"); + link.setPersistenceId(666); + link.setCreationUser("admin"); + link.setCreationDate(created); + link.setLastUpdateUser("user"); + link.setLastUpdateDate(updated); + link.setEnabled(false); + + // Fill some data at the beginning + MStringInput input = (MStringInput) link.getConnectorPart().getForms() + .get(0).getInputs().get(0); + input.setValue("Hi there!"); + + // Serialize it to JSON object + LinkBean bean = new LinkBean(link); + JSONObject json = bean.extract(false); + + // Check for sensitivity + JSONArray all = (JSONArray)json.get("all"); + JSONObject allItem = (JSONObject)all.get(0); + JSONArray connectors = (JSONArray)allItem.get("connector"); + JSONObject connector = (JSONObject)connectors.get(0); + JSONArray inputs = (JSONArray)connector.get("inputs"); + for (Object input1 : inputs) { + assertTrue(((JSONObject)input1).containsKey("sensitive")); + } + + // "Move" it across network in text form + String string = json.toJSONString(); + + // Retrieved transferred object + JSONObject retrievedJson = (JSONObject) JSONValue.parse(string); + LinkBean retrievedBean = new LinkBean(); + retrievedBean.restore(retrievedJson); + MLink target = retrievedBean.getLinks().get(0); + + // Check id and name + assertEquals(666, target.getPersistenceId()); + assertEquals("Connection", target.getName()); + assertEquals("admin", target.getCreationUser()); + assertEquals(created, target.getCreationDate()); + assertEquals("user", target.getLastUpdateUser()); + assertEquals(updated, target.getLastUpdateDate()); + assertEquals(false, target.getEnabled()); + + // Test that value was correctly moved + MStringInput targetInput = (MStringInput) target.getConnectorPart() + .getForms().get(0).getInputs().get(0); + assertEquals("Hi there!", targetInput.getValue()); + } + + @Test + public void testSensitivityFilter() { + Date created = new Date(); + Date updated = new Date(); + MLink link = getLink("ahoj"); + link.setName("Connection"); + link.setPersistenceId(666); + link.setCreationUser("admin"); + link.setCreationDate(created); + link.setLastUpdateUser("user"); + link.setLastUpdateDate(updated); + link.setEnabled(true); + + // Fill some data at the beginning + MStringInput input = (MStringInput) link.getConnectorPart().getForms() + .get(0).getInputs().get(0); + input.setValue("Hi there!"); + + // Serialize it to JSON object + LinkBean bean = new LinkBean(link); + JSONObject json = bean.extract(false); + JSONObject jsonFiltered = bean.extract(true); + + // Sensitive values should exist + JSONArray all = (JSONArray)json.get("all"); + JSONObject allItem = (JSONObject)all.get(0); + JSONArray connectors = (JSONArray)allItem.get("connector"); + JSONObject connector = (JSONObject)connectors.get(0); + JSONArray inputs = (JSONArray)connector.get("inputs"); + assertEquals(3, inputs.size()); + // Inputs are ordered when creating link + JSONObject password = (JSONObject)inputs.get(2); + assertTrue(password.containsKey("value")); + + // Sensitive values should not exist + all = (JSONArray)jsonFiltered.get("all"); + allItem = (JSONObject)all.get(0); + connectors = (JSONArray)allItem.get("connector"); + connector = (JSONObject)connectors.get(0); + inputs = (JSONArray)connector.get("inputs"); + assertEquals(3, inputs.size()); + // Inputs are ordered when creating link + password = (JSONObject)inputs.get(2); + assertFalse(password.containsKey("value")); + } +} http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/common/src/test/java/org/apache/sqoop/json/TestUtil.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/json/TestUtil.java b/common/src/test/java/org/apache/sqoop/json/TestUtil.java index a9aa233..eaf9122 100644 --- a/common/src/test/java/org/apache/sqoop/json/TestUtil.java +++ b/common/src/test/java/org/apache/sqoop/json/TestUtil.java @@ -18,11 +18,11 @@ package org.apache.sqoop.json; import org.apache.sqoop.common.Direction; -import org.apache.sqoop.model.MConnection; +import org.apache.sqoop.model.MLink; import org.apache.sqoop.model.MConnectionForms; import org.apache.sqoop.model.MConnector; import org.apache.sqoop.model.MForm; -import org.apache.sqoop.model.MFramework; +import org.apache.sqoop.model.MDriverConfig; import org.apache.sqoop.model.MInput; import org.apache.sqoop.model.MJob; import org.apache.sqoop.model.MJobForms; @@ -44,23 +44,18 @@ public class TestUtil { getConnectionForms(), getJobForms(), getJobForms()); } - public static MFramework getFramework() { - return new MFramework(getConnectionForms(), getJobForms(), "1"); + public static MDriverConfig getDriverConfig() { + return new MDriverConfig(getConnectionForms(), getJobForms(), "1"); } - public static MConnection getConnection(String name) { - return new MConnection(1, - getConnector(name).getConnectionForms(), - getFramework().getConnectionForms() - ); + public static MLink getLink(String name) { + return new MLink(1, getConnector(name).getConnectionForms(), getDriverConfig() + .getConnectionForms()); } public static MJob getJob(String name) { - return new MJob(1, 2, 1, 2, - getConnector(name).getJobForms(Direction.FROM), - getConnector(name).getJobForms(Direction.TO), - getFramework().getJobForms() - ); + return new MJob(1, 2, 1, 2, getConnector(name).getJobForms(Direction.FROM), getConnector(name) + .getJobForms(Direction.TO), getDriverConfig().getJobForms()); } public static MConnectionForms getConnectionForms() { http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/common/src/test/java/org/apache/sqoop/json/TestValidationBean.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/json/TestValidationBean.java b/common/src/test/java/org/apache/sqoop/json/TestValidationBean.java index c6086dd..f5f3389 100644 --- a/common/src/test/java/org/apache/sqoop/json/TestValidationBean.java +++ b/common/src/test/java/org/apache/sqoop/json/TestValidationBean.java @@ -102,9 +102,9 @@ public class TestValidationBean { } @Test - public void testConnectionValidationBeanSerialization() { + public void testLinkValidationBeanSerialization() { // Serialize it to JSON object - ConnectionValidationBean bean = new ConnectionValidationBean( + LinkValidationBean bean = new LinkValidationBean( getValidation(Status.FINE), getValidation(Status.UNACCEPTABLE) ); @@ -115,7 +115,7 @@ public class TestValidationBean { // Retrieved transferred object JSONObject retrievedJson = (JSONObject) JSONValue.parse(string); - ConnectionValidationBean retrievedBean = new ConnectionValidationBean(); + LinkValidationBean retrievedBean = new LinkValidationBean(); retrievedBean.restore(retrievedJson); assertNull(retrievedBean.getId()); @@ -139,9 +139,9 @@ public class TestValidationBean { } @Test - public void testConnectionValidationBeanId() { + public void testLinkValidationBeanId() { // Serialize it to JSON object - ConnectionValidationBean bean = new ConnectionValidationBean( + LinkValidationBean bean = new LinkValidationBean( getValidation(Status.FINE), getValidation(Status.FINE) ); @@ -153,7 +153,7 @@ public class TestValidationBean { // Retrieved transferred object JSONObject retrievedJson = (JSONObject) JSONValue.parse(string); - ConnectionValidationBean retrievedBean = new ConnectionValidationBean(); + LinkValidationBean retrievedBean = new LinkValidationBean(); retrievedBean.restore(retrievedJson); assertEquals((Long)(long) 10, retrievedBean.getId()); http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/common/src/test/java/org/apache/sqoop/model/TestMAccountableEntity.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/model/TestMAccountableEntity.java b/common/src/test/java/org/apache/sqoop/model/TestMAccountableEntity.java index f3d4166..d56e165 100644 --- a/common/src/test/java/org/apache/sqoop/model/TestMAccountableEntity.java +++ b/common/src/test/java/org/apache/sqoop/model/TestMAccountableEntity.java @@ -41,21 +41,21 @@ public class TestMAccountableEntity { list.add(input); MForm form = new MForm("FORMNAME", list); forms.add(form); - MAccountableEntity connection = new MConnection(123l, new MConnectionForms( + MAccountableEntity link = new MLink(123l, new MConnectionForms( forms), new MConnectionForms(forms)); // Initially creation date and last update date is same - assertEquals(connection.getCreationDate(), connection.getLastUpdateDate()); + assertEquals(link.getCreationDate(), link.getLastUpdateDate()); Date testCreationDate = new Date(); Date testLastUpdateDate = new Date(); - connection.setCreationUser("admin"); - connection.setCreationDate(testCreationDate); - connection.setLastUpdateUser("user"); - connection.setLastUpdateDate(testLastUpdateDate); - connection.setEnabled(false); - assertEquals(testCreationDate, connection.getCreationDate()); - assertEquals("admin", connection.getCreationUser()); - assertEquals(testLastUpdateDate, connection.getLastUpdateDate()); - assertEquals(false, connection.getEnabled()); - assertEquals("user", connection.getLastUpdateUser()); + link.setCreationUser("admin"); + link.setCreationDate(testCreationDate); + link.setLastUpdateUser("user"); + link.setLastUpdateDate(testLastUpdateDate); + link.setEnabled(false); + assertEquals(testCreationDate, link.getCreationDate()); + assertEquals("admin", link.getCreationUser()); + assertEquals(testLastUpdateDate, link.getLastUpdateDate()); + assertEquals(false, link.getEnabled()); + assertEquals("user", link.getLastUpdateUser()); } } http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/common/src/test/java/org/apache/sqoop/model/TestMConnection.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/model/TestMConnection.java b/common/src/test/java/org/apache/sqoop/model/TestMConnection.java deleted file mode 100644 index 27959fb..0000000 --- a/common/src/test/java/org/apache/sqoop/model/TestMConnection.java +++ /dev/null @@ -1,122 +0,0 @@ -/** - * 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.sqoop.model; - -import static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; - -/** - * Test class for org.apache.sqoop.model.MConnection - */ -public class TestMConnection { - - /** - * Test for initialization - */ - @Test - public void testInitialization() { - // Test default constructor - MConnection connection = connection(); - assertEquals(123l, connection.getConnectorId()); - assertEquals("Vampire", connection.getName()); - assertEquals("Buffy", connection.getCreationUser()); - assertEquals(forms1(), connection.getConnectorPart()); - assertEquals(forms2(), connection.getFrameworkPart()); - - // Test copy constructor - MConnection copy = new MConnection(connection); - assertEquals(123l, copy.getConnectorId()); - assertEquals("Vampire", copy.getName()); - assertEquals("Buffy", copy.getCreationUser()); - assertEquals(connection.getCreationDate(), copy.getCreationDate()); - assertEquals(forms1(), copy.getConnectorPart()); - assertEquals(forms2(), copy.getFrameworkPart()); - - // Test constructor for metadata upgrade (the order of forms is different) - MConnection upgradeCopy = new MConnection(connection, forms2(), forms1()); - assertEquals(123l, upgradeCopy.getConnectorId()); - assertEquals("Vampire", upgradeCopy.getName()); - assertEquals("Buffy", upgradeCopy.getCreationUser()); - assertEquals(connection.getCreationDate(), upgradeCopy.getCreationDate()); - assertEquals(forms2(), upgradeCopy.getConnectorPart()); - assertEquals(forms1(), upgradeCopy.getFrameworkPart()); - } - - @Test - public void testClone() { - MConnection connection = connection(); - - // Clone without value - MConnection withoutValue = connection.clone(false); - assertEquals(connection, withoutValue); - assertEquals(MPersistableEntity.PERSISTANCE_ID_DEFAULT, withoutValue.getPersistenceId()); - assertNull(withoutValue.getName()); - assertNull(withoutValue.getCreationUser()); - assertEquals(forms1(), withoutValue.getConnectorPart()); - assertEquals(forms2(), withoutValue.getFrameworkPart()); - assertNull(withoutValue.getConnectorPart().getForm("FORMNAME").getInput("INTEGER-INPUT").getValue()); - assertNull(withoutValue.getConnectorPart().getForm("FORMNAME").getInput("STRING-INPUT").getValue()); - - // Clone with value - MConnection withValue = connection.clone(true); - assertEquals(connection, withValue); - assertEquals(connection.getPersistenceId(), withValue.getPersistenceId()); - assertEquals(connection.getName(), withValue.getName()); - assertEquals(connection.getCreationUser(), withValue.getCreationUser()); - assertEquals(forms1(), withValue.getConnectorPart()); - assertEquals(forms2(), withValue.getFrameworkPart()); - assertEquals(100, withValue.getConnectorPart().getForm("FORMNAME").getInput("INTEGER-INPUT").getValue()); - assertEquals("TEST-VALUE", withValue.getConnectorPart().getForm("FORMNAME").getInput("STRING-INPUT").getValue()); - } - - private MConnection connection() { - MConnection connection = new MConnection(123l, forms1(), forms2()); - connection.setName("Vampire"); - connection.setCreationUser("Buffy"); - return connection; - } - - private MConnectionForms forms1() { - List<MForm> forms = new ArrayList<MForm>(); - MIntegerInput input = new MIntegerInput("INTEGER-INPUT", false); - input.setValue(100); - MStringInput strInput = new MStringInput("STRING-INPUT",false,(short)20); - strInput.setValue("TEST-VALUE"); - List<MInput<?>> list = new ArrayList<MInput<?>>(); - list.add(input); - list.add(strInput); - MForm form = new MForm("FORMNAME", list); - forms.add(form); - return new MConnectionForms(forms); - } - - private MConnectionForms forms2() { - List<MForm> forms = new ArrayList<MForm>(); - MMapInput input = new MMapInput("MAP-INPUT", false); - List<MInput<?>> list = new ArrayList<MInput<?>>(); - list.add(input); - MForm form = new MForm("form", list); - forms.add(form); - return new MConnectionForms(forms); - } - -} http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/common/src/test/java/org/apache/sqoop/model/TestMDriverConfig.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/model/TestMDriverConfig.java b/common/src/test/java/org/apache/sqoop/model/TestMDriverConfig.java new file mode 100644 index 0000000..9c23cc3 --- /dev/null +++ b/common/src/test/java/org/apache/sqoop/model/TestMDriverConfig.java @@ -0,0 +1,47 @@ +/** + * 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.sqoop.model; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; + +/** + * + */ +public class TestMDriverConfig { + + @Test + public void testForms() { + List<MForm> connectionFormList = new ArrayList<MForm>(); + List<MForm> jobFormList = new ArrayList<MForm>(); + connectionFormList.add(new MForm("connection-test", new ArrayList<MInput<?>>())); + jobFormList.add(new MForm("job-test", new ArrayList<MInput<?>>())); + MConnectionForms connectionForms = new MConnectionForms(connectionFormList); + MJobForms jobForms = new MJobForms(jobFormList); + + MDriverConfig driver = new MDriverConfig(connectionForms, jobForms, "1"); + assertEquals(1, driver.getJobForms().getForms().size()); + assertEquals("job-test", driver.getJobForms().getForms().get(0).getName()); + assertEquals(1, driver.getConnectionForms().getForms().size()); + assertEquals("connection-test", driver.getConnectionForms().getForms().get(0).getName()); + } +} http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/common/src/test/java/org/apache/sqoop/model/TestMFramework.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/model/TestMFramework.java b/common/src/test/java/org/apache/sqoop/model/TestMFramework.java deleted file mode 100644 index 5273a90..0000000 --- a/common/src/test/java/org/apache/sqoop/model/TestMFramework.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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.sqoop.model; - -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.*; - -/** - * - */ -public class TestMFramework { - - @Test - public void testForms() { - List<MForm> connectionFormList = new ArrayList<MForm>(); - List<MForm> jobFormList = new ArrayList<MForm>(); - connectionFormList.add(new MForm("connection-test", new ArrayList<MInput<?>>())); - jobFormList.add(new MForm("job-test", new ArrayList<MInput<?>>())); - MConnectionForms connectionForms = new MConnectionForms(connectionFormList); - MJobForms jobForms = new MJobForms(jobFormList); - - MFramework framework = new MFramework(connectionForms, jobForms, "1"); - assertEquals(1, framework.getJobForms().getForms().size()); - assertEquals("job-test", framework.getJobForms().getForms().get(0).getName()); - assertEquals(1, framework.getConnectionForms().getForms().size()); - assertEquals("connection-test", framework.getConnectionForms().getForms().get(0).getName()); - } -} http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/common/src/test/java/org/apache/sqoop/model/TestMLink.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/model/TestMLink.java b/common/src/test/java/org/apache/sqoop/model/TestMLink.java new file mode 100644 index 0000000..1be37a1 --- /dev/null +++ b/common/src/test/java/org/apache/sqoop/model/TestMLink.java @@ -0,0 +1,122 @@ +/** + * 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.sqoop.model; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +/** + * Test class for org.apache.sqoop.model.MConnection + */ +public class TestMLink { + + /** + * Test for initialization + */ + @Test + public void testInitialization() { + // Test default constructor + MLink link = link(); + assertEquals(123l, link.getConnectorId()); + assertEquals("Vampire", link.getName()); + assertEquals("Buffy", link.getCreationUser()); + assertEquals(forms1(), link.getConnectorPart()); + assertEquals(forms2(), link.getFrameworkPart()); + + // Test copy constructor + MLink copy = new MLink(link); + assertEquals(123l, copy.getConnectorId()); + assertEquals("Vampire", copy.getName()); + assertEquals("Buffy", copy.getCreationUser()); + assertEquals(link.getCreationDate(), copy.getCreationDate()); + assertEquals(forms1(), copy.getConnectorPart()); + assertEquals(forms2(), copy.getFrameworkPart()); + + // Test constructor for metadata upgrade (the order of forms is different) + MLink upgradeCopy = new MLink(link, forms2(), forms1()); + assertEquals(123l, upgradeCopy.getConnectorId()); + assertEquals("Vampire", upgradeCopy.getName()); + assertEquals("Buffy", upgradeCopy.getCreationUser()); + assertEquals(link.getCreationDate(), upgradeCopy.getCreationDate()); + assertEquals(forms2(), upgradeCopy.getConnectorPart()); + assertEquals(forms1(), upgradeCopy.getFrameworkPart()); + } + + @Test + public void testClone() { + MLink link = link(); + + // Clone without value + MLink withoutValue = link.clone(false); + assertEquals(link, withoutValue); + assertEquals(MPersistableEntity.PERSISTANCE_ID_DEFAULT, withoutValue.getPersistenceId()); + assertNull(withoutValue.getName()); + assertNull(withoutValue.getCreationUser()); + assertEquals(forms1(), withoutValue.getConnectorPart()); + assertEquals(forms2(), withoutValue.getFrameworkPart()); + assertNull(withoutValue.getConnectorPart().getForm("FORMNAME").getInput("INTEGER-INPUT").getValue()); + assertNull(withoutValue.getConnectorPart().getForm("FORMNAME").getInput("STRING-INPUT").getValue()); + + // Clone with value + MLink withValue = link.clone(true); + assertEquals(link, withValue); + assertEquals(link.getPersistenceId(), withValue.getPersistenceId()); + assertEquals(link.getName(), withValue.getName()); + assertEquals(link.getCreationUser(), withValue.getCreationUser()); + assertEquals(forms1(), withValue.getConnectorPart()); + assertEquals(forms2(), withValue.getFrameworkPart()); + assertEquals(100, withValue.getConnectorPart().getForm("FORMNAME").getInput("INTEGER-INPUT").getValue()); + assertEquals("TEST-VALUE", withValue.getConnectorPart().getForm("FORMNAME").getInput("STRING-INPUT").getValue()); + } + + private MLink link() { + MLink link = new MLink(123l, forms1(), forms2()); + link.setName("Vampire"); + link.setCreationUser("Buffy"); + return link; + } + + private MConnectionForms forms1() { + List<MForm> forms = new ArrayList<MForm>(); + MIntegerInput input = new MIntegerInput("INTEGER-INPUT", false); + input.setValue(100); + MStringInput strInput = new MStringInput("STRING-INPUT",false,(short)20); + strInput.setValue("TEST-VALUE"); + List<MInput<?>> list = new ArrayList<MInput<?>>(); + list.add(input); + list.add(strInput); + MForm form = new MForm("FORMNAME", list); + forms.add(form); + return new MConnectionForms(forms); + } + + private MConnectionForms forms2() { + List<MForm> forms = new ArrayList<MForm>(); + MMapInput input = new MMapInput("MAP-INPUT", false); + List<MInput<?>> list = new ArrayList<MInput<?>>(); + list.add(input); + MForm form = new MForm("form", list); + forms.add(form); + return new MConnectionForms(forms); + } + +} http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java index 3790daa..b4b6966 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java @@ -22,10 +22,10 @@ import java.util.ResourceBundle; import org.apache.sqoop.common.Direction; import org.apache.sqoop.common.VersionInfo; -import org.apache.sqoop.connector.jdbc.configuration.ConnectionConfiguration; +import org.apache.sqoop.connector.jdbc.configuration.LinkConfiguration; import org.apache.sqoop.connector.jdbc.configuration.FromJobConfiguration; import org.apache.sqoop.connector.jdbc.configuration.ToJobConfiguration; -import org.apache.sqoop.connector.spi.MetadataUpgrader; +import org.apache.sqoop.connector.spi.RepositoryUpgrader; import org.apache.sqoop.job.etl.From; import org.apache.sqoop.job.etl.To; import org.apache.sqoop.connector.spi.SqoopConnector; @@ -65,8 +65,8 @@ public class GenericJdbcConnector extends SqoopConnector { } @Override - public Class getConnectionConfigurationClass() { - return ConnectionConfiguration.class; + public Class getLinkConfigurationClass() { + return LinkConfiguration.class; } @Override @@ -97,8 +97,8 @@ public class GenericJdbcConnector extends SqoopConnector { } @Override - public MetadataUpgrader getMetadataUpgrader() { - return new GenericJdbcConnectorMetadataUpgrader(); + public RepositoryUpgrader getRepositoryUpgrader() { + return new GenericJdbcConnectorUpgrader(); } } http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnectorConstants.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnectorConstants.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnectorConstants.java index 62da2db..f63f013 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnectorConstants.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnectorConstants.java @@ -24,7 +24,7 @@ public final class GenericJdbcConnectorConstants { // Resource bundle name public static final String RESOURCE_BUNDLE_NAME = - "generic-jdbc-connector-resources"; + "generic-jdbc-connector-config"; /* * All jdbc connector related configuration is prefixed with this: http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnectorMetadataUpgrader.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnectorMetadataUpgrader.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnectorMetadataUpgrader.java deleted file mode 100644 index cbe72f6..0000000 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnectorMetadataUpgrader.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.sqoop.connector.jdbc; - -import org.apache.log4j.Logger; -import org.apache.sqoop.common.SqoopException; -import org.apache.sqoop.connector.spi.MetadataUpgrader; -import org.apache.sqoop.model.MConnectionForms; -import org.apache.sqoop.model.MForm; -import org.apache.sqoop.model.MInput; -import org.apache.sqoop.model.MJobForms; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class GenericJdbcConnectorMetadataUpgrader extends MetadataUpgrader { - private static final Logger LOG = - Logger.getLogger(GenericJdbcConnectorMetadataUpgrader.class); - - /* - * For now, there is no real upgrade. So copy all data over, - * set the validation messages and error messages to be the same as for the - * inputs in the original one. - */ - - @Override - public void upgrade(MConnectionForms original, - MConnectionForms upgradeTarget) { - doUpgrade(original.getForms(), upgradeTarget.getForms()); - } - - @Override - public void upgrade(MJobForms original, MJobForms upgradeTarget) { - doUpgrade(original.getForms(), upgradeTarget.getForms()); - } - - @SuppressWarnings("unchecked") - private void doUpgrade(List<MForm> original, List<MForm> target) { - // Easier to find the form in the original forms list if we use a map. - // Since the constructor of MJobForms takes a list, - // index is not guaranteed to be the same, so we need to look for - // equivalence - Map<String, MForm> formMap = new HashMap<String, MForm>(); - for (MForm form : original) { - formMap.put(form.getName(), form); - } - for (MForm form : target) { - List<MInput<?>> inputs = form.getInputs(); - MForm originalForm = formMap.get(form.getName()); - if (originalForm == null) { - LOG.warn("Form: '" + form.getName() + "' not present in old " + - "connector. So it and its inputs will not be transferred by the upgrader."); - continue; - } - for (MInput input : inputs) { - try { - MInput originalInput = originalForm.getInput(input.getName()); - input.setValue(originalInput.getValue()); - } catch (SqoopException ex) { - LOG.warn("Input: '" + input.getName() + "' not present in old " + - "connector. So it will not be transferred by the upgrader."); - } - } - } - } -} http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnectorUpgrader.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnectorUpgrader.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnectorUpgrader.java new file mode 100644 index 0000000..8deddb0 --- /dev/null +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnectorUpgrader.java @@ -0,0 +1,83 @@ +/* + * 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.sqoop.connector.jdbc; + +import org.apache.log4j.Logger; +import org.apache.sqoop.common.SqoopException; +import org.apache.sqoop.connector.spi.RepositoryUpgrader; +import org.apache.sqoop.model.MConnectionForms; +import org.apache.sqoop.model.MForm; +import org.apache.sqoop.model.MInput; +import org.apache.sqoop.model.MJobForms; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class GenericJdbcConnectorUpgrader extends RepositoryUpgrader { + private static final Logger LOG = + Logger.getLogger(GenericJdbcConnectorUpgrader.class); + + /* + * For now, there is no real upgrade. So copy all data over, + * set the validation messages and error messages to be the same as for the + * inputs in the original one. + */ + + @Override + public void upgrade(MConnectionForms original, + MConnectionForms upgradeTarget) { + doUpgrade(original.getForms(), upgradeTarget.getForms()); + } + + @Override + public void upgrade(MJobForms original, MJobForms upgradeTarget) { + doUpgrade(original.getForms(), upgradeTarget.getForms()); + } + + @SuppressWarnings("unchecked") + private void doUpgrade(List<MForm> original, List<MForm> target) { + // Easier to find the form in the original forms list if we use a map. + // Since the constructor of MJobForms takes a list, + // index is not guaranteed to be the same, so we need to look for + // equivalence + Map<String, MForm> formMap = new HashMap<String, MForm>(); + for (MForm form : original) { + formMap.put(form.getName(), form); + } + for (MForm form : target) { + List<MInput<?>> inputs = form.getInputs(); + MForm originalForm = formMap.get(form.getName()); + if (originalForm == null) { + LOG.warn("Form: '" + form.getName() + "' not present in old " + + "connector. So it and its inputs will not be transferred by the upgrader."); + continue; + } + for (MInput input : inputs) { + try { + MInput originalInput = originalForm.getInput(input.getName()); + input.setValue(originalInput.getValue()); + } catch (SqoopException ex) { + LOG.warn("Input: '" + input.getName() + "' not present in old " + + "connector. So it will not be transferred by the upgrader."); + } + } + } + } +} http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcExtractor.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcExtractor.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcExtractor.java index 9915603..e52610a 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcExtractor.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcExtractor.java @@ -23,22 +23,23 @@ import java.sql.SQLException; import org.apache.log4j.Logger; import org.apache.sqoop.common.SqoopException; -import org.apache.sqoop.connector.jdbc.configuration.ConnectionConfiguration; +import org.apache.sqoop.connector.jdbc.configuration.LinkConfiguration; import org.apache.sqoop.connector.jdbc.configuration.FromJobConfiguration; import org.apache.sqoop.job.etl.ExtractorContext; import org.apache.sqoop.job.etl.Extractor; -public class GenericJdbcExtractor extends Extractor<ConnectionConfiguration, FromJobConfiguration, GenericJdbcPartition> { +public class GenericJdbcExtractor extends Extractor<LinkConfiguration, FromJobConfiguration, GenericJdbcPartition> { public static final Logger LOG = Logger.getLogger(GenericJdbcExtractor.class); private long rowsRead = 0; @Override - public void extract(ExtractorContext context, ConnectionConfiguration connection, FromJobConfiguration job, GenericJdbcPartition partition) { - String driver = connection.connection.jdbcDriver; - String url = connection.connection.connectionString; - String username = connection.connection.username; - String password = connection.connection.password; + public void extract(ExtractorContext context, LinkConfiguration linkConf, + FromJobConfiguration fromJobConf, GenericJdbcPartition partition) { + String driver = linkConf.link.jdbcDriver; + String url = linkConf.link.connectionString; + String username = linkConf.link.username; + String password = linkConf.link.password; GenericJdbcExecutor executor = new GenericJdbcExecutor(driver, url, username, password); String query = context.getString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_FROM_DATA_SQL); http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcFromDestroyer.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcFromDestroyer.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcFromDestroyer.java index 2df193c..d3a893f 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcFromDestroyer.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcFromDestroyer.java @@ -18,18 +18,18 @@ package org.apache.sqoop.connector.jdbc; import org.apache.log4j.Logger; -import org.apache.sqoop.connector.jdbc.configuration.ConnectionConfiguration; +import org.apache.sqoop.connector.jdbc.configuration.LinkConfiguration; import org.apache.sqoop.connector.jdbc.configuration.FromJobConfiguration; import org.apache.sqoop.job.etl.Destroyer; import org.apache.sqoop.job.etl.DestroyerContext; -public class GenericJdbcFromDestroyer extends Destroyer<ConnectionConfiguration, FromJobConfiguration> { +public class GenericJdbcFromDestroyer extends Destroyer<LinkConfiguration, FromJobConfiguration> { private static final Logger LOG = Logger.getLogger(GenericJdbcFromDestroyer.class); @Override - public void destroy(DestroyerContext context, ConnectionConfiguration connection, FromJobConfiguration job) { + public void destroy(DestroyerContext context, LinkConfiguration linkConf, FromJobConfiguration fromJobConf) { LOG.info("Running generic JDBC connector destroyer"); } http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcFromInitializer.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcFromInitializer.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcFromInitializer.java index 87e0862..9d0c178 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcFromInitializer.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcFromInitializer.java @@ -27,7 +27,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.apache.sqoop.common.MutableContext; import org.apache.sqoop.common.SqoopException; -import org.apache.sqoop.connector.jdbc.configuration.ConnectionConfiguration; +import org.apache.sqoop.connector.jdbc.configuration.LinkConfiguration; import org.apache.sqoop.connector.jdbc.configuration.FromJobConfiguration; import org.apache.sqoop.connector.jdbc.util.SqlTypesUtils; import org.apache.sqoop.job.Constants; @@ -37,7 +37,7 @@ import org.apache.sqoop.schema.Schema; import org.apache.sqoop.schema.type.Column; import org.apache.sqoop.utils.ClassUtils; -public class GenericJdbcFromInitializer extends Initializer<ConnectionConfiguration, FromJobConfiguration> { +public class GenericJdbcFromInitializer extends Initializer<LinkConfiguration, FromJobConfiguration> { private static final Logger LOG = Logger.getLogger(GenericJdbcFromInitializer.class); @@ -45,34 +45,34 @@ public class GenericJdbcFromInitializer extends Initializer<ConnectionConfigurat private GenericJdbcExecutor executor; @Override - public void initialize(InitializerContext context, ConnectionConfiguration connection, FromJobConfiguration job) { - configureJdbcProperties(context.getContext(), connection, job); + public void initialize(InitializerContext context, LinkConfiguration linkConf, FromJobConfiguration fromJobConf) { + configureJdbcProperties(context.getContext(), linkConf, fromJobConf); try { - configurePartitionProperties(context.getContext(), connection, job); - configureTableProperties(context.getContext(), connection, job); + configurePartitionProperties(context.getContext(), linkConf, fromJobConf); + configureTableProperties(context.getContext(), linkConf, fromJobConf); } finally { executor.close(); } } @Override - public List<String> getJars(InitializerContext context, ConnectionConfiguration connection, FromJobConfiguration job) { + public List<String> getJars(InitializerContext context, LinkConfiguration linkConf, FromJobConfiguration fromJobConf) { List<String> jars = new LinkedList<String>(); - jars.add(ClassUtils.jarForClass(connection.connection.jdbcDriver)); + jars.add(ClassUtils.jarForClass(linkConf.link.jdbcDriver)); return jars; } @Override - public Schema getSchema(InitializerContext context, ConnectionConfiguration connectionConfiguration, FromJobConfiguration fromJobConfiguration) { - configureJdbcProperties(context.getContext(), connectionConfiguration, fromJobConfiguration); + public Schema getSchema(InitializerContext context, LinkConfiguration linkConf, FromJobConfiguration fromJobConf) { + configureJdbcProperties(context.getContext(), linkConf, fromJobConf); - String schemaName = fromJobConfiguration.fromTable.tableName; + String schemaName = fromJobConf.fromJobConfig.tableName; if(schemaName == null) { schemaName = "Query"; - } else if(fromJobConfiguration.fromTable.schemaName != null) { - schemaName = fromJobConfiguration.fromTable.schemaName + "." + schemaName; + } else if(fromJobConf.fromJobConfig.schemaName != null) { + schemaName = fromJobConf.fromJobConfig.schemaName + "." + schemaName; } Schema schema = new Schema(schemaName); @@ -117,11 +117,11 @@ public class GenericJdbcFromInitializer extends Initializer<ConnectionConfigurat } } - private void configureJdbcProperties(MutableContext context, ConnectionConfiguration connectionConfig, FromJobConfiguration jobConfig) { - String driver = connectionConfig.connection.jdbcDriver; - String url = connectionConfig.connection.connectionString; - String username = connectionConfig.connection.username; - String password = connectionConfig.connection.password; + private void configureJdbcProperties(MutableContext context, LinkConfiguration connectionConfig, FromJobConfiguration fromJobConfig) { + String driver = connectionConfig.link.jdbcDriver; + String url = connectionConfig.link.connectionString; + String username = connectionConfig.link.username; + String password = connectionConfig.link.password; assert driver != null; assert url != null; @@ -129,15 +129,15 @@ public class GenericJdbcFromInitializer extends Initializer<ConnectionConfigurat executor = new GenericJdbcExecutor(driver, url, username, password); } - private void configurePartitionProperties(MutableContext context, ConnectionConfiguration connectionConfig, FromJobConfiguration jobConfig) { + private void configurePartitionProperties(MutableContext context, LinkConfiguration connectionConfig, FromJobConfiguration fromJobConfig) { // ----- configure column name ----- - String partitionColumnName = jobConfig.fromTable.partitionColumn; + String partitionColumnName = fromJobConfig.fromJobConfig.partitionColumn; if (partitionColumnName == null) { // if column is not specified by the user, // find the primary key of the fromTable (when there is a fromTable). - String tableName = jobConfig.fromTable.tableName; + String tableName = fromJobConfig.fromJobConfig.tableName; if (tableName != null) { partitionColumnName = executor.getPrimaryKey(tableName); } @@ -155,14 +155,14 @@ public class GenericJdbcFromInitializer extends Initializer<ConnectionConfigurat // ----- configure column type, min value, and max value ----- - String minMaxQuery = jobConfig.fromTable.boundaryQuery; + String minMaxQuery = fromJobConfig.fromJobConfig.boundaryQuery; if (minMaxQuery == null) { StringBuilder builder = new StringBuilder(); - String schemaName = jobConfig.fromTable.schemaName; - String tableName = jobConfig.fromTable.tableName; - String tableSql = jobConfig.fromTable.sql; + String schemaName = fromJobConfig.fromJobConfig.schemaName; + String tableName = fromJobConfig.fromJobConfig.tableName; + String tableSql = fromJobConfig.fromJobConfig.sql; if (tableName != null && tableSql != null) { // when both fromTable name and fromTable sql are specified: @@ -234,14 +234,14 @@ public class GenericJdbcFromInitializer extends Initializer<ConnectionConfigurat } } - private void configureTableProperties(MutableContext context, ConnectionConfiguration connectionConfig, FromJobConfiguration jobConfig) { + private void configureTableProperties(MutableContext context, LinkConfiguration connectionConfig, FromJobConfiguration fromJobConfig) { String dataSql; String fieldNames; - String schemaName = jobConfig.fromTable.schemaName; - String tableName = jobConfig.fromTable.tableName; - String tableSql = jobConfig.fromTable.sql; - String tableColumns = jobConfig.fromTable.columns; + String schemaName = fromJobConfig.fromJobConfig.schemaName; + String tableName = fromJobConfig.fromJobConfig.tableName; + String tableSql = fromJobConfig.fromJobConfig.sql; + String tableColumns = fromJobConfig.fromJobConfig.columns; if (tableName != null && tableSql != null) { // when both fromTable name and fromTable sql are specified: http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcLoader.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcLoader.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcLoader.java index 07ae988..991e686 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcLoader.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcLoader.java @@ -17,12 +17,12 @@ */ package org.apache.sqoop.connector.jdbc; -import org.apache.sqoop.connector.jdbc.configuration.ConnectionConfiguration; +import org.apache.sqoop.connector.jdbc.configuration.LinkConfiguration; import org.apache.sqoop.connector.jdbc.configuration.ToJobConfiguration; import org.apache.sqoop.job.etl.Loader; import org.apache.sqoop.job.etl.LoaderContext; -public class GenericJdbcLoader extends Loader<ConnectionConfiguration, ToJobConfiguration> { +public class GenericJdbcLoader extends Loader<LinkConfiguration, ToJobConfiguration> { public static final int DEFAULT_ROWS_PER_BATCH = 100; public static final int DEFAULT_BATCHES_PER_TRANSACTION = 100; @@ -30,11 +30,11 @@ public class GenericJdbcLoader extends Loader<ConnectionConfiguration, ToJobConf private int batchesPerTransaction = DEFAULT_BATCHES_PER_TRANSACTION; @Override - public void load(LoaderContext context, ConnectionConfiguration connection, ToJobConfiguration job) throws Exception{ - String driver = connection.connection.jdbcDriver; - String url = connection.connection.connectionString; - String username = connection.connection.username; - String password = connection.connection.password; + public void load(LoaderContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConf) throws Exception{ + String driver = linkConf.link.jdbcDriver; + String url = linkConf.link.connectionString; + String username = linkConf.link.username; + String password = linkConf.link.password; GenericJdbcExecutor executor = new GenericJdbcExecutor(driver, url, username, password); executor.setAutoCommit(false); http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcPartitioner.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcPartitioner.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcPartitioner.java index a25f344..6b11228 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcPartitioner.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcPartitioner.java @@ -28,13 +28,13 @@ import java.util.List; import java.util.TimeZone; import org.apache.sqoop.common.SqoopException; -import org.apache.sqoop.connector.jdbc.configuration.ConnectionConfiguration; +import org.apache.sqoop.connector.jdbc.configuration.LinkConfiguration; import org.apache.sqoop.connector.jdbc.configuration.FromJobConfiguration; import org.apache.sqoop.job.etl.Partition; import org.apache.sqoop.job.etl.Partitioner; import org.apache.sqoop.job.etl.PartitionerContext; -public class GenericJdbcPartitioner extends Partitioner<ConnectionConfiguration, FromJobConfiguration> { +public class GenericJdbcPartitioner extends Partitioner<LinkConfiguration, FromJobConfiguration> { private static final BigDecimal NUMERIC_MIN_INCREMENT = new BigDecimal(10000 * Double.MIN_VALUE); @@ -47,7 +47,7 @@ public class GenericJdbcPartitioner extends Partitioner<ConnectionConfiguration, private Boolean partitionColumnNull; @Override - public List<Partition> getPartitions(PartitionerContext context,ConnectionConfiguration connection, FromJobConfiguration job) { + public List<Partition> getPartitions(PartitionerContext context,LinkConfiguration linkConf, FromJobConfiguration fromJobConf) { List<Partition> partitions = new LinkedList<Partition>(); numberPartitions = context.getMaxPartitions(); @@ -56,7 +56,7 @@ public class GenericJdbcPartitioner extends Partitioner<ConnectionConfiguration, partitionMinValue = context.getString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MINVALUE); partitionMaxValue = context.getString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE); - partitionColumnNull = job.fromTable.partitionColumnNull; + partitionColumnNull = fromJobConf.fromJobConfig.partitionColumnNull; if (partitionColumnNull == null) { partitionColumnNull = false; } http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToDestroyer.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToDestroyer.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToDestroyer.java index 4ba278e..7bed1d9 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToDestroyer.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToDestroyer.java @@ -18,36 +18,36 @@ package org.apache.sqoop.connector.jdbc; import org.apache.log4j.Logger; -import org.apache.sqoop.connector.jdbc.configuration.ConnectionConfiguration; +import org.apache.sqoop.connector.jdbc.configuration.LinkConfiguration; import org.apache.sqoop.connector.jdbc.configuration.ToJobConfiguration; import org.apache.sqoop.job.etl.Destroyer; import org.apache.sqoop.job.etl.DestroyerContext; -public class GenericJdbcToDestroyer extends Destroyer<ConnectionConfiguration, ToJobConfiguration> { +public class GenericJdbcToDestroyer extends Destroyer<LinkConfiguration, ToJobConfiguration> { private static final Logger LOG = Logger.getLogger(GenericJdbcToDestroyer.class); @Override - public void destroy(DestroyerContext context, ConnectionConfiguration connection, ToJobConfiguration job) { + public void destroy(DestroyerContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConf) { LOG.info("Running generic JDBC connector destroyer"); - final String tableName = job.toTable.tableName; - final String stageTableName = job.toTable.stageTableName; + final String tableName = toJobConf.toJobConfig.tableName; + final String stageTableName = toJobConf.toJobConfig.stageTableName; final boolean stageEnabled = stageTableName != null && stageTableName.length() > 0; if(stageEnabled) { - moveDataToDestinationTable(connection, + moveDataToDestinationTable(linkConf, context.isSuccess(), stageTableName, tableName); } } - private void moveDataToDestinationTable(ConnectionConfiguration connectorConf, + private void moveDataToDestinationTable(LinkConfiguration linkConf, boolean success, String stageTableName, String tableName) { GenericJdbcExecutor executor = - new GenericJdbcExecutor(connectorConf.connection.jdbcDriver, - connectorConf.connection.connectionString, - connectorConf.connection.username, - connectorConf.connection.password); + new GenericJdbcExecutor(linkConf.link.jdbcDriver, + linkConf.link.connectionString, + linkConf.link.username, + linkConf.link.password); try { if(success) { LOG.info("Job completed, transferring data from stage fromTable to " + http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToInitializer.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToInitializer.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToInitializer.java index 73a49b1..5d0ec93 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToInitializer.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToInitializer.java @@ -27,7 +27,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.apache.sqoop.common.MutableContext; import org.apache.sqoop.common.SqoopException; -import org.apache.sqoop.connector.jdbc.configuration.ConnectionConfiguration; +import org.apache.sqoop.connector.jdbc.configuration.LinkConfiguration; import org.apache.sqoop.connector.jdbc.configuration.ToJobConfiguration; import org.apache.sqoop.connector.jdbc.util.SqlTypesUtils; import org.apache.sqoop.job.etl.Initializer; @@ -36,44 +36,42 @@ import org.apache.sqoop.schema.Schema; import org.apache.sqoop.schema.type.Column; import org.apache.sqoop.utils.ClassUtils; -public class GenericJdbcToInitializer extends Initializer<ConnectionConfiguration, ToJobConfiguration> { +public class GenericJdbcToInitializer extends Initializer<LinkConfiguration, ToJobConfiguration> { private GenericJdbcExecutor executor; private static final Logger LOG = Logger.getLogger(GenericJdbcToInitializer.class); @Override - public void initialize(InitializerContext context, ConnectionConfiguration connection, ToJobConfiguration job) { - configureJdbcProperties(context.getContext(), connection, job); + public void initialize(InitializerContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConf) { + configureJdbcProperties(context.getContext(), linkConf, toJobConf); try { - configureTableProperties(context.getContext(), connection, job); + configureTableProperties(context.getContext(), linkConf, toJobConf); } finally { executor.close(); } } @Override - public List<String> getJars(InitializerContext context, ConnectionConfiguration connection, ToJobConfiguration job) { + public List<String> getJars(InitializerContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConf) { List<String> jars = new LinkedList<String>(); - - jars.add(ClassUtils.jarForClass(connection.connection.jdbcDriver)); - + jars.add(ClassUtils.jarForClass(linkConf.link.jdbcDriver)); return jars; } @Override - public Schema getSchema(InitializerContext context, ConnectionConfiguration connectionConfiguration, ToJobConfiguration toJobConfiguration) { - configureJdbcProperties(context.getContext(), connectionConfiguration, toJobConfiguration); + public Schema getSchema(InitializerContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConf) { + configureJdbcProperties(context.getContext(), linkConf, toJobConf); - String schemaName = toJobConfiguration.toTable.tableName; + String schemaName = toJobConf.toJobConfig.tableName; if (schemaName == null) { throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0019, "Table name extraction not supported yet."); } - if(toJobConfiguration.toTable.schemaName != null) { - schemaName = toJobConfiguration.toTable.schemaName + "." + schemaName; + if(toJobConf.toJobConfig.schemaName != null) { + schemaName = toJobConf.toJobConfig.schemaName + "." + schemaName; } Schema schema = new Schema(schemaName); @@ -112,11 +110,11 @@ public class GenericJdbcToInitializer extends Initializer<ConnectionConfiguratio } } - private void configureJdbcProperties(MutableContext context, ConnectionConfiguration connectionConfig, ToJobConfiguration jobConfig) { - String driver = connectionConfig.connection.jdbcDriver; - String url = connectionConfig.connection.connectionString; - String username = connectionConfig.connection.username; - String password = connectionConfig.connection.password; + private void configureJdbcProperties(MutableContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConf) { + String driver = linkConf.link.jdbcDriver; + String url = linkConf.link.connectionString; + String username = linkConf.link.username; + String password = linkConf.link.password; assert driver != null; assert url != null; @@ -124,18 +122,18 @@ public class GenericJdbcToInitializer extends Initializer<ConnectionConfiguratio executor = new GenericJdbcExecutor(driver, url, username, password); } - private void configureTableProperties(MutableContext context, ConnectionConfiguration connectionConfig, ToJobConfiguration jobConfig) { + private void configureTableProperties(MutableContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConfig) { String dataSql; - String schemaName = jobConfig.toTable.schemaName; - String tableName = jobConfig.toTable.tableName; - String stageTableName = jobConfig.toTable.stageTableName; - boolean clearStageTable = jobConfig.toTable.clearStageTable == null ? - false : jobConfig.toTable.clearStageTable; + String schemaName = toJobConfig.toJobConfig.schemaName; + String tableName = toJobConfig.toJobConfig.tableName; + String stageTableName = toJobConfig.toJobConfig.stageTableName; + boolean clearStageTable = toJobConfig.toJobConfig.clearStageTable == null ? + false : toJobConfig.toJobConfig.clearStageTable; final boolean stageEnabled = stageTableName != null && stageTableName.length() > 0; - String tableSql = jobConfig.toTable.sql; - String tableColumns = jobConfig.toTable.columns; + String tableSql = toJobConfig.toJobConfig.sql; + String tableColumns = toJobConfig.toJobConfig.columns; if (tableName != null && tableSql != null) { // when both fromTable name and fromTable sql are specified: http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcValidator.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcValidator.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcValidator.java index 0a60e90..ad1ee5c 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcValidator.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcValidator.java @@ -18,7 +18,7 @@ package org.apache.sqoop.connector.jdbc; import org.apache.sqoop.common.SqoopException; -import org.apache.sqoop.connector.jdbc.configuration.ConnectionConfiguration; +import org.apache.sqoop.connector.jdbc.configuration.LinkConfiguration; import org.apache.sqoop.connector.jdbc.configuration.FromJobConfiguration; import org.apache.sqoop.connector.jdbc.configuration.ToJobConfiguration; import org.apache.sqoop.validation.Status; @@ -34,32 +34,32 @@ import java.sql.SQLException; public class GenericJdbcValidator extends Validator { @Override - public Validation validateConnection(Object configuration) { - Validation validation = new Validation(ConnectionConfiguration.class); - ConnectionConfiguration config = (ConnectionConfiguration)configuration; + public Validation validateLink(Object configuration) { + Validation validation = new Validation(LinkConfiguration.class); + LinkConfiguration linkConf = (LinkConfiguration)configuration; - if(config.connection.jdbcDriver == null) { - validation.addMessage(Status.UNACCEPTABLE, "connection", "jdbcDriver", "Driver can't be empty"); + if(linkConf.link.jdbcDriver == null) { + validation.addMessage(Status.UNACCEPTABLE, "link", "jdbcDriver", "Driver can't be empty"); } else { try { - Class.forName(config.connection.jdbcDriver); + Class.forName(linkConf.link.jdbcDriver); } catch (ClassNotFoundException e) { - validation.addMessage(Status.UNACCEPTABLE, "connection", "jdbcDriver", "Can't load specified driver"); + validation.addMessage(Status.UNACCEPTABLE, "link", "jdbcDriver", "Can't load specified driver"); } } - if(config.connection.connectionString == null) { - validation.addMessage(Status.UNACCEPTABLE, "connection", "connectionString", "JDBC URL can't be empty"); - } else if(!config.connection.connectionString.startsWith("jdbc:")) { - validation.addMessage(Status.UNACCEPTABLE, "connection", "connectionString", "This do not seem as a valid JDBC URL"); + if(linkConf.link.connectionString == null) { + validation.addMessage(Status.UNACCEPTABLE, "link", "connectionString", "JDBC URL can't be empty"); + } else if(!linkConf.link.connectionString.startsWith("jdbc:")) { + validation.addMessage(Status.UNACCEPTABLE, "link", "connectionString", "This do not seem as a valid JDBC URL"); } // See if we can connect to the database try { - DriverManager.getConnection(config.connection.connectionString, - config.connection.username, config.connection.password); + DriverManager.getConnection(linkConf.link.connectionString, + linkConf.link.username, linkConf.link.password); } catch (SQLException e) { - validation.addMessage(Status.ACCEPTABLE, "connection", "Can't connect to the database with given credentials: " + e.getMessage()); + validation.addMessage(Status.ACCEPTABLE, "link", "Can't connect to the database with given credentials: " + e.getMessage()); } // Return final validation object @@ -81,20 +81,20 @@ public class GenericJdbcValidator extends Validator { private Validation validateToJobConfiguration(ToJobConfiguration configuration) { Validation validation = new Validation(FromJobConfiguration.class); - if(configuration.toTable.tableName == null && configuration.toTable.sql == null) { - validation.addMessage(Status.UNACCEPTABLE, "toTable", "Either table name or SQL must be specified"); + if(configuration.toJobConfig.tableName == null && configuration.toJobConfig.sql == null) { + validation.addMessage(Status.UNACCEPTABLE, "toJobConfig", "Either table name or SQL must be specified"); } - if(configuration.toTable.tableName != null && configuration.toTable.sql != null) { - validation.addMessage(Status.UNACCEPTABLE, "toTable", "Both table name and SQL cannot be specified"); + if(configuration.toJobConfig.tableName != null && configuration.toJobConfig.sql != null) { + validation.addMessage(Status.UNACCEPTABLE, "toJobConfig", "Both table name and SQL cannot be specified"); } - if(configuration.toTable.tableName == null && - configuration.toTable.stageTableName != null) { - validation.addMessage(Status.UNACCEPTABLE, "toTable", + if(configuration.toJobConfig.tableName == null && + configuration.toJobConfig.stageTableName != null) { + validation.addMessage(Status.UNACCEPTABLE, "toJobConfig", "Stage table name cannot be specified without specifying table name"); } - if(configuration.toTable.stageTableName == null && - configuration.toTable.clearStageTable != null) { - validation.addMessage(Status.UNACCEPTABLE, "toTable", + if(configuration.toJobConfig.stageTableName == null && + configuration.toJobConfig.clearStageTable != null) { + validation.addMessage(Status.UNACCEPTABLE, "toJobConfig", "Clear stage table cannot be specified without specifying name of " + "the stage table."); } @@ -105,18 +105,18 @@ public class GenericJdbcValidator extends Validator { private Validation validateFromJobConfiguration(FromJobConfiguration configuration) { Validation validation = new Validation(FromJobConfiguration.class); - if(configuration.fromTable.tableName == null && configuration.fromTable.sql == null) { - validation.addMessage(Status.UNACCEPTABLE, "fromTable", "Either table name or SQL must be specified"); + if(configuration.fromJobConfig.tableName == null && configuration.fromJobConfig.sql == null) { + validation.addMessage(Status.UNACCEPTABLE, "fromJobConfig", "Either table name or SQL must be specified"); } - if(configuration.fromTable.tableName != null && configuration.fromTable.sql != null) { - validation.addMessage(Status.UNACCEPTABLE, "fromTable", "Both table name and SQL cannot be specified"); + if(configuration.fromJobConfig.tableName != null && configuration.fromJobConfig.sql != null) { + validation.addMessage(Status.UNACCEPTABLE, "fromJobConfig", "Both table name and SQL cannot be specified"); } - if(configuration.fromTable.schemaName != null && configuration.fromTable.sql != null) { - validation.addMessage(Status.UNACCEPTABLE, "fromTable", "Both schema name and SQL cannot be specified"); + if(configuration.fromJobConfig.schemaName != null && configuration.fromJobConfig.sql != null) { + validation.addMessage(Status.UNACCEPTABLE, "fromJobConfig", "Both schema name and SQL cannot be specified"); } - if(configuration.fromTable.sql != null && !configuration.fromTable.sql.contains(GenericJdbcConnectorConstants.SQL_CONDITIONS_TOKEN)) { - validation.addMessage(Status.UNACCEPTABLE, "fromTable", "sql", "SQL statement must contain placeholder for auto generated " + if(configuration.fromJobConfig.sql != null && !configuration.fromJobConfig.sql.contains(GenericJdbcConnectorConstants.SQL_CONDITIONS_TOKEN)) { + validation.addMessage(Status.UNACCEPTABLE, "fromJobConfig", "sql", "SQL statement must contain placeholder for auto generated " + "conditions - " + GenericJdbcConnectorConstants.SQL_CONDITIONS_TOKEN); } http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/configuration/ConnectionConfiguration.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/configuration/ConnectionConfiguration.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/configuration/ConnectionConfiguration.java deleted file mode 100644 index 6061600..0000000 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/configuration/ConnectionConfiguration.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * 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.sqoop.connector.jdbc.configuration; - -import org.apache.sqoop.model.ConfigurationClass; -import org.apache.sqoop.model.Form; - -/** - * - */ -@ConfigurationClass -public class ConnectionConfiguration { - - @Form public ConnectionForm connection; - - public ConnectionConfiguration() { - connection = new ConnectionForm(); - } -} http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/configuration/ConnectionForm.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/configuration/ConnectionForm.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/configuration/ConnectionForm.java deleted file mode 100644 index 3b5d70a..0000000 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/configuration/ConnectionForm.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * 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.sqoop.connector.jdbc.configuration; - -import org.apache.sqoop.model.FormClass; -import org.apache.sqoop.model.Input; -import org.apache.sqoop.model.Validator; -import org.apache.sqoop.validation.Status; -import org.apache.sqoop.validation.validators.AbstractValidator; -import org.apache.sqoop.validation.validators.NotEmpty; -import org.apache.sqoop.validation.validators.ClassAvailable; -import org.apache.sqoop.validation.validators.StartsWith; - -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.Map; - -/** - * - */ -@FormClass(validators = {@Validator(ConnectionForm.FormValidator.class)}) -public class ConnectionForm { - @Input(size = 128, validators = {@Validator(NotEmpty.class), @Validator(ClassAvailable.class)} ) - public String jdbcDriver; - - @Input(size = 128, validators = {@Validator(value = StartsWith.class, strArg = "jdbc:")} ) - public String connectionString; - - @Input(size = 40) - public String username; - - @Input(size = 40, sensitive = true) - public String password; - - @Input - public Map<String, String> jdbcProperties; - - public static class FormValidator extends AbstractValidator<ConnectionForm> { - @Override - public void validate(ConnectionForm form) { - // See if we can connect to the database - try { - DriverManager.getConnection(form.connectionString, form.username, form.password); - } catch (SQLException e) { - addMessage(Status.ACCEPTABLE, "Can't connect to the database with given credentials: " + e.getMessage()); - } - } - } -}