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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.netflix.astyanax.cql;

import java.nio.ByteBuffer;
import java.util.Date;
import java.util.List;
import java.util.UUID;

Expand Down Expand Up @@ -85,4 +86,11 @@ public interface CqlPreparedStatement extends Execution<CqlStatementResult> {
* @return
*/
CqlPreparedStatement withUUIDValue(UUID value);

/**
* Set the next parameter value to this Long as a timestamp
* @param value
* @return
*/
CqlPreparedStatement withTimestamp(Date value);
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
package com.netflix.astyanax.query;

import java.nio.ByteBuffer;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.google.common.collect.Lists;
import com.netflix.astyanax.Serializer;
import com.netflix.astyanax.serializers.BooleanSerializer;
import com.netflix.astyanax.serializers.DoubleSerializer;
import com.netflix.astyanax.serializers.FloatSerializer;
import com.netflix.astyanax.serializers.IntegerSerializer;
import com.netflix.astyanax.serializers.LongSerializer;
import com.netflix.astyanax.serializers.ShortSerializer;
import com.netflix.astyanax.serializers.StringSerializer;
import com.netflix.astyanax.serializers.UUIDSerializer;
import com.netflix.astyanax.serializers.*;

public abstract class AbstractPreparedCqlQuery<K, C> implements PreparedCqlQuery<K, C> {
private List<ByteBuffer> values = Lists.newArrayList();
Expand Down Expand Up @@ -79,4 +73,9 @@ public PreparedCqlQuery<K, C> withUUIDValue(UUID value) {
return withByteBufferValue(value, UUIDSerializer.get());
}

@Override
public PreparedCqlQuery<K, C> withTimestamp(Date value) {
return withByteBufferValue(value, DateSerializer.get());
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.netflix.astyanax.query;

import java.nio.ByteBuffer;
import java.util.Date;
import java.util.List;
import java.util.UUID;

Expand Down Expand Up @@ -85,4 +86,11 @@ public interface PreparedCqlQuery<K, C> extends Execution<CqlResult<K, C>> {
* @param value
*/
PreparedCqlQuery<K, C> withUUIDValue(UUID value);

/**
* Set the next parameter value to this Date
* @param value
* @return
*/
PreparedCqlQuery<K, C> withTimestamp(Date value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

Expand Down Expand Up @@ -127,8 +128,14 @@ public CqlPreparedStatement withUUIDValue(UUID value) {
bindValues.add(value);
return this;
}

public PreparedStatement getInnerPreparedStatement() {

@Override
public CqlPreparedStatement withTimestamp(Date value) {
bindValues.add(value);
return this;
}

public PreparedStatement getInnerPreparedStatement() {
return pStmt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

Expand Down Expand Up @@ -124,7 +125,12 @@ public PreparedCqlQuery<K, C> withUUIDValue(UUID value) {
return new InternalBoundStatement(pStatement).withUUIDValue(value);
}

@Override
@Override
public PreparedCqlQuery<K, C> withTimestamp(Date value) {
return new InternalBoundStatement(pStatement).withTimestamp(value);
}

@Override
public OperationResult<CqlResult<K, C>> execute() throws ConnectionException {
throw new NotImplementedException();
}
Expand Down Expand Up @@ -221,6 +227,12 @@ public PreparedCqlQuery<K, C> withUUIDValue(UUID value) {
bindList.add(value);
return this;
}

@Override
public PreparedCqlQuery<K, C> withTimestamp(Date value) {
bindList.add(value);
return this;
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.netflix.astyanax.cql.test;

import com.netflix.astyanax.serializers.DateSerializer;
import junit.framework.Assert;

import org.junit.AfterClass;
Expand All @@ -15,13 +16,16 @@
import com.netflix.astyanax.serializers.IntegerSerializer;
import com.netflix.astyanax.serializers.StringSerializer;

import java.util.Date;

public class DirectCqlTests extends KeyspaceTests {

public static ColumnFamily<Integer, String> CF_DIRECT = ColumnFamily
.newColumnFamily(
"cfdirect",
IntegerSerializer.get(),
StringSerializer.get());
StringSerializer.get(),
DateSerializer.get());

public static ColumnFamily<String, String> CF_EMPTY_TABLE = ColumnFamily
.newColumnFamily(
Expand All @@ -31,12 +35,14 @@ public class DirectCqlTests extends KeyspaceTests {
StringSerializer.get());




@BeforeClass
public static void init() throws Exception {
initContext();

keyspace.prepareCqlStatement().withCql("CREATE KEYSPACE astyanaxunittests with REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1};").execute();
keyspace.prepareQuery(CF_DIRECT)
.withCql("CREATE TABLE astyanaxunittests.cfdirect ( key int, column1 text, value bigint, PRIMARY KEY (key) )")
.withCql("CREATE TABLE astyanaxunittests.cfdirect ( key int, column1 text, value bigint, column2 timestamp,PRIMARY KEY (key) )")
.execute();
keyspace.prepareQuery(CF_EMPTY_TABLE)
.withCql("CREATE TABLE astyanaxunittests.empty_table ( key text, column1 text, value text, PRIMARY KEY (key) )")
Expand All @@ -51,6 +57,9 @@ public static void tearDown() throws Exception {
keyspace.prepareQuery(CF_EMPTY_TABLE)
.withCql("DROP TABLE astyanaxunittests.empty_table")
.execute();
keyspace.prepareCqlStatement()
.withCql("DROP KEYSPACE astyanaxunittests")
.execute();
}

@Test
Expand All @@ -59,11 +68,11 @@ public void testCql() throws Exception {
// INSERT VALUES
CqlQuery<Integer, String> cqlQuery = keyspace
.prepareQuery(CF_DIRECT)
.withCql("INSERT INTO astyanaxunittests.cfdirect (key, column1, value) VALUES (?,?,?)");
.withCql("INSERT INTO astyanaxunittests.cfdirect (key, column1, value, column2) VALUES (?,?,?,?)");

for (int i=0; i<10; i++) {
PreparedCqlQuery<Integer, String> pStatement = cqlQuery.asPreparedStatement();
pStatement.withIntegerValue(i).withStringValue(""+i).withLongValue(Long.valueOf(""+i)).execute();
pStatement.withIntegerValue(i).withStringValue(""+i).withLongValue(Long.valueOf(""+i)).withTimestamp(new Date()).execute();
}

// TEST REGULAR CQL
Expand All @@ -79,7 +88,7 @@ public void testCql() throws Exception {

Row<Integer, String> row = result.getResult().getRows().getRow(i);
Assert.assertTrue(i == row.getKey());
Assert.assertEquals(3, row.getColumns().size());
Assert.assertEquals(4, row.getColumns().size());

Integer key = row.getColumns().getIntegerValue("key", null);
Assert.assertTrue(Integer.valueOf(""+i) == key);
Expand All @@ -89,6 +98,9 @@ public void testCql() throws Exception {

Long value = row.getColumns().getLongValue("value", null);
Assert.assertTrue(Long.valueOf(""+i) == value);

Date column2 = row.getColumns().getDateValue("column2", null);
Assert.assertNotNull(column2);
}

// TEST CQL COUNT
Expand Down