org.springframework.data.cassandra.core.CassandraTemplate Java Examples

The following examples show how to use org.springframework.data.cassandra.core.CassandraTemplate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CassandraDataInitializer.java    From spring-fu with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(GenericApplicationContext context) {
	Supplier<CassandraDataAutoConfiguration> configurationSupplier = () -> new CassandraDataAutoConfiguration(context.getBean(CqlSession.class));

	context.registerBean(CassandraCustomConversions.class, () -> configurationSupplier.get().cassandraCustomConversions());
	context.registerBean(CassandraMappingContext.class, () -> getCassandraMappingContext(context, configurationSupplier));
	context.registerBean(CassandraConverter.class, () -> configurationSupplier.get().cassandraConverter(context.getBean(CassandraMappingContext.class), context.getBean(CassandraCustomConversions.class)));
	context.registerBean(SessionFactoryFactoryBean.class, () -> getCassandraSessionFactoryBean(context, configurationSupplier));
	context.registerBean(CassandraTemplate.class, () -> getCassandraTemplate(context, configurationSupplier));
}
 
Example #2
Source File: CassandraDataInitializer.java    From spring-fu with Apache License 2.0 5 votes vote down vote up
private CassandraTemplate getCassandraTemplate(GenericApplicationContext context, Supplier<CassandraDataAutoConfiguration> configurationSupplier) {
	try {
		return configurationSupplier.get().cassandraTemplate(context.getBean(SessionFactory.class), context.getBean(CassandraConverter.class));
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
Example #3
Source File: CassandraZuulRouteStoreTest.java    From zuul-route-cassandra-spring-cloud-starter with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {

    final Cluster cluster = Cluster.builder()
            .addContactPoints(InetAddress.getLoopbackAddress())
            .withPort(9142)
            .build();
    cassandraTemplate = new CassandraTemplate(cluster.connect("zuul"));

    instance = new CassandraZuulRouteStore(cassandraTemplate);
}
 
Example #4
Source File: CassandraEventStore.java    From concursus with MIT License 5 votes vote down vote up
/**
 * Create an {@link EventStore} that persists and retrieves {@link Event}s using Cassandra.
 * @param cassandraTemplate The {@link CassandraTemplate} to use to perform queries against Cassandra.
 * @param objectMapper the {@link ObjectMapper} to use to serialise and deserialise event data.
 * @return The constructed {@link EventStore}
 */
public static EventStore create(CassandraTemplate cassandraTemplate, ObjectMapper objectMapper) {
    return ComposedEventStore.create(
            CassandraEventPersister.create(cassandraTemplate, objectMapper),
            CassandraEventRetriever.create(cassandraTemplate, objectMapper)
    );
}
 
Example #5
Source File: CassandraAggregateCatalogue.java    From concursus with MIT License 5 votes vote down vote up
/**
 * Create a new {@link AggregateCatalogue} that uses Cassandra for persistence.
 * @param cassandraTemplate The {@link CassandraTemplate} to use to execute Cassandra queries.
 * @param bucketCount The number of buckets to use to distribute the catalogue data over multiple rows.
 * @return The constructed {@link AggregateCatalogue}.
 */
public static AggregateCatalogue create(CassandraTemplate cassandraTemplate, int bucketCount) {
    PreparedStatement insertStatement = cassandraTemplate.getSession().prepare(
            "INSERT INTO Catalogue (aggregateType, bucket, aggregateId) VALUES (?, ?, ?)");
    PreparedStatement deleteStatement = cassandraTemplate.getSession().prepare(
            "DELETE FROM Catalogue WHERE aggregateType = ? AND bucket = ? AND aggregateId = ?");
    return new CassandraAggregateCatalogue(bucketCount, cassandraTemplate, insertStatement, deleteStatement);
}
 
Example #6
Source File: CassandraCatalogueBeans.java    From concursus with MIT License 5 votes vote down vote up
@Bean
@Primary
public AggregateCatalogue aggregateCatalogue(Cluster cluster) {
    return CassandraAggregateCatalogue.create(
            new CassandraTemplate(cluster.connect(configuration.getKeyspace())),
            configuration.getCatalogueBucketCount());
}
 
Example #7
Source File: YugabyteCloudConfig.java    From yugastore-java with Apache License 2.0 4 votes vote down vote up
@Bean
public CassandraTemplate cassandraTemplate(Session session) {
	return new CassandraTemplate(session);
}
 
Example #8
Source File: YugabyteYCQLConfig.java    From yugastore-java with Apache License 2.0 4 votes vote down vote up
@Bean
public CassandraTemplate cassandraTemplate(Session session) {
  return new CassandraTemplate(session);
}
 
Example #9
Source File: CassandraStudentRepository.java    From blog_demos with Apache License 2.0 4 votes vote down vote up
public CassandraStudentRepository(CassandraTemplate cassandraTemplate) {
    this.cassandraTemplate = cassandraTemplate;
}
 
Example #10
Source File: YugabyteLocalConfig.java    From yugastore-java with Apache License 2.0 4 votes vote down vote up
@Bean
public CassandraTemplate cassandraTemplate(Session session) {
	return new CassandraTemplate(session);
}
 
Example #11
Source File: CassandraEventRetriever.java    From concursus with MIT License 4 votes vote down vote up
private CassandraEventRetriever(CassandraTemplate cassandraTemplate, BiFunction<String, Type, Object> deserialiser) {
    this.cassandraTemplate = cassandraTemplate;
    this.deserialiser = deserialiser;
}
 
Example #12
Source File: CassandraAggregateCatalogue.java    From concursus with MIT License 4 votes vote down vote up
private CassandraAggregateCatalogue(int bucketCount, CassandraTemplate cassandraTemplate, PreparedStatement insertStatement, PreparedStatement deleteStatement) {
    this.bucketCount = bucketCount;
    this.cassandraTemplate = cassandraTemplate;
    this.insertStatement = insertStatement;
    this.deleteStatement = deleteStatement;
}
 
Example #13
Source File: CassandraEventStoreBeans.java    From concursus with MIT License 4 votes vote down vote up
@Bean
@Primary
public EventStore eventStore(Cluster cluster, ObjectMapper objectMapper) {
    return CassandraEventStore.create(new CassandraTemplate(cluster.connect(configuration.getKeyspace())), objectMapper);
}
 
Example #14
Source File: CassandraEventPersister.java    From concursus with MIT License 4 votes vote down vote up
private CassandraEventPersister(CassandraTemplate cassandraTemplate, PreparedStatement preparedStatement, Function<Object, String> serialiser) {
    this.cassandraTemplate = cassandraTemplate;
    this.preparedStatement = preparedStatement;
    this.serialiser = serialiser;
}
 
Example #15
Source File: Main.java    From blog with MIT License 3 votes vote down vote up
@Bean
public CassandraOperations cassandraTemplate() throws Exception {
    return new CassandraTemplate(session().getObject());
}
 
Example #16
Source File: CassandraZuulProxyStoreTest.java    From zuul-route-cassandra-spring-cloud-starter with Apache License 2.0 3 votes vote down vote up
@Bean
public CassandraOperations cassandraTemplate(Cluster cluster) {
    return new CassandraTemplate(cluster.connect("zuul"));
}
 
Example #17
Source File: CassandraEventStore.java    From concursus with MIT License 3 votes vote down vote up
/**
 * Create an {@link EventStore} that persists and retrieves {@link Event}s using Cassandra.
 * @param cassandraTemplate The {@link CassandraTemplate} to use to perform queries against Cassandra.
 * @param serialiser The serialiser to use to serialise {@link com.opencredo.concursus.data.tuples.Tuple} data.
 * @param deserialiser The deserialiser to use to deserialise {@link com.opencredo.concursus.data.tuples.Tuple} data.
 * @return The constructed {@link EventStore}
 */
public static EventStore create(CassandraTemplate cassandraTemplate, Function<Object, String> serialiser, BiFunction<String, Type, Object> deserialiser) {
    return ComposedEventStore.create(
            CassandraEventPersister.create(cassandraTemplate, serialiser),
            CassandraEventRetriever.create(cassandraTemplate, deserialiser)
    );
}
 
Example #18
Source File: CassandraEventPersister.java    From concursus with MIT License 2 votes vote down vote up
/**
 * Create an {@link EventPersister} that writes events into Cassandra using the supplied {@link CassandraTemplate}
 * and serialisation {@link Function}.
 * @param cassandraTemplate The {@link CassandraTemplate} to use to execute Cassandra queries.
 * @param serialiser The serialiser to use to serialise event data.
 * @return The constructed {@link EventPersister}.
 */
public static EventPersister create(CassandraTemplate cassandraTemplate, Function<Object, String> serialiser) {
    return new CassandraEventPersister(cassandraTemplate, prepareInsert(cassandraTemplate.getSession()), serialiser);
}
 
Example #19
Source File: CassandraEventPersister.java    From concursus with MIT License 2 votes vote down vote up
/**
 * Create an {@link EventPersister} that writes events into Cassandra using the supplied {@link CassandraTemplate}
 * and {@link ObjectMapper}
 * @param cassandraTemplate The {@link CassandraTemplate} to use to execute Cassandra queries.
 * @param objectMapper The {@link ObjectMapper} to use to serialise event data.
 * @return The constructed {@link EventPersister}.
 */
public static EventPersister create(CassandraTemplate cassandraTemplate, ObjectMapper objectMapper) {
    return create(cassandraTemplate, JsonSerialiser.using(objectMapper));
}
 
Example #20
Source File: CassandraEventRetriever.java    From concursus with MIT License 2 votes vote down vote up
/**
 * Construct an {@link EventRetriever} that retrieves events from Cassandra using the supplied
 * {@link CassandraTemplate} and deserialising {@link BiFunction}.
 * @param cassandraTemplate The {@link CassandraTemplate} to use to execute Cassandra queries.
 * @param deserialiser The deserialiser to use to deserialise Event data.
 * @return The constructed {@link EventRetriever}.
 */
public static EventRetriever create(CassandraTemplate cassandraTemplate, BiFunction<String, Type, Object> deserialiser) {
    return new CassandraEventRetriever(cassandraTemplate, deserialiser);
}
 
Example #21
Source File: CassandraEventRetriever.java    From concursus with MIT License 2 votes vote down vote up
/**
 * Construct an {@link EventRetriever} that retrieves events from Cassandra using the supplied
 * {@link CassandraTemplate} and {@link ObjectMapper}
 * @param cassandraTemplate The {@link CassandraTemplate} to use to execute Cassandra queries.
 * @param objectMapper The {@link ObjectMapper} to use to deserialise Event data.
 * @return The constructed {@link EventRetriever}.
 */
public static EventRetriever create(CassandraTemplate cassandraTemplate, ObjectMapper objectMapper) {
    return create(cassandraTemplate, JsonDeserialiser.using(objectMapper));
}