Презентация 3. Java Persistence API. 4. Java Persistence Query Language онлайн
На нашем сайте вы можете скачать и просмотреть онлайн доклад-презентацию на тему 3. Java Persistence API. 4. Java Persistence Query Language абсолютно бесплатно. Урок-презентация на эту тему содержит всего 51 слайд. Все материалы созданы в программе PowerPoint и имеют формат ppt или же pptx. Материалы и темы для презентаций взяты из открытых источников и загружены их авторами, за качество и достоверность информации в них администрация сайта не отвечает, все права принадлежат их создателям. Если вы нашли то, что искали, отблагодарите авторов - поделитесь ссылкой в социальных сетях, а наш сайт добавьте в закладки.
Презентации » Устройства и комплектующие » 3. Java Persistence API. 4. Java Persistence Query Language
Оцените!
Оцените презентацию от 1 до 5 баллов!
- Тип файла:ppt / pptx (powerpoint)
- Всего слайдов:51 слайд
- Для класса:1,2,3,4,5,6,7,8,9,10,11
- Размер файла:215.00 kB
- Просмотров:58
- Скачиваний:0
- Автор:неизвестен
Слайды и текст к этой презентации:
№3 слайд
![Queries of A query can be](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img2.jpg)
Содержание слайда: Queries (2 of 2)
A query can be issued at runtime by supplying the JP QL query criteria, or a criteria object. Example:
TypedQuery<Merchant> query = em.createQuery("SELECT m FROM Merchant m", Merchant.class);
List<Merchant> listM = null;
listM = query.getResultList();
. . . . . . . . . . . .
See P341SelectMerchant project for the full text
№5 слайд
![MerchantDaoImpl Class](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img4.jpg)
Содержание слайда: MerchantDaoImpl Class
@Repository
public class MerchantDaoImpl implements MerchantDao{
@PersistenceContext
private EntityManager em;
. . . . . . . . . . . .
public List<Merchant> findAll(){
TypedQuery<Merchant> query =
em.createQuery("SELECT m FROM Merchant m", Merchant.class);
List<Merchant> listM = null;
listM = query.getResultList();
return listM; }}
№7 слайд
![Main Class SuppressWarnings](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img6.jpg)
Содержание слайда: Main Class
@SuppressWarnings("resource")
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
MerchantService merchantService = context.getBean(MerchantService.class);
List<Merchant> list = merchantService.findAll();
for(Merchant m: list)
System.out.println("name = " + m.getName() + " charge = " +m.getCharge());
}
№8 слайд
![Java Persistence Query](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img7.jpg)
Содержание слайда: Java Persistence Query Language
Java Persistence Query Language (JP QL) is a database-independent query language that operates on the logical entity model as opposed to the physical data model
Queries may also be expressed in SQL to take advantage of the underlying database
The key difference between SQL and JP QL is that instead of selecting from a table, an entity from the application domain model has been specified instead
№12 слайд
![PaymentDaoImpl Class](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img11.jpg)
Содержание слайда: PaymentDaoImpl Class
@Repository
public class PaymentDaoImpl implements PaymentDao{
@PersistenceContext
private EntityManager em;
public List<Payment> findByMerchantId(int id){
TypedQuery<Payment> query = em.createQuery("SELECT p FROM Payment p WHERE p.merchantId = " + id, Payment.class);
return query.getResultList();
}
}
№14 слайд
![Main Class SuppressWarnings](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img13.jpg)
Содержание слайда: Main Class
@SuppressWarnings("resource")
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
PaymentService paymentService = context.getBean(PaymentService.class);
List<Payment> list = paymentService.findByMerchantId(3);
for(Payment p: list)
System.out.println(p.toString());
}
№18 слайд
![DAO amp Service Interfaces](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img17.jpg)
Содержание слайда: DAO & Service Interfaces
public interface CustomerDao {
public Customer findById(int id);
. . . . . . . . . . . . . .
public List<String> getNames(double sumPayed);
}
public interface CustomerService {
public Customer findById(int id);
. . . . . . . . . . . . . .
public List<String> getNames(double sumPayed);
}
№19 слайд
![CustomerDaoImpl Class public](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img18.jpg)
Содержание слайда: CustomerDaoImpl Class
public List<String> getNames(double sumPayed){
String txt = "SELECT DISTINCT c.name FROM ";
txt += "Payment p, Customer c " ;
txt += "WHERE c.id = p.customerId AND p.sumPayed > " + sumPayed;
TypedQuery<String> query = em.createQuery(txt, String.class);
return query.getResultList();
}
№21 слайд
![Main Class SuppressWarnings](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img20.jpg)
Содержание слайда: Main Class
@SuppressWarnings("resource")
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
CustomerService customerService = context.getBean(CustomerService.class);
List<String> list = customerService.getNames(500.0);
for(String s: list)
System.out.println(s);
}
№27 слайд
![Main Class SuppressWarnings](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img26.jpg)
Содержание слайда: Main Class
@SuppressWarnings("resource")
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
PaymentService paymentService = context.getBean(PaymentService.class);
double sum = paymentService.getPaymentSum();
System.out.println("total = " + sum);
}
№30 слайд
![DAO amp Service Interfaces](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img29.jpg)
Содержание слайда: DAO & Service Interfaces
public interface PaymentDao {
public List<Payment> findByMerchantId(int id);
public double getPaymentSum();
public List<Payment> getLargePayments(double limit);
}
public interface PaymentService {
public List<Payment> findByMerchantId(int id);
public double getPaymentSum();
public List<Payment> getLargePayments(double limit);
}
№32 слайд
![Main Class SuppressWarnings](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img31.jpg)
Содержание слайда: Main Class
@SuppressWarnings("resource")
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
PaymentService paymentService = context.getBean(PaymentService.class);
List<Payment> list = paymentService.getLargePayments(750.0);
for (Payment p: list)
System.out.println(p.toString());
}
See P345Parameters project for the full text
№34 слайд
![PaymentDaoImpl Class public](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img33.jpg)
Содержание слайда: PaymentDaoImpl Class
public List<Payment> getLargePayments(double limit){
TypedQuery<Payment> query = em.createQuery ("SELECT p FROM Payment p WHERE p.sumPayed > :limit", Payment.class);
query.setParameter("limit", limit);
return query.getResultList();
}
See P245Parameters project for the full text
№35 слайд
![Executing Queries The](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img34.jpg)
Содержание слайда: Executing Queries
The TypedQuery interface provides three different ways to execute a query:
getSingleResult() - if the query is expected to return a single result
getResultList() - if more than one result may be returned
executeUpdate() - is used to invoke bulk update and delete queries
№36 слайд
![getResultList Method Returns](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img35.jpg)
Содержание слайда: getResultList() Method
Returns a collection containing the query results
If the query did not return any data, the collection is empty
The return type is specified as a List instead of a Collection in order to support queries that specify a sort order
If the query uses the ORDER BY clause to specify a sort order, the results will be put into the result list in the same order
№40 слайд
![Main Class SuppressWarnings](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img39.jpg)
Содержание слайда: Main Class
@SuppressWarnings("resource")
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
MerchantService merchantService = context.getBean(MerchantService.class);
List<Merchant> list = merchantService.getSortedByNeedToPay();
for(Merchant m: list)
System.out.println("name = " + m.getName() + " sumToPay = " + m .getNeedToSend());
}
№42 слайд
![getSingleResult Method](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img41.jpg)
Содержание слайда: getSingleResult() Method
Instead of iterating to the first result in a collection, the object is directly returned
Throws a NoResultException exception when no results are available
Throws a NonUniqueResultException exception if multiple results are available after executing the query
№43 слайд
![Working with Query Results](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img42.jpg)
Содержание слайда: Working with Query Results
The result type of a query is determined by the expressions listed in the SELECT clause of the query:
Basic types, such as String, the primitive types, and JDBC types
Entity types
An array of Object
User-defined types created from a constructor expression
№44 слайд
![Constructor expressions](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img43.jpg)
Содержание слайда: Constructor expressions (1/2)
Provide developers with a way to map array of Object result types to custom objects
Typically this is used to convert the results into JavaBean-style classes that provide getters for the different returned values
A constructor expression is defined in JP QL using the NEW operator in the SELECT clause
№45 слайд
![Constructor expressions The](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img44.jpg)
Содержание слайда: Constructor expressions (2/2)
The argument to the NEW operator is the fully qualified name of the class that will be instantiated to hold the results for each row of data returned
The only requirement on this class is that it has a constructor with arguments matching the exact type and order that will be specified in the query.
№48 слайд
![DAO amp Service Interfaces](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img47.jpg)
Содержание слайда: DAO & Service Interfaces
public interface MerchantDao {
public Merchant findById(int id);
public List<Merchant> getSortedByNeedToPay();
public List<Result> getTotalReport();
}
public interface MerchantService {
public Merchant findById(int id);
public List<Merchant> getSortedByNeedToPay();
public List<Result> getTotalReport();
}
№49 слайд
![MerchantDaoImpl Class public](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img48.jpg)
Содержание слайда: MerchantDaoImpl Class
public List<Result> getTotalReport(){
String txt = "SELECT new com.bionic.edu.Result (m.name, SUM(p.chargePayed)) ";
txt += "FROM Payment p, Merchant m WHERE m.id = p.merchantId GROUP BY m.name";
TypedQuery<Result> query = em.createQuery(txt, Result.class);
return query.getResultList();
}
№50 слайд
![Main Class SuppressWarnings](/documents_6/8a6bf9ebf6f58e1a65b2f27b802093b8/img49.jpg)
Содержание слайда: Main Class
@SuppressWarnings("resource")
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
MerchantService merchantService = context.getBean(MerchantService.class);
List<Result> list = merchantService.getTotalReport();
for(Result r: list)
System.out.format("%1$25s %2$8.2f \n", r.getName(), r.getSum());
}
Скачать все slide презентации 3. Java Persistence API. 4. Java Persistence Query Language одним архивом:
Похожие презентации
-
3. Java Persistence API. 4. Entity Relationships
-
3. Java Persistence API. 5. Transaction Management
-
Программирование JavaScript на базе библиотеки JQuery
-
Java 8 Stream API
-
JDBC стандартный прикладной интерфейс (API) языка Java. (Лекция 16)
-
Web-технологии: HTML, CSS, JavaScript, JQuery
-
Java Sound API
-
ИТ инициатива Java 8
-
JavaScript. Занятие 18
-
Java 4 WEB. Lesson 10 - IO, NIO