use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.
the class DatabaseTypeFilter method isSupportNode.
private boolean isSupportNode(IRepositoryNode node, String[] items) {
if (filterItems == null) {
return true;
}
List<String> asList = Arrays.asList(items);
if (node.getObject() == null) {
if (node.getType() == ENodeType.REFERENCED_PROJECT || node.getType() == ENodeType.SYSTEM_FOLDER) {
return true;
}
if (node.getContentType() != null && node.getContentType().equals(ERepositoryObjectType.METADATA)) {
return true;
}
} else {
Item item = node.getObject().getProperty().getItem();
if (item instanceof DatabaseConnectionItem) {
DatabaseConnectionItem connItem = (DatabaseConnectionItem) item;
DatabaseConnection connection = (DatabaseConnection) connItem.getConnection();
if (connection != null) {
String databaseType = connection.getDatabaseType();
if (databaseType.equals(EDatabaseTypeName.ORACLEFORSID.getDisplayName())) {
databaseType = EDatabaseTypeName.ORACLEFORSID.getXmlName();
} else if (databaseType.equals(EDatabaseTypeName.ORACLESN.getDisplayName())) {
databaseType = EDatabaseTypeName.ORACLESN.getXmlName();
} else if (databaseType.equals(EDatabaseTypeName.ORACLE_OCI.getDisplayName())) {
databaseType = EDatabaseTypeName.ORACLE_OCI.getXmlName();
} else if (databaseType.equals(EDatabaseTypeName.MSSQL.getDisplayName())) {
// for component
databaseType = EDatabaseTypeName.MSSQL.getXmlName();
} else {
databaseType = EDatabaseTypeName.getTypeFromDbType(databaseType).getProduct();
}
if (asList.contains(databaseType)) {
return true;
}
}
} else if (item instanceof FolderItem) {
return true;
}
}
return false;
}
use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.
the class EMFRepositoryNodeManager method getQueryByLabel.
/**
* dev Comment method "getQueryByLabel".
*
* @param node all repository node Type
* @param label search query label
* @return
*/
@SuppressWarnings("unchecked")
public Query getQueryByLabel(RepositoryNode node, String label) {
root = null;
if (node.getObjectType().equals(ERepositoryObjectType.METADATA_CON_QUERY)) {
root = node.getParent().getParent();
} else {
root = SQLBuilderRepositoryNodeManager.getRoot(node);
}
if (root == null) {
return null;
}
DatabaseConnectionItem item = SQLBuilderRepositoryNodeManager.getItem(root);
DatabaseConnection connection = (DatabaseConnection) item.getConnection();
QueriesConnection queriesConnection = connection.getQueries();
if (queriesConnection != null) {
List<Query> queries = queriesConnection.getQuery();
for (Query query : queries) {
if (query.getLabel().equals(label)) {
return query;
}
}
}
return null;
}
use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.
the class EMFRepositoryNodeManager method parseSqlStatement.
@SuppressWarnings("unchecked")
public List<IRepositoryNode> parseSqlStatement(String sql, RepositoryNode currRoot) throws Exception {
// inital the quote depence on the dbtype
IRepositoryViewObject rObject = currRoot.getObject();
DatabaseConnectionItem item = (DatabaseConnectionItem) rObject.getProperty().getItem();
DatabaseConnection dbConnection = (DatabaseConnection) item.getConnection();
String dbType = dbConnection.getDatabaseType();
leftDbQuote = TalendTextUtils.getQuoteByDBType(dbType, true);
rightDbQuote = TalendTextUtils.getQuoteByDBType(dbType, false);
sql = initSqlStatement(sql);
if (sql == null || "".equals(sql) || !sql.startsWith("select ")) {
//$NON-NLS-1$ //$NON-NLS-2$
return Collections.EMPTY_LIST;
}
List<String> tableNames = new ArrayList<String>();
List<String> columnsNames = new ArrayList<String>();
String[] cols = parseSqlToNameList(sql, tableNames, columnsNames);
List<IRepositoryNode> nodes = new ArrayList<IRepositoryNode>();
for (IRepositoryNode tableNode : currRoot.getChildren()) {
for (int i = 0; i < tableNames.size(); i++) {
//$NON-NLS-1$
String tableLabel = "";
if (tableNode.getObject() instanceof MetadataTableRepositoryObject) {
MetadataTableRepositoryObject object = (MetadataTableRepositoryObject) tableNode.getObject();
tableLabel = object.getSourceName();
} else {
tableLabel = tableNode.getObject().getLabel();
}
boolean isNeed = false;
if (cols.length == 1 && cols[0].equals("*")) {
//$NON-NLS-1$
for (String string : tableNames) {
if (string.equals(tableLabel.toLowerCase())) {
nodes.add(tableNode);
isNeed = true;
}
}
}
if (tableLabel != null) {
for (String string : tableNames) {
if (string.equals(tableLabel.toLowerCase())) {
isNeed = true;
}
}
}
if (isNeed) {
for (IRepositoryNode colNode : tableNode.getChildren()) {
//$NON-NLS-1$
String collabel = "";
if (colNode.getObject() instanceof MetadataColumnRepositoryObject) {
MetadataColumnRepositoryObject object2 = (MetadataColumnRepositoryObject) colNode.getObject();
collabel = object2.getSourceName();
} else {
collabel = colNode.getObject().getLabel();
}
if (collabel != null) {
for (String string : columnsNames) {
if ((string.replaceAll("\\" + leftDbQuote, "").replaceAll("\\" + rightDbQuote, "")).equals(//$NON-NLS-1$ //$NON-NLS-2$
collabel.toLowerCase())) {
nodes.add(colNode);
}
// right bracket
if ((string.replaceAll("\\" + leftDbQuote, "").replaceAll("\\" + rightDbQuote, "")).equals(tableLabel.toLowerCase() + "." + collabel.toLowerCase())) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (!nodes.contains(colNode)) {
nodes.add(colNode);
}
}
for (int j = 0; j < relations.size(); j++) {
String[] pks = relations.get(j);
String pk = pks[0];
String fk = pks[1];
boolean isSet = false;
if (pk.equals(collabel.toLowerCase())) {
isSet = true;
//$NON-NLS-1$
pk = tableLabel.toLowerCase() + "." + collabel.toLowerCase();
if (!nodes.contains(colNode)) {
nodes.add(colNode);
}
}
if (fk.equals(collabel.toLowerCase())) {
isSet = true;
//$NON-NLS-1$
fk = tableLabel.toLowerCase() + "." + collabel.toLowerCase();
if (!nodes.contains(colNode)) {
nodes.add(colNode);
}
}
if (pk.equals(tableLabel.toLowerCase() + "." + collabel.toLowerCase())) {
//$NON-NLS-1$
if (!nodes.contains(colNode)) {
nodes.add(colNode);
}
}
if (fk.equals(tableLabel.toLowerCase() + "." + collabel.toLowerCase())) {
//$NON-NLS-1$
if (!nodes.contains(colNode)) {
nodes.add(colNode);
}
}
if (isSet) {
relations.set(j, new String[] { pk, fk });
}
}
}
}
}
}
}
}
return nodes;
}
use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.
the class MetadataColumnComparator method getEMFItem.
public static DatabaseConnectionItem getEMFItem(String id) {
IRepositoryViewObject repositoryObject = DBTreeProvider.getMaps().get(id);
DatabaseConnectionItem item = (DatabaseConnectionItem) repositoryObject.getProperty().getItem();
return item;
}
use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.
the class MetadataColumnComparator method createNewRepositoryNode.
/**
* dev Comment method "createNewRepositoryNode".
*
* @param node
* @param parameters
* @param connection
* @param iMetadataConnection
* @return
*/
@SuppressWarnings("unchecked")
private RepositoryNode createNewRepositoryNode(RepositoryNode node, ConnectionParameters parameters, DatabaseConnection connection, IMetadataConnection iMetadataConnection) {
ManagerConnection managerConnection = new ManagerConnection();
boolean status = managerConnection.check(iMetadataConnection);
connection.setDivergency(!status);
ConnectionHelper.getTables(connection).clear();
if (status) {
// try {
// List<MetadataTable> tablesFromDB = ExtractMetaDataFromDataBase.returnMetaTablesFormConnection(
// iMetadataConnection, 500);
// ExtractMetaDataUtils.getInstance().setReconnect(false);
// for (MetadataTable table : tablesFromDB) {
// List<MetadataColumn> columnsFromDB = new ArrayList<MetadataColumn>();
// columnsFromDB.addAll(ExtractMetaDataFromDataBase.returnMetadataColumnsFormTable(iMetadataConnection,
// table.getSourceName()));
// table.getColumns().clear();
// for (MetadataColumn column : columnsFromDB) {
// column.setLabel(""); //$NON-NLS-1$
// table.getColumns().add(column);
// }
// table.setLabel(""); //$NON-NLS-1$
// ConnectionHelper.getTables(connection).add(table);
// }
// ExtractMetaDataUtils.getInstance().setReconnect(true);
// } catch (Exception e) {
// if (parameters != null) {
// parameters.setConnectionComment(e.getMessage());
// }
// return null;
// }
} else {
if (parameters != null) {
parameters.setConnectionComment(managerConnection.getMessageException() == null ? "" : //$NON-NLS-1$
managerConnection.getMessageException());
}
}
DatabaseConnectionItem item = PropertiesFactory.eINSTANCE.createDatabaseConnectionItem();
Property connectionProperty = PropertiesFactory.eINSTANCE.createProperty();
connectionProperty.setAuthor(((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
connectionProperty.setVersion(VersionUtils.DEFAULT_VERSION);
//$NON-NLS-1$
connectionProperty.setStatusCode("");
item.setProperty(connectionProperty);
// TDI-18665
updatePackage(iMetadataConnection);
DatabaseConnection dbConn = (DatabaseConnection) iMetadataConnection.getCurrentConnection();
item.setConnection(dbConn);
RepositoryObject object = new RepositoryObject(connectionProperty);
//$NON-NLS-1$
object.setLabel("");
ItemState state = PropertiesFactory.eINSTANCE.createItemState();
state.setDeleted(false);
item.setState(state);
if (node == null) {
node = new RepositoryNode(null, null, ENodeType.SYSTEM_FOLDER);
}
RepositoryNode newNode = new RepositoryNode(object, node, ENodeType.SYSTEM_FOLDER);
return newNode;
}
Aggregations