use of orgomg.cwm.resource.relational.Catalog in project tbd-studio-se by Talend.
the class MapRDBMetadataProvider method fillConnection.
@Override
public void fillConnection(DatabaseConnection connection) {
Catalog defaultCatalog = CatalogHelper.createCatalog(getDefaultCatalogName());
ConnectionHelper.addPackage(defaultCatalog, connection);
connection.setSID(getDefaultCatalogName());
}
use of orgomg.cwm.resource.relational.Catalog in project tdi-studio-se by Talend.
the class QueryGuessCommand method getDefaultSchema.
private String getDefaultSchema(String realTableName) {
String schema = "";
List<Schema> schemas = ConnectionHelper.getSchema(this.conn);
Set<Catalog> catalog = ConnectionHelper.getAllCatalogs(this.conn);
for (Schema deScha : schemas) {
for (ModelElement ele : deScha.getOwnedElement()) {
String childeleName = TalendTextUtils.addQuotesWithSpaceFieldForSQLStringForce(TalendTextUtils.declareString(ele.getName()), dbType, true);
if (childeleName.startsWith(TalendTextUtils.QUOTATION_MARK) && childeleName.endsWith(TalendTextUtils.QUOTATION_MARK) && childeleName.length() > 2) {
childeleName = childeleName.substring(1, childeleName.length() - 1);
}
if (childeleName.equals(realTableName)) {
return deScha.getName();
}
}
}
for (Catalog cata : catalog) {
for (ModelElement ele : cata.getOwnedElement()) {
if (ele instanceof Schema) {
for (ModelElement child : ((Schema) ele).getOwnedElement()) {
String childeleName = TalendTextUtils.addQuotesWithSpaceFieldForSQLStringForce(TalendTextUtils.declareString(child.getName()), dbType, true);
if (childeleName.startsWith(TalendTextUtils.QUOTATION_MARK) && childeleName.endsWith(TalendTextUtils.QUOTATION_MARK) && childeleName.length() > 2) {
childeleName = childeleName.substring(1, childeleName.length() - 1);
}
if (childeleName.equals(realTableName)) {
return ele.getName();
}
}
} else {
String eleName = TalendTextUtils.addQuotesWithSpaceFieldForSQLStringForce(TalendTextUtils.declareString(ele.getName()), dbType, true);
if (eleName.startsWith(TalendTextUtils.QUOTATION_MARK) && eleName.endsWith(TalendTextUtils.QUOTATION_MARK) && eleName.length() > 2) {
eleName = eleName.substring(1, eleName.length() - 1);
}
if (eleName.equals(realTableName)) {
return cata.getName();
}
}
}
}
return schema;
}
use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.
the class RepositoryNodeHelper method recursiveFindSchema.
public static DBSchemaRepNode recursiveFindSchema(Schema schema) {
if (schema == null) {
return null;
}
String uuidSchema = getUUID(schema);
if (uuidSchema == null) {
return null;
}
Catalog catalog = CatalogHelper.getParentCatalog(schema);
// Schema's parent is catalog (MS SQL Server)
if (catalog != null) {
DBCatalogRepNode catalogNode = recursiveFindCatalog(catalog);
List<IRepositoryNode> children = catalogNode.getChildren();
if (children.size() > 0) {
IRepositoryNode iRepositoryNode = children.get(0);
if (iRepositoryNode != null && iRepositoryNode instanceof DBSchemaRepNode) {
for (IRepositoryNode childNode : children) {
if (childNode != null && childNode instanceof DBSchemaRepNode) {
DBSchemaRepNode dbSchemaRepNode = (DBSchemaRepNode) childNode;
if (uuidSchema.equals(getUUID(dbSchemaRepNode.getSchema()))) {
return dbSchemaRepNode;
}
}
}
}
}
}
// schema's parent is connection (e.g Oracle)
IRepositoryNode connNode = recursiveFind(ConnectionHelper.getTdDataProvider(schema));
if (connNode != null) {
List<IRepositoryNode> children = connNode.getChildren();
if (children.size() > 0) {
IRepositoryNode iRepositoryNode = children.get(0);
if (iRepositoryNode != null && iRepositoryNode instanceof DBSchemaRepNode) {
for (IRepositoryNode childNode : children) {
if (childNode != null && childNode instanceof DBSchemaRepNode) {
DBSchemaRepNode dbSchemaRepNode = (DBSchemaRepNode) childNode;
if (uuidSchema.equals(getUUID(dbSchemaRepNode.getSchema()))) {
return dbSchemaRepNode;
}
}
}
}
}
}
return null;
}
use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.
the class ConnectionEvaluator method cleanUpCatalog.
/**
* if the Connection don't contain the catalog, remove the catalog from the list.
*
* @param catalogs
*/
private void cleanUpCatalog(List<Catalog> catalogs) {
if (catalogs != null) {
List<Catalog> temp = new ArrayList<Catalog>();
for (Catalog catalog : catalogs) {
if (checkCatalog(catalog.getName()) && setCatalogOk(connection, catalog.getName())) {
temp.add(catalog);
}
}
catalogs.clear();
catalogs.addAll(temp);
}
}
use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.
the class ConnectionEvaluator method executeSqlQuery.
/*
* (non-Javadoc)
*
* @see org.talend.dq.indicators.Evaluator#executeSqlQuery(java.lang.String)
*
* Note that the given statement is not used.
*/
@Override
protected ReturnCode executeSqlQuery(String sqlStatement) throws SQLException {
// assert this.getAnalyzedElements().size() == 1 : "Invalid number of analyzed elements: "
// + this.getAnalyzedElements().size();
ReturnCode ok = new ReturnCode(true);
dataProvider = this.getDataManager();
if (this.elementToIndicators.values().isEmpty()) {
// $NON-NLS-1$
String msg = Messages.getString("Evaluator.NoInidcator1");
log.error(msg);
ok.setReturnCode(msg, false);
return ok;
}
elementIndics = this.elementToIndicators.values().iterator().next();
if (elementIndics.isEmpty()) {
// $NON-NLS-1$
String msg = Messages.getString("Evaluator.NoInidcator2", dataProvider);
log.error(msg);
ok.setReturnCode(msg, false);
return ok;
}
ConnectionIndicator connectionIndicator = getConnectionIndicator();
this.resetCounts(connectionIndicator);
List<Catalog> catalogs = ConnectionHelper.getCatalogs(dataProvider);
if (isTos(dataProvider)) {
cleanUpCatalog(catalogs);
}
if (this.getMonitor() != null) {
this.getMonitor().beginTask("Analyze catalogs", 100);
}
int temp = 0;
if (catalogs.isEmpty()) {
// no catalog, only schemata
List<Schema> schemata = ConnectionHelper.getSchema(dataProvider);
// MOD yyi 2009-11-30 10187
for (Schema tdSchema : schemata) {
if (!checkSchema(tdSchema)) {
// $NON-NLS-1$
ok.setReturnCode(Messages.getString("Evaluator.schemaNotExist", tdSchema.getName()), false);
return ok;
}
}
// for (Schema tdSchema : schemata) {
for (int i = 0; i < schemata.size(); i++) {
Schema tdSchema = schemata.get(i);
if (this.getMonitor() != null) {
this.getMonitor().setTaskName(Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElement", Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementSchema", tdSchema.getName())));
}
evalSchemaIndic(tdSchema, ok);
if (this.getMonitor() != null) {
int current = (i + 1) * 100 / schemata.size();
if (current > temp) {
this.getMonitor().worked(current - temp);
temp = current;
}
}
}
} else {
// MOD yyi 2009-11-30 10187
for (Catalog tdCatalog : catalogs) {
if (!checkCatalog(tdCatalog.getName())) {
// $NON-NLS-1$
ok.setReturnCode(Messages.getString("Evaluator.catalogNotExist", tdCatalog.getName()), false);
return ok;
}
}
// for (Catalog tdCatalog : catalogs) {
for (int i = 0; i < catalogs.size(); i++) {
if (this.continueRun()) {
Catalog tdCatalog = catalogs.get(i);
String catName = tdCatalog.getName();
if (this.getMonitor() != null) {
this.getMonitor().setTaskName(Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElement", Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementCatalog", catName)));
}
if (dbms().supportCatalogSelection()) {
try {
connection.setCatalog(catName);
} catch (SQLException e) {
// $NON-NLS-1$
log.warn("Exception while executing SQL query " + sqlStatement, e);
}
}
CatalogIndicator catalogIndic = SchemaFactory.eINSTANCE.createCatalogIndicator();
// MOD xqliu 2009-1-21 feature 4715
DefinitionHandler.getInstance().setDefaultIndicatorDefinition(catalogIndic);
List<Schema> schemas = CatalogHelper.getSchemas(tdCatalog);
if (schemas.isEmpty()) {
// no schema
evalCatalogIndic(catalogIndic, tdCatalog, ok);
} else {
catalogIndic.setAnalyzedElement(tdCatalog);
// --- create SchemaIndicator for each pair of catalog schema
for (Schema tdSchema : schemas) {
if (this.continueRun()) {
if (this.getMonitor() != null) {
this.getMonitor().setTaskName(Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElement", Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementCatalog", catName) + ", " + Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementSchema", tdSchema.getName())));
}
// --- create SchemaIndicator for each catalog
SchemaIndicator schemaIndic = SchemaFactory.eINSTANCE.createSchemaIndicator();
// MOD xqliu 2009-1-21 feature 4715
DefinitionHandler.getInstance().setDefaultIndicatorDefinition(schemaIndic);
evalSchemaIndicLow(catalogIndic, schemaIndic, tdCatalog, tdSchema, ok);
}
}
catalogIndic.setSchemaCount(schemas.size());
}
if (this.getMonitor() != null) {
int current = (i + 1) * 100 / catalogs.size();
if (current > temp) {
this.getMonitor().worked(current - temp);
temp = current;
}
}
}
}
if (this.getMonitor() != null) {
this.getMonitor().done();
}
}
if (log.isDebugEnabled()) {
printCounts(connectionIndicator);
}
return ok;
}
Aggregations