Skip to content

Commit

Permalink
Add treap backing store for comments
Browse files Browse the repository at this point in the history
  • Loading branch information
davidzof committed Jan 7, 2013
1 parent 27e42e2 commit adfe72e
Show file tree
Hide file tree
Showing 65 changed files with 14,167 additions and 231 deletions.
61 changes: 32 additions & 29 deletions .classpath 100755 → 100644
@@ -1,29 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
87 changes: 36 additions & 51 deletions .project 100755 → 100644
@@ -1,51 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>comments</name>
<comment></comment>
<projects>
<project>Servers</project>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.ajdt.core.ajbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.ajdt.ui.ajnature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>com.springsource.sts.roo.core.nature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>comments</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.ajdt.core.ajbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.ajdt.ui.ajnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
</natures>
</projectDescription>
1 change: 0 additions & 1 deletion .settings/org.eclipse.ajdt.core.prefs
@@ -1,4 +1,3 @@
#Fri Aug 19 14:34:05 CEST 2011
eclipse.preferences.version=1
org.aspectj.ajdt.core.compiler.BuildOptions.showweavemessages=false
org.aspectj.ajdt.core.compiler.lint.BrokeSerialVersionCompatibility=ignore
Expand Down
12 changes: 6 additions & 6 deletions .settings/org.eclipse.core.resources.prefs
@@ -1,6 +1,6 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
#Mon Jan 07 11:15:01 CET 2013
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
4 changes: 4 additions & 0 deletions .settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
23 changes: 11 additions & 12 deletions .settings/org.eclipse.wst.common.component
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="facets">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/resources"/>
<property name="java-output-path" value="target/classes"/>
<property name="context-root" value="comments"/>
</wb-module>
</project-modules>
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="facets">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<property name="java-output-path" value="target/classes"/>
<property name="context-root" value="comments"/>
</wb-module>
</project-modules>
15 changes: 14 additions & 1 deletion pom.xml
Expand Up @@ -123,6 +123,19 @@
<version>2.0.3</version>
</dependency>

<!-- Repository -->
<dependency>
<groupId>fx.sunjoy</groupId>
<artifactId>treapdb</artifactId>
<version>2.1</version>
</dependency>

<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
<version>0.7.0</version>
</dependency>

<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
Expand Down Expand Up @@ -189,7 +202,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>magneato</warName>
<warName>comments</warName>
</configuration>
</plugin>
<plugin>
Expand Down
39 changes: 34 additions & 5 deletions src/main/java/com/abcseo/comments/dao/Repository.java
@@ -1,11 +1,40 @@
/*
* Copyright 2013, David George, Licensed 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.
*/
package com.abcseo.comments.dao;

import com.abcseo.comments.dto.Comment;
import com.abcseo.comments.dto.Comments;

import com.abcseo.comments.dto.CommentResults;

/**
* Comment Repository Interface. A user can add a comment or get a list of comments.
*
* @author David George
*
*/
public interface Repository {
public Comments getComments(String uri, int page, int count);
public void addComment(String uri, Comment c);

/**
* @param uri URI of page for which we want a comment listing
* @param page
* @param count
*
* @return CommentResult object
*/
public CommentResults getComments(String uri, int page, int count);

/**
* @param uri URI of page to which comment is added. There is no max URI length
* @param c Comment to add
* @returns Comment ID
*/
public int addComment(String uri, Comment c);
}
26 changes: 19 additions & 7 deletions src/main/java/com/abcseo/comments/dao/RepositoryMemHashImpl.java
@@ -1,6 +1,17 @@
/*
* Copyright 2013, David George, Licensed 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.
*/
package com.abcseo.comments.dao;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
Expand All @@ -9,9 +20,9 @@
import org.springframework.stereotype.Service;

import com.abcseo.comments.dto.Comment;
import com.abcseo.comments.dto.Comments;
import com.abcseo.comments.dto.CommentResults;

@Service("Repository")
//@Service("Repository")
public class RepositoryMemHashImpl implements Repository {
HashMap<String, ArrayList<Comment>> repository = new HashMap<String, ArrayList<Comment>>();
MessageDigest md;
Expand All @@ -26,8 +37,7 @@ public RepositoryMemHashImpl() {
}

@Override
public Comments getComments(String uri, int page, int count) {
byte[] bytesOfMessage;
public CommentResults getComments(String uri, int page, int count) {

ArrayList<Comment> allComments = repository.get(uri);
if (allComments == null) {
Expand All @@ -40,19 +50,21 @@ public Comments getComments(String uri, int page, int count) {
list.add(c);
}

Comments comments = new Comments(page, count, allComments.size(), list);
CommentResults comments = new CommentResults(page, count, allComments.size(), list);

return comments;
}

@Override
public void addComment(String uri, Comment c) {
public int addComment(String uri, Comment c) {
ArrayList<Comment> comments = repository.get(uri);
if (comments == null) {
comments = new ArrayList<Comment>();
repository.put(uri, comments);
}
comments.add(c);

return comments.size() -1;
}

}

0 comments on commit adfe72e

Please sign in to comment.