Open conchincradle opened 1 year ago
Use DI to manage components and these objects are called Spring Beans aspect-oriented programming (AOP) is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. In computer science, a concern is a particular set of information that has an effect on the code of a computer program. A concern can be as general as the details of database interaction or as specific as performing a primitive calculation, depending on the level of conversation between developers and the program being discussed.
IoC : control of the managing bean and life cycle is part of container instead of programmer
Configuration metadata--------BeanDefinitions----------XML file, annotation-based configuration, Java-based configuration Two types of IoC containers: Bean Factory: interface Resource resource = new ClassPathResource("spring configuration file") BeanFactory beanFactory = new XmlBeanFactory(resource) containsBean getBean XMLBeanFactory
Application Context: perform more enterprise functionalities like transaction AOP, resolving text messages, from properties files, FileSystemXmlApplicationContext------full path ClassPathXmlApplicationContext WebXmlApplicationContext
scopes of beans Singleton- a single instance Prototype: nultiple instances Web app: request session global session
autowired qualifier
Event handling a transaction is a unit of work in which either all operations must execute or none of them to ensure data integrity and consistency ACID Atomicity- atomic, either full or not, the entire sequence of operations should be successful or not Consistency - consistent state Isolation- processing the same data, each transactrion should be isolated to prevent data corruption Durability- the result of transaction should be permanent
Two approaches for transaction management Programmatic Transaction management Declarative Transaction management------- concurrently read problem dirty read: transaction read the uncommitted data from another transaction 脏读就是指当一个事务正在访问数据,并且对数据进行了修改 Non-repeatable read: gets different data from the same query , when another transaction commited data 不可重复读是指在一个事务内,多次读同一数据; Phantom read: insert data while another is reading data, reading transaction will find additional data which doesn't exist before Isolation Level---5 isolation_default isolation_read_uncommitted ------three problems but high efficiency of concurrency isolation_read_commited------solve the dirty read, only read committed data, but non-repeatable, and phantom read锁定正在读取的行, isolation_repeatable read, ------solve the non-repeatable read, 锁定读取的所有的行,不只是正在读取的,但是幻读,也就是人家insert的虽然不可以更改,但是可以增加 isolation -- serializable--锁定整个表格 也就是 默认 不锁定--允许插入和修改 锁定正在读取的行---不允许修改正在读取的行,但是允许修改其他的 锁定整个事务读取的行----不允许修改所有会查询的行,但是允许插入 锁定整个表格--不允许插入,修改
脏读、幻读、不可重复读的区别:
脏读 :脏读就是指当一个事务正在访问数据,并且对数据进行了修改,而这种修改还没有提交到数据库中,这时,另外一个事务也访问 这个数据,然后使用了这个数据。
不可重复读 :是指在一个事务内,多次读同一数据。在这个事务还没有结束时,另外一个事务也访问该同一数据。那么,在第一个事务中的两 次读数据之间,由于第二个事务的修改,那么第一个事务两次读到的的数据可能是不一样的。这样就发生了在一个事务内两次读到的数据是不一样的,因此称为是不 可重复读。例如,一个编辑人员两次读取同一文档,但在两次读取之间,作者重写了该文档。当编辑人员第二次读取文档时,文档已更改。原始读取不可重复。如果 只有在作者全部完成编写后编辑人员才可以读取文档,则可以避免该问题。
幻读 : 是指当事务不是独立执行时发生的一种现象,例如第一个事务对一个表中的数据进行了修改,这种修改涉及到表中的全部数据行。 同时,第二个事务也修改这个表中的数据,这种修改是向表中插入一行新数据。那么,以后就会发生操作第一个事务的用户发现表中还有没有修改的数据行,就好象 发生了幻觉一样。例如,一个编辑人员更改作者提交的文档,但当生产部门将其更改内容合并到该文档的主复本时,发现作者已将未编辑的新材料添加到该文档中。 如果在编辑人员和生产部门完成对原始文档的处理之前,任何人都不能将新材料添加到文档中,则可以避免该问题。
补充 : 基于元数据的 Spring 声明性事务 :
Isolation 属性一共支持五种事务设置,具体介绍如下:
DEFAULT 使用数据库设置的隔离级别 ( 默认 ) ,由 DBA 默认的设置来决定隔离级别 .
READ_UNCOMMITTED 会出现脏读、不可重复读、幻读 ( 隔离级别最低,并发性能高 )
READ_COMMITTED 会出现不可重复读、幻读问题(锁定正在读取的行)
REPEATABLE_READ 会出幻读(锁定所读取的所有行)
SERIALIZABLE 保证所有的情况不会发生(锁表)
AOP disjoint codes into concerns
HTTP hyperText Transfer Protocol clients-------------servers---communicate
a server-side Java program module that is generally written to handle client requests and implement the servlet interface Java Server Pages a programming tool construct web-based applications an extension of servlet and get converted to a servlet by JSP container
Java Development Kit Java Web Server (Apache Tomcat) J2EE, J2SE contains JRE Java Runtime Environment Tomcat: combination of Java servlet and Java Server Page container listens on port 8080
client-browser-HTTP--server-web server web container is a component in the web server that interacts with Java servlets servlet life cycle HttpServletResponse HttpSession
JSP-----HTML include small java------------content presentation Servlet--Java include small html code-------------control, validation they both in server side servlets---controllers, jsps----views
IoC is a core part of the spring framework, which is used to manage the application bean dependecy injection injects dependecies when a bean is vreated and manage the bean life cycle during execution