use of org.eclipse.persistence.testing.models.jpa.extensibility.Employee in project eclipselink by eclipse-ee4j.
the class ExtensibilityTests method testSimpleRefresh.
public void testSimpleRefresh() {
EntityManagerFactory emf = getEntityManagerFactory();
EntityManager em = emf.createEntityManager();
WeakReference<EntityManagerFactoryDelegate> emfRef = new WeakReference<EntityManagerFactoryDelegate>(JpaHelper.getEntityManagerFactory(em).unwrap());
ServerSession session = (ServerSession) getDatabaseSession();
RelationalDescriptor addDescriptor = (RelationalDescriptor) session.getProject().getDescriptor(Address.class);
assertTrue(addDescriptor.getMappingForAttributeName("pobox") != null);
RelationalDescriptor empDescriptor = (RelationalDescriptor) session.getProject().getDescriptor(Employee.class);
assertTrue(empDescriptor.getMappingForAttributeName("phoneNumbers") != null);
session = null;
Map properties = new HashMap();
properties.put(PersistenceUnitProperties.METADATA_SOURCE_XML_FILE, "extension2.xml");
JpaHelper.getEntityManagerFactory(em).refreshMetadata(properties);
session = (ServerSession) getDatabaseSession();
addDescriptor = (RelationalDescriptor) session.getProject().getDescriptor(Address.class);
assertTrue(addDescriptor.getMappingForAttributeName("pobox") == null);
assertTrue(addDescriptor.getMappingForAttributeName("appartmentNumber") != null);
empDescriptor = (RelationalDescriptor) session.getProject().getDescriptor(Employee.class);
assertTrue(empDescriptor.getMappingForAttributeName("phoneNumbers") == null);
persistEmployeeData(emf);
em = emf.createEntityManager();
try {
beginTransaction(em);
Employee emp = (Employee) em.createQuery("select e from ExtensibilityEmployee e where e.firstName = 'Joe'").getSingleResult();
emp.getAddress().set("appartmentNumber", "111");
commitTransaction(em);
em.clear();
clearCache();
emp = em.find(Employee.class, emp.getId());
assertTrue(emp.getAddress().get("appartmentNumber").equals("111"));
} finally {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
em.close();
deleteEmployeeData(emf);
}
System.gc();
assertTrue(emfRef.get() == null);
}
use of org.eclipse.persistence.testing.models.jpa.extensibility.Employee in project eclipselink by eclipse-ee4j.
the class ExtensibilityTests method testUntriggerVHOnDetached.
public void testUntriggerVHOnDetached() {
EntityManagerFactory emf = getEntityManagerFactory();
persistEmployeeData(emf);
EntityManager em = emf.createEntityManager();
Employee emp = (Employee) em.createQuery("select e from ExtensibilityEmployee e where e.firstName = 'Joe'").getSingleResult();
try {
JpaHelper.getEntityManagerFactory(em).refreshMetadata(null);
assertTrue(emp.getAddress().getCity().equals("Herestowm"));
em.close();
em = null;
emp = null;
} finally {
if (em != null && em.isOpen()) {
em.close();
}
deleteEmployeeData(emf);
}
}
use of org.eclipse.persistence.testing.models.jpa.extensibility.Employee in project eclipselink by eclipse-ee4j.
the class ExtensibilityTests method testMergeRefreshed.
public void testMergeRefreshed() {
EntityManagerFactory emf = getEntityManagerFactory();
persistEmployeeData(emf);
EntityManager em = emf.createEntityManager();
try {
beginTransaction(em);
Employee emp = (Employee) em.createQuery("select e from ExtensibilityEmployee e where e.firstName = 'Joe'").getSingleResult();
Address add = emp.getAddress();
emp.getAddress().set("appartmentNumber", "112");
commitTransaction(em);
Map properties = new HashMap();
properties.put(PersistenceUnitProperties.METADATA_SOURCE_XML_FILE, "extension.xml");
JpaHelper.getEntityManagerFactory(em).refreshMetadata(properties);
em.close();
em = emf.createEntityManager();
beginTransaction(em);
add = em.merge(add);
add.set("pobox", "111");
commitTransaction(em);
em.refresh(add);
assertTrue(add.get("pobox").equals("111"));
assertTrue(add.get("appartmentNumber") == null);
} finally {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
em.close();
deleteEmployeeData(emf);
}
}
use of org.eclipse.persistence.testing.models.jpa.extensibility.Employee in project eclipselink by eclipse-ee4j.
the class ExtensibilityTests method testMergeRefreshedManyToMany.
public void testMergeRefreshedManyToMany() {
EntityManagerFactory emf = getEntityManagerFactory();
persistEmployeeData(emf);
EntityManager em = emf.createEntityManager();
Employee emp = null;
PhoneNumber pn = null;
try {
beginTransaction(em);
emp = (Employee) em.createQuery("select e from ExtensibilityEmployee e where e.firstName = 'Joe'").getSingleResult();
pn = new PhoneNumber();
pn.setAreaCode("613");
pn.setNumber("1111111");
em.persist(pn);
List numbers = new ArrayList();
numbers.add(pn);
emp.putExt("phoneNumbers", numbers);
commitTransaction(em);
Map properties = new HashMap();
properties.put(PersistenceUnitProperties.METADATA_SOURCE_XML_FILE, "extension2.xml");
JpaHelper.getEntityManagerFactory(em).refreshMetadata(properties);
em.close();
em = emf.createEntityManager();
emp = em.merge(emp);
assertNull(emp.getExt("phoneNumbers"));
} finally {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
em.close();
deleteEmployeeData(emf);
}
}
use of org.eclipse.persistence.testing.models.jpa.extensibility.Employee in project eclipselink by eclipse-ee4j.
the class ExtensibilityTests method testBasicMapping.
public void testBasicMapping() {
Map props = new HashMap();
props.put(PersistenceUnitProperties.SESSION_NAME, "bla1");
EntityManagerFactory emf = getEntityManagerFactory();
persistEmployeeData(emf);
EntityManager em = emf.createEntityManager();
try {
beginTransaction(em);
Employee emp = (Employee) em.createQuery("select e from ExtensibilityEmployee e where e.firstName = 'Joe'").getSingleResult();
Address add = emp.getAddress();
add.set("pobox", "111");
commitTransaction(em);
em.refresh(emp);
assertTrue("The pobox was not properly saved", emp.getAddress().get("pobox").equals("111"));
em.clear();
clearCache();
add = (Address) em.createQuery("select a from ExtensibilityAddress a where a.pobox = '111'").getSingleResult();
assertTrue("queries on extended Basic mappings fail", add != null);
assertTrue("queries on extended Basic mappings return incorrect results.", add.get("pobox").equals("111"));
} finally {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
em.close();
deleteEmployeeData(emf);
}
}
Aggregations