OPENJPA-1604: Backing out the two previous commits while investigating a couple test failures.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@930957 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Richard G. Curtis 2010-04-05 20:48:54 +00:00
parent b382e52bbd
commit 59cdb21326
8 changed files with 12 additions and 130 deletions

View File

@ -58,8 +58,7 @@ public class QueryMetaData
private String _resultSetMappingName; private String _resultSetMappingName;
private int _lineNum; private int _lineNum;
private int _colNum; private int _colNum;
private int _lockMode;
/** /**
* Construct with the given name. * Construct with the given name.
*/ */
@ -157,14 +156,6 @@ public class QueryMetaData
public void setQueryString(String query) { public void setQueryString(String query) {
_query = query; _query = query;
} }
public void setLockMode(int mode) {
_lockMode = mode;
}
public int getLockMode() {
return _lockMode;
}
/** /**
* Query hints. * Query hints.
@ -218,7 +209,6 @@ public class QueryMetaData
query.setReadOnly(_readOnly.booleanValue()); query.setReadOnly(_readOnly.booleanValue());
if (_resultSetMappingName != null) if (_resultSetMappingName != null)
query.setResultMapping(null, _resultSetMappingName); query.setResultMapping(null, _resultSetMappingName);
query.getFetchConfiguration().setReadLockLevel(_lockMode);
} }
/** /**

View File

@ -25,22 +25,13 @@ import java.io.ObjectOutput;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.LockModeType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
import javax.persistence.Version; import javax.persistence.Version;
@NamedQuery(
@NamedQueries({ name="findEmployeeById"
@NamedQuery(name="findEmployeeById", , query="SELECT c FROM LockEmployee c WHERE c.id = :id"
query="SELECT c FROM LockEmployee c WHERE c.id = :id"), )
@NamedQuery(name="findEmployeeByIdWithLock",
query="SELECT c FROM LockEmployee c WHERE c.id = :id",
lockMode=LockModeType.PESSIMISTIC_READ),
@NamedQuery(name="findEmployeeByIdWithNoLock",
query="SELECT c FROM LockEmployee c WHERE c.id = :id",
lockMode=LockModeType.NONE)
})
@Entity @Entity
public class LockEmployee implements Externalizable { public class LockEmployee implements Externalizable {

View File

@ -1,88 +0,0 @@
/*
* 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.openjpa.persistence.lockmgr;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.persistence.TransactionRequiredException;
import org.apache.openjpa.persistence.test.SQLListenerTestCase;
/**
* Tests the lock mode on named query emits a FOR UPDATE clause in target SQL query.
*
* @author Pinaki Poddar
*
*/
public class TestNamedQueryLockMode extends SQLListenerTestCase {
public void setUp() {
super.setUp(CLEAR_TABLES, LockEmployee.class,
"openjpa.LockManager", "pessimistic",
"openjpa.Optimistic", "false");
}
public void testForUpdateClausePresentInNamedQueryWithLockMode() {
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
assertClausePresentInSQL("FOR UPDATE",
em.createNamedQuery("findEmployeeByIdWithLock").setParameter("id", 0));
em.getTransaction().rollback();
}
public void testNamedQueryWithLockModeMustExecuteInTransaction() {
EntityManager em = emf.createEntityManager();
// execute without a transaction
try {
em.createNamedQuery("findEmployeeByIdWithLock").setParameter("id", 0).getResultList();
fail("Expected " + TransactionRequiredException.class.getName());
} catch (TransactionRequiredException e) {
// Expected
}
}
public void testForUpdateClauseAbsentInQueryWithDefault() {
EntityManager em = emf.createEntityManager();
assertClauseAbsentInSQL("FOR UPDATE",
em.createNamedQuery("findEmployeeById").setParameter("id", 0));
}
public void testForUpdateClauseAbsentInQueryWithExplictNoLock() {
EntityManager em = emf.createEntityManager();
assertClauseAbsentInSQL("FOR UPDATE",
em.createNamedQuery("findEmployeeByIdWithNoLock").setParameter("id", 0));
}
String getLastSQL() {
String last = sql.get(getSQLCount()-1);
assertNotNull("No last sql found", last);
return last;
}
void assertClausePresentInSQL(String clause, Query q) {
q.getResultList();
String last = getLastSQL();
assertTrue(clause + " is not present in " + last, last.toUpperCase().indexOf(clause) != -1);
}
void assertClauseAbsentInSQL(String clause, Query q) {
q.getResultList();
String last = getLastSQL();
assertTrue(clause + " is not absent in " + last, last.toUpperCase().indexOf(clause) == -1);
}
}

View File

@ -94,7 +94,6 @@ import org.apache.openjpa.event.BeanLifecycleCallbacks;
import org.apache.openjpa.event.LifecycleCallbacks; import org.apache.openjpa.event.LifecycleCallbacks;
import org.apache.openjpa.event.LifecycleEvent; import org.apache.openjpa.event.LifecycleEvent;
import org.apache.openjpa.event.MethodLifecycleCallbacks; import org.apache.openjpa.event.MethodLifecycleCallbacks;
import org.apache.openjpa.kernel.LockLevels;
import org.apache.openjpa.kernel.QueryLanguages; import org.apache.openjpa.kernel.QueryLanguages;
import org.apache.openjpa.kernel.jpql.JPQLParser; import org.apache.openjpa.kernel.jpql.JPQLParser;
import org.apache.openjpa.lib.conf.Configurations; import org.apache.openjpa.lib.conf.Configurations;
@ -1776,10 +1775,11 @@ public class AnnotationPersistenceMetaDataParser
meta = getRepository().addQueryMetaData(_cls, query.name()); meta = getRepository().addQueryMetaData(_cls, query.name());
meta.setQueryString(query.query()); meta.setQueryString(query.query());
meta.setLanguage(JPQLParser.LANG_JPQL); meta.setLanguage(JPQLParser.LANG_JPQL);
meta.setLockMode(MixedLockLevelsHelper.toLockLevel(query.lockMode()));
for (QueryHint hint : query.hints()) for (QueryHint hint : query.hints())
meta.addHint(hint.name(), hint.value()); meta.addHint(hint.name(), hint.value());
if (query.lockMode() != null) {
meta.addHint("openjpa.FetchPlan.ReadLockMode", query.lockMode());
}
meta.setSource(getSourceFile(), (el instanceof Class) ? el : null, meta.setSource(getSourceFile(), (el instanceof Class) ? el : null,
SourceTracker.SRC_ANNOTATIONS); SourceTracker.SRC_ANNOTATIONS);
if (isMetaDataMode()) if (isMetaDataMode())

View File

@ -85,7 +85,6 @@ import org.apache.openjpa.persistence.validation.ValidationUtils;
import org.apache.openjpa.util.ExceptionInfo; import org.apache.openjpa.util.ExceptionInfo;
import org.apache.openjpa.util.Exceptions; import org.apache.openjpa.util.Exceptions;
import org.apache.openjpa.util.ImplHelper; import org.apache.openjpa.util.ImplHelper;
import org.apache.openjpa.util.NoTransactionException;
import org.apache.openjpa.util.RuntimeExceptionTranslator; import org.apache.openjpa.util.RuntimeExceptionTranslator;
import org.apache.openjpa.util.UserException; import org.apache.openjpa.util.UserException;
@ -1024,13 +1023,7 @@ public class EntityManagerImpl
if (pq != null) { if (pq != null) {
pq.setInto(del); pq.setInto(del);
} else { } else {
try { meta.setInto(del);
meta.setInto(del);
} catch (NoTransactionException e) {
throw new TransactionRequiredException(_loc.get("named-query-no-txn", name,
meta.getDefiningType(), MixedLockLevelsHelper.fromLockLevel(meta.getLockMode())),
new Throwable[]{e}, name, false);
}
del.compile(); del.compile();
} }

View File

@ -50,7 +50,6 @@ import org.apache.openjpa.kernel.DelegatingQuery;
import org.apache.openjpa.kernel.DelegatingResultList; import org.apache.openjpa.kernel.DelegatingResultList;
import org.apache.openjpa.kernel.FetchConfiguration; import org.apache.openjpa.kernel.FetchConfiguration;
import org.apache.openjpa.kernel.Filters; import org.apache.openjpa.kernel.Filters;
import org.apache.openjpa.kernel.LockLevels;
import org.apache.openjpa.kernel.PreparedQuery; import org.apache.openjpa.kernel.PreparedQuery;
import org.apache.openjpa.kernel.PreparedQueryCache; import org.apache.openjpa.kernel.PreparedQueryCache;
import org.apache.openjpa.kernel.QueryLanguages; import org.apache.openjpa.kernel.QueryLanguages;
@ -509,7 +508,7 @@ public class QueryImpl<X> implements OpenJPAQuerySPI<X>, Serializable {
return false; return false;
} }
FetchConfiguration fetch = _query.getFetchConfiguration(); FetchConfiguration fetch = _query.getFetchConfiguration();
if (fetch.getReadLockLevel() != LockLevels.LOCK_NONE) if (fetch.getReadLockLevel() != 0)
return false; return false;
Boolean registered = cache.register(_id, _query, fetch); Boolean registered = cache.register(_id, _query, fetch);
boolean alreadyCached = (registered == null); boolean alreadyCached = (registered == null);

View File

@ -1674,7 +1674,7 @@ public class XMLPersistenceMetaDataParser
meta.setLanguage(JPQLParser.LANG_JPQL); meta.setLanguage(JPQLParser.LANG_JPQL);
String lockModeStr = attrs.getValue("lock-mode"); String lockModeStr = attrs.getValue("lock-mode");
if (lockModeStr != null) { if (lockModeStr != null) {
meta.setLockMode(MixedLockLevelsHelper.toLockLevel(LockModeType.valueOf(lockModeStr))); meta.addHint("openjpa.FetchPlan.ReadLockMode", LockModeType.valueOf(lockModeStr));
} }
Locator locator = getLocation().getLocator(); Locator locator = getLocation().getLocator();
if (locator != null) { if (locator != null) {

View File

@ -229,7 +229,4 @@ create-emf-depend-error: Failed to create a provider for "{0}" because a \
invalid-version-attribute: Persistence version attribute value "{0}" is not valid. Using version "{1}" by default. invalid-version-attribute: Persistence version attribute value "{0}" is not valid. Using version "{1}" by default.
not-jpql-or-criteria-query: Query is neither a JPQL SELECT nor a Criteria API query. not-jpql-or-criteria-query: Query is neither a JPQL SELECT nor a Criteria API query.
cache-retrieve-override: The setting of CacheRetrieveMode.USE is ignored and set to BYPASS for refresh operation. cache-retrieve-override: The setting of CacheRetrieveMode.USE is ignored and set to BYPASS for refresh operation.
null-detach: Can not detach null entity null-detach: Can not detach null entity
named-query-no-txn: Named query "{0}" declared in "{1}" specifies "{2}" lock mode and hence must be \
created and executed within an active transaction.