Skip to content

Instantly share code, notes, and snippets.

@bartprokop
bartprokop / POM.xml
Created June 9, 2012 20:35
JPA 2.0 for GAE with Maven
<?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">
<!-- Project description -->
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>bart.prokop.name</groupId>
<artifactId>parent-pom</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
@bartprokop
bartprokop / Hector1.java
Created July 16, 2012 07:19
Creating namespace with Cassandra
public static void main(String... args) {
Cluster cluster = HFactory
.getOrCreateCluster("test-cluster", "localhost:9160");
ColumnFamilyDefinition cfDef = HFactory
.createColumnFamilyDefinition("MyKeyspace", "ColumnFamilyName", ComparatorType.BYTESTYPE);
KeyspaceDefinition newKeyspace = HFactory
.createKeyspaceDefinition("MyKeyspace", ThriftKsDef.DEF_STRATEGY_CLASS, 1,
Arrays.asList(cfDef));
cluster.addKeyspace(newKeyspace, true);
}
@bartprokop
bartprokop / Hector2.java
Created July 16, 2012 07:35
Storing simple values in Casandra datastore
public static void main(String... args) throws Exception {
Cluster cluster = HFactory.getOrCreateCluster("test-cluster", "localhost:9160");
Keyspace keyspace = HFactory.createKeyspace("MyKeyspace", cluster);
ColumnFamilyTemplate<String, String> template =
new ThriftColumnFamilyTemplate<String, String>(keyspace, "ColumnFamilyName",
StringSerializer.get(), StringSerializer.get());
ColumnFamilyUpdater<String, String> updater = template.createUpdater("ABCDEFGHIJKLMNOPQ");
updater.setString("firstName", "John");
@bartprokop
bartprokop / Hector4.java
Created July 16, 2012 07:57
Querying whole column family in Cassandra
public static void main(String... args) throws Exception {
Cluster cluster = HFactory.getOrCreateCluster("test-cluster", "localhost:9160");
Keyspace keyspace = HFactory.createKeyspace("MyKeyspace", cluster);
RangeSlicesQuery<String, String, String> q = HFactory
.createRangeSlicesQuery(keyspace, StringSerializer.get(),
StringSerializer.get(), StringSerializer.get());
q.setColumnFamily("ColumnFamilyName");
q.setRange(null, null, false, 2);
@bartprokop
bartprokop / gist:4042145
Created November 8, 2012 22:22
BigTable Email - Vaadin converter
package com.appspot.natanedwin.app;
import com.google.appengine.api.datastore.Email;
import com.vaadin.data.util.converter.Converter;
import com.vaadin.data.util.converter.DefaultConverterFactory;
import java.util.Locale;
/**
* @author Bartłomiej Prokop
*/
class MyVaadinButton extends Button {
@Autowired
private SpringOnClickHandler handler;
}
<?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">
<!-- Project description -->
<modelVersion>4.0.0</modelVersion>
<groupId>name.prokop.bart</groupId>
<artifactId>bart-gae-poc</artifactId>
<version>1</version>
<packaging>war</packaging>
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://appengine.google.com/ns/1.0 http://googleappengine.googlecode.com/svn/branches/1.2.1/java/docs/appengine-web.xsd">
<application>bart-gae-poc</application>
<version>1</version>
<threadsafe>true</threadsafe>
</appengine-web-app>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Natan i Edwin</display-name>
<listener>
<listener-class>com.appspot.bartgaepoc.WarmupListener</listener-class>
</listener>
package com.appspot.bartgaepoc;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class WarmupListener implements ServletContextListener {
private static AnnotationConfigApplicationContext annotationConfigApplicationContext;