Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed README
Empty file.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Spring Data layer for Cassandra.
4 changes: 4 additions & 0 deletions SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
To configure Cassandra, run the following through CLI:
create keyspace KunderaExamples;
use KunderaExamples;
create column family users with comparator=UTF8Type and default_validation_class=UTF8Type and key_validation_class=UTF8Type;
189 changes: 189 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<version>1.1.0-SNAPSHOT</version>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
<name>Spring Data Cassandra</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- versions for commonly-used dependencies -->
<junit.version>4.10</junit.version>
<log4j.version>1.2.16</log4j.version>
<org.slf4j.version>1.6.1</org.slf4j.version>
<org.codehaus.jackson.version>1.6.1</org.codehaus.jackson.version>
<org.springframework.version>3.1.1.RELEASE</org.springframework.version>
<data.commons.version>1.3.1.RELEASE</data.commons.version>
</properties>

<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<comments>
Copyright 2010 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
See the License for the specific language governing permissions and
limitations under the License.
</comments>
</license>
</licenses>

<repositories>
<repository>
<id>sonatype-nexus</id>
<name>Kundera Public Repository</name>
<url>https://oss.sonatype.org/content/repositories/releases</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>terracotta-repository</id>
<url>http://www.terracotta.org/download/reflector/releases</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>maven.scale7.org</id>
<name>Scale7 Maven Repo</name>
<url>https://github.com/s7/mvnrepo/raw/master</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>kundera-missing</id>
<name>Kundera Public Missing Resources Repository</name>
<url>http://kundera.googlecode.com/svn/maven2/maven-missing-resources</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.1.0.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>org.springframework</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>

<dependency>
<groupId>com.netflix.astyanax</groupId>
<artifactId>astyanax</artifactId>
<version>1.0.1</version>
</dependency>

<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${org.springframework.version}</version>
</dependency>

<dependency>
<groupId>com.impetus.client</groupId>
<artifactId>kundera-cassandra</artifactId>
<version>2.0.6</version>
</dependency>

<!-- Spring Data -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons-core</artifactId>
<version>${data.commons.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.2.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.springframework.data.cassandra.core;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.springframework.core.convert.ConversionException;
import org.springframework.data.cassandra.core.convert.CassandraConversionException;


public class CassandraDataObject {
Map<String, Map<String,String>> dataMap = new HashMap<String, Map<String,String>>();

public void clear() {
dataMap.clear();
}

public boolean containsKey(Object key) {
return dataMap.containsKey(key);
}

public Map<String, String> getRow(String rowKey) {
return dataMap.get(rowKey);
}

public Map<String, String> getOnlyRow() throws ConversionException{
if (dataMap.size() != 1){
throw new CassandraConversionException("Requested only row, but had [" + dataMap.size() + "]");
}
Collection<Map<String, String>> columns = dataMap.values();

if (columns == null){
throw new CassandraConversionException("No columns found for only row.");
}
return columns.iterator().next();
}

public boolean isEmpty() {
return dataMap.isEmpty();
}

public void putRow(String rowKey, Map<String, String> columns) {
dataMap.put(rowKey, columns);
}

public void removeRow(Object rowKey) {
this.dataMap.remove(rowKey);
}

public int numRows() {
return this.dataMap.size();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright 2010-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.cassandra.core;

import org.springframework.beans.factory.InitializingBean;

import com.netflix.astyanax.AstyanaxContext;
import com.netflix.astyanax.Keyspace;
import com.netflix.astyanax.connectionpool.NodeDiscoveryType;
import com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl;
import com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor;
import com.netflix.astyanax.impl.AstyanaxConfigurationImpl;
import com.netflix.astyanax.thrift.ThriftFamilyFactory;

/**
* Convenient factory for configuring Cassandra Keyspace.
*
* @author Brian O'Neill
*/
public class CassandraFactoryBean implements InitializingBean {
private String host;
private Integer port;
private String keyspaceName;
protected Keyspace keyspace;
protected AstyanaxContext<Keyspace> context;

public void setHost(String host) {
this.host = host;
}

public void setPort(int port) {
this.port = port;
}

public void setKeyspace(String keyspace) {
this.keyspaceName = keyspace;
}

/*
* (non-Javadoc)
*
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
*/
public Class<? extends Keyspace> getObjectType() {
return Keyspace.class;
}

/*
* (non-Javadoc)
*
* @see org.springframework.beans.factory.FactoryBean#isSingleton()
*/
public boolean isSingleton() {
return true;
}

/*
* (non-Javadoc)
*
* @see
* org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
public void afterPropertiesSet() throws Exception {
try {
context = new AstyanaxContext.Builder()
.forCluster("ClusterName")
.forKeyspace(this.keyspaceName)
.withAstyanaxConfiguration(
new AstyanaxConfigurationImpl()
.setDiscoveryType(NodeDiscoveryType.NONE))
.withConnectionPoolConfiguration(
new ConnectionPoolConfigurationImpl(
"MyConnectionPool").setPort(this.port)
.setMaxConnsPerHost(1)
.setSeeds(this.host + ":" + this.port))
.withConnectionPoolMonitor(
new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());

context.start();
this.keyspace = context.getEntity();
} catch (Throwable e) {
throw new IllegalStateException("Failed to prepare CassandraBolt",
e);
}
}
}
Loading