ClusterName clusterRef = new ClusterName(cluster);
/** * Close the session of the cluster name specified. * * @param name Name of the cluster. * @throws ConnectionException */ @Override public void close(ClusterName name) throws ConnectionException { LOG.info("Closing cassandra session"); sessions.get(name.getName()).close(); sessions.remove(name.getName()); }
/** * Controls if there is a session started for a cluster name. * * @param name cluster name. * @return if the connector is connected to the cluster. */ @Override public boolean isConnected(ClusterName name) { boolean connected; if (sessions.get(name.getName()) != null) { if (sessions.get(name.getName()).getCluster() != null) { connected = true; } else { connected = false; } } else { connected = false; } return connected; }
/** * Multiple insertion in a table. * * @param targetCluster The target cluster. * @param targetTable The target table. * @param rows Collection of rows to insert. * @throws ConnectorException */ @Override public void insert(ClusterName targetCluster, TableMetadata targetTable, Collection<Row> rows, boolean ifNotExists) throws ConnectorException { Session session = sessions.get(targetCluster.getName()); StringBuilder sb= new StringBuilder(); sb.append("BEGIN BATCH "); for (Row row : rows) { String query = insertBlock(row, targetTable, ifNotExists); sb.append(query).append(" "); } sb.append("APPLY BATCH"); CassandraExecutor.execute(sb.toString(), session); }
@Override public void delete(ClusterName targetCluster, TableName tableName, Collection<Filter> whereClauses) throws ConnectorException { Session session = sessions.get(targetCluster.getName()); List<Filter> whereFilters = new ArrayList<>(); for (Filter filter : whereClauses) { whereFilters.add(filter); } DeleteStatement deleteStatement = new DeleteStatement(tableName, whereFilters); String query = deleteStatement.toString(); CassandraExecutor.execute(query, session); }
/** * Insert method to a table. * * @param targetCluster The target cluster. * @param targetTable The target table. * @param row The inserted row. * @throws ConnectorException */ @Override public void insert(ClusterName targetCluster, com.stratio.crossdata.common.metadata.TableMetadata targetTable, Row row, boolean ifNotExists) throws ConnectorException { Session session = sessions.get(targetCluster.getName()); String query = insertBlock(row, targetTable, ifNotExists); CassandraExecutor.execute(query, session); }
@Override public void update(ClusterName targetCluster, TableName tableName, Collection<Relation> assignments, Collection<Filter> whereClauses) throws ConnectorException { Session session = sessions.get(targetCluster.getName()); UpdateTableStatement updateStatement = new UpdateTableStatement(tableName, assignments, whereClauses); String query = updateStatement.toString(); CassandraExecutor.execute(query, session); }
@Override public void truncate(ClusterName targetCluster, TableName tableName) throws ConnectorException { Session session = sessions.get(targetCluster.getName()); TruncateStatement truncateStatement = new TruncateStatement(tableName); String query = truncateStatement.toString(); CassandraExecutor.execute(query, session); }
@Override public void alterCatalog(ClusterName targetCluster, CatalogName catalogName, Map<Selector, Selector> options) throws ConnectorException { session = sessions.get(targetCluster.getName()); String stringOptions = stringKeyspaceOptions(options); if(!stringOptions.isEmpty()){ AlterCatalogStatement alterCatalogStatement = new AlterCatalogStatement(catalogName.getName(), stringOptions); CassandraExecutor.execute(alterCatalogStatement.toString(), session); } }
/** * Drop Catalog that was created previously. * * @param targetCluster The target cluster. * @param name The CatalogName of the Catalog. * @throws ConnectorException */ @Override public void dropCatalog(ClusterName targetCluster, CatalogName name) throws ConnectorException { session = sessions.get(targetCluster.getName()); DropCatalogStatement catalogStatement = new DropCatalogStatement(name.getName(), false); CassandraExecutor.execute(catalogStatement.toString(), session); }
/** * Drop table that was created previously. * * @param targetCluster The target cluster. * @param name The TableName of the Table. * @throws ConnectorException */ @Override public void dropTable(ClusterName targetCluster, TableName name) throws ConnectorException { session = sessions.get(targetCluster.getName()); DropTableStatement tableStatement = new DropTableStatement(name.getQualifiedName(), false); CassandraExecutor.execute(tableStatement.toString(), session); }
if (transformation instanceof Project) { Project project = (Project) transformation; session = sessions.get(project.getClusterName().getName()); List<Pair<String,String>> propertiesList=clusterProperties.get(project.getClusterName().getName()); for(Pair<String,String> props:propertiesList){ if (props.getLeft().equals("DefaultLimit")){
public void createTable(ClusterName targetCluster, TableMetadata tableMetadata) throws ConnectorException { session = sessions.get(targetCluster.getName());
/** * Create Catalog for Cassandra Connector. * * @param targetCluster The target cluster. * @param catalogMetadata The metadata of the catalog that will be created. * @throws ConnectorException */ @Override public void createCatalog(ClusterName targetCluster, CatalogMetadata catalogMetadata) throws ConnectorException { session = sessions.get(targetCluster.getName()); String catalogName = catalogMetadata.getName().getQualifiedName(); Map<Selector, Selector> options = catalogMetadata.getOptions(); String stringOptions = stringKeyspaceOptions(options); CreateCatalogStatement catalogStatement = new CreateCatalogStatement(catalogName, false, stringOptions); CassandraExecutor.execute(catalogStatement.toString(), session); }
@Override public void alterTable(ClusterName targetCluster, TableName name, AlterOptions alterOptions) throws ConnectorException { AlterTableStatement tableStatement; session = sessions.get(targetCluster.getName()); switch (alterOptions.getOption()) { case ALTER_COLUMN: case ADD_COLUMN: case DROP_COLUMN: ColumnType type = alterOptions.getColumnMetadata().getColumnType(); tableStatement = new AlterTableStatement(name, alterOptions.getColumnMetadata().getName() , type, alterOptions.getProperties(), alterOptions.getOption()); CassandraExecutor.execute(tableStatement.toString(), session); break; case ALTER_OPTIONS: tableStatement = new AlterTableStatement(name, null, null, alterOptions.getProperties(), alterOptions.getOption()); CassandraExecutor.execute(tableStatement.toString(), session); break; default: break; } }
throws ConnectorException { checkIndexMetadata(indexMetadata); session = sessions.get(targetCluster.getName()); CreateIndexStatement indexStatement; try {