You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by cl...@apache.org on 2007/01/09 20:07:44 UTC
svn commit: r494526 - in
/incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller:
business/datamapper/PersistentObjectHelper.java
business/jpa/JPAPersistenceStrategy.java business/jpa/JPAQueryImpl.java
pojos/CommentData.orm.xml
Author: clr
Date: Tue Jan 9 11:07:42 2007
New Revision: 494526
URL: http://svn.apache.org/viewvc?view=rev&rev=494526
Log:
Added referer and userAgent fields to CommentData persistence metadata; added new class PersistenceHelper; changed query to avoid flushing
Added:
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/PersistentObjectHelper.java
Modified:
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/jpa/JPAPersistenceStrategy.java
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/jpa/JPAQueryImpl.java
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/CommentData.orm.xml
Added: incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/PersistentObjectHelper.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/PersistentObjectHelper.java?view=auto&rev=494526
==============================================================================
--- incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/PersistentObjectHelper.java (added)
+++ incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/PersistentObjectHelper.java Tue Jan 9 11:07:42 2007
@@ -0,0 +1,42 @@
+/*
+ * 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.roller.business.datamapper;
+
+import org.apache.roller.pojos.PersistentObject;
+
+/**
+ * @author Mitesh Meswani
+ */
+public class PersistentObjectHelper {
+
+ /**
+ * Returns whether given object is already persistent. An object is
+ * persistent if and only if its id field is intialized.
+ * Ideally, all callers of this method should be modified so that a call
+ * to this method is not needed. This requires that Roller code is
+ * changed to distinguish between new, managed, and detached objects.
+ * @param obj
+ * @return true if object is already persistent; false otherwise
+ * @see org.apache.roller.business.jpa.JPAPersistenceStrategy#store(org.apache.roller.pojos.PersistentObject)
+ * for a description of changes needed
+ */
+ public static boolean isObjectPersistent(PersistentObject obj) {
+ return !( obj.getId() == null || obj.getId().trim().equals("") );
+ }
+}
Modified: incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/jpa/JPAPersistenceStrategy.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/jpa/JPAPersistenceStrategy.java?view=diff&rev=494526&r1=494525&r2=494526
==============================================================================
--- incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/jpa/JPAPersistenceStrategy.java (original)
+++ incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/jpa/JPAPersistenceStrategy.java Tue Jan 9 11:07:42 2007
@@ -34,6 +34,7 @@
import org.apache.roller.business.datamapper.DatamapperPersistenceStrategy;
import org.apache.roller.business.datamapper.DatamapperQuery;
import org.apache.roller.business.datamapper.DatamapperRemoveQuery;
+import org.apache.roller.business.datamapper.PersistentObjectHelper;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityManager;
@@ -113,7 +114,7 @@
EntityManager em = getEntityManager(true);
// Roller code calls store even on already managed entity
// Till Roller code is fixed, we will need to have following
- if ( obj.getId() == null || obj.getId().trim().equals("") ) {
+ if (!PersistentObjectHelper.isObjectPersistent(obj)) {
// Object has never been written to database, so save it.
// This makes obj into a persistent instance.
em.persist(obj);
Modified: incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/jpa/JPAQueryImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/jpa/JPAQueryImpl.java?view=diff&rev=494526&r1=494525&r2=494526
==============================================================================
--- incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/jpa/JPAQueryImpl.java (original)
+++ incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/jpa/JPAQueryImpl.java Tue Jan 9 11:07:42 2007
@@ -22,6 +22,7 @@
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.persistence.NoResultException;
+import javax.persistence.FlushModeType;
import org.apache.roller.business.datamapper.DatamapperQuery;
@@ -93,6 +94,8 @@
*/
private Object executeQuery() {
Object result = null;
+ //Never flush for queries. Roller code assumes this behavior
+ q.setFlushMode(FlushModeType.COMMIT);
if (singleResult) {
try {
result = q.getSingleResult();
Modified: incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/CommentData.orm.xml
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/CommentData.orm.xml?view=diff&rev=494526&r1=494525&r2=494526
==============================================================================
--- incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/CommentData.orm.xml (original)
+++ incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/CommentData.orm.xml Tue Jan 9 11:07:42 2007
@@ -115,6 +115,12 @@
<basic name="remoteHost">
<column name="remotehost" insertable="true" updatable="true" unique="false"/>
</basic>
+ <basic name="referrer">
+ <column name="referrer" insertable="true" updatable="true" unique="false"/>
+ </basic>
+ <basic name="userAgent">
+ <column name="useragent" insertable="true" updatable="true" unique="false"/>
+ </basic>
<many-to-one name="weblogEntry" target-entity="org.apache.roller.pojos.WeblogEntryData">
<join-column name="entryid" insertable="true" updatable="true" nullable="false"/>
</many-to-one>