use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class RepositoryValueUtils method getRepositoryAliasName.
/**
* DOC Administrator Comment method "getRepositoryAliasName".
*
* @param connectionItem
* @return
*/
public String getRepositoryAliasName(ConnectionItem connectionItem) {
ERepositoryObjectType repositoryObjectType = ERepositoryObjectType.getItemType(connectionItem);
String aliasName = repositoryObjectType.getAlias();
Connection connection = connectionItem.getConnection();
if (connection instanceof DatabaseConnection) {
if (((DatabaseConnection) connection).getDatabaseType() != null) {
//$NON-NLS-1$
String currentDbType = (String) RepositoryToComponentProperty.getValue(connection, "TYPE", null);
//$NON-NLS-1$ //$NON-NLS-2$
aliasName += " (" + currentDbType + ")";
}
}
return aliasName;
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class DynamicTabbedPropertySection method getRepositoryAliasName.
@Override
public String getRepositoryAliasName(ConnectionItem connectionItem) {
ERepositoryObjectType repositoryObjectType = ERepositoryObjectType.getItemType(connectionItem);
String aliasName = repositoryObjectType.getAlias();
Connection connection = connectionItem.getConnection();
if (connection instanceof DatabaseConnection) {
//$NON-NLS-1$
String currentDbType = (String) RepositoryToComponentProperty.getValue(connection, "TYPE", null);
//$NON-NLS-1$ //$NON-NLS-2$
aliasName += " (" + currentDbType + ")";
}
return aliasName;
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class DynamicTabbedPropertySection method updateRepositoryList.
/**
* ftang Comment method "updateRepositoryList".
*/
@SuppressWarnings("unchecked")
public void updateRepositoryList() {
IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
tableIdAndDbTypeMap = new HashMap<String, String>();
tableIdAndDbSchemaMap = new HashMap<String, String>();
List<ConnectionItem> metadataConnectionsItem = null;
String[] repositoryTableNameList = new String[] {};
String[] repositoryTableValueList = new String[] {};
String[] repositoryConnectionNameList = new String[] {};
String[] repositoryConnectionValueList = new String[] {};
String[] repositoryQueryNameList = new String[] {};
String[] repositoryQueryValueList = new String[] {};
try {
metadataConnectionsItem = factory.getMetadataConnectionsItem();
} catch (PersistenceException e) {
throw new RuntimeException(e);
}
if (metadataConnectionsItem != null) {
repositoryTableMap.clear();
repositoryQueryStoreMap.clear();
repositoryConnectionItemMap.clear();
tablesMap.clear();
queriesMap.clear();
List<String> tableNamesList = new ArrayList<String>();
List<String> tableValuesList = new ArrayList<String>();
List<String> queryStoreNameList = new ArrayList<String>();
List<String> queryStoreValuesList = new ArrayList<String>();
for (ConnectionItem connectionItem : metadataConnectionsItem) {
Connection connection = connectionItem.getConnection();
if (!connection.isReadOnly()) {
//$NON-NLS-1$
repositoryConnectionItemMap.put(connectionItem.getProperty().getId() + "", connectionItem);
for (Object tableObj : ConnectionHelper.getTables(connection)) {
org.talend.core.model.metadata.builder.connection.MetadataTable table;
table = (org.talend.core.model.metadata.builder.connection.MetadataTable) tableObj;
if (factory.getStatus(connectionItem) != ERepositoryStatus.DELETED) {
if (!factory.isDeleted(table)) {
String name = //$NON-NLS-1$
getRepositoryAliasName(connectionItem) + ":" + connectionItem.getProperty().getLabel() + " - " + //$NON-NLS-1$
table.getLabel();
//$NON-NLS-1$
String value = connectionItem.getProperty().getId() + " - " + table.getLabel();
IMetadataTable newTable = ConvertionHelper.convert(table);
repositoryTableMap.put(value, newTable);
if (connection instanceof DatabaseConnection) {
String dbType = ((DatabaseConnection) connection).getDatabaseType();
String schema = ((DatabaseConnection) connection).getUiSchema();
tableIdAndDbTypeMap.put(newTable.getId(), dbType);
if (schema != null && !schema.equals("")) {
//$NON-NLS-1$
tableIdAndDbSchemaMap.put(newTable.getId(), schema);
}
}
addOrderDisplayNames(tableValuesList, tableNamesList, value, name);
// tableNamesList.add(name);
// tableValuesList.add(value);
}
}
}
}
tablesMap.put(connectionItem.getProperty().getId(), tableValuesList);
if (connection instanceof DatabaseConnection && !connection.isReadOnly()) {
DatabaseConnection dbConnection = (DatabaseConnection) connection;
QueriesConnection queriesConnection = dbConnection.getQueries();
if (queriesConnection != null) {
List<Query> qs = queriesConnection.getQuery();
for (Query query : qs) {
String name = //$NON-NLS-1$
getRepositoryAliasName(connectionItem) + ":" + connectionItem.getProperty().getLabel() + " - " + //$NON-NLS-1$
query.getLabel();
//$NON-NLS-1$
String value = connectionItem.getProperty().getId() + " - " + query.getLabel();
repositoryQueryStoreMap.put(value, query);
addOrderDisplayNames(queryStoreValuesList, queryStoreNameList, value, name);
// queryStoreNameList.add(name);
// queryStoreValuesList.add(value);
}
}
}
queriesMap.put(connectionItem.getProperty().getId(), queryStoreValuesList);
}
repositoryTableNameList = tableNamesList.toArray(new String[0]);
repositoryTableValueList = tableValuesList.toArray(new String[0]);
repositoryQueryNameList = queryStoreNameList.toArray(new String[0]);
repositoryQueryValueList = queryStoreValuesList.toArray(new String[0]);
}
initMaps();
for (int i = 0; i < elem.getElementParameters().size(); i++) {
IElementParameter param = elem.getElementParameters().get(i);
if (param.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE) || param.getFieldType().equals(EParameterFieldType.SCHEMA_REFERENCE)) {
IElementParameter repositorySchemaType = param.getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
repositorySchemaType.setListItemsDisplayName(repositoryTableNameList);
repositorySchemaType.setListItemsValue(repositoryTableValueList);
if (!repositoryTableMap.keySet().contains(repositorySchemaType.getValue())) {
List<String> list2 = tablesMap.get(elem.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()));
boolean isNeeded = list2 != null && !list2.isEmpty();
if (repositoryTableNameList.length > 0 && repositoryConnectionValueList.length > 0 && isNeeded) {
repositorySchemaType.setValue(getDefaultRepository(param, true, repositoryConnectionValueList[0]));
// elem.setPropertyValue(EParameterName.REPOSITORY_SCHEMA_TYPE.getName(),
// getDefaultRepository(
// true, repositoryConnectionValueList[0]));
}
}
}
if (param.getName().equals(EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName())) {
param.setListItemsDisplayName(repositoryQueryNameList);
param.setListItemsValue(repositoryQueryValueList);
if (!repositoryQueryStoreMap.keySet().contains(param.getValue())) {
List<String> list2 = queriesMap.get(elem.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()));
boolean isNeeded = list2 != null && !list2.isEmpty();
if (repositoryQueryNameList.length > 0 && repositoryConnectionValueList.length > 0 && isNeeded) {
elem.setPropertyValue(EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName(), getDefaultRepository(elem.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE), false, repositoryConnectionValueList[0]));
}
}
}
if (param.getName().equals(EParameterName.REPOSITORY_PROPERTY_TYPE.getName())) {
updateRepositoryListExtra(param, repositoryConnectionNameList, repositoryConnectionValueList, false);
}
// // for job settings extra (feature 2710)
// if (param.getName().equals(extraRepositoryPropertyTypeName)) {
// updateRepositoryListExtra(param, repositoryConnectionNameList, repositoryConnectionValueList, true);
// }
}
updateQuery();
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class UpdateUrlForRedShiftMigrationTask 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;
try {
if (EDatabaseTypeName.REDSHIFT.getDisplayName().equals(dbConn.getDatabaseType())) {
// old url: //jdbc:[postgresql|paraccel]://localhost:5439/test
String oldUrl = dbConn.getURL();
if (oldUrl != null) {
//$NON-NLS-1$ //$NON-NLS-2$
String newUrl = oldUrl.replaceFirst("jdbc:\\w+:", "jdbc:redshift:");
if (!oldUrl.equals(newUrl)) {
dbConn.setURL(newUrl);
ProxyRepositoryFactory.getInstance().save(item, true);
return ExecutionResult.SUCCESS_NO_ALERT;
}
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class UpdateDbVersionForVerticaMigrationTask method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
if (item instanceof DatabaseConnectionItem) {
DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
if (dbItem.getConnection() instanceof DatabaseConnection) {
DatabaseConnection dbConnection = (DatabaseConnection) dbItem.getConnection();
if (EDatabaseTypeName.VERTICA.equals(EDatabaseTypeName.getTypeFromDbType(dbConnection.getDatabaseType()))) {
boolean modified = false;
if (dbConnection.getDbVersionString().equals(EDatabaseVersion4Drivers.VERTICA_6.name())) {
dbConnection.setDbVersionString(EDatabaseVersion4Drivers.VERTICA_6.getVersionValue());
modified = true;
}
if (modified) {
try {
ProxyRepositoryFactory.getInstance().save(item, true);
return ExecutionResult.SUCCESS_WITH_ALERT;
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
}
}
}
return ExecutionResult.NOTHING_TO_DO;
}
Aggregations