Search in sources :

Example 46 with DatabaseConnection

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

the class DBConnectionDuplicateHandleTest method createConnectionItem.

private DatabaseConnectionItem createConnectionItem(String name, IFolder folder, Boolean isDelete) {
    IPath createPath = Path.EMPTY;
    if (folder != null) {
        createPath = new Path(folder.getFullPath().lastSegment());
    }
    // connection
    DatabaseConnection createConnection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
    createConnection.setName(name);
    createConnection.setLabel(name);
    // $NON-NLS-1$
    createConnection.setUsername("UserName");
    // $NON-NLS-1$
    createConnection.setRawPassword("Password");
    // $NON-NLS-1$
    createConnection.setURL("URL");
    createConnection.setDatabaseType(EDatabaseTypeName.MYSQL.getXmlName());
    createConnection.setContextMode(true);
    // ~connection
    DatabaseConnectionItem createDatabaseConnectionItem = PropertiesFactory.eINSTANCE.createDatabaseConnectionItem();
    org.talend.core.model.properties.Property createDatabaseConnectionProperty = PropertiesFactory.eINSTANCE.createProperty();
    createDatabaseConnectionProperty.setId(EcoreUtil.generateUUID());
    createDatabaseConnectionProperty.setItem(createDatabaseConnectionItem);
    createDatabaseConnectionProperty.setLabel(createConnection.getName());
    createDatabaseConnectionItem.setProperty(createDatabaseConnectionProperty);
    createDatabaseConnectionItem.setConnection(createConnection);
    try {
        factory.create(createDatabaseConnectionItem, createPath, false);
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    return createDatabaseConnectionItem;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Property(org.talend.core.model.properties.Property) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 47 with DatabaseConnection

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

the class AbstractCommonActionProviderRealProjectTest method createConnectionItem.

private String createConnectionItem(String name, IFolder folder, Boolean isDelete) {
    IPath createPath = Path.EMPTY;
    if (folder != null) {
        createPath = new Path(folder.getFullPath().lastSegment());
    }
    // connection
    DatabaseConnection createConnection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
    createConnection.setName(name);
    // $NON-NLS-1$
    createConnection.setUsername("UserName");
    // $NON-NLS-1$
    createConnection.setRawPassword("Password");
    // $NON-NLS-1$
    createConnection.setURL("URL");
    createConnection.setDatabaseType(EDatabaseTypeName.MYSQL.getXmlName());
    // ~connection
    createDatabaseConnectionItem = PropertiesFactory.eINSTANCE.createDatabaseConnectionItem();
    org.talend.core.model.properties.Property createDatabaseConnectionProperty = PropertiesFactory.eINSTANCE.createProperty();
    createDatabaseConnectionProperty.setId(EcoreUtil.generateUUID());
    createDatabaseConnectionProperty.setItem(createDatabaseConnectionItem);
    createDatabaseConnectionProperty.setLabel(createConnection.getName());
    createDatabaseConnectionItem.setProperty(createDatabaseConnectionProperty);
    createDatabaseConnectionItem.setConnection(createConnection);
    try {
        factory.create(createDatabaseConnectionItem, createPath, false);
    } catch (PersistenceException e) {
        log.error(e, e);
        Assert.fail(e.getMessage());
    }
    return createDatabaseConnectionProperty.getId();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection)

Example 48 with DatabaseConnection

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

the class UpdateAfterMergeTosApiTask method updateConnectionFile.

/**
 * DOC bZhou Comment method "addConnectionFileToUpdate".
 */
private void updateConnectionFile() {
    File rawDir = getWorkspacePath().append(EResourceConstant.METADATA.getPath()).toFile();
    ArrayList<File> fileList = new ArrayList<File>();
    if (rawDir.exists()) {
        getAllFilesFromFolder(rawDir, fileList, new FilenameFilter() {

            public boolean accept(File dir, String name) {
                return name.endsWith(FactoriesUtil.ITEM_EXTENSION);
            }
        });
    }
    for (File file : fileList) {
        IFile iFile = WorkspaceUtils.fileToIFile(file);
        Property property = PropertyHelper.getProperty(iFile);
        if (property != null) {
            Item item = property.getItem();
            EResourceConstant type = EResourceConstant.getTypedConstant(item);
            if (type == EResourceConstant.DB_CONNECTIONS) {
                DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
                DatabaseConnection connection = (DatabaseConnection) dbItem.getConnection();
                String otherParameter = ConnectionHelper.getOtherParameter(connection);
                if (!StringUtils.isBlank(otherParameter)) {
                    connection.setUiSchema(otherParameter);
                    EMFSharedResources.getInstance().saveResource(connection.eResource());
                }
            }
        }
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) Item(org.talend.core.model.properties.Item) FolderItem(org.talend.core.model.properties.FolderItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EResourceConstant(org.talend.resource.EResourceConstant) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Property(org.talend.core.model.properties.Property) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 49 with DatabaseConnection

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

the class UpdateMsSqlToJdbcTask method doExecute.

@Override
protected boolean doExecute() throws Exception {
    List<IRepositoryViewObject> allConnectionObject = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.METADATA_CONNECTIONS);
    for (IRepositoryViewObject object : allConnectionObject) {
        ConnectionItem item = (ConnectionItem) object.getProperty().getItem();
        if (item.getConnection() instanceof DatabaseConnection) {
            DatabaseConnection connection = (DatabaseConnection) item.getConnection();
            String rawType = connection.getDatabaseType();
            if (StringUtils.equalsIgnoreCase(rawType, SQLSERVER22008_TYPE)) {
                connection.setDatabaseType(SupportDBUrlType.GENERICJDBCDEFAULTURL.getDBKey());
                connection.setDriverClass(null);
                connection.setDriverClass(PluginConstant.EMPTY_STRING);
            }
            ProxyRepositoryFactory.getInstance().save(item);
        } else {
            // $NON-NLS-1$ //$NON-NLS-2$
            log.warn("Database " + object.getProperty().getLabel() + " Ignored: It's not a Database Connection!");
        }
    }
    return true;
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection)

Example 50 with DatabaseConnection

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

the class UpdateFileAfterMergeConnectionTask method fillConnectionNameLabel.

/**
 * fill connection's name or label if they are null.
 */
private void fillConnectionNameLabel() {
    // $NON-NLS-1$
    File connectionFolder = getWorkspacePath().append("metadata").toFile();
    ArrayList<File> fileList = new ArrayList<File>();
    FilesUtils.getAllFilesFromFolder(connectionFolder, fileList, new FilenameFilter() {

        public boolean accept(File dir, String name) {
            if (name.endsWith("item")) {
                // $NON-NLS-1$
                return true;
            }
            return false;
        }
    });
    for (File file : fileList) {
        Connection connection = getConnectionFromFile(file);
        if (connection == null) {
            continue;
        }
        Property property = PropertyHelper.getProperty(connection);
        if (connection.getName() == null && connection.getLabel() == null) {
            if (property.getLabel() != null) {
                connection.setName(property.getLabel());
                connection.setLabel(property.getLabel());
            }
        } else {
            if (connection.getName() != null && connection.getLabel() == null) {
                connection.setLabel(connection.getName());
            } else if (connection.getName() == null && connection.getLabel() != null) {
                connection.setName(connection.getLabel());
            }
        }
        if (connection instanceof DatabaseConnection) {
            DatabaseConnection dbconn = (DatabaseConnection) connection;
            String[] urlParamArray = DatabaseConnStrUtil.analyseURL(dbconn.getDatabaseType(), dbconn.getDbVersionString(), dbconn.getURL());
            if (StringUtils.isEmpty(dbconn.getServerName()) || StringUtils.isEmpty(dbconn.getPort()) || StringUtils.isEmpty(dbconn.getAdditionalParams())) {
                fillParametersFromURL(dbconn, urlParamArray);
            }
        }
        EMFUtil.saveResource(connection.eResource());
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) ArrayList(java.util.ArrayList) 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) File(java.io.File) Property(org.talend.core.model.properties.Property)

Aggregations

DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)211 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)66 Connection (org.talend.core.model.metadata.builder.connection.Connection)53 ConnectionItem (org.talend.core.model.properties.ConnectionItem)42 ArrayList (java.util.ArrayList)41 PersistenceException (org.talend.commons.exception.PersistenceException)41 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)39 Test (org.junit.Test)33 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)30 Property (org.talend.core.model.properties.Property)30 Item (org.talend.core.model.properties.Item)26 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)20 IElementParameter (org.talend.core.model.process.IElementParameter)19 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)18 RepositoryNode (org.talend.repository.model.RepositoryNode)18 SQLException (java.sql.SQLException)17 TdTable (org.talend.cwm.relational.TdTable)17 Catalog (orgomg.cwm.resource.relational.Catalog)17 List (java.util.List)15 ReturnCode (org.talend.utils.sugars.ReturnCode)14