From 94ce778451a9061f8cfc92ca9550f81e060f2db0 Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Thu, 17 Aug 2017 12:14:00 -0400 Subject: [PATCH] formatting --- .../core/AbstractSessionOperations.java | 1 - .../core/operation/AbstractOperation.java | 8 +- .../operation/AbstractOptionalOperation.java | 13 +- .../operation/AbstractStreamOperation.java | 9 +- .../core/operation/Transformational.java | 2 +- .../core/prepared/PreparedStatementTest.java | 1 - .../core/simple/SimpleUserTest.java | 297 ++++++++++-------- .../test/integration/core/tuple/Album.java | 13 +- .../core/tuple/AlbumInformation.java | 9 +- .../test/integration/core/tuple/DslTest.java | 22 +- .../test/integration/core/tuple/Photo.java | 3 +- .../integration/core/tuple/PhotoAlbum.java | 7 +- .../integration/core/tuple/PhotoFolder.java | 9 +- .../integration/core/tuple/TupleTest.java | 222 ++++++------- .../core/tuplecollection/Author.java | 9 +- .../core/tuplecollection/Book.java | 16 +- .../core/tuplecollection/Section.java | 9 +- 17 files changed, 321 insertions(+), 329 deletions(-) diff --git a/src/main/java/net/helenus/core/AbstractSessionOperations.java b/src/main/java/net/helenus/core/AbstractSessionOperations.java index 071170f..b7c8344 100644 --- a/src/main/java/net/helenus/core/AbstractSessionOperations.java +++ b/src/main/java/net/helenus/core/AbstractSessionOperations.java @@ -28,7 +28,6 @@ import net.helenus.support.HelenusException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - public abstract class AbstractSessionOperations { final Logger logger = LoggerFactory.getLogger(getClass()); diff --git a/src/main/java/net/helenus/core/operation/AbstractOperation.java b/src/main/java/net/helenus/core/operation/AbstractOperation.java index c868fcc..e9b4f18 100644 --- a/src/main/java/net/helenus/core/operation/AbstractOperation.java +++ b/src/main/java/net/helenus/core/operation/AbstractOperation.java @@ -41,12 +41,12 @@ public abstract class AbstractOperation> } public E sync() { - return Executioner.INSTANCE.sync(sessionOps, options(buildStatement()), - traceContext, this, showValues); + return Executioner.INSTANCE.sync( + sessionOps, options(buildStatement()), traceContext, this, showValues); } public CompletableFuture async() { - return Executioner.INSTANCE.async(sessionOps, options(buildStatement()), - traceContext, this, showValues); + return Executioner.INSTANCE.async( + sessionOps, options(buildStatement()), traceContext, this, showValues); } } diff --git a/src/main/java/net/helenus/core/operation/AbstractOptionalOperation.java b/src/main/java/net/helenus/core/operation/AbstractOptionalOperation.java index a2c5d93..66134e3 100644 --- a/src/main/java/net/helenus/core/operation/AbstractOptionalOperation.java +++ b/src/main/java/net/helenus/core/operation/AbstractOptionalOperation.java @@ -20,13 +20,12 @@ import com.datastax.driver.core.ResultSet; import com.google.common.base.Function; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import net.helenus.core.AbstractSessionOperations; - import java.util.Optional; import java.util.concurrent.CompletableFuture; +import net.helenus.core.AbstractSessionOperations; public abstract class AbstractOptionalOperation> - extends AbstractStatementOperation implements Transformational> { + extends AbstractStatementOperation implements Transformational> { public AbstractOptionalOperation(AbstractSessionOperations sessionOperations) { super(sessionOperations); @@ -52,12 +51,12 @@ public abstract class AbstractOptionalOperation sync() { - return Executioner.INSTANCE.>sync(sessionOps, options(buildStatement()), - traceContext, this, showValues); + return Executioner.INSTANCE.>sync( + sessionOps, options(buildStatement()), traceContext, this, showValues); } public CompletableFuture> async() { - return Executioner.INSTANCE.>async(sessionOps, options(buildStatement()), - traceContext, this, showValues); + return Executioner.INSTANCE.>async( + sessionOps, options(buildStatement()), traceContext, this, showValues); } } diff --git a/src/main/java/net/helenus/core/operation/AbstractStreamOperation.java b/src/main/java/net/helenus/core/operation/AbstractStreamOperation.java index a261cb6..abbd9bf 100644 --- a/src/main/java/net/helenus/core/operation/AbstractStreamOperation.java +++ b/src/main/java/net/helenus/core/operation/AbstractStreamOperation.java @@ -20,7 +20,6 @@ import com.datastax.driver.core.ResultSet; import com.google.common.base.Function; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; - import java.util.concurrent.CompletableFuture; import java.util.stream.Stream; import net.helenus.core.AbstractSessionOperations; @@ -51,12 +50,12 @@ public abstract class AbstractStreamOperation sync() { - return Executioner.INSTANCE.>sync(sessionOps, options(buildStatement()), - traceContext, this, showValues); + return Executioner.INSTANCE.>sync( + sessionOps, options(buildStatement()), traceContext, this, showValues); } public CompletableFuture> async() { - return Executioner.INSTANCE.>async(sessionOps, options(buildStatement()), - traceContext, this, showValues); + return Executioner.INSTANCE.>async( + sessionOps, options(buildStatement()), traceContext, this, showValues); } } diff --git a/src/main/java/net/helenus/core/operation/Transformational.java b/src/main/java/net/helenus/core/operation/Transformational.java index a4449c2..f6e4e76 100644 --- a/src/main/java/net/helenus/core/operation/Transformational.java +++ b/src/main/java/net/helenus/core/operation/Transformational.java @@ -3,5 +3,5 @@ package net.helenus.core.operation; import com.datastax.driver.core.ResultSet; public interface Transformational { - E transform(ResultSet resultSet); + E transform(ResultSet resultSet); } diff --git a/src/test/java/net/helenus/test/integration/core/prepared/PreparedStatementTest.java b/src/test/java/net/helenus/test/integration/core/prepared/PreparedStatementTest.java index 47b4c08..fc7e170 100644 --- a/src/test/java/net/helenus/test/integration/core/prepared/PreparedStatementTest.java +++ b/src/test/java/net/helenus/test/integration/core/prepared/PreparedStatementTest.java @@ -15,7 +15,6 @@ */ package net.helenus.test.integration.core.prepared; - import com.datastax.driver.core.ResultSet; import java.math.BigDecimal; import net.helenus.core.Helenus; diff --git a/src/test/java/net/helenus/test/integration/core/simple/SimpleUserTest.java b/src/test/java/net/helenus/test/integration/core/simple/SimpleUserTest.java index 9484656..5e4c43b 100644 --- a/src/test/java/net/helenus/test/integration/core/simple/SimpleUserTest.java +++ b/src/test/java/net/helenus/test/integration/core/simple/SimpleUserTest.java @@ -15,192 +15,221 @@ */ package net.helenus.test.integration.core.simple; - import static net.helenus.core.Query.eq; +import net.helenus.core.Helenus; import net.helenus.core.HelenusSession; +import net.helenus.core.Operator; +import net.helenus.support.Fun; +import net.helenus.test.integration.build.AbstractEmbeddedCassandraTest; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import net.helenus.core.Helenus; -import net.helenus.core.Operator; -import net.helenus.support.Fun; -import net.helenus.test.integration.build.AbstractEmbeddedCassandraTest; - -import java.util.Optional; public class SimpleUserTest extends AbstractEmbeddedCassandraTest { - static User user; + static User user; - static HelenusSession session; + static HelenusSession session; - @BeforeClass - public static void beforeTest() { - session = Helenus.init(getSession()).showCql().add(User.class).autoCreateDrop().get(); - user = Helenus.dsl(User.class, session.getMetadata()); - } + @BeforeClass + public static void beforeTest() { + session = Helenus.init(getSession()).showCql().add(User.class).autoCreateDrop().get(); + user = Helenus.dsl(User.class, session.getMetadata()); + } - public static class UserImpl implements User { + public static class UserImpl implements User { - Long id; - String name; - Integer age; - UserType type; + Long id; + String name; + Integer age; + UserType type; - @Override - public Long id() { - return id; - } + @Override + public Long id() { + return id; + } - @Override - public String name() { - return name; - } + @Override + public String name() { + return name; + } - @Override - public Integer age() { - return age; - } + @Override + public Integer age() { + return age; + } - @Override - public UserType type() { - return type; - } + @Override + public UserType type() { + return type; + } + } - } + @Test + public void testCruid() throws Exception { - @Test - public void testCruid() throws Exception { + UserImpl newUser = new UserImpl(); + newUser.id = 100L; + newUser.name = "alex"; + newUser.age = 34; + newUser.type = UserType.USER; - UserImpl newUser = new UserImpl(); - newUser.id = 100L; - newUser.name = "alex"; - newUser.age = 34; - newUser.type = UserType.USER; + // CREATE - // CREATE + session.upsert(newUser).sync(); - session.upsert(newUser).sync(); + // READ - // READ + // select row and map to entity - // select row and map to entity + User actual = + session + .selectAll(User.class) + .mapTo(User.class) + .where(user::id, eq(100L)) + .sync() + .findFirst() + .get(); + assertUsers(newUser, actual); - User actual = session.selectAll(User.class).mapTo(User.class).where(user::id, eq(100L)).sync().findFirst().get(); - assertUsers(newUser, actual); + // select as object - // select as object + actual = session.select(User.class).where(user::id, eq(100L)).sync().findFirst().get(); + assertUsers(newUser, actual); - actual = session.select(User.class).where(user::id, eq(100L)).sync().findFirst().get(); - assertUsers(newUser, actual); + // select by columns - // select by columns + actual = + session + .select() + .column(user::id) + .column(user::name) + .column(user::age) + .column(user::type) + .mapTo(User.class) + .where(user::id, eq(100L)) + .sync() + .findFirst() + .get(); + assertUsers(newUser, actual); - actual = session.select() - .column(user::id) - .column(user::name) - .column(user::age) - .column(user::type) - .mapTo(User.class) - .where(user::id, eq(100L)) - .sync().findFirst().get(); - assertUsers(newUser, actual); + // select by columns - // select by columns + actual = + session + .select(User.class) + .mapTo(User.class) + .where(user::id, eq(100L)) + .sync() + .findFirst() + .get(); + assertUsers(newUser, actual); - actual = session.select(User.class) - .mapTo(User.class) - .where(user::id, eq(100L)) - .sync().findFirst().get(); - assertUsers(newUser, actual); + // select as object and mapTo - // select as object and mapTo + actual = + session + .select(user::id, user::name, user::age, user::type) + .mapTo(User.class) + .where(user::id, eq(100L)) + .sync() + .findFirst() + .get(); + assertUsers(newUser, actual); - actual = session.select(user::id, user::name, user::age, user::type) - .mapTo(User.class) - .where(user::id, eq(100L)) - .sync().findFirst().get(); - assertUsers(newUser, actual); + // select single column - // select single column + String name = session.select(user::name).where(user::id, eq(100L)).sync().findFirst().get()._1; - String name = session.select(user::name) - .where(user::id, eq(100L)) - .sync().findFirst().get()._1; + Assert.assertEquals(newUser.name(), name); - Assert.assertEquals(newUser.name(), name); + // select single column in array tuple - // select single column in array tuple + name = + (String) + session + .select() + .column(user::name) + .where(user::id, eq(100L)) + .sync() + .findFirst() + .get() + ._a[0]; - name = (String) session.select() - .column(user::name) - .where(user::id, eq(100L)) - .sync().findFirst().get()._a[0]; + Assert.assertEquals(newUser.name(), name); - Assert.assertEquals(newUser.name(), name); + // UPDATE - // UPDATE + session + .update(user::name, "albert") + .set(user::age, 35) + .where(user::id, Operator.EQ, 100L) + .sync(); - session.update(user::name, "albert") - .set(user::age, 35) - .where(user::id, Operator.EQ, 100L).sync(); + long cnt = session.count(user).where(user::id, Operator.EQ, 100L).sync(); + Assert.assertEquals(1L, cnt); - long cnt = session.count(user).where(user::id, Operator.EQ, 100L).sync(); - Assert.assertEquals(1L, cnt); + name = + session + .select(user::name) + .where(user::id, Operator.EQ, 100L) + .map(t -> "_" + t._1) + .sync() + .findFirst() + .get(); - name = session.select(user::name) - .where(user::id, Operator.EQ, 100L) - .map(t -> "_" + t._1) - .sync() - .findFirst() - .get(); + Assert.assertEquals("_albert", name); - Assert.assertEquals("_albert", name); + User u = session.select(User.class).where(user::id, eq(100L)).sync().findFirst().get(); - User u = session.select(User.class).where(user::id, eq(100L)).sync().findFirst().get(); + Assert.assertEquals(Long.valueOf(100L), u.id()); + Assert.assertEquals("albert", u.name()); + Assert.assertEquals(Integer.valueOf(35), u.age()); - Assert.assertEquals(Long.valueOf(100L), u.id()); - Assert.assertEquals("albert", u.name()); - Assert.assertEquals(Integer.valueOf(35), u.age()); + // INSERT + User greg = + session + .insert() + .value(user::name, "greg") + .value(user::age, 44) + .value(user::type, UserType.USER) + .value(user::id, 1234L) + .sync(); - // INSERT - User greg = session.insert() - .value(user::name, "greg") - .value(user::age, 44) - .value(user::type, UserType.USER) - .value(user::id, 1234L) - .sync(); + session + .update() + .set(user::name, null) + .set(user::age, null) + .set(user::type, null) + .where(user::id, eq(100L)) + .sync(); - session.update() - .set(user::name, null) - .set(user::age, null) - .set(user::type, null) - .where(user::id, eq(100L)).sync(); + Fun.Tuple3 tuple = + session + .select(user::name, user::age, user::type) + .where(user::id, eq(100L)) + .sync() + .findFirst() + .get(); + Assert.assertNull(tuple._1); + Assert.assertNull(tuple._2); + Assert.assertNull(tuple._3); - Fun.Tuple3 tuple = session.select(user::name, user::age, user::type) - .where(user::id, eq(100L)).sync().findFirst().get(); + // DELETE - Assert.assertNull(tuple._1); - Assert.assertNull(tuple._2); - Assert.assertNull(tuple._3); + session.delete(user).where(user::id, eq(100L)).sync(); - // DELETE - - session.delete(user).where(user::id, eq(100L)).sync(); - - cnt = session.select().count().where(user::id, eq(100L)).sync(); - Assert.assertEquals(0L, cnt); - - } - - private void assertUsers(User expected, User actual) { - Assert.assertEquals(expected.id(), actual.id()); - Assert.assertEquals(expected.name(), actual.name()); - Assert.assertEquals(expected.age(), actual.age()); - Assert.assertEquals(expected.type(), actual.type()); - } + cnt = session.select().count().where(user::id, eq(100L)).sync(); + Assert.assertEquals(0L, cnt); + } + private void assertUsers(User expected, User actual) { + Assert.assertEquals(expected.id(), actual.id()); + Assert.assertEquals(expected.name(), actual.name()); + Assert.assertEquals(expected.age(), actual.age()); + Assert.assertEquals(expected.type(), actual.type()); + } } diff --git a/src/test/java/net/helenus/test/integration/core/tuple/Album.java b/src/test/java/net/helenus/test/integration/core/tuple/Album.java index 64f2df5..8cc2c43 100644 --- a/src/test/java/net/helenus/test/integration/core/tuple/Album.java +++ b/src/test/java/net/helenus/test/integration/core/tuple/Album.java @@ -25,13 +25,12 @@ import net.helenus.mapping.annotation.Types; @Table public interface Album { - @PartitionKey(ordinal=1) - int id(); + @PartitionKey(ordinal = 1) + int id(); - AlbumInformation info(); - - @Types.Tuple({DataType.Name.TEXT, DataType.Name.TEXT}) - @Column(ordinal=1) - TupleValue infoNoMapping(); + AlbumInformation info(); + @Types.Tuple({DataType.Name.TEXT, DataType.Name.TEXT}) + @Column(ordinal = 1) + TupleValue infoNoMapping(); } diff --git a/src/test/java/net/helenus/test/integration/core/tuple/AlbumInformation.java b/src/test/java/net/helenus/test/integration/core/tuple/AlbumInformation.java index 10cff73..7211999 100644 --- a/src/test/java/net/helenus/test/integration/core/tuple/AlbumInformation.java +++ b/src/test/java/net/helenus/test/integration/core/tuple/AlbumInformation.java @@ -21,10 +21,9 @@ import net.helenus.mapping.annotation.Tuple; @Tuple public interface AlbumInformation { - @Column(ordinal=0) - String about(); - - @Column(ordinal=1) - String place(); + @Column(ordinal = 0) + String about(); + @Column(ordinal = 1) + String place(); } diff --git a/src/test/java/net/helenus/test/integration/core/tuple/DslTest.java b/src/test/java/net/helenus/test/integration/core/tuple/DslTest.java index c597289..41667d5 100644 --- a/src/test/java/net/helenus/test/integration/core/tuple/DslTest.java +++ b/src/test/java/net/helenus/test/integration/core/tuple/DslTest.java @@ -15,22 +15,20 @@ */ package net.helenus.test.integration.core.tuple; +import net.helenus.core.Helenus; +import net.helenus.test.integration.build.AbstractEmbeddedCassandraTest; import org.junit.Assert; import org.junit.Test; -import net.helenus.core.Helenus; -import net.helenus.test.integration.build.AbstractEmbeddedCassandraTest; - public class DslTest extends AbstractEmbeddedCassandraTest { - @Test - public void testDslBeforeSessionInit() { - Assert.assertNotNull(Helenus.dsl(Album.class)); - } - - @Test - public void testSessionInitAddingDslProxy() { - Assert.assertNotNull(Helenus.init(getSession()).showCql().add(Helenus.dsl(Album.class))); - } + @Test + public void testDslBeforeSessionInit() { + Assert.assertNotNull(Helenus.dsl(Album.class)); + } + @Test + public void testSessionInitAddingDslProxy() { + Assert.assertNotNull(Helenus.init(getSession()).showCql().add(Helenus.dsl(Album.class))); + } } diff --git a/src/test/java/net/helenus/test/integration/core/tuple/Photo.java b/src/test/java/net/helenus/test/integration/core/tuple/Photo.java index 8606325..ffae61c 100644 --- a/src/test/java/net/helenus/test/integration/core/tuple/Photo.java +++ b/src/test/java/net/helenus/test/integration/core/tuple/Photo.java @@ -20,6 +20,5 @@ import net.helenus.mapping.annotation.Tuple; @Tuple public interface Photo { - byte[] blob(); - + byte[] blob(); } diff --git a/src/test/java/net/helenus/test/integration/core/tuple/PhotoAlbum.java b/src/test/java/net/helenus/test/integration/core/tuple/PhotoAlbum.java index 8404eee..a499e2c 100644 --- a/src/test/java/net/helenus/test/integration/core/tuple/PhotoAlbum.java +++ b/src/test/java/net/helenus/test/integration/core/tuple/PhotoAlbum.java @@ -21,9 +21,8 @@ import net.helenus.mapping.annotation.Table; @Table public interface PhotoAlbum { - @PartitionKey - int id(); - - PhotoFolder folder(); + @PartitionKey + int id(); + PhotoFolder folder(); } diff --git a/src/test/java/net/helenus/test/integration/core/tuple/PhotoFolder.java b/src/test/java/net/helenus/test/integration/core/tuple/PhotoFolder.java index 7fdbd8f..2b3a541 100644 --- a/src/test/java/net/helenus/test/integration/core/tuple/PhotoFolder.java +++ b/src/test/java/net/helenus/test/integration/core/tuple/PhotoFolder.java @@ -21,10 +21,9 @@ import net.helenus.mapping.annotation.Tuple; @Tuple public interface PhotoFolder { - @Column(ordinal=0) - String name(); - - @Column(ordinal=1) - Photo photo(); + @Column(ordinal = 0) + String name(); + @Column(ordinal = 1) + Photo photo(); } diff --git a/src/test/java/net/helenus/test/integration/core/tuple/TupleTest.java b/src/test/java/net/helenus/test/integration/core/tuple/TupleTest.java index 1f7c84c..ae99255 100644 --- a/src/test/java/net/helenus/test/integration/core/tuple/TupleTest.java +++ b/src/test/java/net/helenus/test/integration/core/tuple/TupleTest.java @@ -15,180 +15,158 @@ */ package net.helenus.test.integration.core.tuple; - - import static net.helenus.core.Query.eq; -import net.helenus.core.HelenusSession; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - import com.datastax.driver.core.DataType; import com.datastax.driver.core.TupleType; import com.datastax.driver.core.TupleValue; import net.helenus.core.Helenus; +import net.helenus.core.HelenusSession; import net.helenus.test.integration.build.AbstractEmbeddedCassandraTest; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; public class TupleTest extends AbstractEmbeddedCassandraTest { - static Album album; + static Album album; - static HelenusSession session; + static HelenusSession session; - @BeforeClass - public static void beforeTest() { - Helenus.clearDslCache(); - session = Helenus.init(getSession()).showCql().add(Album.class).autoCreateDrop().get(); - album = Helenus.dsl(Album.class, session.getMetadata()); - } + @BeforeClass + public static void beforeTest() { + Helenus.clearDslCache(); + session = Helenus.init(getSession()).showCql().add(Album.class).autoCreateDrop().get(); + album = Helenus.dsl(Album.class, session.getMetadata()); + } - @Test - public void testPrint() { - System.out.println(album); - } + @Test + public void testPrint() { + System.out.println(album); + } - @Test - public void testCruid() { + @Test + public void testCruid() { - AlbumInformation info = new AlbumInformation() { + AlbumInformation info = + new AlbumInformation() { - @Override - public String about() { - return "Cassandra"; - } + @Override + public String about() { + return "Cassandra"; + } - @Override - public String place() { - return "San Jose"; - } + @Override + public String place() { + return "San Jose"; + } + }; - }; + // CREATE (C) + session.insert().value(album::id, 123).value(album::info, info).sync(); - // CREATE (C) + // READ (R) - session.insert() - .value(album::id, 123) - .value(album::info, info) - .sync(); + AlbumInformation actual = + session.select(album::info).where(album::id, eq(123)).sync().findFirst().get()._1; - // READ (R) + Assert.assertEquals(info.about(), actual.about()); + Assert.assertEquals(info.place(), actual.place()); - AlbumInformation actual = session.select(album::info).where(album::id, eq(123)).sync().findFirst().get()._1; + // UPDATE (U) - Assert.assertEquals(info.about(), actual.about()); - Assert.assertEquals(info.place(), actual.place()); + // unfortunately this is not working right now in Cassandra, can not update a single column in tuple :( + //session.update() + // .set(album.info()::about, "Helenus") + // .where(album::id, eq(123)) + // .sync(); - // UPDATE (U) + AlbumInformation expected = + new AlbumInformation() { - // unfortunately this is not working right now in Cassandra, can not update a single column in tuple :( - //session.update() - // .set(album.info()::about, "Helenus") - // .where(album::id, eq(123)) - // .sync(); + @Override + public String about() { + return "Helenus"; + } - AlbumInformation expected = new AlbumInformation() { + @Override + public String place() { + return "Santa Cruz"; + } + }; - @Override - public String about() { - return "Helenus"; - } + session.update().set(album::info, expected).where(album::id, eq(123)).sync(); - @Override - public String place() { - return "Santa Cruz"; - } + actual = session.select(album::info).where(album::id, eq(123)).sync().findFirst().get()._1; - }; + Assert.assertEquals(expected.about(), actual.about()); + Assert.assertEquals(expected.place(), actual.place()); - session.update() - .set(album::info, expected) - .where(album::id, eq(123)) - .sync(); + // INSERT (I) + // let's insert null ;) - actual = session.select(album::info).where(album::id, eq(123)).sync().findFirst().get()._1; + session.update().set(album::info, null).where(album::id, eq(123)).sync(); - Assert.assertEquals(expected.about(), actual.about()); - Assert.assertEquals(expected.place(), actual.place()); + actual = session.select(album::info).where(album::id, eq(123)).sync().findFirst().get()._1; + Assert.assertNull(actual); - // INSERT (I) - // let's insert null ;) + // DELETE (D) + session.delete().where(album::id, eq(123)).sync(); - session.update() - .set(album::info, null) - .where(album::id, eq(123)) - .sync(); + long cnt = session.select(album::info).where(album::id, eq(123)).sync().count(); + Assert.assertEquals(0, cnt); + } - actual = session.select(album::info).where(album::id, eq(123)).sync().findFirst().get()._1; - Assert.assertNull(actual); + @Test + public void testNoMapping() { - // DELETE (D) - session.delete().where(album::id, eq(123)).sync(); + TupleType tupleType = session.getMetadata().newTupleType(DataType.text(), DataType.text()); + TupleValue info = tupleType.newValue(); - long cnt = session.select(album::info).where(album::id, eq(123)).sync().count(); - Assert.assertEquals(0, cnt); + info.setString(0, "Cassandra"); + info.setString(1, "San Jose"); + // CREATE (C) - } + session.insert().value(album::id, 555).value(album::infoNoMapping, info).sync(); - @Test - public void testNoMapping() { + // READ (R) - TupleType tupleType = session.getMetadata().newTupleType(DataType.text(), DataType.text()); - TupleValue info = tupleType.newValue(); + TupleValue actual = + session.select(album::infoNoMapping).where(album::id, eq(555)).sync().findFirst().get()._1; - info.setString(0, "Cassandra"); - info.setString(1, "San Jose"); + Assert.assertEquals(info.getString(0), actual.getString(0)); + Assert.assertEquals(info.getString(1), actual.getString(1)); - // CREATE (C) + // UPDATE (U) - session.insert() - .value(album::id, 555) - .value(album::infoNoMapping, info) - .sync(); + TupleValue expected = tupleType.newValue(); - // READ (R) + expected.setString(0, "Helenus"); + expected.setString(1, "Los Altos"); - TupleValue actual = session.select(album::infoNoMapping).where(album::id, eq(555)).sync().findFirst().get()._1; + session.update().set(album::infoNoMapping, expected).where(album::id, eq(555)).sync(); - Assert.assertEquals(info.getString(0), actual.getString(0)); - Assert.assertEquals(info.getString(1), actual.getString(1)); + actual = + session.select(album::infoNoMapping).where(album::id, eq(555)).sync().findFirst().get()._1; - // UPDATE (U) + Assert.assertEquals(expected.getString(0), actual.getString(0)); + Assert.assertEquals(expected.getString(1), actual.getString(1)); - TupleValue expected = tupleType.newValue(); + // INSERT (I) + // let's insert null ;) - expected.setString(0, "Helenus"); - expected.setString(1, "Los Altos"); + session.update().set(album::infoNoMapping, null).where(album::id, eq(555)).sync(); - session.update() - .set(album::infoNoMapping, expected) - .where(album::id, eq(555)) - .sync(); + actual = + session.select(album::infoNoMapping).where(album::id, eq(555)).sync().findFirst().get()._1; + Assert.assertNull(actual); - actual = session.select(album::infoNoMapping).where(album::id, eq(555)).sync().findFirst().get()._1; - - Assert.assertEquals(expected.getString(0), actual.getString(0)); - Assert.assertEquals(expected.getString(1), actual.getString(1)); - - // INSERT (I) - // let's insert null ;) - - session.update() - .set(album::infoNoMapping, null) - .where(album::id, eq(555)) - .sync(); - - actual = session.select(album::infoNoMapping).where(album::id, eq(555)).sync().findFirst().get()._1; - Assert.assertNull(actual); - - // DELETE (D) - session.delete().where(album::id, eq(555)).sync(); - - long cnt = session.select(album::infoNoMapping).where(album::id, eq(555)).sync().count(); - Assert.assertEquals(0, cnt); - - } + // DELETE (D) + session.delete().where(album::id, eq(555)).sync(); + long cnt = session.select(album::infoNoMapping).where(album::id, eq(555)).sync().count(); + Assert.assertEquals(0, cnt); + } } diff --git a/src/test/java/net/helenus/test/integration/core/tuplecollection/Author.java b/src/test/java/net/helenus/test/integration/core/tuplecollection/Author.java index bcf4135..8e4af61 100644 --- a/src/test/java/net/helenus/test/integration/core/tuplecollection/Author.java +++ b/src/test/java/net/helenus/test/integration/core/tuplecollection/Author.java @@ -21,10 +21,9 @@ import net.helenus.mapping.annotation.Tuple; @Tuple public interface Author { - @Column(ordinal=0) - String name(); - - @Column(ordinal=1) - String city(); + @Column(ordinal = 0) + String name(); + @Column(ordinal = 1) + String city(); } diff --git a/src/test/java/net/helenus/test/integration/core/tuplecollection/Book.java b/src/test/java/net/helenus/test/integration/core/tuplecollection/Book.java index 88841a3..a243efb 100644 --- a/src/test/java/net/helenus/test/integration/core/tuplecollection/Book.java +++ b/src/test/java/net/helenus/test/integration/core/tuplecollection/Book.java @@ -18,24 +18,22 @@ package net.helenus.test.integration.core.tuplecollection; import java.util.List; import java.util.Map; import java.util.Set; - import net.helenus.mapping.annotation.PartitionKey; import net.helenus.mapping.annotation.Table; @Table public interface Book { - @PartitionKey - int id(); + @PartitionKey + int id(); - List authors(); + List authors(); - Set reviewers(); + Set reviewers(); - Map contents(); + Map contents(); - Map notes(); - - Map writers(); + Map notes(); + Map writers(); } diff --git a/src/test/java/net/helenus/test/integration/core/tuplecollection/Section.java b/src/test/java/net/helenus/test/integration/core/tuplecollection/Section.java index 4159658..f2edc33 100644 --- a/src/test/java/net/helenus/test/integration/core/tuplecollection/Section.java +++ b/src/test/java/net/helenus/test/integration/core/tuplecollection/Section.java @@ -21,10 +21,9 @@ import net.helenus.mapping.annotation.Tuple; @Tuple public interface Section { - @Column(ordinal=0) - String title(); - - @Column(ordinal=1) - int page(); + @Column(ordinal = 0) + String title(); + @Column(ordinal = 1) + int page(); }