A bit more documentation, and fixes of names.

Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/2ac3d33c
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/2ac3d33c
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/2ac3d33c

Branch: refs/heads/develop
Commit: 2ac3d33c6ca8719c03b1ecb2cc1152e2255c8014
Parents: 2e228a6
Author: niclas <[email protected]>
Authored: Sat Feb 18 17:14:08 2017 +0800
Committer: niclas <[email protected]>
Committed: Sat Feb 18 17:14:08 2017 +0800

----------------------------------------------------------------------
 .../entitystore/cassandra/CassandraCluster.java | 20 +++--
 .../CassandraEntityStoreConfiguration.java      | 80 +++++++++++++++++++-
 .../cassandra/CassandraMapEntityStoreTest.java  |  2 +-
 3 files changed, 93 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/2ac3d33c/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 147ae83..a8d3d29 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
@@ -46,13 +46,14 @@ import org.apache.polygene.api.configuration.Configuration;
 import org.apache.polygene.api.injection.scope.This;
 import org.apache.polygene.api.mixin.Mixins;
 import org.apache.polygene.api.service.ServiceActivation;
+import org.apache.polygene.spi.entitystore.EntityStoreException;
 
 @Mixins( CassandraCluster.Mixin.class )
 public interface CassandraCluster
 {
     String CURRENT_STORAGE_VERSION = "1";
-    String DEFAULT_KEYSPACE_NAME = "polygene:entitystore";
-    String DEFAULT_TABLE_NAME = "polygene:entitystore:entities";
+    String DEFAULT_KEYSPACE_NAME = "polygene";
+    String DEFAULT_TABLE_NAME = "entitystore";
     String IDENTITY_COLUMN = "id";
     String VERSION_COLUMN = "version";
     String USECASE_COLUMN = "usecase";
@@ -123,7 +124,7 @@ public interface CassandraCluster
         public String tableName()
         {
             CassandraEntityStoreConfiguration config = configuration.get();
-            String tableName = config.table().get();
+            String tableName = config.entityTableName().get();
             if( tableName == null )
             {
                 tableName = DEFAULT_TABLE_NAME;
@@ -154,9 +155,16 @@ public interface CassandraCluster
             KeyspaceMetadata keyspace = cluster.getMetadata().getKeyspace( 
keyspaceName );
             if( keyspace == null )
             {
-                createKeyspace( keyspaceName, config.replicationFactor().get() 
);
-                session = cluster.connect( keyspaceName );
-                createPolygeneStateTable( tableName );
+                if( config.createIfMissing().get() )
+                {
+                    createKeyspace( keyspaceName, 
config.replicationFactor().get() );
+                    session = cluster.connect( keyspaceName );
+                    createPolygeneStateTable( tableName );
+                }
+                else
+                {
+                    throw new EntityStoreException( "Keyspace '" + 
keyspaceName + "' does not exist." );
+                }
             }
             else
             {

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/2ac3d33c/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 4a5e512..9fd8c1f 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
@@ -28,23 +28,99 @@ import org.apache.polygene.api.property.Property;
 public interface CassandraEntityStoreConfiguration
     extends ConfigurationComposite
 {
-
+    /**
+     * A comma or space separated list of <code>hostname:port</code> to the 
Cassandra cluster.
+     * <p>
+     *     A small list of hostnames should be given, as the client is capable 
to discover the topology by itself
+     *     and only need one host that it can connect to.
+     * </p>
+     * <p>
+     *     Also not that Cassandra refuse to bind to all interfaces on a host, 
so you need to know which hostname
+     *     corresponds to the interface that Cassandra is bound to. This may 
not include 'localhost'.
+     * </p>
+     * @return A comma or space separated list of hostnames (and port) to use 
to connect to the Cassandra cluster.
+     */
     @Optional
     Property<String> hostnames();
 
+    /** The replication factor to be used, if a KEYSPACE is created.
+     *
+     * @return The replication factor to use in the keyspace if a keyspace is 
created. Default: 3
+     */
     @Optional
     Property<Integer> replicationFactor();
 
+    /**
+     * Username for connecting the client to the Cassandra cluster.
+     * <p>
+     *     The Cassandra client uses the CQL interface.
+     * </p>
+     * @return The Username to use to connect to the Cassandra cluster. If 
empty, then no user name will be attempted.
+     */
     @UseDefaults
     Property<String> username();
 
+    /**
+     * Password for connecting the client to the Cassandra cluster.
+     * <p>
+     *     The Cassandra client uses the CQL interface.
+     * </p>
+     * @return The password to use to connect to the Cassandra cluster. If 
empty, then no password will be attempted.
+     */
     @UseDefaults
     Property<String> password();
 
+    /**
+     * The name of the KEYSPACE to be used.
+     *
+     * @return The name of the KEYSPACE to use If null, then the default 
<code>KEYSPACE polygene</code> will be used.
+     */
     @Optional
     Property<String> keySpace();
 
+    /**
+     * The name of the entity TABLE to be used.
+     * <p>
+     * All entities are stored in the same table, with one entity per row. The 
required table schema is as follows;
+     * </p>
+     * <pre><code>
+     *     CREATE TABLE entitystore (
+     *         id text,
+     *         version text,
+     *         appversion text,
+     *         storeversion text,
+     *         modified timestamp,
+     *         usecase text,
+     *         props map<text,text>,
+     *         assocs map<text,text>,
+     *         manyassocs map<text,text>,
+     *         namedassocs map<text,text>,
+     *         PRIMARY KEY (id)
+     * );
+     *
+     * </code></pre>
+     *
+     * @return the name of the Entity table. If it returns null the default 
name of <code>entitystore</code> will be used.
+     */
     @Optional
-    Property<String> table();
+    Property<String> entityTableName();
+
+    /**
+     * Defines whether a KEYSPACE and entity TABLE should be created if not 
already present in the Cassandra cluster.
+     * <p>
+     * The default keyspace that could be created is defined as follows;
+     * </p>
+     * <pre><code>
+     *     CREATE KEYSPACE sensetif WITH replication = 
{'class':'SimpleStrategy', 'replication_factor' : $replicationFactor };
+     * </code></pre>
+     * <p>
+     *     The <code>$replicationFactor</code> refers to the {@link 
CassandraEntityStoreConfiguration#replicationFactor()}
+     *     configuration property above.
+     * </p>
+     *
+     * @return true if the KEYSPACE and TABLE should be created, false if an 
Exception should be thrown if it is missing.
+     */
+    @UseDefaults
+    Property<Boolean> createIfMissing();
 }
 // END SNIPPET: config
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/2ac3d33c/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 3f5cc12..21580f5 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
@@ -65,7 +65,7 @@ public class CassandraMapEntityStoreTest
 
         CassandraEntityStoreConfiguration cassandraConfig = config.forMixin( 
CassandraEntityStoreConfiguration.class ).declareDefaults();
         cassandraConfig.keySpace().set( "polygene:test" );
-        cassandraConfig.table().set( "polygene:test:entities" );
+        cassandraConfig.entityTableName().set( "polygene:test:entities" );
         cassandraConfig.replicationFactor().set( 1 );
         // START SNIPPET: assembly
     }

Reply via email to