Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id CA5E4200C20 for ; Sun, 19 Feb 2017 18:17:13 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id C8D4F160B63; Sun, 19 Feb 2017 17:17:13 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C8B6E160B3F for ; Sun, 19 Feb 2017 18:17:12 +0100 (CET) Received: (qmail 17882 invoked by uid 500); 19 Feb 2017 17:17:12 -0000 Mailing-List: contact commits-help@polygene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@polygene.apache.org Delivered-To: mailing list commits@polygene.apache.org Received: (qmail 17860 invoked by uid 99); 19 Feb 2017 17:17:12 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 19 Feb 2017 17:17:12 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C3B80DFF38; Sun, 19 Feb 2017 17:17:11 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: niclas@apache.org To: commits@polygene.apache.org Date: Sun, 19 Feb 2017 17:17:11 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/3] polygene-java git commit: Moved to more UseDefaults, and fixing the bugs to get this to work. archived-at: Sun, 19 Feb 2017 17:17:14 -0000 Repository: polygene-java Updated Branches: refs/heads/develop ba600a555 -> c248324a4 Moved to more UseDefaults, and fixing the bugs to get this to work. Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/3384c1bd Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/3384c1bd Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/3384c1bd Branch: refs/heads/develop Commit: 3384c1bd6c361a6c0e1e2100d4604b2eb658b0e4 Parents: ba600a5 Author: niclas Authored: Sun Feb 19 16:18:22 2017 +0800 Committer: niclas Committed: Sun Feb 19 16:18:22 2017 +0800 ---------------------------------------------------------------------- extensions/entitystore-cassandra/build.gradle | 2 +- .../entitystore/cassandra/CassandraCluster.java | 61 +++++++++++++------- .../CassandraEntityStoreConfiguration.java | 4 +- .../cassandra/CassandraMapEntityStoreTest.java | 4 +- .../cassandra/EmptyCassandraTableMixin.java | 3 +- 5 files changed, 44 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3384c1bd/extensions/entitystore-cassandra/build.gradle ---------------------------------------------------------------------- diff --git a/extensions/entitystore-cassandra/build.gradle b/extensions/entitystore-cassandra/build.gradle index 2fb41a2..1056b96 100644 --- a/extensions/entitystore-cassandra/build.gradle +++ b/extensions/entitystore-cassandra/build.gradle @@ -32,7 +32,7 @@ dependencies { runtime polygene.core.runtime testCompile polygene.internals.testsupport - testCompile polygene.extension( 'valueserialization-orgjson' ) + testCompile polygene.extension( 'valueserialization-jackson' ) testRuntime libraries.logback } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3384c1bd/extensions/entitystore-cassandra/src/main/java/org/apache/polygene/entitystore/cassandra/CassandraCluster.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-cassandra/src/main/java/org/apache/polygene/entitystore/cassandra/CassandraCluster.java b/extensions/entitystore-cassandra/src/main/java/org/apache/polygene/entitystore/cassandra/CassandraCluster.java index 701471c..8672a71 100644 --- a/extensions/entitystore-cassandra/src/main/java/org/apache/polygene/entitystore/cassandra/CassandraCluster.java +++ b/extensions/entitystore-cassandra/src/main/java/org/apache/polygene/entitystore/cassandra/CassandraCluster.java @@ -43,6 +43,8 @@ import com.datastax.driver.core.Cluster; import com.datastax.driver.core.KeyspaceMetadata; import com.datastax.driver.core.PreparedStatement; import com.datastax.driver.core.Session; +import com.datastax.driver.core.exceptions.AlreadyExistsException; +import com.datastax.driver.core.exceptions.InvalidQueryException; import org.apache.polygene.api.common.Optional; import org.apache.polygene.api.configuration.Configuration; import org.apache.polygene.api.injection.scope.Service; @@ -140,7 +142,7 @@ public interface CassandraCluster { CassandraEntityStoreConfiguration config = configuration.get(); String tableName = config.entityTableName().get(); - if( tableName == null ) + if( tableName == null || tableName.isEmpty() ) { tableName = DEFAULT_TABLE_NAME; } @@ -152,21 +154,26 @@ public interface CassandraCluster { configuration.refresh(); CassandraEntityStoreConfiguration config = configuration.get(); - cluster = clusterBuilder.build(config); + cluster = clusterBuilder.build( config ); keyspaceName = config.keySpace().get(); - if( keyspaceName == null ) + if( keyspaceName == null || keyspaceName.isEmpty() ) { keyspaceName = DEFAULT_KEYSPACE_NAME; } String tableName = tableName(); KeyspaceMetadata keyspace = cluster.getMetadata().getKeyspace( keyspaceName ); + boolean createIfMissing = config.createIfMissing().get(); if( keyspace == null ) { - if( config.createIfMissing().get() ) + if( createIfMissing ) { - createKeyspace( keyspaceName, config.replicationFactor().get() ); + Integer replication = config.replicationFactor().get(); + if( replication == null || replication <= 0 ) + { + replication = 3; + } + createKeyspace( keyspaceName, replication ); session = cluster.connect( keyspaceName ); - createPolygeneStateTable( tableName ); } else { @@ -178,7 +185,10 @@ public interface CassandraCluster session = cluster.connect( keyspaceName ); } session.init(); - + if( createIfMissing ) + { + createPolygeneStateTable( tableName ); + } getEntityStatement = session.prepare( "SELECT " + IDENTITY_COLUMN + ", " + VERSION_COLUMN + ", " @@ -195,7 +205,7 @@ public interface CassandraCluster + IDENTITY_COLUMN + " = ?" ); getVersionStatement = session.prepare( "SELECT " - + VERSION_COLUMN + ", " + + VERSION_COLUMN + " FROM " + tableName + " WHERE " + IDENTITY_COLUMN + " = ?" ); @@ -211,24 +221,31 @@ public interface CassandraCluster + ASSOCIATIONS_COLUMN + ", " + MANYASSOCIATIONS_COLUMN + ", " + NAMEDASSOCIATIONS_COLUMN - + " ) VALUES (?,?,?," + CURRENT_STORAGE_VERSION + "?,?,?,?,?,?)" ); + + " ) VALUES (?,?,?,'" + CURRENT_STORAGE_VERSION + "',?,?,?,?,?,?)" ); } private void createPolygeneStateTable( String tableName ) { - session.execute( "CREATE TABLE " + tableName + "(\n" - + " " + IDENTITY_COLUMN + " text,\n" - + " " + VERSION_COLUMN + " text,\n" - + " " + APP_VERSION_COLUMN + " text,\n" - + " " + STORE_VERSION_COLUMN + " text,\n" - + " " + LASTMODIFIED_COLUMN + " timestamp,\n" - + " " + USECASE_COLUMN + " text,\n" - + " " + PROPERTIES_COLUMN + " map,\n" - + " " + ASSOCIATIONS_COLUMN + " map,\n" - + " " + MANYASSOCIATIONS_COLUMN + " map,\n" - + " " + NAMEDASSOCIATIONS_COLUMN + " map,\n" - + " PRIMARY KEY (" + IDENTITY_COLUMN + ")\n" - + " )" ); + try + { + session.execute( "CREATE TABLE " + tableName + "(\n" + + " " + IDENTITY_COLUMN + " text,\n" + + " " + VERSION_COLUMN + " text,\n" + + " " + APP_VERSION_COLUMN + " text,\n" + + " " + STORE_VERSION_COLUMN + " text,\n" + + " " + LASTMODIFIED_COLUMN + " timestamp,\n" + + " " + USECASE_COLUMN + " text,\n" + + " " + PROPERTIES_COLUMN + " map,\n" + + " " + ASSOCIATIONS_COLUMN + " map,\n" + + " " + MANYASSOCIATIONS_COLUMN + " map,\n" + + " " + NAMEDASSOCIATIONS_COLUMN + " map,\n" + + " PRIMARY KEY (" + IDENTITY_COLUMN + ")\n" + + " )" ); + } + catch( AlreadyExistsException e ) + { + // This is OK, as we try to create on every connect(). + } } private void createKeyspace( String keyspaceName, int replication ) http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3384c1bd/extensions/entitystore-cassandra/src/main/java/org/apache/polygene/entitystore/cassandra/CassandraEntityStoreConfiguration.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-cassandra/src/main/java/org/apache/polygene/entitystore/cassandra/CassandraEntityStoreConfiguration.java b/extensions/entitystore-cassandra/src/main/java/org/apache/polygene/entitystore/cassandra/CassandraEntityStoreConfiguration.java index f212d78..0cfdf54 100644 --- a/extensions/entitystore-cassandra/src/main/java/org/apache/polygene/entitystore/cassandra/CassandraEntityStoreConfiguration.java +++ b/extensions/entitystore-cassandra/src/main/java/org/apache/polygene/entitystore/cassandra/CassandraEntityStoreConfiguration.java @@ -82,7 +82,7 @@ public interface CassandraEntityStoreConfiguration * * @return The name of the KEYSPACE to use If null, then the default KEYSPACE polygene will be used. */ - @Optional + @UseDefaults Property keySpace(); /** @@ -109,7 +109,7 @@ public interface CassandraEntityStoreConfiguration * * @return the name of the Entity table. If it returns null the default name of entitystore will be used. */ - @Optional + @UseDefaults Property entityTableName(); /** http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3384c1bd/extensions/entitystore-cassandra/src/test/java/org/apache/polygene/entitystore/cassandra/CassandraMapEntityStoreTest.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-cassandra/src/test/java/org/apache/polygene/entitystore/cassandra/CassandraMapEntityStoreTest.java b/extensions/entitystore-cassandra/src/test/java/org/apache/polygene/entitystore/cassandra/CassandraMapEntityStoreTest.java index 21580f5..3a7464a 100644 --- a/extensions/entitystore-cassandra/src/test/java/org/apache/polygene/entitystore/cassandra/CassandraMapEntityStoreTest.java +++ b/extensions/entitystore-cassandra/src/test/java/org/apache/polygene/entitystore/cassandra/CassandraMapEntityStoreTest.java @@ -64,9 +64,7 @@ public class CassandraMapEntityStoreTest // END SNIPPET: assembly CassandraEntityStoreConfiguration cassandraConfig = config.forMixin( CassandraEntityStoreConfiguration.class ).declareDefaults(); - cassandraConfig.keySpace().set( "polygene:test" ); - cassandraConfig.entityTableName().set( "polygene:test:entities" ); - cassandraConfig.replicationFactor().set( 1 ); + cassandraConfig.createIfMissing().set( true ); // START SNIPPET: assembly } // END SNIPPET: assembly http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3384c1bd/extensions/entitystore-cassandra/src/test/java/org/apache/polygene/entitystore/cassandra/EmptyCassandraTableMixin.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-cassandra/src/test/java/org/apache/polygene/entitystore/cassandra/EmptyCassandraTableMixin.java b/extensions/entitystore-cassandra/src/test/java/org/apache/polygene/entitystore/cassandra/EmptyCassandraTableMixin.java index e25c79a..4f16dd8 100644 --- a/extensions/entitystore-cassandra/src/test/java/org/apache/polygene/entitystore/cassandra/EmptyCassandraTableMixin.java +++ b/extensions/entitystore-cassandra/src/test/java/org/apache/polygene/entitystore/cassandra/EmptyCassandraTableMixin.java @@ -33,7 +33,6 @@ public class EmptyCassandraTableMixin @Override public void removeAll() { - Delete delete = QueryBuilder.delete().from(cluster.keyspaceName(), cluster.tableName()); - cluster.session().execute( delete ); + cluster.session().execute( "TRUNCATE TABLE " + cluster.tableName() + ";"); } }