use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.
the class CassandraOldVersionMetadataHandler method getColumns.
@Override
public List<Object> getColumns(NoSQLConnection connection, String ksName, String cfName) throws NoSQLServerException {
List<Object> columns = new ArrayList<Object>();
try {
Object keySpace = getKeySpace(connection, ksName);
if (keySpace == null) {
return columns;
}
// $NON-NLS-1$
Collection<Object> cfDefs = (List<Object>) NoSQLReflection.invokeMethod(keySpace, "getCfDefs");
for (Object cfDef : cfDefs) {
// $NON-NLS-1$
String name = (String) NoSQLReflection.invokeMethod(cfDef, "getName");
if (name != null && cfName.equals(name)) {
// $NON-NLS-1$
columns.addAll((List<Object>) NoSQLReflection.invokeMethod(cfDef, "getColumnMetadata"));
break;
}
}
} catch (Exception e) {
throw new NoSQLServerException(e);
}
return columns;
}
use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.
the class CassandraOldVersionMetadataHandler method closeConnections.
@Override
public void closeConnections() throws NoSQLServerException {
try {
if (cluster != null) {
// $NON-NLS-1$
Object connMgr = NoSQLReflection.invokeMethod(cluster, "getConnectionManager");
// $NON-NLS-1$
NoSQLReflection.invokeMethod(connMgr, "shutdown");
cluster = null;
}
} catch (NoSQLReflectionException e) {
throw new NoSQLServerException(e);
}
}
use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.
the class CassandraOldVersionMetadataHandler method getColumnTalendType.
@Override
public String getColumnTalendType(Object column) throws NoSQLServerException {
String talendType = null;
try {
String dbType = getColumnDbType(column);
MappingTypeRetriever mappingTypeRetriever = MetadataTalendType.getMappingTypeRetriever(ICassandraConstants.DBM_ID);
talendType = mappingTypeRetriever.getDefaultSelectedTalendType(dbType);
if (talendType == null) {
talendType = JavaTypesManager.STRING.getId();
}
} catch (Exception e) {
throw new NoSQLServerException(e);
}
return talendType;
}
use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.
the class MongoDBConnectionUtil method getMongo4ConnStringVersion.
public static synchronized Object getMongo4ConnStringVersion(NoSQLConnection connection, ContextType contextType, ClassLoader classLoader, boolean requireAuth, boolean requireEncryption) throws NoSQLServerException {
Object mongo = null;
String user = connection.getAttributes().get(IMongoDBAttributes.USERNAME);
String pass = connection.getAttributes().get(IMongoDBAttributes.PASSWORD);
if (contextType != null) {
user = ContextParameterUtils.getOriginalValue(contextType, user);
pass = ContextParameterUtils.getOriginalValue(contextType, pass);
} else {
pass = connection.getValue(pass, false);
}
try {
String connString = extractFromContext(connection, IMongoDBAttributes.CONN_STRING);
Object clientSettingsBuilder = // $NON-NLS-1$ //$NON-NLS-2$
NoSQLReflection.invokeStaticMethod(// $NON-NLS-1$ //$NON-NLS-2$
"com.mongodb.MongoClientSettings", // $NON-NLS-1$ //$NON-NLS-2$
"builder", new Object[0], classLoader);
Object connectionString = NoSQLReflection.newInstance("com.mongodb.ConnectionString", new Object[] { connString }, classLoader, String.class);
clientSettingsBuilder = NoSQLReflection.invokeMethod(clientSettingsBuilder, "applyConnectionString", new Object[] { connectionString }, connectionString.getClass());
Object mongoCredential = getCredential(connection, contextType, user, pass, classLoader);
clientSettingsBuilder = NoSQLReflection.invokeMethod(clientSettingsBuilder, "credential", new Object[] { mongoCredential }, Class.forName("com.mongodb.MongoCredential", true, classLoader));
String authMechanism = connection.getAttributes().get(IMongoDBAttributes.AUTHENTICATION_MECHANISM);
//
if ((requireAuth && authMechanism.equals(IMongoConstants.X509)) || requireEncryption) {
// enable ssl & context
// $NON-NLS-1$
Class<?> blockClasszz = Class.forName("com.mongodb.Block", false, classLoader);
Class[] interfaces = new Class[1];
interfaces[0] = blockClasszz;
Object block = Proxy.newProxyInstance(classLoader, interfaces, (proxy, method, args) -> {
switch(method.getName()) {
case // $NON-NLS-1$
"apply":
if (args[0] != null) {
SSLContext sslContext = null;
if (requireAuth && authMechanism.equals(IMongoConstants.X509)) {
sslContext = mongoX509SSLContext(connection);
} else if (requireEncryption) {
sslContext = StudioSSLContextProvider.getContext();
}
// $NON-NLS-1$
NoSQLReflection.invokeMethod(// $NON-NLS-1$
args[0], // $NON-NLS-1$
"context", // $NON-NLS-1$
new Object[] { sslContext }, // $NON-NLS-1$
SSLContext.class);
}
return null;
default:
throw new NoSQLServerException(// $NON-NLS-1$
Messages.getString("MongoDBConnectionUtil.CannotFindMethod", method.getName()));
}
});
clientSettingsBuilder = NoSQLReflection.invokeMethod(clientSettingsBuilder, "applyToSslSettings", new Object[] { block }, blockClasszz);
// $NON-NLS-1$
blockClasszz = Class.forName("com.mongodb.Block", false, classLoader);
interfaces = new Class[1];
interfaces[0] = blockClasszz;
block = Proxy.newProxyInstance(classLoader, interfaces, (proxy, method, args) -> {
switch(method.getName()) {
case // $NON-NLS-1$
"apply":
if (args[0] != null) {
// $NON-NLS-1$
NoSQLReflection.invokeMethod(// $NON-NLS-1$
args[0], // $NON-NLS-1$
"enabled", // $NON-NLS-1$
new Object[] { true }, boolean.class);
}
return null;
default:
throw new Exception(// $NON-NLS-1$
"MongoDBConnectionUtil.CannotFindMethod" + method.getName());
}
});
clientSettingsBuilder = NoSQLReflection.invokeMethod(clientSettingsBuilder, "applyToSslSettings", new Object[] { block }, blockClasszz);
}
Object mongoClientSettings = NoSQLReflection.invokeMethod(clientSettingsBuilder, "build", new Object[0]);
mongo = // $NON-NLS-1$ //$NON-NLS-2$
NoSQLReflection.invokeStaticMethod(// $NON-NLS-1$ //$NON-NLS-2$
"com.mongodb.client.MongoClients", // $NON-NLS-1$ //$NON-NLS-2$
"create", new Object[] { mongoClientSettings }, classLoader, // $NON-NLS-1$
Class.forName("com.mongodb.MongoClientSettings", true, classLoader));
mongos.add(mongo);
} catch (Exception e) {
throw new NoSQLServerException(e);
}
return mongo;
}
use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.
the class MongoDBConnectionUtil method getDB.
public static synchronized Object getDB(NoSQLConnection connection, String dbName, Object mongoClient) throws NoSQLServerException {
Object db = null;
if (StringUtils.isEmpty(dbName)) {
return db;
}
try {
String requireAuthAttr = connection.getAttributes().get(IMongoDBAttributes.REQUIRED_AUTHENTICATION);
boolean requireAuth = requireAuthAttr == null ? false : Boolean.valueOf(requireAuthAttr);
//
String requireEncryptionAttr = connection.getAttributes().get(IMongoDBAttributes.REQUIRED_ENCRYPTION);
boolean requireEncryption = requireEncryptionAttr == null ? false : Boolean.valueOf(requireEncryptionAttr);
updateConfigProperties(requireEncryption);
if (isUpgradeLatestVersion(connection)) {
if (mongoClient == null) {
mongoClient = getMongo(connection, requireAuth, requireEncryption);
}
db = // $NON-NLS-1$
NoSQLReflection.invokeMethod(// $NON-NLS-1$
mongoClient, // $NON-NLS-1$
"getDatabase", new Object[] { dbName });
} else if (isUpgradeVersion(connection)) {
if (mongoClient == null) {
mongoClient = getMongo(connection, requireAuth, requireEncryption);
}
db = // $NON-NLS-1$
NoSQLReflection.invokeMethod(// $NON-NLS-1$
mongoClient, // $NON-NLS-1$
"getDB", new Object[] { dbName });
} else {
if (mongoClient == null) {
mongoClient = getMongo(connection);
}
// $NON-NLS-1$
db = NoSQLReflection.invokeMethod(mongoClient, "getDB", new Object[] { dbName });
// Do authenticate
if (requireAuth) {
String userName = connection.getAttributes().get(IMongoDBAttributes.USERNAME);
String password = connection.getValue(connection.getAttributes().get(IMongoDBAttributes.PASSWORD), false);
if (connection.isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
userName = ContextParameterUtils.getOriginalValue(contextType, userName);
password = ContextParameterUtils.getOriginalValue(contextType, password);
}
if (userName != null && password != null) {
boolean authorized = (Boolean) NoSQLReflection.invokeMethod(db, "authenticate", // $NON-NLS-1$
new Object[] { userName, password.toCharArray() });
if (!authorized) {
// $NON-NLS-1$
throw new NoSQLServerException(Messages.getString("MongoDBConnectionUtil.ConnotLogon", dbName));
}
}
}
}
} catch (NoSQLReflectionException e) {
throw new NoSQLServerException(e);
}
return db;
}
Aggregations