use of org.talend.components.jdbc.runtime.setting.AllSetting in project components by Talend.
the class QueryGeneratorTest method testCommonQueryGeneratorWithContext.
@Test
public void testCommonQueryGeneratorWithContext() {
AllSetting setting = new AllSetting();
setting.setSchema(createTestSchema());
String result = QueryUtils.generateNewQuery("General JDBC", null, null, "context.mytable", setting);
Assert.assertEquals("\"SELECT \n \\\"\"+context.mytable+\"\\\".\\\"ID1\\\", \n \\\"\"+context.mytable+\"\\\".\\\"NAME1\\\"\nFROM \\\"\"+context.mytable+\"\\\"\"", result);
}
use of org.talend.components.jdbc.runtime.setting.AllSetting in project components by Talend.
the class QueryGeneratorTest method testCommonQueryGeneratorWithStringLiteral.
@Test
public void testCommonQueryGeneratorWithStringLiteral() {
AllSetting setting = new AllSetting();
setting.setSchema(createTestSchema());
String result = QueryUtils.generateNewQuery("General JDBC", null, null, "\"mytable\"", setting);
Assert.assertEquals("\"SELECT \n \\\"mytable\\\".\\\"ID1\\\", \n \\\"mytable\\\".\\\"NAME1\\\"\nFROM \\\"mytable\\\"\"", result);
}
use of org.talend.components.jdbc.runtime.setting.AllSetting in project components by Talend.
the class QueryGeneratorTest method testCommonQueryGeneratorWithStringLiteralAndDBCatalogAndDBSchema.
@Test
public void testCommonQueryGeneratorWithStringLiteralAndDBCatalogAndDBSchema() {
AllSetting setting = new AllSetting();
setting.setSchema(createTestSchema());
String result = QueryUtils.generateNewQuery("General JDBC", "\"mydatabase\"", "\"mydbschema\"", "\"mytable\"", setting);
Assert.assertEquals("\"SELECT \n \\\"mydatabase\\\".\\\"mydbschema\\\".\\\"mytable\\\".\\\"ID1\\\", \n \\\"mydatabase\\\".\\\"mydbschema\\\".\\\"mytable\\\".\\\"NAME1\\\"\nFROM \\\"mydatabase\\\".\\\"mydbschema\\\".\\\"mytable\\\"\"", result);
}
use of org.talend.components.jdbc.runtime.setting.AllSetting in project components by Talend.
the class TJDBCConnectionProperties method getRuntimeSetting.
@Override
public AllSetting getRuntimeSetting() {
AllSetting setting = new AllSetting();
CommonUtils.setCommonConnectionInfo(setting, connection);
setting.setShareConnection(this.shareConnection.getValue());
setting.setSharedConnectionName(this.sharedConnectionName.getValue());
setting.setUseDataSource(this.useDataSource.getValue());
setting.setDataSource(this.dataSource.getValue());
setting.setUseAutoCommit(this.useAutoCommit.getValue());
setting.setAutocommit(this.autocommit.getValue());
return setting;
}
use of org.talend.components.jdbc.runtime.setting.AllSetting in project components by Talend.
the class JDBCConnectionModule method afterSelectClass.
public ValidationResult afterSelectClass() {
List<String> driverClasses = new ArrayList<>();
AllSetting setting = new AllSetting();
setting.setDriverPaths(driverTable.drivers.getValue());
List<String> jar_maven_paths = setting.getDriverPaths();
try {
List<URL> urls = new ArrayList<>();
for (String maven_path : jar_maven_paths) {
URL url = new URL(removeQuote(maven_path));
urls.add(url);
}
URLClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[0]), this.getClass().getClassLoader());
for (URL jarUrl : urls) {
try (JarInputStream jarInputStream = new JarInputStream(jarUrl.openStream())) {
JarEntry nextJarEntry = jarInputStream.getNextJarEntry();
while (nextJarEntry != null) {
boolean isFile = !nextJarEntry.isDirectory();
if (isFile) {
String name = nextJarEntry.getName();
if (name != null && name.toLowerCase().endsWith(".class")) {
String className = changeFileNameToClassName(name);
try {
Class clazz = classLoader.loadClass(className);
if (Driver.class.isAssignableFrom(clazz)) {
driverClasses.add(clazz.getName());
}
} catch (Throwable th) {
// ignore all the exceptions, especially the class not found exception when look up a class
// outside the jar
}
}
}
nextJarEntry = jarInputStream.getNextJarEntry();
}
}
}
} catch (Exception ex) {
return new ValidationResult(ValidationResult.Result.ERROR, ex.getMessage());
}
if (driverClasses.isEmpty()) {
return new ValidationResult(ValidationResult.Result.ERROR, "not found any Driver class, please make sure the jar is right");
}
driverClass.setPossibleValues(driverClasses);
driverClass.setValue(driverClasses.get(0));
return ValidationResult.OK;
}
Aggregations