use of org.talend.core.model.metadata.builder.connection.FileConnection in project tdi-studio-se by Talend.
the class AddQuoteMarkMigrationTask method addQuote.
/**
* Add quote marks to the separators.
*
* yzhang Comment method "addQuote".
*
* @throws PersistenceException
*/
private void addQuote(ConnectionItem connItem) throws PersistenceException {
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
boolean modified = false;
Connection conn = connItem.getConnection();
if (conn instanceof FileConnection) {
FileConnection fileConnection = (FileConnection) conn;
String old = null;
old = fileConnection.getFieldSeparatorValue();
if (!isWithinQuote(old)) {
fileConnection.setFieldSeparatorValue(surroundDQuote(old));
modified = true;
}
old = fileConnection.getRowSeparatorValue();
if (!isWithinQuote(old)) {
fileConnection.setRowSeparatorValue(surroundDQuote(old));
modified = true;
}
old = fileConnection.getEscapeChar();
if (!isWithinQuote(old)) {
fileConnection.setEscapeChar(TalendTextUtils.addQuotes(old));
modified = true;
}
old = fileConnection.getTextEnclosure();
if (!isWithinQuote(old)) {
fileConnection.setTextEnclosure(TalendTextUtils.addQuotes(old));
modified = true;
}
}
if (modified) {
factory.save(connItem);
}
}
use of org.talend.core.model.metadata.builder.connection.FileConnection in project tdq-studio-se by Talend.
the class ConnectionUtils method isConnectionAvailable.
/**
* This method is used to check conectiton is avalible for analysis or report ,when analysis or report runs.
*
* @param analysisDataProvider
* @return
*/
public static ReturnCode isConnectionAvailable(Connection analysisDataProvider) {
ReturnCode returnCode = new ReturnCode();
if (analysisDataProvider == null) {
returnCode.setOk(false);
// $NON-NLS-1$
returnCode.setMessage(Messages.getString("ConnectionUtils.checkConnFailTitle"));
return returnCode;
}
// check hive connection
IMetadataConnection metadataConnection = ConvertionHelper.convert(analysisDataProvider);
if (metadataConnection != null) {
if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metadataConnection.getDbType())) {
try {
// need to do this first when check for hive embed connection.
if (isHiveEmbedded(analysisDataProvider)) {
JavaSqlFactory.doHivePreSetup(analysisDataProvider);
}
HiveConnectionManager.getInstance().checkConnection(metadataConnection);
returnCode.setOk(true);
} catch (ClassNotFoundException e) {
returnCode.setOk(false);
returnCode.setMessage(e.toString());
} catch (InstantiationException e) {
returnCode.setOk(false);
returnCode.setMessage(e.toString());
} catch (IllegalAccessException e) {
returnCode.setOk(false);
returnCode.setMessage(e.toString());
} catch (SQLException e) {
returnCode.setOk(false);
returnCode.setMessage(e.toString());
}
return returnCode;
}
}
// MOD klliu check file connection is available
if (analysisDataProvider instanceof FileConnection) {
FileConnection fileConn = (FileConnection) analysisDataProvider;
// ADD msjian TDQ-4559 2012-2-28: when the fileconnection is context mode, getOriginalFileConnection.
if (fileConn.isContextMode()) {
IRepositoryContextService service = CoreRuntimePlugin.getInstance().getRepositoryContextService();
if (service != null) {
fileConn = service.cloneOriginalValueConnection(fileConn);
}
}
// TDQ-4559 ~
String filePath = fileConn.getFilePath();
try {
BufferedReader filePathAvailable = FilesUtils.isFilePathAvailable(filePath, fileConn);
if (filePathAvailable == null) {
returnCode.setOk(false);
// $NON-NLS-1$ //$NON-NLS-2$
returnCode.setMessage(Messages.getString("ConnectionUtils.checkConnFailTitle") + " " + filePath);
}
} catch (UnsupportedEncodingException e) {
returnCode.setOk(false);
returnCode.setMessage(e.toString());
} catch (FileNotFoundException e) {
returnCode.setOk(false);
returnCode.setMessage(e.toString());
} catch (IOException e) {
returnCode.setOk(false);
returnCode.setMessage(e.toString());
}
return returnCode;
}
// ~
Properties props = new Properties();
props.put(TaggedValueHelper.USER, JavaSqlFactory.getUsername(analysisDataProvider));
props.put(TaggedValueHelper.PASSWORD, JavaSqlFactory.getPassword(analysisDataProvider));
if (analysisDataProvider instanceof DatabaseConnection) {
// MOD qiongli TDQ-11507,for GeneralJdbc,should check connection too after validation jar and jdbc driver .
if (isTcompJdbc(analysisDataProvider) || isGeneralJdbc(analysisDataProvider)) {
ReturnCode rcJdbc = checkJdbcJarFilePathDriverClassName((DatabaseConnection) analysisDataProvider);
if (!rcJdbc.isOk()) {
return rcJdbc;
}
}
// MOD qiongli 2014-5-14 in order to check and connect a dbConnection by a correct driver,replace
// 'ConnectionUtils.checkConnection(...)' with 'managerConn.check(metadataConnection)'.
ManagerConnection managerConn = new ManagerConnection();
returnCode.setOk(managerConn.check(metadataConnection));
returnCode.setMessage(managerConn.getMessageException());
}
return returnCode;
}
use of org.talend.core.model.metadata.builder.connection.FileConnection in project tdq-studio-se by Talend.
the class ConnectionUtils method getRetrieveAllMetadata.
/**
* if the connection has sid return false, else return true (don't need the TaggedValue any more).
*
* @param element
* @return
*/
public static boolean getRetrieveAllMetadata(ModelElement element) {
if (element != null && element instanceof Connection) {
if (element instanceof DatabaseConnection) {
DatabaseConnection dbConn = (DatabaseConnection) element;
String sid = JavaSqlFactory.getSID(dbConn);
if (sid != null && !"".equals(sid.trim())) {
// $NON-NLS-1$
// MOD klliu bug 22900
TaggedValue taggedValue = TaggedValueHelper.getTaggedValue(TaggedValueHelper.RETRIEVE_ALL, element.getTaggedValue());
// if connection is created by 4.2 or 5.0 ,the tagedValue(RETRIEVE_ALL) has been removed.
if (taggedValue != null) {
String value = taggedValue.getValue();
if (value.equals("true")) {
// $NON-NLS-1$
return true;
}
}
// ~
if (ConnectionHelper.isOracle(dbConn) || isPostgresql(dbConn)) {
String uiSchema = dbConn.getUiSchema();
if (uiSchema != null && !"".equals(uiSchema.trim())) {
// $NON-NLS-1$
return false;
} else {
return true;
}
} else {
return false;
}
} else {
return true;
}
} else if (element instanceof FileConnection) {
// do file connection can filter catalog/schema?
return true;
}
}
return true;
}
use of org.talend.core.model.metadata.builder.connection.FileConnection in project tdq-studio-se by Talend.
the class RespositoryDetailView method createDataProviderDetail.
private void createDataProviderDetail(ConnectionItem connectionItem) {
Connection dataProvider = connectionItem.getConnection();
Property dbProperty = connectionItem.getProperty();
boolean isDelimitedFile = ConnectionUtils.isDelimitedFileConnection(dataProvider);
// MOD qiongli 2011-9-21 TDQ-3317
Connection origValueConn = null;
if (dataProvider.isContextMode()) {
if (dataProvider instanceof DatabaseConnection) {
origValueConn = ConnectionUtils.getOriginalDatabaseConnection((DatabaseConnection) dataProvider);
} else if (dataProvider instanceof FileConnection) {
origValueConn = ConnectionUtils.getOriginalFileConnection((FileConnection) dataProvider);
}
}
if (!isDelimitedFile) {
createName(origValueConn == null ? dataProvider : origValueConn);
}
if (origValueConn != null) {
createContextDetail(dataProvider);
}
if (dbProperty != null) {
createPurpose(dbProperty);
createDescription(dbProperty);
} else {
createPurpose(origValueConn == null ? dataProvider : origValueConn);
createDescription(origValueConn == null ? dataProvider : origValueConn);
}
// MOD mzhao xmldb have no actual connection.
if (dataProvider != null) {
String connectionString = JavaSqlFactory.getURL(dataProvider);
// $NON-NLS-1$
newLabelAndText(gContainer, DefaultMessagesImpl.getString("RespositoryDetailView.URL"), connectionString);
}
// MOD gdbu 2011-9-16 TDQ-3337
String subtype = PluginConstant.EMPTY_STRING;
String version = PluginConstant.EMPTY_STRING;
if (dataProvider instanceof DatabaseConnection) {
subtype = TaggedValueHelper.getValueString(TaggedValueHelper.DB_PRODUCT_NAME, dataProvider);
if (PluginConstant.EMPTY_STRING.equals(subtype)) {
// tagged values not present in local connection file.
ConnectionUtils.updataTaggedValueForConnectionItem(dataProvider);
subtype = TaggedValueHelper.getValueString(TaggedValueHelper.DB_PRODUCT_NAME, dataProvider);
if (!PluginConstant.EMPTY_STRING.equals(subtype)) {
version = TaggedValueHelper.getValueString(TaggedValueHelper.DB_PRODUCT_VERSION, dataProvider);
}
} else {
version = TaggedValueHelper.getValueString(TaggedValueHelper.DB_PRODUCT_VERSION, dataProvider);
}
} else {
subtype = isDelimitedFile ? SupportDBUrlType.DELIMITEDFILE.getLanguage() : PluginConstant.EMPTY_STRING;
if (!DQRepositoryNode.isOnFilterring()) {
version = PluginConstant.EMPTY_STRING;
}
}
// ~TDQ-3337
// $NON-NLS-1$
newLabelAndText(gContainer, DefaultMessagesImpl.getString("RespositoryDetailView.type2"), subtype);
// $NON-NLS-1$
newLabelAndText(gContainer, "Version: ", version);
}
Aggregations