7 changed files with 413 additions and 325 deletions
@ -1,146 +1,146 @@
@@ -1,146 +1,146 @@
|
||||
/* |
||||
* Copyright 2009 SpringSource Inc. |
||||
* |
||||
* 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 org.springframework.mock.staticmock; |
||||
|
||||
import javax.persistence.PersistenceException; |
||||
|
||||
import junit.framework.Assert; |
||||
|
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
import org.junit.runners.JUnit4; |
||||
|
||||
import static org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl.*; |
||||
|
||||
|
||||
/** |
||||
* Test for static entity mocking framework. |
||||
* @author Rod Johnson |
||||
* @author Ramnivas Laddad |
||||
* |
||||
*/ |
||||
@MockStaticEntityMethods |
||||
@RunWith(JUnit4.class) |
||||
public class AnnotationDrivenStaticEntityMockingControlTest { |
||||
|
||||
@Test |
||||
public void testNoArgIntReturn() { |
||||
int expectedCount = 13; |
||||
Person.countPeople(); |
||||
expectReturn(expectedCount); |
||||
playback(); |
||||
Assert.assertEquals(expectedCount, Person.countPeople()); |
||||
} |
||||
|
||||
@Test(expected=PersistenceException.class) |
||||
public void testNoArgThrows() { |
||||
Person.countPeople(); |
||||
expectThrow(new PersistenceException()); |
||||
playback(); |
||||
Person.countPeople(); |
||||
} |
||||
|
||||
@Test |
||||
public void testArgMethodMatches() { |
||||
long id = 13; |
||||
Person found = new Person(); |
||||
Person.findPerson(id); |
||||
expectReturn(found); |
||||
playback(); |
||||
Assert.assertEquals(found, Person.findPerson(id)); |
||||
} |
||||
|
||||
|
||||
@Test |
||||
public void testLongSeriesOfCalls() { |
||||
long id1 = 13; |
||||
long id2 = 24; |
||||
Person found1 = new Person(); |
||||
Person.findPerson(id1); |
||||
expectReturn(found1); |
||||
Person found2 = new Person(); |
||||
Person.findPerson(id2); |
||||
expectReturn(found2); |
||||
Person.findPerson(id1); |
||||
expectReturn(found1); |
||||
Person.countPeople(); |
||||
expectReturn(0); |
||||
playback(); |
||||
|
||||
Assert.assertEquals(found1, Person.findPerson(id1)); |
||||
Assert.assertEquals(found2, Person.findPerson(id2)); |
||||
Assert.assertEquals(found1, Person.findPerson(id1)); |
||||
Assert.assertEquals(0, Person.countPeople()); |
||||
} |
||||
|
||||
// Note delegation is used when tests are invalid and should fail, as otherwise
|
||||
// the failure will occur on the verify() method in the aspect after
|
||||
// this method returns, failing the test case
|
||||
@Test |
||||
public void testArgMethodNoMatchExpectReturn() { |
||||
try { |
||||
new Delegate().testArgMethodNoMatchExpectReturn(); |
||||
Assert.fail(); |
||||
} catch (IllegalArgumentException expected) { |
||||
} |
||||
} |
||||
|
||||
@Test(expected=IllegalArgumentException.class) |
||||
public void testArgMethodNoMatchExpectThrow() { |
||||
new Delegate().testArgMethodNoMatchExpectThrow(); |
||||
} |
||||
|
||||
private void called(Person found, long id) { |
||||
Assert.assertEquals(found, Person.findPerson(id)); |
||||
} |
||||
|
||||
@Test |
||||
public void testReentrant() { |
||||
long id = 13; |
||||
Person found = new Person(); |
||||
Person.findPerson(id); |
||||
expectReturn(found); |
||||
playback(); |
||||
called(found, id); |
||||
} |
||||
|
||||
@Test(expected=IllegalStateException.class) |
||||
public void testRejectUnexpectedCall() { |
||||
new Delegate().rejectUnexpectedCall(); |
||||
} |
||||
|
||||
@Test(expected=IllegalStateException.class) |
||||
public void testFailTooFewCalls() { |
||||
new Delegate().failTooFewCalls(); |
||||
} |
||||
|
||||
@Test |
||||
public void testEmpty() { |
||||
// Test that verification check doesn't blow up if no replay() call happened
|
||||
} |
||||
|
||||
@Test(expected=IllegalStateException.class) |
||||
public void testDoesntEverReplay() { |
||||
new Delegate().doesntEverReplay(); |
||||
} |
||||
|
||||
@Test(expected=IllegalStateException.class) |
||||
public void testDoesntEverSetReturn() { |
||||
new Delegate().doesntEverSetReturn(); |
||||
} |
||||
} |
||||
|
||||
/* |
||||
* Copyright 2002-2010 the original author or authors. |
||||
* |
||||
* 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 org.springframework.mock.staticmock; |
||||
|
||||
import javax.persistence.PersistenceException; |
||||
|
||||
import junit.framework.Assert; |
||||
|
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
import org.junit.runners.JUnit4; |
||||
|
||||
import static org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl.*; |
||||
|
||||
|
||||
/** |
||||
* Test for static entity mocking framework. |
||||
* @author Rod Johnson |
||||
* @author Ramnivas Laddad |
||||
* |
||||
*/ |
||||
@MockStaticEntityMethods |
||||
@RunWith(JUnit4.class) |
||||
public class AnnotationDrivenStaticEntityMockingControlTest { |
||||
|
||||
@Test |
||||
public void testNoArgIntReturn() { |
||||
int expectedCount = 13; |
||||
Person.countPeople(); |
||||
expectReturn(expectedCount); |
||||
playback(); |
||||
Assert.assertEquals(expectedCount, Person.countPeople()); |
||||
} |
||||
|
||||
@Test(expected=PersistenceException.class) |
||||
public void testNoArgThrows() { |
||||
Person.countPeople(); |
||||
expectThrow(new PersistenceException()); |
||||
playback(); |
||||
Person.countPeople(); |
||||
} |
||||
|
||||
@Test |
||||
public void testArgMethodMatches() { |
||||
long id = 13; |
||||
Person found = new Person(); |
||||
Person.findPerson(id); |
||||
expectReturn(found); |
||||
playback(); |
||||
Assert.assertEquals(found, Person.findPerson(id)); |
||||
} |
||||
|
||||
|
||||
@Test |
||||
public void testLongSeriesOfCalls() { |
||||
long id1 = 13; |
||||
long id2 = 24; |
||||
Person found1 = new Person(); |
||||
Person.findPerson(id1); |
||||
expectReturn(found1); |
||||
Person found2 = new Person(); |
||||
Person.findPerson(id2); |
||||
expectReturn(found2); |
||||
Person.findPerson(id1); |
||||
expectReturn(found1); |
||||
Person.countPeople(); |
||||
expectReturn(0); |
||||
playback(); |
||||
|
||||
Assert.assertEquals(found1, Person.findPerson(id1)); |
||||
Assert.assertEquals(found2, Person.findPerson(id2)); |
||||
Assert.assertEquals(found1, Person.findPerson(id1)); |
||||
Assert.assertEquals(0, Person.countPeople()); |
||||
} |
||||
|
||||
// Note delegation is used when tests are invalid and should fail, as otherwise
|
||||
// the failure will occur on the verify() method in the aspect after
|
||||
// this method returns, failing the test case
|
||||
@Test |
||||
public void testArgMethodNoMatchExpectReturn() { |
||||
try { |
||||
new Delegate().testArgMethodNoMatchExpectReturn(); |
||||
Assert.fail(); |
||||
} catch (IllegalArgumentException expected) { |
||||
} |
||||
} |
||||
|
||||
@Test(expected=IllegalArgumentException.class) |
||||
public void testArgMethodNoMatchExpectThrow() { |
||||
new Delegate().testArgMethodNoMatchExpectThrow(); |
||||
} |
||||
|
||||
private void called(Person found, long id) { |
||||
Assert.assertEquals(found, Person.findPerson(id)); |
||||
} |
||||
|
||||
@Test |
||||
public void testReentrant() { |
||||
long id = 13; |
||||
Person found = new Person(); |
||||
Person.findPerson(id); |
||||
expectReturn(found); |
||||
playback(); |
||||
called(found, id); |
||||
} |
||||
|
||||
@Test(expected=IllegalStateException.class) |
||||
public void testRejectUnexpectedCall() { |
||||
new Delegate().rejectUnexpectedCall(); |
||||
} |
||||
|
||||
@Test(expected=IllegalStateException.class) |
||||
public void testFailTooFewCalls() { |
||||
new Delegate().failTooFewCalls(); |
||||
} |
||||
|
||||
@Test |
||||
public void testEmpty() { |
||||
// Test that verification check doesn't blow up if no replay() call happened
|
||||
} |
||||
|
||||
@Test(expected=IllegalStateException.class) |
||||
public void testDoesntEverReplay() { |
||||
new Delegate().doesntEverReplay(); |
||||
} |
||||
|
||||
@Test(expected=IllegalStateException.class) |
||||
public void testDoesntEverSetReturn() { |
||||
new Delegate().doesntEverSetReturn(); |
||||
} |
||||
} |
||||
|
||||
|
||||
@ -1,76 +1,92 @@
@@ -1,76 +1,92 @@
|
||||
package org.springframework.mock.staticmock; |
||||
|
||||
import java.rmi.RemoteException; |
||||
|
||||
import javax.persistence.PersistenceException; |
||||
|
||||
import junit.framework.Assert; |
||||
|
||||
import org.junit.Ignore; |
||||
import org.junit.Test; |
||||
import org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl; |
||||
import org.springframework.mock.staticmock.MockStaticEntityMethods; |
||||
|
||||
//Used because verification failures occur after method returns,
|
||||
//so we can't test for them in the test case itself
|
||||
@MockStaticEntityMethods |
||||
@Ignore // This isn't meant for direct testing; rather it is driven from AnnotationDrivenStaticEntityMockingControl
|
||||
public class Delegate { |
||||
|
||||
@Test |
||||
public void testArgMethodNoMatchExpectReturn() { |
||||
long id = 13; |
||||
Person found = new Person(); |
||||
Person.findPerson(id); |
||||
AnnotationDrivenStaticEntityMockingControl.expectReturn(found); |
||||
AnnotationDrivenStaticEntityMockingControl.playback(); |
||||
Assert.assertEquals(found, Person.findPerson(id + 1)); |
||||
} |
||||
|
||||
@Test |
||||
public void testArgMethodNoMatchExpectThrow() { |
||||
long id = 13; |
||||
Person found = new Person(); |
||||
Person.findPerson(id); |
||||
AnnotationDrivenStaticEntityMockingControl.expectThrow(new PersistenceException()); |
||||
AnnotationDrivenStaticEntityMockingControl.playback(); |
||||
Assert.assertEquals(found, Person.findPerson(id + 1)); |
||||
} |
||||
|
||||
@Test |
||||
public void failTooFewCalls() { |
||||
long id = 13; |
||||
Person found = new Person(); |
||||
Person.findPerson(id); |
||||
AnnotationDrivenStaticEntityMockingControl.expectReturn(found); |
||||
Person.countPeople(); |
||||
AnnotationDrivenStaticEntityMockingControl.expectReturn(25); |
||||
AnnotationDrivenStaticEntityMockingControl.playback(); |
||||
Assert.assertEquals(found, Person.findPerson(id)); |
||||
} |
||||
|
||||
@Test |
||||
public void doesntEverReplay() { |
||||
Person.countPeople(); |
||||
} |
||||
|
||||
@Test |
||||
public void doesntEverSetReturn() { |
||||
Person.countPeople(); |
||||
AnnotationDrivenStaticEntityMockingControl.playback(); |
||||
} |
||||
|
||||
@Test |
||||
public void rejectUnexpectedCall() { |
||||
AnnotationDrivenStaticEntityMockingControl.playback(); |
||||
Person.countPeople(); |
||||
} |
||||
|
||||
@Test(expected=RemoteException.class) |
||||
public void testVerificationFailsEvenWhenTestFailsInExpectedManner() throws RemoteException { |
||||
Person.countPeople(); |
||||
AnnotationDrivenStaticEntityMockingControl.playback(); |
||||
// No calls to allow verification failure
|
||||
throw new RemoteException(); |
||||
} |
||||
} |
||||
/* |
||||
* Copyright 2002-2010 the original author or authors. |
||||
* |
||||
* 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 org.springframework.mock.staticmock; |
||||
|
||||
import java.rmi.RemoteException; |
||||
|
||||
import javax.persistence.PersistenceException; |
||||
|
||||
import junit.framework.Assert; |
||||
|
||||
import org.junit.Ignore; |
||||
import org.junit.Test; |
||||
import org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl; |
||||
import org.springframework.mock.staticmock.MockStaticEntityMethods; |
||||
|
||||
//Used because verification failures occur after method returns,
|
||||
//so we can't test for them in the test case itself
|
||||
@MockStaticEntityMethods |
||||
@Ignore // This isn't meant for direct testing; rather it is driven from AnnotationDrivenStaticEntityMockingControl
|
||||
public class Delegate { |
||||
|
||||
@Test |
||||
public void testArgMethodNoMatchExpectReturn() { |
||||
long id = 13; |
||||
Person found = new Person(); |
||||
Person.findPerson(id); |
||||
AnnotationDrivenStaticEntityMockingControl.expectReturn(found); |
||||
AnnotationDrivenStaticEntityMockingControl.playback(); |
||||
Assert.assertEquals(found, Person.findPerson(id + 1)); |
||||
} |
||||
|
||||
@Test |
||||
public void testArgMethodNoMatchExpectThrow() { |
||||
long id = 13; |
||||
Person found = new Person(); |
||||
Person.findPerson(id); |
||||
AnnotationDrivenStaticEntityMockingControl.expectThrow(new PersistenceException()); |
||||
AnnotationDrivenStaticEntityMockingControl.playback(); |
||||
Assert.assertEquals(found, Person.findPerson(id + 1)); |
||||
} |
||||
|
||||
@Test |
||||
public void failTooFewCalls() { |
||||
long id = 13; |
||||
Person found = new Person(); |
||||
Person.findPerson(id); |
||||
AnnotationDrivenStaticEntityMockingControl.expectReturn(found); |
||||
Person.countPeople(); |
||||
AnnotationDrivenStaticEntityMockingControl.expectReturn(25); |
||||
AnnotationDrivenStaticEntityMockingControl.playback(); |
||||
Assert.assertEquals(found, Person.findPerson(id)); |
||||
} |
||||
|
||||
@Test |
||||
public void doesntEverReplay() { |
||||
Person.countPeople(); |
||||
} |
||||
|
||||
@Test |
||||
public void doesntEverSetReturn() { |
||||
Person.countPeople(); |
||||
AnnotationDrivenStaticEntityMockingControl.playback(); |
||||
} |
||||
|
||||
@Test |
||||
public void rejectUnexpectedCall() { |
||||
AnnotationDrivenStaticEntityMockingControl.playback(); |
||||
Person.countPeople(); |
||||
} |
||||
|
||||
@Test(expected=RemoteException.class) |
||||
public void testVerificationFailsEvenWhenTestFailsInExpectedManner() throws RemoteException { |
||||
Person.countPeople(); |
||||
AnnotationDrivenStaticEntityMockingControl.playback(); |
||||
// No calls to allow verification failure
|
||||
throw new RemoteException(); |
||||
} |
||||
} |
||||
|
||||
@ -1,8 +1,24 @@
@@ -1,8 +1,24 @@
|
||||
package org.springframework.mock.staticmock; |
||||
|
||||
import javax.persistence.Entity; |
||||
|
||||
@Entity |
||||
public class Person { |
||||
} |
||||
|
||||
/* |
||||
* Copyright 2002-2010 the original author or authors. |
||||
* |
||||
* 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 org.springframework.mock.staticmock; |
||||
|
||||
import javax.persistence.Entity; |
||||
|
||||
@Entity |
||||
public class Person { |
||||
} |
||||
|
||||
|
||||
@ -1,84 +1,100 @@
@@ -1,84 +1,100 @@
|
||||
package org.springframework.mock.staticmock; |
||||
|
||||
privileged aspect Person_Roo_Entity { |
||||
|
||||
@javax.persistence.PersistenceContext |
||||
transient javax.persistence.EntityManager Person.entityManager; |
||||
|
||||
@javax.persistence.Id |
||||
@javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.AUTO) |
||||
@javax.persistence.Column(name = "id") |
||||
private java.lang.Long Person.id; |
||||
|
||||
@javax.persistence.Version |
||||
@javax.persistence.Column(name = "version") |
||||
private java.lang.Integer Person.version; |
||||
|
||||
public java.lang.Long Person.getId() { |
||||
return this.id; |
||||
} |
||||
|
||||
public void Person.setId(java.lang.Long id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public java.lang.Integer Person.getVersion() { |
||||
return this.version; |
||||
} |
||||
|
||||
public void Person.setVersion(java.lang.Integer version) { |
||||
this.version = version; |
||||
} |
||||
|
||||
@org.springframework.transaction.annotation.Transactional |
||||
public void Person.persist() { |
||||
if (this.entityManager == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)"); |
||||
this.entityManager.persist(this); |
||||
} |
||||
|
||||
@org.springframework.transaction.annotation.Transactional |
||||
public void Person.remove() { |
||||
if (this.entityManager == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)"); |
||||
this.entityManager.remove(this); |
||||
} |
||||
|
||||
@org.springframework.transaction.annotation.Transactional |
||||
public void Person.flush() { |
||||
if (this.entityManager == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)"); |
||||
this.entityManager.flush(); |
||||
} |
||||
|
||||
@org.springframework.transaction.annotation.Transactional |
||||
public void Person.merge() { |
||||
if (this.entityManager == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)"); |
||||
Person merged = this.entityManager.merge(this); |
||||
this.entityManager.flush(); |
||||
this.id = merged.getId(); |
||||
} |
||||
|
||||
public static long Person.countPeople() { |
||||
javax.persistence.EntityManager em = new Person().entityManager; |
||||
if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)"); |
||||
return (Long) em.createQuery("select count(o) from Person o").getSingleResult(); |
||||
} |
||||
|
||||
public static java.util.List<Person> Person.findAllPeople() { |
||||
javax.persistence.EntityManager em = new Person().entityManager; |
||||
if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)"); |
||||
return em.createQuery("select o from Person o").getResultList(); |
||||
} |
||||
|
||||
public static Person Person.findPerson(java.lang.Long id) { |
||||
if (id == null) throw new IllegalArgumentException("An identifier is required to retrieve an instance of Person"); |
||||
javax.persistence.EntityManager em = new Person().entityManager; |
||||
if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)"); |
||||
return em.find(Person.class, id); |
||||
} |
||||
|
||||
public static java.util.List<Person> Person.findPersonEntries(int firstResult, int maxResults) { |
||||
javax.persistence.EntityManager em = new Person().entityManager; |
||||
if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)"); |
||||
return em.createQuery("select o from Person o").setFirstResult(firstResult).setMaxResults(maxResults).getResultList(); |
||||
} |
||||
|
||||
} |
||||
/* |
||||
* Copyright 2002-2010 the original author or authors. |
||||
* |
||||
* 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 org.springframework.mock.staticmock; |
||||
|
||||
privileged aspect Person_Roo_Entity { |
||||
|
||||
@javax.persistence.PersistenceContext |
||||
transient javax.persistence.EntityManager Person.entityManager; |
||||
|
||||
@javax.persistence.Id |
||||
@javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.AUTO) |
||||
@javax.persistence.Column(name = "id") |
||||
private java.lang.Long Person.id; |
||||
|
||||
@javax.persistence.Version |
||||
@javax.persistence.Column(name = "version") |
||||
private java.lang.Integer Person.version; |
||||
|
||||
public java.lang.Long Person.getId() { |
||||
return this.id; |
||||
} |
||||
|
||||
public void Person.setId(java.lang.Long id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public java.lang.Integer Person.getVersion() { |
||||
return this.version; |
||||
} |
||||
|
||||
public void Person.setVersion(java.lang.Integer version) { |
||||
this.version = version; |
||||
} |
||||
|
||||
@org.springframework.transaction.annotation.Transactional |
||||
public void Person.persist() { |
||||
if (this.entityManager == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)"); |
||||
this.entityManager.persist(this); |
||||
} |
||||
|
||||
@org.springframework.transaction.annotation.Transactional |
||||
public void Person.remove() { |
||||
if (this.entityManager == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)"); |
||||
this.entityManager.remove(this); |
||||
} |
||||
|
||||
@org.springframework.transaction.annotation.Transactional |
||||
public void Person.flush() { |
||||
if (this.entityManager == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)"); |
||||
this.entityManager.flush(); |
||||
} |
||||
|
||||
@org.springframework.transaction.annotation.Transactional |
||||
public void Person.merge() { |
||||
if (this.entityManager == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)"); |
||||
Person merged = this.entityManager.merge(this); |
||||
this.entityManager.flush(); |
||||
this.id = merged.getId(); |
||||
} |
||||
|
||||
public static long Person.countPeople() { |
||||
javax.persistence.EntityManager em = new Person().entityManager; |
||||
if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)"); |
||||
return (Long) em.createQuery("select count(o) from Person o").getSingleResult(); |
||||
} |
||||
|
||||
public static java.util.List<Person> Person.findAllPeople() { |
||||
javax.persistence.EntityManager em = new Person().entityManager; |
||||
if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)"); |
||||
return em.createQuery("select o from Person o").getResultList(); |
||||
} |
||||
|
||||
public static Person Person.findPerson(java.lang.Long id) { |
||||
if (id == null) throw new IllegalArgumentException("An identifier is required to retrieve an instance of Person"); |
||||
javax.persistence.EntityManager em = new Person().entityManager; |
||||
if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)"); |
||||
return em.find(Person.class, id); |
||||
} |
||||
|
||||
public static java.util.List<Person> Person.findPersonEntries(int firstResult, int maxResults) { |
||||
javax.persistence.EntityManager em = new Person().entityManager; |
||||
if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)"); |
||||
return em.createQuery("select o from Person o").setFirstResult(firstResult).setMaxResults(maxResults).getResultList(); |
||||
} |
||||
|
||||
} |
||||
|
||||
Loading…
Reference in new issue