use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.
the class QueryTypeController method getGuessQueryCommand.
/**
* DOC nrousseau Comment method "getGuessQueryCommand".
*
* @return
*/
private QueryGuessCommand getGuessQueryCommand() {
// Map<String, IMetadataTable> repositoryTableMap = null;
IMetadataTable newRepositoryMetadata = null;
String realTableName = null;
String realTableId = null;
String schemaName = "";
// Only for getting the real table name.
if (elem.getPropertyValue(EParameterName.SCHEMA_TYPE.getName()).equals(EmfComponent.REPOSITORY)) {
IElementParameter repositorySchemaTypeParameter = elem.getElementParameter(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
if (repositorySchemaTypeParameter != null) {
final Object value = repositorySchemaTypeParameter.getValue();
if (elem instanceof Node) {
/* value can be devided means the value like "connectionid - label" */
String[] keySplitValues = value.toString().split(" - ");
if (keySplitValues.length > 1) {
String connectionId = value.toString().split(" - ")[0];
String tableLabel = value.toString().split(" - ")[1];
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
if (repobj != null) {
Property property = repobj.getProperty();
if (property != null) {
item = property.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
Connection connection = ((ConnectionItem) item).getConnection();
for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
// bug 20365
if (table.getLabel().equals(tableLabel)) {
IMetadataTable repositoryMetadata = ConvertionHelper.convert(table);
realTableName = repositoryMetadata.getTableName();
realTableId = repositoryMetadata.getId();
// }
break;
}
}
}
}
// if (repositoryTableMap.containsKey(value)) {
// IMetadataTable repositoryMetadata = repositoryTableMap.get(value);
// realTableName = repositoryMetadata.getTableName();
// realTableId = repositoryMetadata.getId();
// }
}
}
// }
// }
}
// Ends
Connection repositoryConnection = null;
boolean useExisting = false;
IElementParameter elementParameter = elem.getElementParameter(EParameterName.USE_EXISTING_CONNECTION.name());
if (elem instanceof Node) {
IProcess process = ((Node) elem).getProcess();
if (elementParameter != null && Boolean.valueOf(String.valueOf(elementParameter.getValue()))) {
String connName = (String) elem.getPropertyValue("CONNECTION");
for (INode node : process.getGraphicalNodes()) {
if (node.getElementName().equals(connName)) {
useExisting = true;
final Object propertyValue = node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
if (propertyValue != null) {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(propertyValue.toString());
if (repobj != null) {
Property property = repobj.getProperty();
if (property != null) {
item = property.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
repositoryConnection = ((ConnectionItem) item).getConnection();
} else {
initConnectionParameters();
repositoryConnection = TracesConnectionUtils.createConnection(connParameters);
}
}
break;
}
}
}
}
if (!useExisting && elem.getPropertyValue(EParameterName.PROPERTY_TYPE.getName()).equals(EmfComponent.REPOSITORY)) {
final Object propertyValue = elem.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
if (propertyValue != null) {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(propertyValue.toString());
if (repobj != null) {
Property property = repobj.getProperty();
if (property != null) {
item = property.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
repositoryConnection = ((ConnectionItem) item).getConnection();
}
}
} else {
initConnectionParameters();
repositoryConnection = TracesConnectionUtils.createConnection(connParameters);
}
QueryGuessCommand cmd = null;
INode node = null;
if (elem instanceof INode) {
node = (INode) elem;
} else {
// else instanceof Connection
node = ((IConnection) elem).getSource();
}
List<IMetadataTable> metadataList = node.getMetadataList();
newRepositoryMetadata = metadataList.get(0);
// for tInformixRow
if (newRepositoryMetadata.getListColumns().size() == 0 && metadataList.size() > 1) {
newRepositoryMetadata = metadataList.get(1);
}
if (newRepositoryMetadata == null) {
String schemaSelected = (String) node.getPropertyValue(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
if (schemaSelected != null) {
// repositoryMetadata = repositoryTableMap.get(schemaSelected);
} else if (newRepositoryMetadata == null) {
MessageDialog.openWarning(new Shell(), Messages.getString("QueryTypeController.alert"), //$NON-NLS-1$ //$NON-NLS-2$
Messages.getString("QueryTypeController.nothingToGuess"));
return cmd;
}
}
cmd = new QueryGuessCommand(node, newRepositoryMetadata, repositoryConnection);
cmd.setMaps(dynamicProperty.getTableIdAndDbTypeMap(), dynamicProperty.getTableIdAndDbSchemaMap(), null);
//$NON-NLS-1$
String type = getValueFromRepositoryName("TYPE");
if ("Oracle".equalsIgnoreCase(type)) {
type = EDatabaseTypeName.ORACLEFORSID.getDisplayName();
}
cmd.setParameters(realTableId, realTableName, type);
return cmd;
}
use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.
the class QueryTypeController method createButtonCommand.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createButtonCommand(org
* .eclipse.swt.widgets.Button)
*/
@Override
protected Command createButtonCommand(Button button) {
if (button.getData(NAME).equals(GUESS_QUERY_NAME)) {
return getGuessQueryCommand();
}
if (button.getData(NAME).equals(REPOSITORY_CHOICE)) {
RepositoryReviewDialog dialog = new RepositoryReviewDialog(button.getShell(), ERepositoryObjectType.METADATA_CON_QUERY, null);
if (dialog.open() == RepositoryReviewDialog.OK) {
RepositoryNode node = dialog.getResult();
while (node.getObject().getProperty().getItem() == null || (!(node.getObject().getProperty().getItem() instanceof ConnectionItem))) {
node = node.getParent();
}
String id = node.getObject().getProperty().getId();
String name = dialog.getResult().getObject().getLabel();
String paramName = (String) button.getData(PARAMETER_NAME);
//$NON-NLS-1$
String value = id + " - " + name;
Query query = MetadataToolHelper.getQueryFromRepository(value);
if (query != null) {
IElementParameter queryText = getQueryTextElementParameter(elem);
if (queryText != null) {
return new RepositoryChangeQueryCommand(elem, query, EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName(), value);
}
}
}
}
return null;
}
use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.
the class PropertyTypeController method initCDC.
private void initCDC(CompoundCommand cc, ConnectionItem originalConnectionItem) {
if (!(elem instanceof Node)) {
return;
}
Node node = (Node) elem;
// ConnectionItem originalConnectionItem = repositoryConnectionItem;
ConnectionItem connectionItem = originalConnectionItem;
Connection originalConnection = connectionItem.getConnection();
Connection connection = connectionItem.getConnection();
if (node.getComponent().getName().contains("CDC")) {
// to replace by a flag CDC in component? //$NON-NLS-1$
if (originalConnectionItem instanceof DatabaseConnectionItem) {
final DatabaseConnection databaseConnection = (DatabaseConnection) connection;
CDCConnection cdcConn = databaseConnection.getCdcConns();
if (cdcConn != null) {
EList cdcTypes = cdcConn.getCdcTypes();
if (cdcTypes != null && !cdcTypes.isEmpty()) {
CDCType cdcType = (CDCType) cdcTypes.get(0);
// replace property by CDC property.
String propertyId = cdcType.getLinkDB();
try {
IRepositoryViewObject object = ProxyRepositoryFactory.getInstance().getLastVersion(propertyId);
if (object != null) {
if (object.getProperty().getItem() instanceof DatabaseConnectionItem) {
DatabaseConnectionItem dbConnItem = (DatabaseConnectionItem) object.getProperty().getItem();
// replace connection by CDC connection
connectionItem = dbConnItem;
connection = dbConnItem.getConnection();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
// set cdc type mode.
IElementParameter logModeParam = node.getElementParameter(EParameterName.CDC_TYPE_MODE.getName());
if (logModeParam != null) {
String cdcTypeMode = ((DatabaseConnection) originalConnection).getCdcTypeMode();
Command logModeCmd = new PropertyChangeCommand(node, EParameterName.CDC_TYPE_MODE.getName(), CDCTypeMode.LOG_MODE.getName().equals(cdcTypeMode));
cc.add(logModeCmd);
}
// set lib for as400 so far.
//$NON-NLS-1$
final String name = "SOURCE_LIB";
IElementParameter libParam = node.getElementParameter(name);
if (libParam != null) {
Object propValue;
if (connection.isContextMode() && ContextParameterUtils.isContainContextParam(databaseConnection.getSID())) {
propValue = databaseConnection.getSID();
} else {
propValue = TalendTextUtils.addQuotes(databaseConnection.getSID());
}
Command libSettingCmd = new PropertyChangeCommand(node, name, propValue);
cc.add(libSettingCmd);
}
}
}
}
}
}
use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.
the class AbstractPreferenceComposite method updateContextValue.
protected void updateContextValue(boolean update) {
if (!update) {
return;
}
IElementParameter proElement = elem.getElementParameter(EParameterName.PROPERTY_TYPE.getName()).getChildParameters().get(EParameterName.PROPERTY_TYPE.getName());
Object value = proElement.getValue();
if (value instanceof String && ((String) value).equalsIgnoreCase(EmfComponent.REPOSITORY)) {
String id = (String) elem.getElementParameter(//$NON-NLS-1$
EParameterName.PROPERTY_TYPE.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue();
String propertyType = EParameterName.PROPERTY_TYPE.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName();
ConnectionItem connectionItem = UpdateRepositoryUtils.getConnectionItemByItemId(id);
Connection connection = connectionItem.getConnection();
ChangeValuesFromRepository command = new ChangeValuesFromRepository(elem, connection, propertyType, id);
getCommandStack().execute(command);
}
}
use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.
the class ImplicitContextLoadHelper method loadPropertyTypeFromPreference.
/**
* DOC hcw Comment method "reloadPropertyType".
*
* @param element
* @param extraComposite
* @param languagePrefix
* @param elementParameter
*/
private static void loadPropertyTypeFromPreference(Element element, ExtraComposite extraComposite, String languagePrefix, IElementParameter elementParameter) {
String propertyType = (String) getPreferenceValue(languagePrefix, EParameterName.PROPERTY_TYPE, String.class);
String id = (String) getPreferenceValue(languagePrefix, EParameterName.REPOSITORY_PROPERTY_TYPE, String.class);
Connection repositoryConnection = null;
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(id);
if (repobj != null) {
Property tmpproperty = repobj.getProperty();
if (tmpproperty != null) {
item = tmpproperty.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
repositoryConnection = ((ConnectionItem) item).getConnection();
} else {
repositoryConnection = null;
}
ChangeValuesFromRepository cmd1 = new ChangeValuesFromRepository(element, repositoryConnection, getExtraParameterName(EParameterName.PROPERTY_TYPE) + ":" + EParameterName.PROPERTY_TYPE.getName(), //$NON-NLS-1$
propertyType);
ChangeValuesFromRepository cmd2 = new ChangeValuesFromRepository(element, repositoryConnection, getExtraParameterName(EParameterName.PROPERTY_TYPE) + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), //$NON-NLS-1$
id);
AbstractMultiPageTalendEditor part = (AbstractMultiPageTalendEditor) ((IProcess2) element).getEditor();
if (part instanceof AbstractMultiPageTalendEditor) {
Object adapter = (part).getTalendEditor().getAdapter(CommandStack.class);
if (adapter != null) {
CommandStack commandStack = ((CommandStack) adapter);
commandStack.execute(cmd1);
commandStack.execute(cmd2);
}
}
}
Aggregations