use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.
the class CassandraMetadataHandler method getKeySpace.
private Object getKeySpace(NoSQLConnection connection, String ksName) throws NoSQLServerException {
ContextType contextType = null;
if (StringUtils.isEmpty(ksName)) {
return null;
}
if (connection.isContextMode()) {
contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
}
if (contextType != null) {
ksName = ContextParameterUtils.getOriginalValue(contextType, ksName);
}
// if ksName has quote,then case sensitive
boolean hasQuote = (ksName.charAt(0) == '"') && (ksName.charAt(ksName.length() - 1) == '"');
try {
initCluster(connection);
List<Object> keySpaces = getKeySpaces(connection);
for (Object keySpace : keySpaces) {
// $NON-NLS-1$
String tmpKsName = (String) NoSQLReflection.invokeMethod(keySpace, "getName");
if (hasQuote) {
ksName = TalendQuoteUtils.removeQuotesIfExist(ksName);
if (ksName.equals(tmpKsName)) {
return keySpace;
}
// case in-sensitive by default for kaName
} else if (ksName.equalsIgnoreCase(tmpKsName)) {
return keySpace;
}
}
} catch (Exception e) {
throw new NoSQLServerException(e);
}
return null;
}
use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.
the class CassandraMetadataHandler method getColumnFamilyNames.
@Override
public Set<String> getColumnFamilyNames(NoSQLConnection connection, String ksName) throws NoSQLServerException {
Set<String> cfNames = new HashSet<String>();
try {
Object keySpace = null;
if (ksName == null) {
keySpace = getKeySpace(connection);
} else {
keySpace = getKeySpace(connection, ksName);
if (keySpace == null) {
return cfNames;
}
}
if (keySpace == null) {
List<String> ksNames = getKeySpaceNames(connection);
for (String name : ksNames) {
cfNames.addAll(getColumnFamilyNames(connection, name));
}
} else {
// $NON-NLS-1$
Collection tables = (Collection) NoSQLReflection.invokeMethod(keySpace, "getTables");
for (Object table : tables) {
// $NON-NLS-1$
String cfName = (String) NoSQLReflection.invokeMethod(table, "getName");
cfNames.add(cfName);
}
}
} catch (Exception e) {
throw new NoSQLServerException(e);
}
return cfNames;
}
use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.
the class CassandraMetadataHandler method initCluster.
private void initCluster(NoSQLConnection connection) throws NoSQLServerException {
try {
if (cluster != null) {
// $NON-NLS-1$
boolean isClosed = (Boolean) NoSQLReflection.invokeMethod(cluster, "isClosed");
if (!isClosed) {
return;
}
}
ClassLoader classLoader = NoSQLClassLoaderFactory.getClassLoader(connection);
ContextType contextType = null;
String host = connection.getAttributes().get(ICassandraAttributies.HOST);
String port = connection.getAttributes().get(ICassandraAttributies.PORT);
if (connection.isContextMode()) {
contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
}
if (contextType != null) {
host = ContextParameterUtils.getOriginalValue(contextType, host);
port = ContextParameterUtils.getOriginalValue(contextType, port);
}
// $NON-NLS-1$ //$NON-NLS-2$
cluster = NoSQLReflection.invokeStaticMethod("com.datastax.driver.core.Cluster", "builder", classLoader);
// $NON-NLS-1$
cluster = NoSQLReflection.invokeMethod(cluster, "addContactPoint", new Object[] { host });
// //$NON-NLS-1$
cluster = NoSQLReflection.invokeMethod(cluster, "withPort", new Object[] { Integer.valueOf(port) }, int.class);
// Do authenticate
String requireAuthAttr = connection.getAttributes().get(ICassandraAttributies.REQUIRED_AUTHENTICATION);
boolean requireAuth = requireAuthAttr == null ? false : Boolean.valueOf(requireAuthAttr);
if (requireAuth) {
String username = connection.getAttributes().get(ICassandraAttributies.USERNAME);
String password = connection.getValue(connection.getAttributes().get(ICassandraAttributies.PASSWORD), false);
if (contextType != null) {
username = ContextParameterUtils.getOriginalValue(contextType, username);
password = ContextParameterUtils.getOriginalValue(contextType, password);
}
// $NON-NLS-1$
cluster = NoSQLReflection.invokeMethod(cluster, "withCredentials", new Object[] { username, password });
}
// $NON-NLS-1$
cluster = NoSQLReflection.invokeMethod(cluster, "build");
} catch (Exception e) {
throw new NoSQLServerException(e);
}
}
use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.
the class CassandraOldVersionMetadataHandler method getKeySpace.
private Object getKeySpace(NoSQLConnection connection, String ksName) throws NoSQLServerException {
ContextType contextType = null;
if (StringUtils.isEmpty(ksName)) {
return null;
}
if (connection.isContextMode()) {
contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
}
if (contextType != null) {
ksName = ContextParameterUtils.getOriginalValue(contextType, ksName);
}
Object ksDef = null;
try {
// $NON-NLS-1$
ksDef = NoSQLReflection.invokeMethod(getOrCreateCluster(connection), "describeKeyspace", new Object[] { ksName });
} catch (Exception e) {
throw new NoSQLServerException(e);
}
return ksDef;
}
use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.
the class CassandraOldVersionMetadataHandler method checkConnection.
@Override
public boolean checkConnection(NoSQLConnection connection) throws NoSQLServerException {
cluster = null;
try {
ContextType contextType = null;
String ksName = connection.getAttributes().get(ICassandraAttributies.DATABASE);
if (connection.isContextMode()) {
contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
}
if (contextType != null) {
ksName = ContextParameterUtils.getOriginalValue(contextType, ksName);
}
Object cCluster = getOrCreateCluster(connection);
// if cancel to interrupt check connection, throw exception
if (Thread.currentThread().interrupted()) {
// $NON-NLS-1$
throw new InterruptedException();
}
if (StringUtils.isEmpty(ksName)) {
// $NON-NLS-1$
NoSQLReflection.invokeMethod(cCluster, "describeClusterName");
} else {
// $NON-NLS-1$
Object ksDef = NoSQLReflection.invokeMethod(cCluster, "describeKeyspace", new Object[] { ksName });
if (ksDef == null) {
throw new NoSQLServerException("Keyspace '" + ksName + "' doesn't exist!");
}
}
return true;
} catch (Exception e) {
if (e instanceof InterruptedException) {
// $NON-NLS-1$
throw new NoSQLServerException(Messages.getString("noSQLConnectionTest.cancelCheckConnection"), e);
} else {
throw new NoSQLServerException(e);
}
}
}
Aggregations