Search in sources :

Example 86 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ConnectionUtilsTest method testCheckGeneralJdbcJarFilePathDriverClassNameCase2.

/**
 * Test method for
 * {@link org.talend.cwm.db.connection.ConnectionUtils#checkGeneralJdbcJarFilePathDriverClassName(org.talend.core.model.metadata.builder.connection.DatabaseConnection)}
 * . case 2 driverClass is null or empty
 */
@Test
public void testCheckGeneralJdbcJarFilePathDriverClassNameCase2() {
    String driverClass = StringUtils.EMPTY;
    // $NON-NLS-1$
    String driverName = "mysql-connector-java-5.1.12-bin.jar";
    CopyTheJarFile();
    DatabaseConnection createDatabaseConnection = ConnectionFactoryImpl.eINSTANCE.createDatabaseConnection();
    createDatabaseConnection.setDriverClass(driverClass);
    createDatabaseConnection.setDriverJarPath(driverName);
    // driver class is empty case
    ReturnCode rc = ConnectionUtils.checkJdbcJarFilePathDriverClassName(createDatabaseConnection);
    // $NON-NLS-1$
    Assert.assertFalse("The driver of conection is empty so that should not be found", rc.isOk());
    // $NON-NLS-1$
    Assert.assertEquals(Messages.getString("ConnectionUtils.DriverClassEmpty"), rc.getMessage());
    // driver class is Null case
    driverClass = null;
    createDatabaseConnection.setDriverClass(driverClass);
    rc = ConnectionUtils.checkJdbcJarFilePathDriverClassName(createDatabaseConnection);
    // $NON-NLS-1$
    Assert.assertFalse("The driver of conection is Null so that should not be found", rc.isOk());
    // $NON-NLS-1$
    Assert.assertEquals(Messages.getString("ConnectionUtils.DriverClassEmpty"), rc.getMessage());
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Test(org.junit.Test)

Example 87 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ConnectionUtilsTest method testCheckGeneralJdbcJarFilePathDriverClassNameCase4.

/**
 * Test method for
 * {@link org.talend.cwm.db.connection.ConnectionUtils#checkGeneralJdbcJarFilePathDriverClassName(org.talend.core.model.metadata.builder.connection.DatabaseConnection)}
 * . case 4 The jar can not be found case
 */
@Test
public void testCheckGeneralJdbcJarFilePathDriverClassNameCase4() {
    // $NON-NLS-1$
    String driverClass = "om.mysql.jdbc.Driver";
    // $NON-NLS-1$
    String driverName = "mysql-connector-java-5.1.12-bin111111.jar";
    CopyTheJarFile();
    DatabaseConnection createDatabaseConnection = ConnectionFactoryImpl.eINSTANCE.createDatabaseConnection();
    createDatabaseConnection.setDriverClass(driverClass);
    createDatabaseConnection.setDriverJarPath(driverName);
    ReturnCode rc = ConnectionUtils.checkJdbcJarFilePathDriverClassName(createDatabaseConnection);
    // $NON-NLS-1$
    Assert.assertFalse("The driver is not exist so that should not be found", rc.isOk());
    // $NON-NLS-1$
    Assert.assertEquals(Messages.getString("ConnectionUtils.JarFileCanNotBeFound"), rc.getMessage());
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Test(org.junit.Test)

Example 88 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ConnectionUtilsTest method testCheckGeneralJdbcJarFilePathDriverClassNameCase3.

/**
 * Test method for
 * {@link org.talend.cwm.db.connection.ConnectionUtils#checkGeneralJdbcJarFilePathDriverClassName(org.talend.core.model.metadata.builder.connection.DatabaseConnection)}
 * . case 3 driverName is null or empty
 */
@Test
public void testCheckGeneralJdbcJarFilePathDriverClassNameCase3() {
    // $NON-NLS-1$
    String driverClass = "om.mysql.jdbc.Driver";
    String driverName = StringUtils.EMPTY;
    CopyTheJarFile();
    DatabaseConnection createDatabaseConnection = ConnectionFactoryImpl.eINSTANCE.createDatabaseConnection();
    createDatabaseConnection.setDriverClass(driverClass);
    createDatabaseConnection.setDriverJarPath(driverName);
    // driver name is empty case
    ReturnCode rc = ConnectionUtils.checkJdbcJarFilePathDriverClassName(createDatabaseConnection);
    // $NON-NLS-1$
    Assert.assertFalse("The class of driver is empty so that should not be found", rc.isOk());
    // $NON-NLS-1$
    Assert.assertEquals(Messages.getString("ConnectionUtils.DriverJarFileEmpty"), rc.getMessage());
    // driver name is Null case
    driverClass = null;
    createDatabaseConnection.setDriverJarPath(driverName);
    rc = ConnectionUtils.checkJdbcJarFilePathDriverClassName(createDatabaseConnection);
    // $NON-NLS-1$
    Assert.assertFalse("The class of driver is Null so that should not be found", rc.isOk());
    // $NON-NLS-1$
    Assert.assertEquals(Messages.getString("ConnectionUtils.DriverJarFileEmpty"), rc.getMessage());
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Test(org.junit.Test)

Example 89 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class UDIHelper method validate.

public static ReturnCode validate(IndicatorDefinition indicatorDefinition) {
    ReturnCode rc = new ReturnCode(true);
    List<String> errorList = new ArrayList<String>();
    // MOD mzhao feature 11128, In case of Java UDI, No expression is allowed to be saved.
    if (!containsJavaUDI(indicatorDefinition)) {
        if (0 == indicatorDefinition.getSqlGenericExpression().size()) {
            // $NON-NLS-1$
            errorList.add(Messages.getString("UDIHelper.validateNoExpression"));
            rc.setOk(false);
        }
    }
    if (PluginConstant.EMPTY_STRING.equals(indicatorDefinition.getName())) {
        // $NON-NLS-1$
        errorList.add(Messages.getString("UDIHelper.validateNoName"));
        rc.setOk(false);
    }
    for (Expression exp : indicatorDefinition.getSqlGenericExpression()) {
        if (null == exp.getBody() || exp.getBody().length() + 1 < MIN_EXPRESSION_LENGTH) {
            // $NON-NLS-1$
            errorList.add(Messages.getString("UDIHelper.validateTooShort"));
            rc.setOk(false);
        }
    }
    // $NON-NLS-1$
    String message = Messages.getString("UDIHelper.validateCannotSave");
    // $NON-NLS-1$
    String wrap = System.getProperty("line.separator");
    for (int i = 0; i < errorList.size(); i++) {
        message += wrap + (i + 1) + org.talend.dataquality.PluginConstant.DOT_STRING + errorList.get(i);
    }
    rc.setMessage(message);
    return rc;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) Expression(orgomg.cwm.objectmodel.core.Expression) ArrayList(java.util.ArrayList)

Example 90 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class AbstractSchemaEvaluator method reloadConnectionAfterException.

/**
 * DOC scorreia Comment method "reloadConnection".
 *
 * @param catalog
 */
protected void reloadConnectionAfterException(String catalog) {
    nbExceptions++;
    if (nbExceptions < MAX_EXCEPTION) {
        // not yet
        return;
    }
    ReturnCode connClosed = super.closeConnection();
    if (!connClosed.isOk()) {
        // $NON-NLS-1$
        log.error(Messages.getString("AbstractSchemaEvaluator.ReloadProblem", connClosed.getMessage()));
    }
    Connection dp = this.getDataManager();
    TypedReturnCode<java.sql.Connection> conn = JavaSqlFactory.createConnection(dp);
    if (!conn.isOk()) {
        log.error(conn.getMessage());
        return;
    }
    // else ok
    this.setConnection(conn.getObject());
    this.selectCatalog(catalog);
    // reset the number of exceptions
    nbExceptions = 0;
}
Also used : TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) Connection(org.talend.core.model.metadata.builder.connection.Connection)

Aggregations

ReturnCode (org.talend.utils.sugars.ReturnCode)175 ArrayList (java.util.ArrayList)42 TypedReturnCode (org.talend.utils.sugars.TypedReturnCode)42 Test (org.junit.Test)29 File (java.io.File)26 Connection (org.talend.core.model.metadata.builder.connection.Connection)26 Indicator (org.talend.dataquality.indicators.Indicator)25 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)20 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)18 Analysis (org.talend.dataquality.analysis.Analysis)18 Property (org.talend.core.model.properties.Property)17 IFile (org.eclipse.core.resources.IFile)16 IRepositoryNode (org.talend.repository.model.IRepositoryNode)16 IFolder (org.eclipse.core.resources.IFolder)15 SQLException (java.sql.SQLException)14 PersistenceException (org.talend.commons.exception.PersistenceException)11 TdColumn (org.talend.cwm.relational.TdColumn)11 IOException (java.io.IOException)10 EObject (org.eclipse.emf.ecore.EObject)10 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)10