Search in sources :

Example 16 with NoSQLServerException

use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.

the class CassandraOldVersionMetadataHandler method getKeySpaces.

private List<Object> getKeySpaces(NoSQLConnection connection) throws NoSQLServerException {
    List<Object> keySpaces = new ArrayList<Object>();
    try {
        List<Object> ksDefs = (List<Object>) NoSQLReflection.invokeMethod(getOrCreateCluster(connection), // $NON-NLS-1$
        "describeKeyspaces");
        keySpaces.addAll(ksDefs);
    } catch (NoSQLReflectionException e) {
        throw new NoSQLServerException(e);
    }
    return keySpaces;
}
Also used : NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException)

Example 17 with NoSQLServerException

use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.

the class CassandraOldVersionMetadataHandler method getKeySpaceNames.

@Override
public List<String> getKeySpaceNames(NoSQLConnection connection) throws NoSQLServerException {
    List<String> ksNames = new ArrayList<String>();
    try {
        List<Object> keySpaces = getKeySpaces(connection);
        for (Object keySpace : keySpaces) {
            // $NON-NLS-1$
            String ksName = (String) NoSQLReflection.invokeMethod(keySpace, "getName");
            ksNames.add(ksName);
        }
    } catch (Exception e) {
        throw new NoSQLServerException(e);
    }
    return ksNames;
}
Also used : NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) ArrayList(java.util.ArrayList) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException)

Example 18 with NoSQLServerException

use of org.talend.repository.nosql.exceptions.NoSQLServerException 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;
}
Also used : NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) Iterator(java.util.Iterator) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException) HashSet(java.util.HashSet)

Example 19 with NoSQLServerException

use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.

the class CassandraMetadataHandler method getColumnTalendType.

@Override
public String getColumnTalendType(Object column) throws NoSQLServerException {
    String talendType = null;
    try {
        String dbType = getColumnDbType(column);
        MappingTypeRetriever mappingTypeRetriever = MetadataTalendType.getMappingTypeRetriever(dbmsId);
        talendType = mappingTypeRetriever.getDefaultSelectedTalendType(dbType);
        if (talendType == null) {
            talendType = JavaTypesManager.STRING.getId();
        }
    } catch (Exception e) {
        throw new NoSQLServerException(e);
    }
    return talendType;
}
Also used : MappingTypeRetriever(org.talend.core.model.metadata.MappingTypeRetriever) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException)

Example 20 with NoSQLServerException

use of org.talend.repository.nosql.exceptions.NoSQLServerException 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;
}
Also used : NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) ArrayList(java.util.ArrayList) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException)

Aggregations

NoSQLServerException (org.talend.repository.nosql.exceptions.NoSQLServerException)36 NoSQLReflectionException (org.talend.repository.nosql.exceptions.NoSQLReflectionException)33 ArrayList (java.util.ArrayList)13 ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)13 ASN1Object (org.bouncycastle.asn1.ASN1Object)9 JSONObject (org.talend.utils.json.JSONObject)9 List (java.util.List)7 JSONException (org.talend.utils.json.JSONException)6 HashSet (java.util.HashSet)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 SSLContext (javax.net.ssl.SSLContext)3 File (java.io.File)2 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 MappingTypeRetriever (org.talend.core.model.metadata.MappingTypeRetriever)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1