You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2014/10/02 19:26:53 UTC
git commit: Initial commit of map module
Repository: incubator-usergrid
Updated Branches:
refs/heads/map b644cc0aa -> 9a8bed510
Initial commit of map module
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/9a8bed51
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/9a8bed51
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/9a8bed51
Branch: refs/heads/map
Commit: 9a8bed5106934e8d4013f272954d5c340ec1612d
Parents: b644cc0
Author: Todd Nine <to...@apache.org>
Authored: Thu Oct 2 11:26:49 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Thu Oct 2 11:26:49 2014 -0600
----------------------------------------------------------------------
.../collection/event/EntityDeleted.java | 17 ++
.../collection/event/EntityVersionCreated.java | 17 ++
.../collection/event/EntityVersionDeleted.java | 17 ++
stack/corepersistence/map/pom.xml | 64 +++++
.../usergrid/persistence/map/MapManager.java | 69 +++++
.../persistence/map/MapManagerFactory.java | 30 +++
.../usergrid/persistence/map/MapScope.java | 40 +++
.../persistence/map/guice/MapModule.java | 61 +++++
.../persistence/map/impl/MapManagerImpl.java | 117 +++++++++
.../persistence/map/impl/MapScopeImpl.java | 91 +++++++
.../persistence/map/impl/MapSerialization.java | 64 +++++
.../map/impl/MapSerializationImpl.java | 254 +++++++++++++++++++
.../persistence/map/MapManagerTest.java | 96 +++++++
.../persistence/map/guice/TestMapModule.java | 16 ++
stack/corepersistence/pom.xml | 1 +
15 files changed, 954 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9a8bed51/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/event/EntityDeleted.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/event/EntityDeleted.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/event/EntityDeleted.java
index 1c075f1..f25042c 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/event/EntityDeleted.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/event/EntityDeleted.java
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
package org.apache.usergrid.persistence.collection.event;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9a8bed51/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/event/EntityVersionCreated.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/event/EntityVersionCreated.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/event/EntityVersionCreated.java
index 9d7761c..2b9c023 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/event/EntityVersionCreated.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/event/EntityVersionCreated.java
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
package org.apache.usergrid.persistence.collection.event;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9a8bed51/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/event/EntityVersionDeleted.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/event/EntityVersionDeleted.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/event/EntityVersionDeleted.java
index ff7d960..aedcf3a 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/event/EntityVersionDeleted.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/event/EntityVersionDeleted.java
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
package org.apache.usergrid.persistence.collection.event;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9a8bed51/stack/corepersistence/map/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/map/pom.xml b/stack/corepersistence/map/pom.xml
new file mode 100644
index 0000000..cf88702
--- /dev/null
+++ b/stack/corepersistence/map/pom.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <artifactId>persistence</artifactId>
+ <groupId>org.apache.usergrid</groupId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <description>The module for handling map operations</description>
+
+ <artifactId>map</artifactId>
+
+ <dependencies>
+
+
+ <dependency>
+ <groupId>org.apache.usergrid</groupId>
+ <artifactId>common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+
+
+ <!-- lang utils for setting uuids etc -->
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>${commons.lang.version}</version>
+ </dependency>
+
+ <!-- tests -->
+
+ <dependency>
+ <groupId>org.apache.usergrid</groupId>
+ <artifactId>common</artifactId>
+ <version>${project.version}</version>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.jukito</groupId>
+ <artifactId>jukito</artifactId>
+ <version>${jukito.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.apache.usergrid</groupId>
+ <artifactId>collection</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9a8bed51/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/MapManager.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/MapManager.java b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/MapManager.java
new file mode 100644
index 0000000..d1d5f1b
--- /dev/null
+++ b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/MapManager.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.map;
+
+
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.core.migration.Migration;
+
+
+/**
+ * Generator of a map manager instance
+ */
+public interface MapManager {
+
+
+ /**
+ * Return the string, null if not found
+ */
+ public String getString( final String key );
+
+ /**
+ * Return the string, null if not found
+ */
+ public void putString( final String key, final String value );
+
+
+ /**
+ * Return the uuid, null if not found
+ */
+ public UUID getUuid( final String key );
+
+ /**
+ * Return the uuid, null if not found
+ */
+ public UUID putUuid( final String key, final UUID putUuid );
+
+ /**
+ * Return the long, null if not found
+ */
+ public Long getLong( final String key );
+
+ /**
+ * Return the long, null if not found
+ */
+ public Long putLong( final String key, final Long value );
+
+ /**
+ * Delete the key
+ *
+ * @param key The key used to delete the entry
+ */
+ public void delete( final String key );
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9a8bed51/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/MapManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/MapManagerFactory.java b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/MapManagerFactory.java
new file mode 100644
index 0000000..1575765
--- /dev/null
+++ b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/MapManagerFactory.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.map;
+
+
+/**
+ * Factory for creating map managers
+ */
+public interface MapManagerFactory {
+
+ /**
+ * Get the map manager
+ */
+ public MapManager getMapManager( final MapScope scope );
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9a8bed51/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/MapScope.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/MapScope.java b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/MapScope.java
new file mode 100644
index 0000000..05f64f4
--- /dev/null
+++ b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/MapScope.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.map;
+
+
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+
+/**
+ * Interface for the scope of a map
+ * Note that application isn't actually an application, but an ownerId. ApplicationScope needs renamed.
+ *
+ *
+ */
+public interface MapScope extends ApplicationScope {
+
+
+ /**
+ * Get the name of the the map
+ * @return
+ */
+ public String getName();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9a8bed51/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/guice/MapModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/guice/MapModule.java b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/guice/MapModule.java
new file mode 100644
index 0000000..b6c1410
--- /dev/null
+++ b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/guice/MapModule.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.map.guice;
+
+
+import org.apache.usergrid.persistence.core.migration.Migration;
+import org.apache.usergrid.persistence.map.MapManager;
+import org.apache.usergrid.persistence.map.MapManagerFactory;
+import org.apache.usergrid.persistence.map.impl.MapManagerImpl;
+import org.apache.usergrid.persistence.map.impl.MapSerialization;
+import org.apache.usergrid.persistence.map.impl.MapSerializationImpl;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Key;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
+import com.google.inject.multibindings.Multibinder;
+
+
+/**
+ * Simple module for wiring our collection api
+ *
+ * @author tnine
+ */
+public class MapModule extends AbstractModule {
+
+
+ @Override
+ protected void configure() {
+
+ // create a guice factory for getting our collection manager
+ install( new FactoryModuleBuilder().implement( MapManager.class, MapManagerImpl.class )
+ .build( MapManagerFactory.class ) );
+
+
+ bind( MapSerialization.class).to( MapSerializationImpl.class );
+
+ Multibinder<Migration> migrationBinding = Multibinder.newSetBinder( binder(), Migration.class );
+ migrationBinding.addBinding().to( Key.get( MapSerialization.class ) );
+
+ }
+
+
+
+}
+
+
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9a8bed51/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapManagerImpl.java b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapManagerImpl.java
new file mode 100644
index 0000000..7ae1214
--- /dev/null
+++ b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapManagerImpl.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.map.impl;
+
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.UUID;
+
+import org.apache.cassandra.db.marshal.BytesType;
+import org.apache.cassandra.db.marshal.ReversedType;
+import org.apache.cassandra.db.marshal.UTF8Type;
+import org.apache.cassandra.db.marshal.UUIDType;
+
+import org.apache.usergrid.persistence.core.astyanax.CompositeFieldSerializer;
+import org.apache.usergrid.persistence.core.astyanax.MultiTennantColumnFamily;
+import org.apache.usergrid.persistence.core.astyanax.MultiTennantColumnFamilyDefinition;
+import org.apache.usergrid.persistence.core.astyanax.OrganizationScopedRowKeySerializer;
+import org.apache.usergrid.persistence.core.astyanax.ScopedRowKey;
+import org.apache.usergrid.persistence.core.migration.Migration;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.map.MapManager;
+import org.apache.usergrid.persistence.map.MapScope;
+
+import com.google.inject.Inject;
+import com.google.inject.assistedinject.Assisted;
+import com.netflix.astyanax.Keyspace;
+import com.netflix.astyanax.MutationBatch;
+import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
+import com.netflix.astyanax.connectionpool.exceptions.NotFoundException;
+import com.netflix.astyanax.model.Column;
+import com.netflix.astyanax.model.ColumnFamily;
+import com.netflix.astyanax.model.CompositeBuilder;
+import com.netflix.astyanax.model.CompositeParser;
+import com.netflix.astyanax.serializers.BooleanSerializer;
+import com.netflix.astyanax.serializers.StringSerializer;
+;
+
+
+/**
+ * Implementation of the map manager
+ */
+public class MapManagerImpl implements MapManager {
+
+
+
+
+ private final MapScope scope;
+ private final MapSerialization mapSerialization;
+
+
+ @Inject
+ public MapManagerImpl( @Assisted final MapScope scope, final MapSerialization mapSerialization) {
+ this.scope = scope;
+ this.mapSerialization = mapSerialization;
+ }
+
+
+ @Override
+ public String getString( final String key ) {
+ return mapSerialization.getString( scope, key );
+ }
+
+
+ @Override
+ public void putString( final String key, final String value ) {
+ mapSerialization.putString( scope, key, value );
+ }
+
+
+ @Override
+ public UUID getUuid( final String key ) {
+ return null;
+ }
+
+
+ @Override
+ public UUID putUuid( final String key, final UUID putUuid ) {
+ return null;
+ }
+
+
+ @Override
+ public Long getLong( final String key ) {
+ return null;
+ }
+
+
+ @Override
+ public Long putLong( final String key, final Long value ) {
+ return null;
+ }
+
+
+ @Override
+ public void delete( final String key ) {
+
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9a8bed51/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapScopeImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapScopeImpl.java b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapScopeImpl.java
new file mode 100644
index 0000000..e18f8b4
--- /dev/null
+++ b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapScopeImpl.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.map.impl;
+
+
+import org.apache.usergrid.persistence.map.MapScope;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+
+/**
+ * The scope impl
+ */
+public class MapScopeImpl implements MapScope {
+
+ private final Id owner;
+ private final String name;
+
+
+ public MapScopeImpl( final Id owner, final String name ) {
+ this.owner = owner;
+ this.name = name;
+ }
+
+
+
+ @Override
+ public Id getApplication() {
+ return owner;
+ }
+
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+
+ @Override
+ public boolean equals( final Object o ) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( !( o instanceof MapScopeImpl ) ) {
+ return false;
+ }
+
+ final MapScopeImpl mapScope = ( MapScopeImpl ) o;
+
+ if ( !name.equals( mapScope.name ) ) {
+ return false;
+ }
+ if ( !owner.equals( mapScope.owner ) ) {
+ return false;
+ }
+
+ return true;
+ }
+
+
+ @Override
+ public int hashCode() {
+ int result = owner.hashCode();
+ result = 31 * result + name.hashCode();
+ return result;
+ }
+
+
+ @Override
+ public String toString() {
+ return "MapScopeImpl{" +
+ "owner=" + owner +
+ ", name='" + name + '\'' +
+ '}';
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9a8bed51/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerialization.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerialization.java b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerialization.java
new file mode 100644
index 0000000..5b1abaa
--- /dev/null
+++ b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerialization.java
@@ -0,0 +1,64 @@
+package org.apache.usergrid.persistence.map.impl;/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.core.migration.Migration;
+import org.apache.usergrid.persistence.map.MapScope;
+
+
+public interface MapSerialization extends Migration {
+ /**
+ * Return the string, null if not found
+ */
+ public String getString( final MapScope scope, final String key );
+
+ /**
+ * Return the string, null if not found
+ */
+ public void putString(final MapScope scope, final String key, final String value );
+
+
+ /**
+ * Return the uuid, null if not found
+ */
+ public UUID getUuid(final MapScope scope, final String key );
+
+ /**
+ * Return the uuid, null if not found
+ */
+ public UUID putUuid(final MapScope scope, final String key, final UUID putUuid );
+
+ /**
+ * Return the long, null if not found
+ */
+ public Long getLong(final MapScope scope, final String key );
+
+ /**
+ * Return the long, null if not found
+ */
+ public Long putLong(final MapScope scope, final String key, final Long value );
+
+ /**
+ * Delete the key
+ *
+ * @param key The key used to delete the entry
+ */
+ public void delete(final MapScope scope, final String key );}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9a8bed51/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerializationImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerializationImpl.java b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerializationImpl.java
new file mode 100644
index 0000000..0475a75
--- /dev/null
+++ b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapSerializationImpl.java
@@ -0,0 +1,254 @@
+package org.apache.usergrid.persistence.map.impl;/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.UUID;
+
+import org.apache.cassandra.db.marshal.BytesType;
+import org.apache.cassandra.db.marshal.UTF8Type;
+
+import org.apache.usergrid.persistence.core.astyanax.CompositeFieldSerializer;
+import org.apache.usergrid.persistence.core.astyanax.MultiTennantColumnFamily;
+import org.apache.usergrid.persistence.core.astyanax.MultiTennantColumnFamilyDefinition;
+import org.apache.usergrid.persistence.core.astyanax.OrganizationScopedRowKeySerializer;
+import org.apache.usergrid.persistence.core.astyanax.ScopedRowKey;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.map.MapScope;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import com.netflix.astyanax.Keyspace;
+import com.netflix.astyanax.MutationBatch;
+import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
+import com.netflix.astyanax.connectionpool.exceptions.NotFoundException;
+import com.netflix.astyanax.model.Column;
+import com.netflix.astyanax.model.CompositeBuilder;
+import com.netflix.astyanax.model.CompositeParser;
+import com.netflix.astyanax.serializers.BooleanSerializer;
+import com.netflix.astyanax.serializers.StringSerializer;
+
+
+@Singleton
+public class MapSerializationImpl implements MapSerialization {
+
+ private static final MapKeySerializer KEY_SERIALIZER = new MapKeySerializer();
+ private static final OrganizationScopedRowKeySerializer<String> MAP_KEY_SERIALIZER =
+ new OrganizationScopedRowKeySerializer<>( KEY_SERIALIZER );
+
+
+ private static final MapEntrySerializer ENTRY_SERIALIZER = new MapEntrySerializer();
+ private static final OrganizationScopedRowKeySerializer<MapEntryKey> MAP_ENTRY_SERIALIZER =
+ new OrganizationScopedRowKeySerializer<>( ENTRY_SERIALIZER );
+
+
+ private static final BooleanSerializer BOOLEAN_SERIALIZER = BooleanSerializer.get();
+
+ private static final StringSerializer STRING_SERIALIZER = StringSerializer.get();
+
+
+ /**
+ * CFs where the row key contains the source node id
+ */
+ private static final MultiTennantColumnFamily<ApplicationScope, MapEntryKey, Boolean> MAP_ENTRIES =
+ new MultiTennantColumnFamily<>( "Map_Entries", MAP_ENTRY_SERIALIZER, BOOLEAN_SERIALIZER );
+
+
+ /**
+ * CFs where the row key contains the source node id
+ */
+ private static final MultiTennantColumnFamily<ApplicationScope, String, String> MAP_KEYS =
+ new MultiTennantColumnFamily<>( "Map_Keys", MAP_KEY_SERIALIZER, STRING_SERIALIZER );
+
+
+
+ private final Keyspace keyspace;
+
+
+ @Inject
+ public MapSerializationImpl( final Keyspace keyspace ) {this.keyspace = keyspace;}
+
+
+ @Override
+ public String getString( final MapScope scope, final String key ) {
+ //add it to the entry
+ final ScopedRowKey<ApplicationScope, MapEntryKey> entryRowKey = MapEntryKey.fromKey( scope, key );
+
+
+ try {
+ final Column<Boolean> result =
+ keyspace.prepareQuery( MAP_ENTRIES ).getKey( entryRowKey ).getColumn( true ).execute().getResult();
+
+ return result.getStringValue();
+ }
+ catch ( NotFoundException nfe ) {
+ //nothing to return
+ return null;
+ }
+ catch ( ConnectionException e ) {
+ throw new RuntimeException( "Unable to connect to cassandra", e );
+ }
+ }
+
+
+ @Override
+ public void putString( final MapScope scope, final String key, final String value ) {
+ final MutationBatch batch = keyspace.prepareMutationBatch();
+
+ //add it to the entry
+ final ScopedRowKey<ApplicationScope, MapEntryKey> entryRowKey = MapEntryKey.fromKey( scope, key );
+
+ //serialize to the entry
+ batch.withRow( MAP_ENTRIES, entryRowKey ).putColumn( true, value );
+
+ //add it to the keys
+
+ final ScopedRowKey<ApplicationScope, String> keyRowKey =
+ ScopedRowKey.fromKey( ( ApplicationScope ) scope, key );
+
+ //serialize to the entry
+ batch.withRow( MAP_KEYS, keyRowKey ).putColumn( key, true );
+
+ try {
+ batch.execute();
+ }
+ catch ( ConnectionException e ) {
+ throw new RuntimeException( "Unable to connect to cassandra", e );
+ }
+ }
+
+
+ @Override
+ public UUID getUuid( final MapScope scope, final String key ) {
+ return null;
+ }
+
+
+ @Override
+ public UUID putUuid( final MapScope scope, final String key, final UUID putUuid ) {
+ return null;
+ }
+
+
+ @Override
+ public Long getLong( final MapScope scope, final String key ) {
+ return null;
+ }
+
+
+ @Override
+ public Long putLong( final MapScope scope, final String key, final Long value ) {
+ return null;
+ }
+
+
+ @Override
+ public void delete( final MapScope scope, final String key ) {
+
+ }
+
+
+ @Override
+ public Collection<MultiTennantColumnFamilyDefinition> getColumnFamilies()
+ {
+ final MultiTennantColumnFamilyDefinition mapEntries = new MultiTennantColumnFamilyDefinition( MAP_ENTRIES,
+ BytesType.class.getSimpleName(), BytesType.class.getSimpleName(), BytesType.class.getSimpleName(), MultiTennantColumnFamilyDefinition.CacheOption.KEYS );
+
+
+ final MultiTennantColumnFamilyDefinition mapKeys = new MultiTennantColumnFamilyDefinition( MAP_KEYS,
+ BytesType.class.getSimpleName(), UTF8Type.class.getSimpleName(), BytesType.class.getSimpleName(), MultiTennantColumnFamilyDefinition.CacheOption.KEYS );
+
+ return Arrays.asList( mapEntries, mapKeys );
+ }
+
+
+ /**
+ * Inner class to serialize and edgeIdTypeKey
+ */
+
+
+ /**
+ * Inner class to serialize and edgeIdTypeKey
+ */
+ private static class MapKeySerializer implements CompositeFieldSerializer<String> {
+
+
+ @Override
+ public void toComposite( final CompositeBuilder builder, final String key ) {
+ builder.addString( key );
+ }
+
+
+ @Override
+ public String fromComposite( final CompositeParser composite ) {
+ final String key = composite.readString();
+
+ return key;
+ }
+ }
+
+
+ /**
+ * Inner class to serialize and edgeIdTypeKey
+ */
+ private static class MapEntrySerializer implements CompositeFieldSerializer<MapEntryKey> {
+
+ @Override
+ public void toComposite( final CompositeBuilder builder, final MapEntryKey key ) {
+
+ builder.addString( key.mapName );
+ builder.addString( key.key );
+ }
+
+
+ @Override
+ public MapEntryKey fromComposite( final CompositeParser composite ) {
+
+ final String mapName = composite.readString();
+
+ final String entryKey = composite.readString();
+
+ return new MapEntryKey( mapName, entryKey );
+ }
+ }
+
+
+ /**
+ * Entries for serializing map entries and keys to a row
+ */
+ private static class MapEntryKey {
+ public final String mapName;
+ public final String key;
+
+
+ private MapEntryKey( final String mapName, final String key ) {
+ this.mapName = mapName;
+ this.key = key;
+ }
+
+
+ /**
+ * Create a scoped row key from the key
+ */
+ public static ScopedRowKey<ApplicationScope, MapEntryKey> fromKey( final MapScope mapScope, final String key ) {
+ return ScopedRowKey.fromKey( ( ApplicationScope ) mapScope, new MapEntryKey( mapScope.getName(), key ) );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9a8bed51/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/MapManagerTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/MapManagerTest.java b/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/MapManagerTest.java
new file mode 100644
index 0000000..19db661
--- /dev/null
+++ b/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/MapManagerTest.java
@@ -0,0 +1,96 @@
+package org.apache.usergrid.persistence.map;
+
+
+import org.jukito.UseModules;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
+import org.apache.usergrid.persistence.core.cassandra.ITRunner;
+import org.apache.usergrid.persistence.map.guice.TestMapModule;
+import org.apache.usergrid.persistence.map.impl.MapScopeImpl;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+
+import com.google.inject.Inject;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+
+@RunWith( ITRunner.class )
+@UseModules( { TestMapModule.class } )
+public class MapManagerTest {
+
+
+ @Inject
+ @Rule
+ public MigrationManagerRule migrationManagerRule;
+
+
+ @Inject
+ protected MapManagerFactory mmf;
+
+ protected MapScope scope;
+
+
+ @Before
+ public void mockApp() {
+ this.scope = new MapScopeImpl( new SimpleId( "application" ), "testMap" );
+ }
+
+
+ @Test
+ public void writeReadString() {
+ MapManager mm = mmf.getMapManager( this.scope );
+
+ final String key = "key";
+ final String value = "value";
+
+ mm.putString( key, value );
+
+ final String returned = mm.getString( key );
+
+ assertEquals( value, returned );
+ }
+
+
+ @Test
+ public void readMissingEntry() {
+ MapManager mm = mmf.getMapManager( this.scope );
+
+ final String returned = mm.getString( "key" );
+
+ assertNull( returned );
+ }
+
+
+ @Test
+ public void deleteString() {
+ MapManager mm = mmf.getMapManager( this.scope );
+
+ final String key = "key";
+ final String value = "value";
+
+ mm.putString( key, value );
+
+ final String returned = mm.getString( key );
+
+ assertEquals( value, returned );
+
+ mm.delete( key );
+
+ final String postDelete = mm.getString( key );
+
+ assertNull( postDelete );
+ }
+
+
+ @Test( expected = IllegalArgumentException.class )
+ public void nullInput() {
+ MapManager mm = mmf.getMapManager( this.scope );
+
+ mm.putString( null, null );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9a8bed51/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/guice/TestMapModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/guice/TestMapModule.java b/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/guice/TestMapModule.java
new file mode 100644
index 0000000..739bb67
--- /dev/null
+++ b/stack/corepersistence/map/src/test/java/org/apache/usergrid/persistence/map/guice/TestMapModule.java
@@ -0,0 +1,16 @@
+package org.apache.usergrid.persistence.map.guice;
+
+
+import org.apache.usergrid.persistence.collection.guice.TestModule;
+import org.apache.usergrid.persistence.core.guice.CommonModule;
+
+
+
+public class TestMapModule extends TestModule {
+
+ @Override
+ protected void configure() {
+ install( new CommonModule());
+ install( new MapModule() );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9a8bed51/stack/corepersistence/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/pom.xml b/stack/corepersistence/pom.xml
index 701f369..7edc9f2 100644
--- a/stack/corepersistence/pom.xml
+++ b/stack/corepersistence/pom.xml
@@ -67,6 +67,7 @@
<module>graph</module>
<module>queryindex</module>
<module>common</module>
+ <module>map</module>
</modules>
<build>