@Test public void testGetApplicationSession() { Session session = dataStaxCluster.getApplicationSession(); String keyspaceName = session.getLoggedKeyspace(); assertEquals(cassandraFig.getApplicationKeyspace(), keyspaceName); }
@SuppressWarnings("unchecked") private UDTValue convertValue(Object value, CassandraEntityMapper<?> mapper, CassandraClient cassandraClient) { String keyspace = cassandraClient.getSession().getLoggedKeyspace(); UserType userType = cassandraClient.getSession() .getCluster() .getMetadata() .getKeyspace(keyspace) .getUserType(mapper.getName()); UDTValue udtValue = userType.newValue(); for (String name : mapper.getNonKeyColumnNames()) { Object fieldValue = mapper.getColumnValueForName(name, value, cassandraClient); if (fieldValue != null) { udtValue.set(name, fieldValue, (Class<Object>) fieldValue.getClass()); } else { udtValue.setToNull(name); } } return udtValue; } }
@Test public void testGetClusterSession() { Session session = dataStaxCluster.getClusterSession(); String clusterName = session.getCluster().getClusterName(); String keyspaceName = session.getLoggedKeyspace(); // cluster session is not logged to a keyspace assertNull(keyspaceName); assertNotNull(clusterName); }
@Override public String getLoggedKeyspace() { return session.getLoggedKeyspace(); }
/** {@inheritDoc} */ @Override public String getLoggedKeyspace() { return mProxy.getLoggedKeyspace(); }
public CassandraSessionHolder(Session session) { this.cluster = session.getCluster(); this.session = session; this.keyspace = session.getLoggedKeyspace(); this.managedSession = false; }
/** * constructor * @param session the underlying session * @param catalog the metadata catalog * @param beanMapper the bean mapper */ DBSession(Session session, MetadataCatalog catalog, BeanMapper beanMapper) { this.session = session; this.keyspacename = session.getLoggedKeyspace(); this.isKeyspacenameAssigned = (keyspacename != null); this.preparedStatementCache = new PreparedStatementCache(session); }
private String keyspace(Session session, Table table) { String keyspace = table.schema(); if (keyspace == null) { keyspace = session.getLoggedKeyspace(); } return keyspace; }
ColumnMetadata getColumnMetadata(String columnName) { ColumnMetadata metadata = tableMetadata.getColumn(columnName); if (metadata == null) { throw new RuntimeException("table " + session.getLoggedKeyspace() + "." + tablename + " does not support column '" + columnName + "'"); } return metadata; }
@Override public PreparedStatement createPreparedStatement(Session session) throws DriverException { String cacheKey = String.valueOf(session.getLoggedKeyspace()).concat("|").concat(this.cql); log.debug("Cacheable PreparedStatement in Keyspace {}", session.getLoggedKeyspace()); Map<String, PreparedStatement> sessionCache = getOrCreateSessionLocalCache(session); return getOrPrepareStatement(session, cacheKey, sessionCache); }
private static TableMetadata loadTableMetadata(Session session, String tablename) { TableMetadata tableMetadata = session.getCluster().getMetadata().getKeyspace(session.getLoggedKeyspace()).getTable(tablename); if (tableMetadata == null) { throw new RuntimeException("table " + session.getLoggedKeyspace() + "." + tablename + " is not defined in keyspace '" + session.getLoggedKeyspace() + "'"); } return tableMetadata; }
@Override public KeyspaceMetadata getKeyspaceMetadata() { // noinspection ConstantConditions return getCqlOperations().execute((SessionCallback<KeyspaceMetadata>) session -> { KeyspaceMetadata keyspaceMetadata = session.getCluster().getMetadata().getKeyspace(session.getLoggedKeyspace()); Assert.state(keyspaceMetadata != null, String.format("Metadata for keyspace [%s] not available", session.getLoggedKeyspace())); return keyspaceMetadata; }); } }
if (session.getLoggedKeyspace() != null) { keyspaceInitialized = true; } else {
private static void initializeUDTs(Session session) { MappingManager mapping = new MappingManager(session); String keyspace = session.getLoggedKeyspace(); LOG.debug("Registering endpoint and annotation UDTs to keyspace {}", keyspace); mapping.udtCodec(EndpointUDT.class, keyspace); mapping.udtCodec(AnnotationUDT.class, keyspace); }
public InitializationStatus initializeTypes() { KeyspaceMetadata keyspaceMetadata = session.getCluster() .getMetadata() .getKeyspace(session.getLoggedKeyspace()); return types.stream() .map(type -> type.initialize(keyspaceMetadata, session)) .reduce((left, right) -> left.reduce(right)) .orElse(InitializationStatus.ALREADY_DONE); } }
static KeyspaceMetadata getKeyspaceMetadata(Session session) { String keyspace = session.getLoggedKeyspace(); Cluster cluster = session.getCluster(); KeyspaceMetadata keyspaceMetadata = cluster.getMetadata().getKeyspace(keyspace); if (keyspaceMetadata == null) { throw new IllegalStateException(String.format( "Cannot read keyspace metadata for give keyspace: %s and cluster: %s", keyspace, cluster.getClusterName())); } return keyspaceMetadata; }
public InitializationStatus initializeTables() { KeyspaceMetadata keyspaceMetadata = session.getCluster() .getMetadata() .getKeyspace(session.getLoggedKeyspace()); return module.moduleTables() .stream() .map(table -> table.initialize(keyspaceMetadata, session)) .reduce((left, right) -> left.reduce(right)) .orElse(InitializationStatus.ALREADY_DONE); }
public CassandraTableManager ensureAllTables() { KeyspaceMetadata keyspaceMetadata = session.getCluster() .getMetadata() .getKeyspace(session.getLoggedKeyspace()); module.moduleTables() .stream() .filter(table -> keyspaceMetadata.getTable(table.getName()) == null) .forEach(table -> session.execute(table.getCreateStatement())); return this; }
@Inject public CassandraTypesProvider(CassandraModule module, Session session) { KeyspaceMetadata keyspaceMetadata = session.getCluster() .getMetadata() .getKeyspace(session.getLoggedKeyspace()); userTypes = module.moduleTypes() .stream() .collect(Guavate.toImmutableMap( CassandraType::getName, type -> keyspaceMetadata.getUserType(type.getName()))); }
@Inject public CassandraTypesProvider(CassandraModule module, Session session) { KeyspaceMetadata keyspaceMetadata = session.getCluster() .getMetadata() .getKeyspace(session.getLoggedKeyspace()); userTypes = module.moduleTypes() .stream() .collect(Guavate.toImmutableMap( CassandraType::getName, type -> keyspaceMetadata.getUserType(type.getName()))); }