incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From z..@apache.org
Subject svn commit: r924891 - in /incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog: BlogAuthorImpl.java BlogAuthorManagerImpl.java BlogEntryManagerImpl.java BlogListAdapter.java BlogListIterator.java
Date Thu, 18 Mar 2010 16:49:54 GMT
Author: zoe
Date: Thu Mar 18 16:49:54 2010
New Revision: 924891

URL: http://svn.apache.org/viewvc?rev=924891&view=rev
Log:
ARIES-225 Code to avoid copying the persistence entities into memory

Added:
    incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogListAdapter.java
    incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogListIterator.java
Modified:
    incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogAuthorImpl.java
    incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogAuthorManagerImpl.java
    incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogEntryManagerImpl.java

Modified: incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogAuthorImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogAuthorImpl.java?rev=924891&r1=924890&r2=924891&view=diff
==============================================================================
--- incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogAuthorImpl.java
(original)
+++ incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogAuthorImpl.java
Thu Mar 18 16:49:54 2010
@@ -27,62 +27,56 @@ import org.apache.aries.samples.blog.api
 import org.apache.aries.samples.blog.persistence.api.Author;
 import org.apache.aries.samples.blog.persistence.api.Entry;
 
+public class BlogAuthorImpl implements BlogAuthor {
+	private static Calendar cal = Calendar.getInstance();
+	private Author author;
 
+	public BlogAuthorImpl(Author a) {
+		author = a;
+	}
+
+	public String getBio() {
+		return author.getBio();
+	}
+
+	public String getEmailAddress() {
+		return author.getEmail();
+	}
+
+	public String getFullName() {
+		return author.getName();
+	}
+
+	public String getName() {
+		return author.getDisplayName();
+	}
+
+	public String getDateOfBirth() {
+		Date dob = author.getDob();
+
+		int year = 0;
+		int month = 0;
+		int date = 0;
+
+		synchronized (cal) {
+			if (dob != null) {
+				cal.setTime(dob);
+				year = cal.get(Calendar.YEAR);
+				month = cal.get(Calendar.MONTH) + 1;
+				date = cal.get(Calendar.DATE);
+			}
+		}
+		return year + "-" + month + "-" + date;
+
+	}
 
-public class BlogAuthorImpl implements BlogAuthor
-{
-  private static Calendar cal = Calendar.getInstance();
-  private Author author;
-  
-  public BlogAuthorImpl(Author a)
-  {
-    author = a;
-  }
-
-  public String getBio()
-  {
-    return author.getBio();
-  }
-
-  public String getEmailAddress()
-  {
-    return author.getEmail();
-  }
-
-  public String getFullName()
-  {
-    return author.getName();
-  }
-
-  public String getName()
-  {
-    return author.getDisplayName();
-  }
-
-  public String getDateOfBirth()
-  {
-    Date dob = author.getDob();
-    
-    int year;
-    int month;
-    int date;
-    
-    synchronized (cal) {
-      cal.setTime(dob);
-      year = cal.get(Calendar.YEAR);
-      month = cal.get(Calendar.MONTH) + 1;
-      date = cal.get(Calendar.DATE);
-    }
-    
-    return year + "-" + month + "-" + date;
-  }
-  
 	public List<? extends BlogEntry> getEntries() {
 		return adapt(author.getEntries());
 	}
-	
-	private List<? extends BlogEntry> adapt (List<? extends Entry> list) {
-		List<BlogEntryImpl> bei = null;;
+
+	private List<? extends BlogEntry> adapt(List<? extends Entry> list) {
+		List<BlogEntryImpl> bei = null;
+		;
 		return bei;
 	}
 }
\ No newline at end of file

Modified: incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogAuthorManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogAuthorManagerImpl.java?rev=924891&r1=924890&r2=924891&view=diff
==============================================================================
--- incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogAuthorManagerImpl.java
(original)
+++ incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogAuthorManagerImpl.java
Thu Mar 18 16:49:54 2010
@@ -84,15 +84,8 @@ public class BlogAuthorManagerImpl imple
   
 	private List<? extends BlogAuthor> adaptAuthor(
 			List<? extends Author> authors) {
-		List<BlogAuthorImpl> list = new ArrayList<BlogAuthorImpl>();
-
-		Iterator<? extends Author> a = authors.iterator();
-		while (a.hasNext()) {
-			list.add(new BlogAuthorImpl(a.next()));
-		}
-
-		return list;
+			return new BlogListAdapter<BlogAuthor, Author>(authors, BlogAuthorImpl.class, Author.class);
 
 	}
-  
+ 
 }

Modified: incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogEntryManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogEntryManagerImpl.java?rev=924891&r1=924890&r2=924891&view=diff
==============================================================================
--- incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogEntryManagerImpl.java
(original)
+++ incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogEntryManagerImpl.java
Thu Mar 18 16:49:54 2010
@@ -77,7 +77,7 @@ public class BlogEntryManagerImpl implem
   {
     if(startDate == null || "".equals(startDate)) throw new IllegalArgumentException("A valid
start date must be supplied");
     if(endDate == null || "".equals(endDate)) throw new IllegalArgumentException("A valid
end date must be supplied");
-    SimpleDateFormat sdf = new SimpleDateFormat("dd-mm-yyyy");
+    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
     Date start = sdf.parse(startDate);
     Date end = sdf.parse(endDate);
 	List <? extends Entry> entries = persistenceService.getBlogEntriesModifiedBetween(start,
end);
@@ -145,7 +145,7 @@ public class BlogEntryManagerImpl implem
   
   private Date parseDate(String dateString) throws ParseException
   {
-    SimpleDateFormat sdf = new SimpleDateFormat("dd-mm-yyyy");
+    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
     return sdf.parse(dateString);
   }
 
@@ -155,14 +155,8 @@ public class BlogEntryManagerImpl implem
     return new BlogEntryImpl(persistenceService.getBlogEntryById(id));
   }
   
-	private List <? extends BlogEntry> adaptEntries(List<? extends Entry> e) {
-		  List<BlogEntryImpl> posts = new ArrayList<BlogEntryImpl>();
-		    
-		    for (Entry entry : e) {
-		      posts.add(new BlogEntryImpl(entry));
-		    }
-		      
-		return posts;
-	}
+	private List <? extends BlogEntry> adaptEntries(List<? extends Entry> entries)
{
+		return new BlogListAdapter<BlogEntry, Entry>(entries, BlogEntryImpl.class, Entry.class);
+  }
 	
 }
\ No newline at end of file

Added: incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogListAdapter.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogListAdapter.java?rev=924891&view=auto
==============================================================================
--- incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogListAdapter.java
(added)
+++ incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogListAdapter.java
Thu Mar 18 16:49:54 2010
@@ -0,0 +1,165 @@
+/**
+ * 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.
+ */
+package org.apache.aries.samples.blog;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+public class BlogListAdapter<F, B> implements List<F> {
+
+	private List<? extends B> backendList;
+	private Class<? extends F> frontendClazz;
+	private Class<B> backendClazz;
+
+	public BlogListAdapter(List<? extends B> backendList,
+			Class<? extends F> frontendClazz, Class<B> backendClazz) {
+		this.backendList = backendList;
+		this.frontendClazz = frontendClazz;
+		this.backendClazz = backendClazz;
+	}
+
+	public void add() {
+		throw new UnsupportedOperationException(
+				"Modifications to the list are not supported");
+	}
+
+	public boolean add(F e) {
+		throw new UnsupportedOperationException(
+				"Modifications to the list are not supported");
+	}
+
+	public void add(int index, F element) {
+		throw new UnsupportedOperationException(
+				"Modifications to the list are not supported");
+	}
+
+	public boolean addAll(Collection<? extends F> c) {
+		throw new UnsupportedOperationException(
+				"Modifications to the list are not supported");
+	}
+
+	public boolean addAll(int index, Collection<? extends F> c) {
+		throw new UnsupportedOperationException(
+				"Modifications to the list are not supported");
+	}
+
+	public void clear() {
+		throw new UnsupportedOperationException(
+				"Modifications to the list are not supported");
+
+	}
+
+	public boolean contains(Object o) {
+		throw new UnsupportedOperationException("Contains() is not supported");
+
+	}
+
+	public boolean containsAll(Collection<?> c) {
+		throw new UnsupportedOperationException(
+				"ContainsAll() is not supported");
+	}
+
+	public F get(int index) {
+		Constructor<F> c;
+		try {
+			c = (Constructor<F>) frontendClazz.getConstructor(backendClazz);
+			return c.newInstance(backendList.get(index));
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} 
+		return null;
+	}
+
+	public int indexOf(Object o) {
+		throw new UnsupportedOperationException("IndexOf() is not supported");
+	}
+
+	public boolean isEmpty() {
+		return backendList.isEmpty();
+	}
+
+	public Iterator iterator() {
+		return new BlogListIterator(backendList.listIterator(), frontendClazz,
+				backendClazz);
+	}
+
+	public int lastIndexOf(Object o) {
+		throw new UnsupportedOperationException(
+				"lastIndexOf() is not supported");
+	}
+
+	public ListIterator listIterator() {
+		return new BlogListIterator(backendList.listIterator(), frontendClazz,
+				backendClazz);
+	}
+
+	public ListIterator listIterator(int index) {
+		return new BlogListIterator(backendList.listIterator(index),
+				frontendClazz, backendClazz);
+	}
+
+	public boolean remove(Object o) {
+		throw new UnsupportedOperationException(
+				"Modifications to the list are not supported");
+	}
+
+	public F remove(int index) {
+		throw new UnsupportedOperationException(
+				"Modifications to the list are not supported");
+	}
+
+	public boolean removeAll(Collection c) {
+		throw new UnsupportedOperationException(
+				"Modifications to the list are not supported");
+	}
+
+	public boolean retainAll(Collection c) {
+		throw new UnsupportedOperationException(
+				"Modifications to the list are not supported");
+	}
+
+	public Object set(int index, Object element) {
+		throw new UnsupportedOperationException(
+				"Modifications to the list are not supported");
+	}
+
+	public int size() {
+		return backendList.size();
+	}
+
+	public List subList(int fromIndex, int toIndex) {
+		throw new UnsupportedOperationException("subList() is not supported");
+	}
+
+	public Object[] toArray() {
+		throw new UnsupportedOperationException("toArray() is not supported");
+	}
+
+	public Object[] toArray(Object[] a) {
+		throw new UnsupportedOperationException(
+				"toArray(Object[] a) is not supported");
+	}
+
+}
+

Added: incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogListIterator.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogListIterator.java?rev=924891&view=auto
==============================================================================
--- incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogListIterator.java
(added)
+++ incubator/aries/trunk/samples/blog/blog-biz/src/main/java/org/apache/aries/samples/blog/BlogListIterator.java
Thu Mar 18 16:49:54 2010
@@ -0,0 +1,100 @@
+/**
+ * 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.
+ */
+package org.apache.aries.samples.blog;
+
+import java.lang.reflect.Constructor;
+import java.util.ListIterator;
+
+public class BlogListIterator<B, F> implements ListIterator<F> {
+
+	private ListIterator<? extends B> internalListIterator;
+
+	private Class<? extends F> frontendClazz;
+	private Class<B> backendClazz;
+
+	public BlogListIterator(ListIterator<? extends B> listIterator,
+			Class<? extends F> frontendClazz, Class<B> backendClazz) {
+		this.internalListIterator = listIterator;
+		this.frontendClazz = frontendClazz;
+		this.backendClazz = backendClazz;
+	}
+
+	public void add(Object e) {
+		throw new UnsupportedOperationException("");
+	}
+
+	public boolean hasNext() {
+		return internalListIterator.hasNext();
+	}
+
+	public boolean hasPrevious() {
+		return internalListIterator.hasPrevious();
+	}
+
+	public F next() {
+		try {
+			return getConstructor().newInstance(internalListIterator.next());
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	public int nextIndex() {
+		return internalListIterator.nextIndex();
+	}
+
+	public F previous() {	
+		try {
+			return getConstructor().newInstance(internalListIterator.previous());
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	public int previousIndex() {
+		// TODO Auto-generated method stub
+		return 0;
+	}
+
+	public void remove() {
+		throw new UnsupportedOperationException(
+				"Modifications to the list are not supported");
+	}
+
+	public void set(Object e) {
+		throw new UnsupportedOperationException(
+				"Modifications to the list are not supported");
+	}
+
+	private Constructor<F> getConstructor() {
+		Constructor<F> c;
+		try {
+			c = (Constructor<F>) frontendClazz.getConstructor(backendClazz);
+			return c;
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		return null;
+	}
+}



Mime
View raw message