Search in sources :

Example 41 with AllSetting

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);
}
Also used : AllSetting(org.talend.components.jdbc.runtime.setting.AllSetting) Test(org.junit.Test)

Example 42 with AllSetting

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);
}
Also used : AllSetting(org.talend.components.jdbc.runtime.setting.AllSetting) Test(org.junit.Test)

Example 43 with AllSetting

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);
}
Also used : AllSetting(org.talend.components.jdbc.runtime.setting.AllSetting) Test(org.junit.Test)

Example 44 with AllSetting

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;
}
Also used : AllSetting(org.talend.components.jdbc.runtime.setting.AllSetting)

Example 45 with AllSetting

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;
}
Also used : JarInputStream(java.util.jar.JarInputStream) ArrayList(java.util.ArrayList) JarEntry(java.util.jar.JarEntry) ValidationResult(org.talend.daikon.properties.ValidationResult) URL(java.net.URL) AllSetting(org.talend.components.jdbc.runtime.setting.AllSetting) URLClassLoader(java.net.URLClassLoader)

Aggregations

AllSetting (org.talend.components.jdbc.runtime.setting.AllSetting)56 Test (org.junit.Test)38 RuntimeInfo (org.talend.daikon.runtime.RuntimeInfo)11 ExecutionEngine (org.talend.components.api.component.runtime.ExecutionEngine)7 JDBCDatastoreProperties (org.talend.components.jdbc.datastore.JDBCDatastoreProperties)6 JDBCDatasetProperties (org.talend.components.jdbc.dataset.JDBCDatasetProperties)4 Connection (java.sql.Connection)3 InputStream (java.io.InputStream)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 JarEntry (java.util.jar.JarEntry)1 JarInputStream (java.util.jar.JarInputStream)1 BeforeClass (org.junit.BeforeClass)1 JDBCAvroRegistryString (org.talend.components.jdbc.avro.JDBCAvroRegistryString)1 JDBCConnectionModule (org.talend.components.jdbc.module.JDBCConnectionModule)1 TJDBCConnectionDefinition (org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionDefinition)1