use of org.talend.core.model.metadata.IMetadataConnection in project tdi-studio-se by Talend.
the class SessionTreeNodeUtils method getSessionTreeNode.
public static SessionTreeNode getSessionTreeNode(DatabaseConnection dbconnection, RepositoryNode repositoryNode, String selectedContext) throws Exception {
// hyWang add for bug 0007014
IMetadataConnection iMetadataConnection = null;
iMetadataConnection = ConvertionHelper.convert(dbconnection, false, selectedContext);
String url = dbconnection.getURL();
if (url == null || url.equals("")) {
url = iMetadataConnection.getUrl();
}
// bug 17980
SQLConnection connection = null;
DriverShim wapperDriver = null;
List list = createSQLConnection(dbconnection, selectedContext, iMetadataConnection);
if (list != null && list.size() > 0) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i) instanceof SQLConnection) {
connection = (SQLConnection) list.get(i);
}
if (list.get(i) instanceof DriverShim) {
wapperDriver = (DriverShim) list.get(i);
}
}
}
ISQLAlias alias = createSQLAlias("Repository Name", url, dbconnection.getUsername(), //$NON-NLS-1$
dbconnection.getRawPassword(), // fix bug for 7014,added by hyWang
dbconnection.getSID() == null || dbconnection.getSID().length() == 0 ? (dbconnection.getDatasourceName() == null || //$NON-NLS-1$
dbconnection.getDatasourceName().length() == 0 ? //$NON-NLS-1$
"Database" : dbconnection.getDatasourceName()) : dbconnection.getSID());
SessionTreeModel stm = new SessionTreeModel();
SessionTreeNode session;
if (wapperDriver != null && (iMetadataConnection.getDriverClass().equals(EDatabase4DriverClassName.JAVADB_EMBEDED.getDriverClass()) || iMetadataConnection.getDbType().equals(EDatabaseTypeName.JAVADB_EMBEDED.getDisplayName()) || iMetadataConnection.getDbType().equals(EDatabaseTypeName.JAVADB_DERBYCLIENT.getDisplayName()) || iMetadataConnection.getDbType().equals(EDatabaseTypeName.JAVADB_JCCJDBC.getDisplayName()) || iMetadataConnection.getDbType().equals(EDatabaseTypeName.HSQLDB_IN_PROGRESS.getDisplayName()))) {
session = stm.createSessionTreeNode(new SQLConnection[] { connection, connection }, alias, null, dbconnection.getRawPassword(), repositoryNode, wapperDriver);
} else {
session = stm.createSessionTreeNode(new SQLConnection[] { connection, connection }, alias, null, dbconnection.getRawPassword(), repositoryNode);
}
return session;
}
use of org.talend.core.model.metadata.IMetadataConnection in project tdi-studio-se by Talend.
the class TableNode method isNodeSameToColumn.
/**
* Check if ColumnNode and Column are the same.
*
* @param node ColumnNode
* @param column MetadataColumnImpl
* @return isNodeSameToColumn
* @exception
*/
private boolean isNodeSameToColumn(ColumnNode node, MetadataColumnImpl column) {
SessionTreeNode sessionTreeNode = node.getSession();
TableColumnInfo[] tableColumnInfo = null;
try {
tableColumnInfo = sessionTreeNode.getMetaData().getColumnInfo(ptableInfo);
} catch (SQLException e) {
SqlBuilderPlugin.log(e.getMessage(), e);
return false;
}
// Retrive metadataColumns from Database
IMetadataConnection iMetadataConnection = ConvertionHelper.convert(connection);
List<TdColumn> metadataColumns = new ArrayList<TdColumn>();
metadataColumns = ExtractMetaDataFromDataBase.returnMetadataColumnsFormTable(iMetadataConnection, getLabelText());
Iterator iterate = metadataColumns.iterator();
while (iterate.hasNext()) {
MetadataColumn metadataColumn = (MetadataColumn) iterate.next();
for (TableColumnInfo info : tableColumnInfo) {
if (metadataColumn.getLabel().equals(node.getLabelText()) && info.getColumnName().equals(node.getLabelText())) {
boolean divergency = isEquivalent(metadataColumn, column);
metadataColumn.setDivergency(divergency);
return divergency;
}
}
}
return true;
}
use of org.talend.core.model.metadata.IMetadataConnection in project tdi-studio-se by Talend.
the class EMFRepositoryNodeManager method getPKFromTables.
public List<String[]> getPKFromTables(List<MetadataTable> tables, String selectedContext) {
List<String[]> fks = new ArrayList<String[]>();
//$NON-NLS-1$
String fk = "";
//$NON-NLS-1$
String pk = "";
IMetadataConnection iMetadataConnection = null;
if (root != null) {
try {
DatabaseConnection databaseConnection = (DatabaseConnection) SQLBuilderRepositoryNodeManager.getItem(root).getConnection();
iMetadataConnection = ConvertionHelper.convert(databaseConnection, false, selectedContext);
dbMetaData = rnmanager.getDatabaseMetaData(iMetadataConnection);
} catch (final Exception e) {
//$NON-NLS-1$
final String mainMsg = Messages.getString("EMFRepositoryNodeManager.DBConnection.Text");
Display.getDefault().syncExec(new Runnable() {
/*
* (non-Javadoc)
*
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
new ErrorDialogWidthDetailArea(new Shell(), SqlBuilderPlugin.PLUGIN_ID, mainMsg, e.getMessage());
}
});
}
}
for (MetadataTable table : tables) {
try {
if (dbMetaData != null && table.getSourceName() != null) {
ResultSet resultSet;
if (dbMetaData.supportsSchemasInDataManipulation() && !"".equals(iMetadataConnection.getSchema())) {
// bug 0006949 added
if (dbMetaData.getCatalogs() != null) {
resultSet = dbMetaData.getExportedKeys(null, iMetadataConnection.getSchema(), table.getSourceName());
} else {
//$NON-NLS-1$
resultSet = dbMetaData.getExportedKeys("", iMetadataConnection.getSchema(), table.getSourceName());
}
} else {
if (dbMetaData.getCatalogs() != null) {
resultSet = dbMetaData.getExportedKeys(null, iMetadataConnection.getSchema(), table.getSourceName());
} else {
//$NON-NLS-1$
resultSet = dbMetaData.getExportedKeys("", iMetadataConnection.getSchema(), table.getSourceName());
}
}
if (resultSet != null) {
ResultSetMetaData metadata = resultSet.getMetaData();
int[] relevantIndeces = new int[metadata.getColumnCount()];
for (int i = 1; i <= metadata.getColumnCount(); i++) {
relevantIndeces[i - 1] = i;
}
while (resultSet.next()) {
for (int relevantIndece : relevantIndeces) {
String key = metadata.getColumnName(relevantIndece);
if (key.toUpperCase().equals("FKCOLUMN_NAME")) {
//$NON-NLS-1$
fk += resultSet.getString(relevantIndece);
} else if (key.toUpperCase().equals("FKTABLE_NAME")) {
//$NON-NLS-1$
//$NON-NLS-1$
fk = resultSet.getString(relevantIndece) + ".";
} else if (key.toUpperCase().equals("PKCOLUMN_NAME")) {
//$NON-NLS-1$
//$NON-NLS-1$
pk = table.getSourceName() + "." + resultSet.getString(relevantIndece);
}
}
if (!"".equals(fk) && !"".equals(pk)) {
//$NON-NLS-1$ //$NON-NLS-2$
String[] strs = new String[2];
strs[0] = pk;
strs[1] = fk;
fks.add(strs);
//$NON-NLS-1$
fk = "";
//$NON-NLS-1$
pk = "";
}
}
resultSet.close();
}
}
} catch (Exception e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("EMFRepositoryNodeManager.logMessage"), e);
}
}
if (!relations.isEmpty()) {
fks.addAll(relations);
relations.clear();
}
return fks;
}
use of org.talend.core.model.metadata.IMetadataConnection in project tdi-studio-se by Talend.
the class MetadataColumnComparator method getRepositoryNodeByBuildIn.
/**
* dev Comment method "getRepositoryNodeByBuildIn".
*
* @param node
* @param parameters
* @return
*/
@SuppressWarnings("unchecked")
public RepositoryNode getRepositoryNodeByBuildIn(RepositoryNode node, ConnectionParameters parameters) {
DatabaseConnection connection = createConnection(parameters);
if (connection == null) {
return null;
}
IMetadataConnection iMetadataConnection = ConvertionHelper.convert(connection);
RepositoryNode newNode = createNewRepositoryNode(node, parameters, connection, iMetadataConnection);
return newNode;
}
Aggregations