Презентация 3. Java Persistence API. 5. Transaction Management онлайн
На нашем сайте вы можете скачать и просмотреть онлайн доклад-презентацию на тему 3. Java Persistence API. 5. Transaction Management абсолютно бесплатно. Урок-презентация на эту тему содержит всего 42 слайда. Все материалы созданы в программе PowerPoint и имеют формат ppt или же pptx. Материалы и темы для презентаций взяты из открытых источников и загружены их авторами, за качество и достоверность информации в них администрация сайта не отвечает, все права принадлежат их создателям. Если вы нашли то, что искали, отблагодарите авторов - поделитесь ссылкой в социальных сетях, а наш сайт добавьте в закладки.
Презентации » Устройства и комплектующие » 3. Java Persistence API. 5. Transaction Management
Оцените!
Оцените презентацию от 1 до 5 баллов!
- Тип файла:ppt / pptx (powerpoint)
- Всего слайдов:42 слайда
- Для класса:1,2,3,4,5,6,7,8,9,10,11
- Размер файла:531.50 kB
- Просмотров:64
- Скачиваний:0
- Автор:неизвестен
Слайды и текст к этой презентации:
№2 слайд
![Database Transaction A](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img1.jpg)
Содержание слайда: Database Transaction
A database transaction is a sequence of actions that are treated as a single unit of work
These actions should either complete entirely or take no effect at all
Transaction management is an important part of RDBMS oriented enterprise applications to ensure data integrity and consistency.
№3 слайд
![ACID of Atomicity. A](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img2.jpg)
Содержание слайда: ACID (1 of 2)
Atomicity. A transaction should be treated as a single unit of operation which means either the entire sequence of operations is successful or unsuccessful
Consistency. This represents the consistency of the referential integrity of the database, unique primary keys in tables etc
№4 слайд
![ACID of Isolation. There may](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img3.jpg)
Содержание слайда: ACID (2 of 2)
Isolation. There may be many transactions processing with the same data set at the same time, each transaction should be isolated from others to prevent data corruption
Durability. Once a transaction has completed, the results of this transaction have to be made permanent and cannot be erased from the database due to system failure.
№5 слайд
![Spring Transaction Management](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img4.jpg)
Содержание слайда: Spring Transaction Management
Spring framework provides an abstract layer on top of different underlying transaction management APIs
Local transactions are specific to a single transactional resource like a JDBC connection
Global transactions can span multiple transactional resources like transaction in a distributed system
№6 слайд
![Local Transactions Local](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img5.jpg)
Содержание слайда: Local Transactions
Local transaction management can be useful in a centralized computing environment where application components and resources are located at a single site, and transaction management only involves a local data manager running on a single machine
Local transactions are easier to be implemented
№7 слайд
![Global Transactions Global](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img6.jpg)
Содержание слайда: Global Transactions
Global transaction management is required in a distributed computing environment where all the resources are distributed across multiple systems
A global transaction is executed across multiple systems, and its execution requires coordination between the global transaction management system and all the local data managers of all the involved systems
№8 слайд
![Programmatic vs. Declarative](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img7.jpg)
Содержание слайда: Programmatic vs. Declarative
Spring supports two types of transaction management:
Programmatic transaction management: you have manage the transaction with the help of programming. That gives you extreme flexibility, but it is difficult to maintain
Declarative transaction management: you separate transaction management from the business code. You only use annotations or XML based configuration to manage the transactions
№10 слайд
![Spring Transaction](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img9.jpg)
Содержание слайда: Spring Transaction Abstractions
The key to the Spring transaction abstraction is defined by PlatformTransactionManager interface in the org.springframework.transaction package:
public interface PlatformTransactionManager {
TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException;
void commit(TransactionStatus status) throws TransactionException;
void rollback(TransactionStatus status) throws TransactionException;
}
№11 слайд
![PlatformTransactionManager](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img10.jpg)
Содержание слайда: PlatformTransactionManager
getTransaction - returns a currently active transaction or create a new one, according to the specified propagation behavior
commit - commits the given transaction, with regard to its status
rollback - performs a rollback of the given transaction
№13 слайд
![TransactionDefinition Methods](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img12.jpg)
Содержание слайда: TransactionDefinition Methods
getPropagationBehavior - returns the propagation behavior
getIsolationLevel - returns the degree to which this transaction is isolated from the work of other transactions
getName - returns the name of the transaction
getTimeout - returns the time in seconds in which the transaction must complete
isReadOnly - returns whether the transaction is read-only.
№14 слайд
![Isolation Level of](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img13.jpg)
Содержание слайда: Isolation Level (1 of 2)
TransactionDefinition.ISOLATION_DEFAULT - the default isolation level
TransactionDefinition.ISOLATION_READ_COMMITTED -
indicates that dirty reads are prevented; non-
repeatable reads and phantom reads can occur
TransactionDefinition.ISOLATION_READ_UNCOMMITTED -dirty reads, non-repeatable reads and phantom reads can occur
№16 слайд
![Propagation Types of](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img15.jpg)
Содержание слайда: Propagation Types (1 of 2)
TransactionDefinition.PROPAGATION_MANDATORY - support a current transaction; throw an exception if no current transaction exists
TransactionDefinition.PROPAGATION_NESTED - execute within a nested transaction if a current transaction exists
TransactionDefinition.PROPAGATION_NEVER - do not support a current transaction; throw an exception if a current transaction exists
TransactionDefinition.PROPAGATION_NOT_SUPPORTED - do not support a current transaction; rather always execute non-transactionally
№17 слайд
![Propagation Types of](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img16.jpg)
Содержание слайда: Propagation Types (2 of 2)
TransactionDefinition.PROPAGATION_REQUIRED - support a current transaction; create a new one if none exists
TransactionDefinition.PROPAGATION_REQUIRES_NEW - create a new transaction, suspending the current transaction if one exists
TransactionDefinition.PROPAGATION_SUPPORTS - support a current transaction; execute non-transactionally if none exists
TransactionDefinition.TIMEOUT_DEFAULT - use the default timeout of the underlying transaction system, or none if timeouts are not supported
№18 слайд
![TransactionStatus interface](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img17.jpg)
Содержание слайда: TransactionStatus interface
Provides a simple way for transactional code to control transaction execution and query transaction status
public interface TransactionStatus extends SavepointManager {
boolean isNewTransaction();
boolean hasSavepoint();
void setRollbackOnly();
boolean isRollbackOnly();
boolean isCompleted();
}
№19 слайд
![TransactionStatus Methods](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img18.jpg)
Содержание слайда: TransactionStatus Methods
hasSavepoint - returns whether this transaction internally carries a savepoint, that is, has been created as nested transaction based on a savepoint
isCompleted - returns whether this transaction has already been committed or rolled back
isNewTransaction - returns true in case the present transaction is new
isRollbackOnly - returns whether the transaction has been marked as rollback-only
setRollbackOnly - sets the transaction rollback-only
№20 слайд
![Declarative Transaction](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img19.jpg)
Содержание слайда: Declarative Transaction Management
This approach allows you to manage the transaction with the help of configuration instead of hard coding in your source code
So you can separate transaction management from the business code by using annotations or XML based configuration to manage the transactions
The bean configuration will specify the methods to be transactional
№22 слайд
![Using Transactional You can](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img21.jpg)
Содержание слайда: Using @Transactional
You can place the @Transactional annotation
before a class definition, or a public method on a class
A transaction begins before method annotated with @Transactional. It commits after method ends normally, and rollbacks if RuntimeException occurs.
All methods for class annotated with @Transactional are transactional.
№27 слайд
![Save Service Implementation](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img26.jpg)
Содержание слайда: Save Service Implementation
@Named
public class CustomerServiceImpl implements CustomerService{
@Inject
private CustomerDao customerDao;
public Customer findById(int id) {
return customerDao.findById(id);
}
@Transactional
public void save(Customer customer){
customerDao.save(customer);
}
}
№29 слайд
![PaymentDaoImpl Class package](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img28.jpg)
Содержание слайда: PaymentDaoImpl Class
package com.bionic.edu;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.stereotype.Repository;
@Repository
public class PaymentDaoImpl implements PaymentDao{
@PersistenceContext
private EntityManager em;
public void save(Payment p){
em.persist(p);
}
}
№32 слайд
![CustomerServiceImpl Class](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img31.jpg)
Содержание слайда: CustomerServiceImpl Class
package com.bionic.edu;
import javax.inject.Inject;
import javax.inject.Named;
import org.springframework.transaction.annotation.Transactional;
@Named
public class CustomerServiceImpl implements CustomerService{
@Inject
private CustomerDao customerDao;
@Transactional
public void save(Customer c){ customerDao.save(c); } }
№33 слайд
![PaymentServiceImpl Class](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img32.jpg)
Содержание слайда: PaymentServiceImpl Class
@Named
public class PaymentServiceImpl implements PaymentService{
@Inject
private PaymentDao paymentDao;
@Inject
private CustomerService customerService;
@Transactional
public void add(Customer c, Payment p){
customerService.save(c);
p.setCustomerId(c.getId());
paymentDao.save(p);
}}
№34 слайд
![Output INSERT on table](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img33.jpg)
Содержание слайда: Output
INSERT on table 'PAYMENT' caused a violation of foreign key constraint 'CUSTOMER_FK' for key (0).
The reason is that propagation value of @Transactional annotation is REQUERED by default – so transaction for customerService.save(c) method will be commited along with paymentService.add(Customer c, Payment p) method
See P362AddCustPayment project for the full text
№35 слайд
![CustomerServiceImpl Class](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img34.jpg)
Содержание слайда: CustomerServiceImpl Class
package com.bionic.edu;
import javax.inject.Inject;
import javax.inject.Named;
import org.springframework.transaction.annotation.Transactional;
@Named
public class CustomerServiceImpl implements CustomerService{
@Inject
private CustomerDao customerDao;
@Transactional(propagation=Propagation.NESTED)
public void save(Customer c){ customerDao.save(c); } }
№37 слайд
![CustomerServiceImpl Class](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img36.jpg)
Содержание слайда: CustomerServiceImpl Class
package com.bionic.edu;
import javax.inject.Inject;
import javax.inject.Named;
import org.springframework.transaction.annotation.Transactional;
@Named
public class CustomerServiceImpl implements CustomerService{
@Inject
private CustomerDao customerDao;
@Transactional(propagation=Propagation.REQUIRES_NEW)
public void save(Customer c){ customerDao.save(c); } }
№38 слайд
![Output Customer and Payment](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img37.jpg)
Содержание слайда: Output
Customer and Payment entities are successfully saved
The problem is in the risk of data integrity violation – rollback of PaymentServiceImpl.add transaction does not cause rollback of CustomerServiceImp.save transaction
See P364AddCustPayment project for the full text
№40 слайд
![Customer Entity Entity public](/documents_6/06e66f3a0b2ccd1e2c4cedc78d656a94/img39.jpg)
Содержание слайда: Customer Entity
@Entity
public class Customer {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
. . . . . . . . . . . . . .
@OneToMany(mappedBy="customer", cascade=CascadeType.PERSIST)
private Collection<Payment> payments;
. . . . . . . . . . . . . .
Скачать все slide презентации 3. Java Persistence API. 5. Transaction Management одним архивом:
Похожие презентации
-
3. Java Persistence API. 4. Entity Relationships
-
3. Java Persistence API. 4. Java Persistence Query Language
-
Java 8 Stream API
-
JDBC стандартный прикладной интерфейс (API) языка Java. (Лекция 16)
-
Java Sound API
-
ИТ инициатива Java 8
-
JavaScript. Занятие 18
-
Java 4 WEB. Lesson 10 - IO, NIO
-
Основы программирование: Введение в Java. Коллекции
-
JavaScript. Плюсы и минусы