use of org.talend.components.jdbc.tjdbcsp.TJDBCSPProperties in project components by Talend.
the class JDBCSPTestIT method test_basic_no_connector.
@Test
public void test_basic_no_connector() throws Exception {
TJDBCSPDefinition definition = new TJDBCSPDefinition();
TJDBCSPProperties properties = DBTestUtils.createCommonJDBCSPProperties(allSetting, definition);
properties.spName.setValue("SYSCS_UTIL.SYSCS_EMPTY_STATEMENT_CACHE");
JDBCSPSourceOrSink sourceOrSink = new JDBCSPSourceOrSink();
sourceOrSink.initialize(null, properties);
ValidationResult result = sourceOrSink.validate(null);
Assert.assertTrue(result.getStatus() == ValidationResult.Result.OK);
}
use of org.talend.components.jdbc.tjdbcsp.TJDBCSPProperties in project components by Talend.
the class JDBCSPTestIT method test_basic_as_output_and_no_input.
@SuppressWarnings("rawtypes")
@Test
public void test_basic_as_output_and_no_input() throws Exception {
TJDBCSPDefinition definition = new TJDBCSPDefinition();
TJDBCSPProperties properties = DBTestUtils.createCommonJDBCSPProperties(allSetting, definition);
properties.spName.setValue("SYSCS_UTIL.SYSCS_DISABLE_LOG_ARCHIVE_MODE");
properties.main.schema.setValue(DBTestUtils.createSPSchema1(tablename));
properties.spParameterTable.parameterTypes.setValue(Arrays.asList(SPParameterTable.ParameterType.IN.name()));
properties.spParameterTable.schemaColumns.setValue(Arrays.asList("PARAMETER"));
JDBCSPSink sink = new JDBCSPSink();
sink.initialize(null, properties);
ValidationResult result = sink.validate(null);
Assert.assertTrue(result.getStatus() == ValidationResult.Result.OK);
WriteOperation operation = sink.createWriteOperation();
JDBCSPWriter writer = (JDBCSPWriter) operation.createWriter(null);
try {
writer.open("wid");
IndexedRecord r1 = new GenericData.Record(properties.main.schema.getValue());
r1.put(0, 0);
writer.write(r1);
} finally {
writer.close();
}
}
use of org.talend.components.jdbc.tjdbcsp.TJDBCSPProperties in project components by Talend.
the class DBTestUtils method createCommonJDBCSPProperties.
public static TJDBCSPProperties createCommonJDBCSPProperties(AllSetting allSetting, TJDBCSPDefinition definition) {
TJDBCSPProperties properties = (TJDBCSPProperties) definition.createRuntimeProperties();
// properties.connection.driverTable.drivers.setValue(Arrays.asList(driverPath));
properties.connection.driverClass.setValue(allSetting.getDriverClass());
properties.connection.jdbcUrl.setValue(allSetting.getJdbcUrl());
properties.connection.userPassword.userId.setValue(allSetting.getUsername());
properties.connection.userPassword.password.setValue(allSetting.getPassword());
return properties;
}
use of org.talend.components.jdbc.tjdbcsp.TJDBCSPProperties in project components by Talend.
the class JDBCSPTestIT method test_basic_as_output_and_input.
@SuppressWarnings("rawtypes")
@Test
public void test_basic_as_output_and_input() throws Exception {
TJDBCSPDefinition definition = new TJDBCSPDefinition();
TJDBCSPProperties properties = DBTestUtils.createCommonJDBCSPProperties(allSetting, definition);
properties.spName.setValue("SYSCS_UTIL.SYSCS_DISABLE_LOG_ARCHIVE_MODE");
Schema schema = DBTestUtils.createSPSchema3(tablename);
properties.main.schema.setValue(schema);
properties.schemaFlow.schema.setValue(schema);
properties.spParameterTable.parameterTypes.setValue(Arrays.asList(SPParameterTable.ParameterType.IN.name()));
properties.spParameterTable.schemaColumns.setValue(Arrays.asList("PARAMETER1"));
JDBCSPSink sink = new JDBCSPSink();
sink.initialize(null, properties);
ValidationResult result = sink.validate(null);
Assert.assertTrue(result.getStatus() == ValidationResult.Result.OK);
WriteOperation operation = sink.createWriteOperation();
JDBCSPWriter writer = (JDBCSPWriter) operation.createWriter(null);
try {
writer.open("wid");
IndexedRecord r1 = new GenericData.Record(properties.main.schema.getValue());
r1.put(0, 0);
r1.put(1, "wangwei");
writer.write(r1);
List<IndexedRecord> writeResult = writer.getSuccessfulWrites();
Assert.assertEquals(1, writeResult.size());
IndexedRecord record = writeResult.get(0);
Assert.assertEquals(Integer.valueOf(0), record.get(0));
Assert.assertEquals("wangwei", record.get(1));
writer.cleanWrites();
} finally {
writer.close();
}
}
use of org.talend.components.jdbc.tjdbcsp.TJDBCSPProperties in project components by Talend.
the class JDBCSPTestIT method test_basic_as_input.
@SuppressWarnings("rawtypes")
@Test
public void test_basic_as_input() throws Exception {
TJDBCSPDefinition definition = new TJDBCSPDefinition();
TJDBCSPProperties properties = DBTestUtils.createCommonJDBCSPProperties(allSetting, definition);
properties.isFunction.setValue(true);
properties.returnResultIn.setValue("PARAMETER");
properties.spName.setValue("SYSCS_UTIL.SYSCS_GET_DATABASE_NAME");
Schema schema = DBTestUtils.createSPSchema2(tablename);
properties.main.schema.setValue(schema);
properties.schemaFlow.schema.setValue(schema);
JDBCSPSource source = new JDBCSPSource();
source.initialize(null, properties);
ValidationResult result = source.validate(null);
Assert.assertTrue(result.getStatus() == ValidationResult.Result.OK);
Reader reader = source.createReader(null);
try {
reader.start();
IndexedRecord row = (IndexedRecord) reader.getCurrent();
String v1 = (String) row.get(0);
Assert.assertEquals("memory:myDB", v1);
// only output one row when it works as a input component
Assert.assertFalse(reader.advance());
reader.close();
} finally {
reader.close();
}
}
Aggregations