use of org.talend.components.snowflake.SnowflakeConnectionProperties in project components by Talend.
the class SnowflakeSourceOrSink method validateConnectionProperties.
protected static ValidationResultMutable validateConnectionProperties(SnowflakeProvideConnectionProperties properties) {
ValidationResultMutable vr = new ValidationResultMutable();
vr.setStatus(Result.OK);
SnowflakeConnectionProperties connectionProperties = properties.getConnectionProperties();
StringBuilder missingProperties = new StringBuilder();
if (StringUtils.isEmpty(connectionProperties.account.getValue())) {
missingProperties.append("'Account', ");
}
if (StringUtils.isEmpty(connectionProperties.userPassword.password.getValue())) {
missingProperties.append("'Password', ");
}
if (StringUtils.isEmpty(connectionProperties.userPassword.userId.getValue())) {
missingProperties.append("'UserID', ");
}
if (StringUtils.isEmpty(connectionProperties.schemaName.getValue())) {
missingProperties.append("'Schema', ");
}
if (StringUtils.isEmpty(connectionProperties.db.getValue())) {
missingProperties.append("'Database', ");
}
if (!missingProperties.toString().isEmpty()) {
vr.setStatus(Result.ERROR);
vr.setMessage(i18nMessages.getMessage("error.requiredPropertyIsEmpty", missingProperties.toString().substring(0, missingProperties.length() - 2)));
}
return vr;
}
use of org.talend.components.snowflake.SnowflakeConnectionProperties in project components by Talend.
the class SnowflakeSourceOrSink method getSchemaNames.
protected List<NamedThing> getSchemaNames(RuntimeContainer container, Connection connection) throws IOException {
// Returns the list with a table names (for the wh, db and schema)
List<NamedThing> returnList = new ArrayList<>();
SnowflakeConnectionProperties connProps = getEffectiveConnectionProperties(container);
try {
DatabaseMetaData metaData = connection.getMetaData();
// Fetch all tables in the db and schema provided
String[] types = { "TABLE" };
ResultSet resultIter = metaData.getTables(getCatalog(connProps), getDbSchema(connProps), null, types);
String tableName = null;
while (resultIter.next()) {
tableName = resultIter.getString("TABLE_NAME");
returnList.add(new SimpleNamedThing(tableName, tableName));
}
} catch (SQLException se) {
throw new IOException(i18nMessages.getMessage("error.searchingTable", getCatalog(connProps), getDbSchema(connProps), se.getMessage()), se);
}
return returnList;
}
use of org.talend.components.snowflake.SnowflakeConnectionProperties in project components by Talend.
the class SnowflakeWriter method open.
@Override
public void open(String uId) throws IOException {
this.uId = uId;
processingConnection = sink.createConnection(container);
uploadConnection = sink.createConnection(container);
if (null == mainSchema) {
mainSchema = sink.getRuntimeSchema(container);
}
SnowflakeConnectionProperties connectionProperties = sprops.getConnectionProperties();
Map<LoaderProperty, Object> prop = new HashMap<>();
boolean isUpperCase = sprops.convertColumnsAndTableToUppercase.getValue();
String tableName = isUpperCase ? sprops.getTableName().toUpperCase() : sprops.getTableName();
prop.put(LoaderProperty.tableName, tableName);
prop.put(LoaderProperty.schemaName, connectionProperties.schemaName.getStringValue());
prop.put(LoaderProperty.databaseName, connectionProperties.db.getStringValue());
switch(sprops.outputAction.getValue()) {
case INSERT:
prop.put(LoaderProperty.operation, Operation.INSERT);
break;
case UPDATE:
prop.put(LoaderProperty.operation, Operation.MODIFY);
break;
case UPSERT:
prop.put(LoaderProperty.operation, Operation.UPSERT);
break;
case DELETE:
prop.put(LoaderProperty.operation, Operation.DELETE);
break;
}
List<Field> columns = mainSchema.getFields();
List<String> keyStr = new ArrayList<>();
List<String> columnsStr = new ArrayList<>();
for (Field f : columns) {
String dbColumnName = f.getProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME);
String fName = isUpperCase ? dbColumnName.toUpperCase() : dbColumnName;
columnsStr.add(fName);
if (null != f.getProp(SchemaConstants.TALEND_COLUMN_IS_KEY)) {
keyStr.add(fName);
}
}
row = new Object[columnsStr.size()];
prop.put(LoaderProperty.columns, columnsStr);
if (sprops.outputAction.getValue() == UPSERT) {
keyStr.clear();
keyStr.add(sprops.upsertKeyColumn.getValue());
}
if (keyStr.size() > 0) {
prop.put(LoaderProperty.keys, keyStr);
}
prop.put(LoaderProperty.remoteStage, "~");
loader = (StreamLoader) LoaderFactory.createLoader(prop, uploadConnection, processingConnection);
loader.setListener(listener);
loader.start();
}
use of org.talend.components.snowflake.SnowflakeConnectionProperties in project components by Talend.
the class SnowflakeRuntime method createConnection.
/**
* Creates or gets connection.
* If component use existing connection then get it by reference component id from container(and check if it's not closed),
* else creates new connection using {@link DriverManager} and saves it in container.
*
* @param container - runtime container
* @param connProps - properties, than contain all required settings for establishing new connection or get it by stored
* reference id.
* @return active connection.
* @throws IOException may be thrown if referenced connection is closed or if failed to create connection using
* {@link DriverManager}
*/
protected Connection createConnection(RuntimeContainer container) throws IOException {
Connection conn = null;
SnowflakeConnectionProperties connectionProperties = getConnectionProperties();
String refComponentId = connectionProperties.getReferencedComponentId();
// Using another component's connection
if (refComponentId != null) {
// In a runtime container
if (container != null) {
conn = (Connection) container.getComponentData(refComponentId, KEY_CONNECTION);
try {
if (conn != null && !conn.isClosed()) {
return conn;
}
} catch (SQLException ex) {
throw new IOException(ex);
}
throw new IOException(I18N_MESSAGES.getMessage("error.refComponentNotConnected", refComponentId));
}
// Design time
connectionProperties = connectionProperties.getReferencedConnectionProperties();
// FIXME This should not happen - but does as of now
if (connectionProperties == null) {
throw new IOException(I18N_MESSAGES.getMessage("error.refComponentWithoutProperties", refComponentId));
}
}
conn = DriverManagerUtils.getConnection(connectionProperties);
if (container != null) {
container.setComponentData(container.getCurrentComponentId(), KEY_CONNECTION, conn);
container.setComponentData(container.getCurrentComponentId(), KEY_CONNECTION_PROPERTIES, connectionProperties);
}
return conn;
}
use of org.talend.components.snowflake.SnowflakeConnectionProperties in project components by Talend.
the class SnowflakeSourceOrSink method getSchema.
protected Schema getSchema(RuntimeContainer container, Connection connection, String tableName) throws IOException {
Schema tableSchema = null;
SnowflakeConnectionProperties connProps = getEffectiveConnectionProperties(container);
try {
JDBCTableMetadata tableMetadata = new JDBCTableMetadata();
tableMetadata.setDatabaseMetaData(connection.getMetaData()).setCatalog(getCatalog(connProps)).setDbSchema(getDbSchema(connProps)).setTablename(tableName);
tableSchema = getSnowflakeAvroRegistry().inferSchema(tableMetadata);
if (tableSchema == null)
throw new IOException(i18nMessages.getMessage("error.tableNotFound", tableName));
} catch (SQLException se) {
throw new IOException(se);
}
return tableSchema;
}
Aggregations