use of org.talend.repository.nosql.exceptions.NoSQLReflectionException in project tbd-studio-se by Talend.
the class CassandraMetadataHandler method getSuperColumnFamilyNames.
@Override
public Set<String> getSuperColumnFamilyNames(NoSQLConnection connection, String ksName) throws NoSQLServerException {
Set<String> scfNames = new HashSet<String>();
Object session = null;
ClassLoader classLoader = NoSQLClassLoaderFactory.getClassLoader(connection);
try {
if (ksName == null) {
List<String> ksNames = getKeySpaceNames(connection);
for (String name : ksNames) {
scfNames.addAll(getColumnFamilyNames(connection, name));
}
} else {
initCluster(connection);
// $NON-NLS-1$ //$NON-NLS-2$
session = NoSQLReflection.invokeMethod(cluster, "connect", new Object[] { "system" });
Object toPrepare = // $NON-NLS-1$
NoSQLReflection.newInstance(// $NON-NLS-1$
"com.datastax.driver.core.SimpleStatement", new Object[] { "select * from schema_columnfamilies where keyspace_name =?" }, // $NON-NLS-1$
classLoader);
Object prepared = // $NON-NLS-1$
NoSQLReflection.invokeMethod(// $NON-NLS-1$
session, // $NON-NLS-1$
"prepare", // $NON-NLS-1$
new Object[] { toPrepare }, // $NON-NLS-1$
Class.forName("com.datastax.driver.core.RegularStatement", false, classLoader));
Object statement = // $NON-NLS-1$
NoSQLReflection.invokeMethod(// $NON-NLS-1$
prepared, // $NON-NLS-1$
"bind", // $NON-NLS-1$
new Object[] { new Object[] { ksName } }, Object[].class);
// Statement
Object resultSet = // $NON-NLS-1$
NoSQLReflection.invokeMethod(// $NON-NLS-1$
session, // $NON-NLS-1$
"execute", // $NON-NLS-1$
new Object[] { statement }, // $NON-NLS-1$
Class.forName("com.datastax.driver.core.Statement", false, classLoader));
// $NON-NLS-1$
Iterator iterator = (Iterator) NoSQLReflection.invokeMethod(resultSet, "iterator");
while (iterator.hasNext()) {
Object row = iterator.next();
// String type = row.getString("type");s
// $NON-NLS-1$ //$NON-NLS-2$
String type = (String) NoSQLReflection.invokeMethod(row, "getString", new Object[] { "type" });
String scfName = (String) NoSQLReflection.invokeMethod(row, "getString", // $NON-NLS-1$ //$NON-NLS-2$
new Object[] { "columnfamily_name" });
if (type.equalsIgnoreCase("super")) {
// $NON-NLS-1$
scfNames.add(scfName);
}
}
}
} catch (Exception e) {
throw new NoSQLServerException(e);
} finally {
try {
if (session != null) {
// $NON-NLS-1$
NoSQLReflection.invokeMethod(session, "close");
closeConnections();
}
} catch (NoSQLReflectionException e) {
// only for debug
e.printStackTrace();
}
}
return scfNames;
}
use of org.talend.repository.nosql.exceptions.NoSQLReflectionException in project tbd-studio-se by Talend.
the class CassandraMetadataHandler method getKeySpaces.
private List<Object> getKeySpaces(NoSQLConnection connection) throws NoSQLServerException {
List<Object> keySpaces = new ArrayList<Object>();
initCluster(connection);
try {
// $NON-NLS-1$
Object metadata = NoSQLReflection.invokeMethod(cluster, "getMetadata");
// $NON-NLS-1$
keySpaces.addAll((List) NoSQLReflection.invokeMethod(metadata, "getKeyspaces"));
} catch (NoSQLReflectionException e) {
throw new NoSQLServerException(e);
}
return keySpaces;
}
use of org.talend.repository.nosql.exceptions.NoSQLReflectionException 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;
}
use of org.talend.repository.nosql.exceptions.NoSQLReflectionException in project tbd-studio-se by Talend.
the class MongoDBConnectionUtil method getCollectionNames.
public static synchronized Set<String> getCollectionNames(NoSQLConnection connection, String dbName, Object mongoClient) throws NoSQLServerException {
Set<String> collectionNames = new HashSet<String>();
Object db = null;
if (mongoClient == null) {
mongoClient = getMongoVersioned(connection);
}
if (dbName != null) {
db = getDB(connection, dbName, mongoClient);
} else {
dbName = connection.getAttributes().get(IMongoDBAttributes.DATABASE);
if (connection.isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
dbName = ContextParameterUtils.getOriginalValue(contextType, dbName);
}
db = getDB(connection, dbName, mongoClient);
}
if (db == null) {
List<String> databaseNames = getDatabaseNames(connection, mongoClient);
for (String databaseName : databaseNames) {
collectionNames.addAll(getCollectionNames(connection, databaseName, mongoClient));
}
} else {
try {
if (isUpgradeLatestVersion(connection)) {
// $NON-NLS-1$
Iterable<String> iter = (Iterable<String>) NoSQLReflection.invokeMethod(db, "listCollectionNames");
Iterator<String> iterator = iter.iterator();
while (iterator.hasNext()) {
collectionNames.add(iterator.next());
}
} else {
// $NON-NLS-1$
collectionNames = (Set<String>) NoSQLReflection.invokeMethod(db, "getCollectionNames");
}
} catch (NoSQLReflectionException e) {
throw new NoSQLServerException(e);
}
}
return collectionNames;
}
use of org.talend.repository.nosql.exceptions.NoSQLReflectionException in project tbd-studio-se by Talend.
the class Neo4jConnectionUtil method getDB.
public static synchronized Object getDB(NoSQLConnection connection, boolean useCache) throws NoSQLServerException {
if (useCache && graphDb != null) {
return graphDb;
}
Object db = null;
ClassLoader classLoader = NoSQLClassLoaderFactory.getClassLoader(connection);
try {
boolean isRemote = Boolean.valueOf(connection.getAttributes().get(INeo4jAttributes.REMOTE_SERVER));
if (isRemote) {
String serverUrl = StringUtils.trimToEmpty(connection.getAttributes().get(INeo4jAttributes.SERVER_URL));
if (connection.isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
serverUrl = ContextParameterUtils.getOriginalValue(contextType, serverUrl);
}
if (isNeedAuthorization(connection)) {
String usename = StringUtils.trimToEmpty(connection.getAttributes().get(INeo4jAttributes.USERNAME));
String password = StringUtils.trimToEmpty(connection.getAttributes().get(INeo4jAttributes.PASSWORD));
if (connection.isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
usename = ContextParameterUtils.getOriginalValue(contextType, usename);
password = ContextParameterUtils.getOriginalValue(contextType, password);
} else {
password = connection.getValue(password, false);
}
db = NoSQLReflection.newInstance(// $NON-NLS-1$
"org.neo4j.rest.graphdb.RestGraphDatabase", // $NON-NLS-1$
new Object[] { serverUrl, usename, password }, classLoader);
} else {
db = // $NON-NLS-1$
NoSQLReflection.newInstance(// $NON-NLS-1$
"org.neo4j.rest.graphdb.RestGraphDatabase", // $NON-NLS-1$
new Object[] { serverUrl }, classLoader);
}
} else {
String dbPath = StringUtils.trimToEmpty(connection.getAttributes().get(INeo4jAttributes.DATABASE_PATH));
if (connection.isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
dbPath = ContextParameterUtils.getOriginalValue(contextType, dbPath);
}
Object dbFactory = // $NON-NLS-1$
NoSQLReflection.newInstance(// $NON-NLS-1$
"org.neo4j.graphdb.factory.GraphDatabaseFactory", // $NON-NLS-1$
new Object[0], classLoader);
if (isVersionSince32(connection)) {
File dbFile = new File(dbPath);
db = // $NON-NLS-1$
NoSQLReflection.invokeMethod(// $NON-NLS-1$
dbFactory, // $NON-NLS-1$
"newEmbeddedDatabase", new Object[] { dbFile });
} else {
db = // $NON-NLS-1$
NoSQLReflection.invokeMethod(// $NON-NLS-1$
dbFactory, // $NON-NLS-1$
"newEmbeddedDatabase", new Object[] { dbPath });
}
}
registerShutdownHook(db);
} catch (NoSQLReflectionException e) {
throw new NoSQLServerException(e);
}
return graphDb = db;
}
Aggregations