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;
}
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();
}
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());
}
}
}
}
}
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;
}
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());
}
}
Aggregations