use of org.talend.sqlbuilder.dbstructure.nodes.TableNode in project tdi-studio-se by Talend.
the class SessionTreeNodeManager method convert2INode.
/**
* DOC qianbing Comment method "convert2INode". Converts the RepositoryNode input to INode. INode is used for the
* sql editor,result viewer and the detail viewer.
*
* @param repositoryNode RepositoryNode
* @param selectedContext
* @return INode
*/
public INode convert2INode(RepositoryNode repositoryNode, String selectedContext, SessionTreeNode sessionTreeNode) throws Exception {
// Creates the SessionTreeNode.
RepositoryNodeType nodeType = getRepositoryType(repositoryNode);
if (nodeType.equals(RepositoryNodeType.DATABASE)) {
// processes the database
DatabaseModel model = sessionTreeNode.getDbModel();
INode[] nodes = model.getChildNodes();
DatabaseNode dn = (DatabaseNode) nodes[0];
return dn;
} else if (nodeType.equals(RepositoryNodeType.TABLE)) {
// processes the table
MetadataTableRepositoryObject tableObject = (MetadataTableRepositoryObject) repositoryNode.getObject();
MetadataTable table = tableObject.getTable();
String realName = table.getSourceName();
DatabaseModel model = sessionTreeNode.getDbModel();
INode[] nodes = model.getChildNodes();
DatabaseNode dn = (DatabaseNode) nodes[0];
nodes = dn.getChildNodes();
CatalogNode cn = (CatalogNode) nodes[0];
nodes = cn.getChildNodes();
if (nodes != null && nodes.length > 0) {
for (INode node : nodes) {
TableNode tableNode = (TableNode) node;
if (tableNode.getName().equals(realName)) {
return node;
}
}
}
} else if (nodeType.equals(RepositoryNodeType.COLUMN)) {
// Processes the column.
// Gets the repositoryNode's parent,should be the repositoryNode of table infomation.
repositoryNode = repositoryNode.getParent();
return convert2INode(repositoryNode, selectedContext, sessionTreeNode);
}
return null;
}
use of org.talend.sqlbuilder.dbstructure.nodes.TableNode in project tdi-studio-se by Talend.
the class ImportedKeysTab method getDataSet.
public DataSet getDataSet() throws Exception {
INode node = getNode();
if (node == null) {
return null;
}
if (node.getSession() == null) {
return null;
}
if (node instanceof TableNode) {
TableNode tableNode = (TableNode) node;
ITableInfo ti = tableNode.getTableInfo();
if (tableNode.getTableInfo() == null) {
return null;
}
ResultSet resultSet = null;
SessionTreeNode treeNode = node.getSession();
// For synonym table, should get the corresponding table.
if (ti.getType().equals("SYNONYM")) {
//$NON-NLS-1$
String realTableName = ExtractMetaDataFromDataBase.getTableNameBySynonym(treeNode.getInteractiveConnection().getConnection(), ti.getSimpleName());
resultSet = treeNode.getMetaData().getJDBCMetaData().getImportedKeys(ti.getCatalogName(), ti.getSchemaName(), realTableName);
} else {
resultSet = node.getSession().getMetaData().getImportedKeys((tableNode.getTableInfo()));
}
DataSet dataSet = new DataSet(null, resultSet, new int[] { 3, 4, 8, 9, 10, 11, 12, 13, 14 });
resultSet.close();
return dataSet;
}
return null;
}
use of org.talend.sqlbuilder.dbstructure.nodes.TableNode in project tdi-studio-se by Talend.
the class PrimaryKeysTab method getDataSet.
public DataSet getDataSet() throws Exception {
INode node = getNode();
if (node == null) {
return null;
}
if (node.getSession() == null) {
return null;
}
if (node instanceof TableNode) {
TableNode tableNode = (TableNode) node;
ITableInfo ti = tableNode.getTableInfo();
if (tableNode.getTableInfo() == null) {
return null;
}
ResultSet resultSet = null;
SessionTreeNode treeNode = node.getSession();
// For synonym table, should get the corresponding table name .
if (ti.getType().equals("SYNONYM")) {
//$NON-NLS-1$
String realTableName = ExtractMetaDataFromDataBase.getTableNameBySynonym(treeNode.getInteractiveConnection().getConnection(), ti.getSimpleName());
resultSet = treeNode.getMetaData().getJDBCMetaData().getPrimaryKeys(ti.getCatalogName(), ti.getSchemaName(), realTableName);
} else {
resultSet = node.getSession().getMetaData().getPrimaryKeys((tableNode.getTableInfo()));
}
DataSet dataSet = new DataSet(null, resultSet, new int[] { 4, 5, 6 });
resultSet.close();
return dataSet;
}
return null;
}
use of org.talend.sqlbuilder.dbstructure.nodes.TableNode in project tdi-studio-se by Talend.
the class ExportedKeysTab method getDataSet.
public DataSet getDataSet() throws Exception {
INode node = getNode();
if (node == null) {
return null;
}
if (node.getSession() == null) {
return null;
}
if (node instanceof TableNode) {
TableNode tableNode = (TableNode) node;
ITableInfo ti = tableNode.getTableInfo();
if (tableNode.getTableInfo() == null) {
return null;
}
ResultSet resultSet = null;
SessionTreeNode treeNode = node.getSession();
// For synonym table, should get the corresponding table.
if (ti.getType().equals("SYNONYM")) {
//$NON-NLS-1$
String realTableName = ExtractMetaDataFromDataBase.getTableNameBySynonym(treeNode.getInteractiveConnection().getConnection(), ti.getSimpleName());
resultSet = treeNode.getMetaData().getJDBCMetaData().getExportedKeys(ti.getCatalogName(), ti.getSchemaName(), realTableName);
} else {
resultSet = node.getSession().getMetaData().getExportedKeys((tableNode.getTableInfo()));
}
DataSet dataSet = new DataSet(null, resultSet, new int[] { 4, 7, 8, 9, 10, 11, 12, 13, 14 });
resultSet.close();
return dataSet;
}
return null;
}
use of org.talend.sqlbuilder.dbstructure.nodes.TableNode in project tdi-studio-se by Talend.
the class UnsignedWordRule method evaluate.
//$NON-NLS-1$
@SuppressWarnings("unchecked")
public IToken evaluate(ICharacterScanner scanner) {
int c = scanner.read();
if (fDetector.isWordStart((char) c)) {
if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) {
fBuffer.setLength(0);
do {
fBuffer.append((char) c);
c = scanner.read();
} while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c));
scanner.unread();
String tokenName = fBuffer.substring(0, fBuffer.length()).toLowerCase();
IToken token = (IToken) fWords.get(tokenName);
if (token != null) {
if ((token == fTableToken) && (dictionary != null)) {
ArrayList list = (ArrayList) dictionary.getByTableName(tokenName);
if (list != null) {
for (int j = 0; j < list.size(); j++) {
TableNode nd = (TableNode) list.get(j);
ArrayList ls = null;
try {
ls = (ArrayList) nd.getColumnNames();
} catch (Throwable e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("UnsignedWordRule.logMessage"), e);
}
if (ls != null) {
TreeSet colTree = (TreeSet) dictionary.getColumnListByTableName(tokenName);
if (colTree == null && j == 0) {
colTree = new TreeSet();
dictionary.putColumnsByTableName(tokenName, colTree);
for (int i = 0; i < ls.size(); i++) {
String lo = ((String) ls.get(i));
addWord(lo, fColumnToken);
colTree.add(lo);
}
}
}
}
}
}
return token;
}
if (fDefaultToken.isUndefined()) {
unreadBuffer(scanner);
}
return fDefaultToken;
}
}
scanner.unread();
return Token.UNDEFINED;
}
Aggregations