Search in sources :

Example 71 with Connection

use of org.talend.core.model.metadata.builder.connection.Connection in project tdi-studio-se by Talend.

the class UpgrateDatabaseTypeForSybaseConnection method execute.

@Override
public ExecutionResult execute(Item item) {
    try {
        if (item instanceof DatabaseConnectionItem) {
            DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
            Connection connection = dbItem.getConnection();
            if (connection instanceof DatabaseConnection) {
                DatabaseConnection dbconn = (DatabaseConnection) connection;
                if (dbconn.getProductId().equals(EDatabaseTypeName.SYBASEASE.getProduct())) {
                    dbconn.setDatabaseType(EDatabaseTypeName.SYBASEASE.getDisplayName());
                }
            }
            ProxyRepositoryFactory.getInstance().save(dbItem, true);
        }
        return ExecutionResult.SUCCESS_WITH_ALERT;
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 72 with Connection

use of org.talend.core.model.metadata.builder.connection.Connection in project tdi-studio-se by Talend.

the class FileJSONTableWizardPage method createControl.

/**
     * Create the first composite, addComponentsAndControls and initialize TableWizardPage.
     * 
     * @see IDialogPage#createControl(Composite)
     */
public void createControl(final Composite parent) {
    final AbstractForm.ICheckListener listener = new AbstractForm.ICheckListener() {

        public void checkPerformed(final AbstractForm source) {
            if (source.isStatusOnError()) {
                FileJSONTableWizardPage.this.setPageComplete(false);
                setErrorMessage(source.getStatus());
            } else {
                FileJSONTableWizardPage.this.setPageComplete(isRepositoryObjectEditable);
                setErrorMessage(null);
                setMessage(source.getStatus(), source.getStatusLevel());
            }
        }
    };
    Composite theForm = null;
    Connection connection = null;
    if (metadataTable.getNamespace() != null) {
        if (metadataTable.getNamespace() instanceof Package) {
            Package pkg = (Package) metadataTable.getNamespace();
            if (!pkg.getDataManager().isEmpty()) {
                connection = (Connection) pkg.getDataManager().get(0);
            }
        }
    }
    theForm = (Composite) new JsonSwitch() {

        public Object caseJSONFileConnection(final JSONFileConnection object) {
            JSONFileConnection jsonFileConnection = (JSONFileConnection) connectionItem.getConnection();
            boolean isInputModel = jsonFileConnection.isInputModel();
            if (isInputModel) {
                JSONFileStep3Form xmlFileStep3Form = new JSONFileStep3Form(parent, connectionItem, metadataTable, null, TableHelper.getTableNames(object, metadataTable.getLabel()));
                xmlFileStep3Form.setReadOnly(!isRepositoryObjectEditable);
                xmlFileStep3Form.setListener(listener);
                return xmlFileStep3Form;
            } else {
                JSONFileOutputStep3Form xmlFileOutputStep3Form = new JSONFileOutputStep3Form(parent, connectionItem, metadataTable, TableHelper.getTableNames(object, metadataTable.getLabel()));
                xmlFileOutputStep3Form.setReadOnly(!isRepositoryObjectEditable);
                xmlFileOutputStep3Form.setListener(listener);
                return xmlFileOutputStep3Form;
            }
        }
    }.doSwitch(connection);
    setControl(theForm);
}
Also used : JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) Composite(org.eclipse.swt.widgets.Composite) JsonSwitch(org.talend.repository.model.json.util.JsonSwitch) JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) AbstractForm(org.talend.metadata.managment.ui.wizard.AbstractForm) Package(orgomg.cwm.objectmodel.core.Package)

Example 73 with Connection

use of org.talend.core.model.metadata.builder.connection.Connection in project tdi-studio-se by Talend.

the class RenameDriverJarPathForDBConnectionMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    if (item instanceof DatabaseConnectionItem) {
        Connection connection = ((DatabaseConnectionItem) item).getConnection();
        if (connection instanceof DatabaseConnection) {
            DatabaseConnection dbConn = (DatabaseConnection) connection;
            String oldJarPath = dbConn.getDriverJarPath();
            String newJarPath = null;
            try {
                if (oldJarPath != null && !"".equals(oldJarPath.trim())) {
                    //$NON-NLS-1$
                    IPath path = Path.fromOSString(oldJarPath);
                    if (path.isAbsolute()) {
                        newJarPath = path.lastSegment();
                    }
                }
                if (newJarPath != null) {
                    dbConn.setDriverJarPath(newJarPath);
                    ProxyRepositoryFactory.getInstance().save(item, true);
                    return ExecutionResult.SUCCESS_NO_ALERT;
                }
            } catch (Exception e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : IPath(org.eclipse.core.runtime.IPath) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 74 with Connection

use of org.talend.core.model.metadata.builder.connection.Connection in project tdi-studio-se by Talend.

the class GenericDragAndDropHandlerTest method testIsGenericRepositoryValue.

@Test
public void testIsGenericRepositoryValue() {
    Connection connection = mock(Connection.class);
    AbstractDragAndDropServiceHandler abstractDragAndDropServiceHandler = mock(AbstractDragAndDropServiceHandler.class);
    List<ComponentProperties> componentProsList = new ArrayList<>();
    boolean isGenericRepositoryValue = abstractDragAndDropServiceHandler.isGenericRepositoryValue(componentProsList, //$NON-NLS-1$
    "paramName1");
    assertEquals(false, isGenericRepositoryValue);
    connection = mock(GenericConnection.class);
    GenericDragAndDropHandler genericDragAndDropHandler = mock(GenericDragAndDropHandler.class);
    when(genericDragAndDropHandler.canHandle(connection)).thenReturn(true);
    //$NON-NLS-1$
    isGenericRepositoryValue = genericDragAndDropHandler.isGenericRepositoryValue(null, "paramName2");
    assertEquals(false, isGenericRepositoryValue);
// PowerMockito.mockStatic(ComponentsUtils.class);
// ComponentProperties mockComponentProperties = mock(ComponentProperties.class);
// when(ComponentsUtils.getComponentPropertiesFromSerialized(null)).thenReturn(mockComponentProperties);
// List<Property> propertyValues = new ArrayList<Property>();
// Property element = ComponentPropertyFactory.newReturnsProperty();
// propertyValues.add(element);
// when(ComponentsUtils.getAllValuedProperties(mockComponentProperties)).thenReturn(propertyValues);
//        isGenericRepositoryValue = genericDragAndDropHandler.isGenericRepositoryValue(connection, "QueryMode");//$NON-NLS-1$
// assertEquals(true, isGenericRepositoryValue);
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) ArrayList(java.util.ArrayList) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) AbstractDragAndDropServiceHandler(org.talend.core.model.utils.AbstractDragAndDropServiceHandler) Test(org.junit.Test)

Aggregations

Connection (org.talend.core.model.metadata.builder.connection.Connection)74 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)42 ConnectionItem (org.talend.core.model.properties.ConnectionItem)39 PersistenceException (org.talend.commons.exception.PersistenceException)28 IElementParameter (org.talend.core.model.process.IElementParameter)27 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)26 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)20 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)19 Item (org.talend.core.model.properties.Item)19 ArrayList (java.util.ArrayList)14 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)14 Property (org.talend.core.model.properties.Property)14 ChangeValuesFromRepository (org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository)13 QueriesConnection (org.talend.core.model.metadata.builder.connection.QueriesConnection)12 XmlFileConnection (org.talend.core.model.metadata.builder.connection.XmlFileConnection)9 IConnection (org.talend.core.model.process.IConnection)9 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)8 IDynamicProperty (org.talend.core.ui.properties.tab.IDynamicProperty)8 List (java.util.List)7 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)7