| /******************************************************************************* |
| * Copyright (c) 1998, 2012 Oracle and/or its affiliates. All rights reserved. |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 |
| * which accompanies this distribution. |
| * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
| * and the Eclipse Distribution License is available at |
| * http://www.eclipse.org/org/documents/edl-v10.php. |
| * |
| * Contributors: |
| * Oracle - initial impl |
| ******************************************************************************/ |
| package example; |
| |
| import java.util.List; |
| |
| import javax.persistence.EntityManager; |
| import javax.persistence.EntityManagerFactory; |
| import javax.persistence.Query; |
| |
| import model.Order; |
| |
| /** |
| * Test the performance of reading an Order object model. |
| * @author James Sutherland |
| */ |
| public class QueryTest extends Test { |
| |
| public static void main(String[] args) throws Exception { |
| try { |
| QueryTest test = new QueryTest(); |
| test.setup(); |
| test.test(); |
| } catch (Exception error) { |
| error.printStackTrace(); |
| } |
| System.exit(0); |
| } |
| |
| public void runTest(EntityManagerFactory factory) { |
| EntityManager em = factory.createEntityManager(); |
| Query query = em.createNamedQuery("findOrdersByCustomer"); |
| int index = this.random.nextInt(this.customerIds.length); |
| query.setParameter("customerId", this.customerIds[index]); |
| List<Order> result = query.getResultList(); |
| for (Order order : result) { |
| order.getCustomer().toString(); |
| order.getOrderLines().size(); |
| } |
| em.close(); |
| } |
| } |