polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [1/3] polygene-java git commit: Moved to more UseDefaults, and fixing the bugs to get this to work.
Date Sun, 19 Feb 2017 17:17:11 GMT
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 <niclas@spicter.com>
Authored: Sun Feb 19 16:18:22 2017 +0800
Committer: niclas <niclas@spicter.com>
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<text,text>,\n"
-                             + "   " + ASSOCIATIONS_COLUMN + " map<text,text>,\n"
-                             + "   " + MANYASSOCIATIONS_COLUMN + " map<text,text>,\n"
-                             + "   " + NAMEDASSOCIATIONS_COLUMN + " map<text,text>,\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<text,text>,\n"
+                                 + "   " + ASSOCIATIONS_COLUMN + " map<text,text>,\n"
+                                 + "   " + MANYASSOCIATIONS_COLUMN + " map<text,text>,\n"
+                                 + "   " + NAMEDASSOCIATIONS_COLUMN + " map<text,text>,\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 <code>KEYSPACE
polygene</code> will be used.
      */
-    @Optional
+    @UseDefaults
     Property<String> keySpace();
 
     /**
@@ -109,7 +109,7 @@ public interface CassandraEntityStoreConfiguration
      *
      * @return the name of the Entity table. If it returns null the default name of <code>entitystore</code>
will be used.
      */
-    @Optional
+    @UseDefaults
     Property<String> 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() + ";");
     }
 }


Mime
View raw message