use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class ConnectionCreateAction method run.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
IMetadataTable meta = null;
IMetadataTable newMetadata = null;
String connectionName = null;
if (getSelectedObjects().isEmpty()) {
return;
}
List parts = getSelectedObjects();
if (parts.size() == 1) {
Object o = parts.get(0);
if (!(o instanceof NodePart)) {
return;
}
nodePart = (NodePart) o;
} else {
return;
}
Node node = (Node) nodePart.getModel();
if (curNodeConnector.isMultiSchema()) {
if (getText().equals(getNewOutputMenuName())) {
// boolean nameOk = false;
// while (!nameOk) {
//
// if (node.isELTComponent()) {
// connectionName = "Default";
// } else {
// connectionName = askForConnectionName(node.getLabel(), connectionName);
// }
// if (connectionName.equals("")) { //$NON-NLS-1$
// return;
// }
// if (connecType.equals(EConnectionType.TABLE) ||
// node.getProcess().checkValidConnectionName(connectionName)) {
// nameOk = true;
// } else {
// String message = Messages.getString("ConnectionCreateAction.errorCreateConnectionName",
// connectionName); //$NON-NLS-1$
// MessageDialog.openError(getWorkbenchPart().getSite().getShell(), Messages
// .getString("ConnectionCreateAction.error"), message); //$NON-NLS-1$
// }
// }
//
// if (connecType.equals(EConnectionType.TABLE)) {
// meta = new MetadataTable();
// meta.setTableName(connectionName);
// meta.setLabel(connectionName);
// // meta.setTableId(node.getMetadataList().size());
// newMetadata = meta;
// } else {
// boolean metaExist = false;
// for (int i = 0; i < node.getMetadataList().size(); i++) {
// if ((node.getMetadataList().get(i)).getTableName().equals(connectionName)) {
// metaExist = true;
// }
// }
// if (!metaExist) {
// meta = new MetadataTable();
// meta.setTableName(connectionName);
// newMetadata = meta;
// }
// }
} else {
String tableName;
// int tableId = -1;
if (connecType == EConnectionType.TABLE) {
int end = getText().length() - 1;
//$NON-NLS-1$
int start = getText().lastIndexOf("(") + 1;
tableName = getText().substring(start, end);
// table = Integer.parseInt(stringId);
// tableName = getText().substring(0, start - 2);
meta = node.getMetadataTable(tableName);
// meta = (IMetadataTable) node.getMetadataList().get(tableId);
connectionName = meta.getLabel();
} else {
tableName = getText();
// tableId = -1;
meta = node.getMetadataTable(tableName);
// for (int i = 0; i < node.getMetadataList().size(); i++) {
// IMetadataTable table = (IMetadataTable) node.getMetadataList().get(i);
// if (table.getTableName().equals(tableName)) {
// meta = (IMetadataTable) node.getMetadataList().get(i);
// }
// }
connectionName = meta.getTableName();
}
}
// for built-in only:
if (meta != null) {
meta.setAttachedConnector(curNodeConnector.getName());
}
} else {
if (connecType == EConnectionType.TABLE) {
if (getText().equals(getDefaultTableName())) {
//$NON-NLS-1$
int end = getText().lastIndexOf("(") - 1;
int start = 0;
if (end >= start) {
connectionName = getText().substring(start, end);
meta = node.getMetadataList().get(0);
meta.setAttachedConnector(curNodeConnector.getName());
} else if (getText().endsWith(".")) {
connectionName = askForConnectionName(node.getLabel(), null);
if (connectionName != null && !"".equals(connectionName)) {
connectionName = getText() + connectionName;
}
meta = node.getMetadataList().get(0);
meta.setAttachedConnector(curNodeConnector.getName());
}
} else if (getText().equals(getNewOutputMenuName()) && getDefaultTableName() != null) {
if (node.getComponent().getName().equals("tELTOracleInput")) {
//$NON-NLS-1$
connectionName = askForConnectionNameAndSchema(node.getLabel(), null);
} else {
connectionName = askForConnectionName(node.getLabel(), null);
}
} else {
// if (node.isELTComponent() && node.getComponentName().endsWith("Input"))
if (node.getComponent().getName().equals("tELTOracleInput")) {
//$NON-NLS-1$
connectionName = askForConnectionNameAndSchema(node.getLabel(), getDefaultSchemaName());
} else {
connectionName = askForConnectionName(node.getLabel(), null);
}
}
} else {
if (connecType.hasConnectionCategory(IConnectionCategory.FLOW)) {
connectionName = node.getProcess().generateUniqueConnectionName(Process.DEFAULT_ROW_CONNECTION_NAME);
} else if (connecType.hasConnectionCategory(IConnectionCategory.CAMEL)) {
connectionName = ConnectionUtil.generateUniqueConnectionName(connecType, node.getProcess(), curNodeConnector);
} else {
connectionName = curNodeConnector.getLinkName();
}
}
if (node.getMetadataList().size() == 0) {
meta = null;
} else {
meta = node.getMetadataFromConnector(curNodeConnector.getName());
}
}
/**
* Create a mouse down event that thinks it is over the blob and dispatch it. This is a bit of a fudge to mimic
* what the user ought to do.
*/
Point point = null;
point = nodePart.getFigure().getClientArea().getCenter();
Point p = point;
nodePart.getFigure().translateToAbsolute(p);
Canvas canvas = (Canvas) nodePart.getViewer().getControl();
Event event = new Event();
event.button = 1;
event.count = 0;
event.detail = 0;
event.end = 0;
event.height = 0;
event.keyCode = 0;
event.start = 0;
event.stateMask = 0;
// any old time... doesn't matter
event.time = 9516624;
event.type = 3;
event.widget = canvas;
event.width = 0;
event.x = p.x + 3;
event.y = p.y + 3;
/**
* Set the connection tool to be the current tool
*/
listArgs = new ArrayList<Object>();
if (connecType.equals(EConnectionType.FLOW_MAIN) || connecType.equals(EConnectionType.FLOW_REF) || connecType.equals(EConnectionType.TABLE)) {
if (meta == null) {
listArgs.add(null);
} else {
listArgs.add(meta.getTableName());
}
} else {
listArgs.add(node.getUniqueName());
}
String baseName = node.getConnectionName();
String fromConnectionName = null;
if (node.getProcess().checkValidConnectionName(baseName)) {
fromConnectionName = node.getProcess().generateUniqueConnectionName(baseName);
}
if (fromConnectionName != null && connecType.hasConnectionCategory(IConnectionCategory.FLOW) && node.getProcess().checkValidConnectionName(fromConnectionName, false) && !curNodeConnector.isMultiSchema()) {
listArgs.add(fromConnectionName);
} else {
listArgs.add(connectionName);
}
listArgs.add(newMetadata);
TalendConnectionCreationTool myConnectTool = new TalendConnectionCreationTool(new CreationFactory() {
@Override
public Object getNewObject() {
return listArgs;
}
@Override
public Object getObjectType() {
return curNodeConnector.getName();
}
}, true);
myConnectTool.performConnectionStartWith(nodePart);
nodePart.getViewer().getEditDomain().setActiveTool(myConnectTool);
canvas.notifyListeners(3, event);
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class TracesConnectionUtils method getEnabledTraceColumns.
public static List<String> getEnabledTraceColumns(final IConnection conn) {
List<String> enabledColumns = new ArrayList<String>();
List<Map<String, Object>> values = getTraceConnectionFilterValues(conn);
IMetadataTable table = conn.getMetadataTable();
if (values != null && conn != null && !values.isEmpty()) {
for (Map<String, Object> line : values) {
Object column = line.get(IConnection.TRACE_SCHEMA_COLUMN);
if (isTraceColumnEnabled(conn, line, column)) {
enabledColumns.add((String) column);
}
}
} else if (table != null) {
for (IMetadataColumn column : table.getListColumns()) {
enabledColumns.add(column.getLabel());
}
}
return enabledColumns;
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class TracesConnectionUtils method setTraceColumnValues.
public static void setTraceColumnValues(final IConnection conn, final String columnName, String condition, boolean enable) {
if (conn == null || columnName == null || EMPTY.equals(columnName)) {
return;
}
if (condition == null) {
condition = EMPTY;
}
IMetadataTable table = conn.getMetadataTable();
List<Map<String, Object>> values = getTraceConnectionFilterValues(conn);
if (table != null && values != null) {
Map<String, Object> foundLine = null;
for (Map<String, Object> line : values) {
Object column = line.get(IConnection.TRACE_SCHEMA_COLUMN);
if (columnName.equals(column)) {
// found
foundLine = line;
break;
}
}
if (foundLine == null) {
// not found
foundLine = new HashMap<String, Object>();
foundLine.put(IConnection.TRACE_SCHEMA_COLUMN, columnName);
values.add(foundLine);
}
foundLine.put(IConnection.TRACE_SCHEMA_COLUMN_CHECKED, new Boolean(enable));
foundLine.put(IConnection.TRACE_SCHEMA_COLUMN_CONDITION, condition);
}
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class ComponentChooseDialog method getPropertyPublicPart.
private Command getPropertyPublicPart(RepositoryNode selectedNode, IElementParameter param, Node node, ConnectionItem connectionItem) {
param.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
ChangeValuesFromRepository command2 = new ChangeValuesFromRepository(node, connectionItem.getConnection(), param.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), //$NON-NLS-1$
selectedNode.getObject().getProperty().getId());
if (selectedNode.getObject() instanceof IMetadataTable) {
IMetadataTable metadataTable = (IMetadataTable) selectedNode.getObject();
command2.setTable(metadataTable);
}
return command2;
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class ConvertRepositoryNodeToProcessNode method convertToProcessNode.
public void convertToProcessNode(ConnectionItem connectionItem, String tableName) throws ProcessorException {
EDatabaseComponentName name = EDatabaseComponentName.getCorrespondingComponentName(connectionItem, ERepositoryObjectType.METADATA_CONNECTIONS);
String componentName = null;
componentName = name.getDefaultComponentName();
IComponent dbInputComponent = ComponentsFactoryProvider.getInstance().get(componentName, ComponentCategory.CATEGORY_4_DI.getName());
Process process = new Process(GuessSchemaProcess.getNewmockProperty());
node = new Node(dbInputComponent, process);
selectedContext = node.getProcess().getContextManager().getDefaultContext();
// TDI-20011
IMetadataTable table = UpdateRepositoryUtils.getTableByName(connectionItem, tableName);
if (table == null) {
table = new MetadataTable();
table.setTableName(tableName);
table.setLabel(tableName);
}
IElementParameter propertyParam = ((Node) node).getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
IElementParameter schemaParam = ((Node) node).getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
if (schemaParam == null) {
schemaParam = ((Node) node).getElementParameterFromField(EParameterFieldType.SCHEMA_REFERENCE);
}
String propertyId = connectionItem.getProperty().getId();
String schema = databaseConnection.getUiSchema();
String dbType = databaseConnection.getDatabaseType();
//$NON-NLS-1$
String value = connectionItem.getProperty().getId() + " - " + table.getLabel();
CompoundCommand cc = new CompoundCommand();
// inital parameters command
ChangeValuesFromRepository changeValueCommand = new ChangeValuesFromRepository(node, databaseConnection, propertyParam.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), //$NON-NLS-1$
propertyId);
changeValueCommand.ignoreContextMode(true);
cc.add(changeValueCommand);
// change metadata command
RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) node, //$NON-NLS-1$
schemaParam.getName() + ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName(), value, table, null, null);
cc.add(changeMetadataCommand);
// guess query command
QueryGuessCommand queryGuessCommand = new QueryGuessCommand(node, node.getMetadataList().get(0), schema, dbType, databaseConnection);
cc.add(queryGuessCommand);
// execute the commands
cc.execute();
//$NON-NLS-1$
IElementParameter query = node.getElementParameter("QUERY");
//
memoSQL = query.getValue().toString();
String memoSQLTemp = TalendTextUtils.removeQuotesIfExist(memoSQL);
if ((memoSQLTemp == null || memoSQLTemp.equals("")) && tableName != null && !tableName.equals("")) {
//$NON-NLS-1$
boolean check = !Pattern.matches("^\\w+$", tableName);
boolean isJDBCForMysql = databaseConnection.getURL() == null ? false : databaseConnection.getURL().startsWith("jdbc:mysql");
if ((dbType.equals(EDatabaseTypeName.MYSQL.getDisplayName()) || isJDBCForMysql) && check) {
tableName = TalendQuoteUtils.addQuotes(tableName, TalendQuoteUtils.ANTI_QUOTE);
}
memoSQL = "select * from " + tableName;
memoSQL = TalendTextUtils.addSQLQuotes(memoSQL);
}
}
Aggregations