Transaction Management for XML Stored in Relational Database Systems
- 格式:pdf
- 大小:172.50 KB
- 文档页数:9
XML技术在商品管理系统中的应用摘要:该文详细阐述了XML及其特点,并分析了在商品管理系统中使用XML的优势。
通过XML技术在商品管理系统中应用的举例,说明XML将对商品管理系统产生重要影响。
关键词:XML 商品管理系统应用XML(eXtensible Markup Language,可扩展标记语言),作为专门在互联网上传递信息的语言,已经被广泛认为是继Java之后Internet上最激动人心的新兴技术,其应用以及渗透到与网络数据相关的各个领域。
如今,绝大多数网络应用都需要利用数据库技术来采集、保存、管理、传递和发布大量的数据。
由于XML文档本身就是一个数据集合,所以可以将其看成是一个数据库,XML格式的文档不仅可以存储各种数据,还可以定义数据结构,代替数据字典,采用XML技术可以明确地标记数据记录中的每个字段内容。
另外,XML可以用来标记数据信息中的每个片段,使得这些信息可以以不同的方式来显示,并且可以用特定的有效方式来对数据资料进行搜寻、排序、筛选与处理。
1 XML的特点XML使设计者很容易地以标准化的、连续的方式来描述并传输来自任意应用程序的结构化数据,它的优势十分显著,主要表现在以下几个方面。
1.1 可扩展性XML允许各个组织和个人建立适合他们自己想要的标记集合或标记库,并且这些标记集合可以迅速地投入到互联网的使用中。
[1]其次,XML具有相对于其他应用系统较强的抗变化能力,因此多种程序设计语言都可以相当直接地创建和使用XML。
1.2 信息搜索的快捷性XML通过给数据内容贴上标记来描述其含义,搜索引擎不用遍历整个文档,只需查找指定标记的内容就可以了,这大大减轻了网络服务器的负担,极大地降低了网络流量。
[2]1.3 轻松的跨平台应用XML可以定义自己的数据格式,很容易使用软件工具去读、写、交互这些格式的文档。
[1]不仅如此,XML可以支持各种通道的数据传输,不同系统或不同设备之间完全可以采用XML作为信息交换的平台和媒介,建立起更为有效的应用。
事务管理TransactionManagement一、事务事务是一个非常重要的编程概念,使用事务,可以很简单地构造出可靠稳定的应用程序,尤其对那些需要进行并发数据访问的应用程序,事务更是重要的多。
使用事务,便可以利用事务的四个重要属性:ACID。
* 原子性( atomic):事务中包含的各项操作必须全部成功执行或者全部不执行。
任何一项操作失败,将导致整个事务失败,其他已经执行的任务所作的数据操作都将被撤销,只有所有的操作全部成功,整个事务才算是成功完成。
* 一致性( consistent):保证了当事务结束后,系统状态是一致的。
那么什么是一致的系统状态?例如,如果银行始终遵循着"银行账号必须保持正态平衡"的原则,那么银行系统的状态就是一致的。
上面的转账例子中,在取钱的过程中,账户会出现负态平衡,在事务结束之后,系统又回到一致的状态。
这样,系统的状态对于客户来说,始终是一致的。
* 隔离性( isolated):使得并发执行的事务,彼此无法看到对方的中间状态。
保证了并发执行的事务顺序执行,而不会导致系统状态不一致。
* 持久性( durable):保证了事务完成后所作的改动都会被持久化,即使是发生灾难性的失败。
可恢复性资源保存了一份事务日志,如果资源发生故障,可以通过日志来将数据重建起来。
二、事务界定两种事务界定的模型* 声明式事务界定* 编程式事务界定三、设计DAO时需要考虑的问题* 事务要如何开始?* 事务应如何结束?* 哪一个对象将负责开始一个事务?* 哪一个对象将负责结束一个事务?* DAO是否要负责事务的开始和结束?* 应用程序是否需要通过多个DAO访问数据?* 事务涉及到一个DAO还是多个DAO?* 一个DAO是否调用另一个DA 的方法?了解上述问题的答案将有助于选择最适合的DAO的事务界定策略。
在DAO中有两种主要的界定事务的策略。
一种方式是让DAO负责界定事务,另一种将事务界定交给调用这个DAO方法的对象处理。
英文原文:The Java programming language and platform have emerged as major technologies for performing e-business functions. Java programming standards have enabled portability of applications and the reuse of application components across computing platforms. Sun Microsystems' Java Community Process continues to be a strong base for the growth of the Java infrastructure and language standards. This growth of open standards creates new opportunities for designers and developers of applications and services .Applications of JavaJava uses many familiar programming concepts and constructs and allows portability by providing a common interface through an external Java Virtual Machine (JVM). A virtual machine is a self-contained operating environment, created by a software layer that behaves as if it were a separate computer. Benefits of creating virtual machines include better exploitation of powerful computing resources and isolation of applications to prevent cross-corruption and improve security.The JVM allows computing devices with limited processors or memory to handle more advanced applications by calling up software instructions inside the JVM to perform most of the work. This also reduces the size and complexity of Java applications because many of the core functions and processing instructions were built into the JVM. As a result, software developers no longer need to re-create the same application for every operating system. Java also provides security by instructing the application to interact with the virtual machine, which served as a barrier between applications and the core system, effectively protecting systems from malicious code.Among other things, Java is tailor-made for the growing Internet because it makes it easy to develop new, dynamic applications that could make the most of the Internet's power and capabilities. Java is now an open standard, meaning that no single entity controls its development and the tools for writing programs in the language are available to everyone. The power of open standards like Java is the ability to break down barriers and speed up progress.Today, you can find Java technology in networks and devices that range from the Internet and scientific supercomputers to laptops and cell phones, from Wall Street market simulators tohome game players and credit cards. There are over 3 million Java developers and now there are several versions of the code. Most large corporations have in-house Java developers. In addition, the majority of key software vendors use Java in their commercial applications (Lazaridis, 2003).ApplicationsJava on the World Wide WebJava has found a place on some of the most popular websites in the world and the uses of Java continues to grow. Java applications not only provide unique user interfaces, they also help to power the backend of websites. Everybody is probably familiar with eBay and Amazon have been Java pioneers on the World Wide Web.eBayFounded in 1995, eBay enables e-commerce on a local, national and international basis with an array of Web sites.You can find it on eBay, even if you didn't know it existed. On a typical day, more than 100 million items are listed on eBay in tens of thousands of categories. on eBay; the world's largest online marketplace.eBay uses Java almost everywhere. To address some security issues, eBay chose Sun Microsystems' Java System Identity Manager as the platform for revamping its identity management system. The task at hand was to provide identity management for more than 12,000 eBay employees and contractors.Now more than a thousand eBay software developers work daily with Java applications. Java's inherent portability allows eBay to move to new hardware to take advantage of new technology, packaging, or pricing, without having to rewrite Java code.Amazon has created a Web Service application that enables users to browse their product catalog and place orders. uses a Java application that searches the Amazon catalog for books whose subject matches a user-selected topic. The application displays ten books that match the chosen topic, and shows the author name, book title, list price, Amazon discount price, and the cover icon. The user may optionally view one review per displayed title and make a buying decision.Java in Data Warehousing & MiningAlthough many companies currently benefit from data warehousing to support corporatedecision making, new business intelligence approaches continue to emerge that can be powered by Java technology. Applications such as data warehousing, data mining, Enterprise Information Portals and Knowledge Management Systems are able to provide insight into customer retention, purchasing patterns, and even future buying behavior.These applications can not only tell what has happened but why and what may happen given certain business conditions; As a result of this information growth, people at all levels inside the enterprise, as well as suppliers, customers, and others in the value chain, are clamoring for subsets of the vast stores of information to help them make business decisions. While collecting and storing vast amounts of data is one thing, utilizing and deploying that data throughout the organization is another.The technical challenges inherent in integrating disparate data formats, platforms, and applications are significant. However, emerging standards such as the Application Programming Interfaces that comprise the Java platform, as well as Extendable Markup Language technologies can facilitate the interchange of data and the development of next generation data warehousing and business intelligence applications. While Java technology has been used extensively for client side access and to presentation layer challenges, it is rapidly emerging as a significant tool for developing scaleable server side programs. The Java2 Platform, Enterprise Edition (J2EE) provides the object, transaction, and security support for building such systems.Metadata IssuesOne of the key issues that business intelligence developers must solve is that of incompatible metadata formats. Metadata can be defined as information about data or simply "data about data." In practice, metadata is what most tools, databases, applications, and other information processes use to define, relate, and manipulate data objects within their own environments. It defines the structure and meaning of data objects managed by an application so that the application knows how to process requests or jobs involving those data objects. Developers can use this schema to create views for users. Also, users can browse the schema to better understand the structure and function of the database tables before launching a query.To address the metadata issue, a group of companies have joined to develop the Java Metadata Interface (JMI) API. The JMI API permits the access and manipulation of metadata in Java with standard metadata services. JMI is based on the Meta Object Facility (MOF)specification from the Object Management Group (OMG). The MOF provides a model and a set of interfaces for the creation, storage, access, Metamodel and metadata interchange is done via XML and uses the XML Metadata Interchange (XMI) specification, also from the OMG. JMI leverages Java technology to create an end-to-end data warehousing and business intelligence solutions framework.Enterprise JavaBeansA key tool provided by J2EE is Enterprise JavaBeans (EJB), an architecture for the development of component-based distributed business applications. Applications written using the EJB architecture are scalable, transactional, secure, and multi-user aware. These applications may be written once and then deployed on any server platform that supports J2EE. The EJB architecture makes it easy for developers to write components, since they do not need to understand or deal with complex, system-level details such as thread management, resource pooling, and transaction and security management. This allows for role-based development where component assemblers, platform providers and application assemblers can focus on their area of responsibility further simplifying application development.Data Storage & AccessData stored in existing applications can be accessed with specialized connectors. Integration and interoperability of these data sources is further enabled by the metadata repository that contains metamodels of the data contained in the sources, which then can be accessed and interchanged uniformly via the JMI API. These metamodels capture the essential structure and semantics of business components, allowing them to be accessed and queried via the JMI API or to be interchanged via XML. Through all of these processes, the J2EE infrastructure ensures the security and integrity of the data through transaction management and propagation and the underlying security architecture.To consolidate historical information for analysis of sales and marketing trends, a data warehouse is often the best solution. In this example, data can be extracted from the operational systems with a variety of Extract, Transform and Load tools (ETL). The metamodels allow EJBs designed for filtering, transformation, and consolidation of data to operate uniformly on data from diverse data sources as the bean is able to query the metamodel to identify and extract the pertinent fields. Queries and reports can be run against the data warehouse that containsinformation from numerous sources in a consistent, enterprise-wide fashion through the use of the JMI API.Java in Industrial SettingsMany people know Java only as a tool on the World Wide Web that enables sites to perform some of their fancier functions such as interactivity and animation. However, the actual uses for Java are much more widespread. Since Java is an object-oriented language, the time needed for application development is minimal.In addition, Java's automatic memory management and lack of pointers remove some leading causes of programming errors. Most importantly, application developers do not need to create different versions of the software for different platforms. The advantages available through Java have even found their way into hardware. The emerging new Java devices are streamlined systems that exploit network servers for much of their processing power, storage, content, and administration.Benefits of JavaThe benefits of Java translate across many industries, and some are specific to the control and automation environment. Java's ability to run on any platform enables the organization to make use of the existing equipment while enhancing the application.IntegrationWith few exceptions, applications running on the factory floor were never intended to exchange information with systems in the executive office, but managers have recently discovered the need for that type of information. Before Java, that often meant bringing together data from systems written on different platforms in different languages at different times. Integration was usually done on a piecemeal basis, once it worked, was unique to the two applications it was tying together. Additional integration required developing a brand new system from scratch, raising the cost of integration.ScalabilityAnother benefit of Java in the industrial environment is its scalability. Even when internal compatibility is not an issue, companies often face difficulties when suppliers with whom they share information have incompatible systems. This becomes more of a problem as supply-chain management takes on a more critical role which requires manufacturers to interact more withoffshore suppliers and clients. The greatest efficiency comes when all systems can communicate with each other and share information seamlessly. Since Java is so ubiquitous, it often solves these problems.Dynamic Web Page DevelopmentJava has been used by both large and small organizations for a wide variety of applications beyond consumer oriented websites. Sandia, a multiprogram laboratory of the U.S. Department of Energy's National Nuclear Security Administration, has developed a unique Java application. The lab was tasked with developing an enterprise-wide inventory tracking and equipment maintenance system that provides dynamic Web pages.ConclusionOpen standards have driven the e-business revolution. As e-business continues to develop, various computing technologies help to drive its evolution. The Java programming language and platform have emerged as major technologies for performing e-business functions. the time needed for application development is minimal. Java also encourages good software engineering practices with clear separation of interfaces and implementations as well as easy exception handling. Java's automatic memory management and lack of pointers remove some leading causes of programming errors. The advantages available through Java have also found their way into hardware. The emerging new Java devices are streamlined systems that exploit network servers for much of their processing power, storage, content, and administration.中文翻译:Java编程语言和Java平台,已成为主要的实现电子商务功能的技术。
enabletransactionmanagement用法enableTransactionManagement是一个方法,用于在一个应用程序中启用事务管理。
它通常用于配置一个事务管理器,以便应用程序可以开始使用事务来管理数据库操作或其他资源的访问。
该方法的使用方式可能会因不同的框架或平台而有所不同。
以下是一个典型的例子,用于在Spring框架中启用事务管理:1. 首先,在应用程序的配置文件(通常是一个XML文件,如applicationContext.xml)中添加以下代码,以启用事务管理器:<tx:annotation-driven/>2. 在需要启用事务管理的类或方法上添加@Transactional注解,示例如下:
@Transactionalpublic void performDatabaseOperation() { 在此方法中执行数据库操作}此时,当performDatabaseOperation方法被调用时,事务管理器会自动为该方法开启一个事务,如果该方法成功执行,则事务会被提交,否则会被回滚。
需要注意的是,具体的用法会根据具体的框架和平台而有所不同。
在使用enableTransactionManagement方法时,建议查阅相关框架或平台的文档,以了解更详细的用法和配置方式。
Spring事物的配置(Transactional)Spring 事务管理分为编程式和声明式的两种⽅式。
编程式事务指的是通过编码⽅式实现事务;声明式事务基于 AOP,将具体业务逻辑与事务处理解耦。
声明式事务管理使业务代码逻辑不受污染, 因此在实际使⽤中声明式事务⽤的⽐较多。
声明式事务有两种⽅式,⼀种是在配置⽂件(xml)中做相关的事务规则声明,另⼀种是基于@Transactional注解的⽅式。
需要明确⼏点: 1、默认配置下 Spring 只会回滚运⾏时、未检查异常(继承⾃ RuntimeException 的异常)或者 Error。
2、@Transactional 注解只能应⽤到 public ⽅法才有效。
3、@Transactional 注解可以被应⽤于接⼝定义和接⼝⽅法、类定义和类的 public ⽅法上。
然⽽仅仅 @Transactional 注解的出现不⾜以开启事务⾏为,它仅仅是⼀种元数据,能够被可以识别 @Transactional 注解和上述的配置适当的具有事务⾏为的beans所使⽤。
其实是 <tx:annotation-driven/>元素的出现开启了事务⾏为。
4、注解不可以继承,建议在具体的类(或类的⽅法)上使⽤ @Transactional 注解,⽽不要使⽤在类所要实现的任何接⼝上。
当然可以在接⼝上使⽤@Transactional 注解,但是这将只有当你设置了基于接⼝的代理时它才⽣效。
Spring配置⽂件中关于事务配置总是由三个组成部分,分别是DataSource、TransactionManager和代理机制这三部分,⽆论哪种配置⽅式,⼀般变化的只是代理机制这部分。
DataSource、TransactionManager这两部分只是会根据数据访问⽅式有所变化,⽐如使⽤Hibernate进⾏数据访问时,DataSource实际为SessionFactory,TransactionManager的实现为HibernateTransactionManager。
spring事务管理(xml配置)与spring⾃带连接数据库JdbcTemplate 什么是事务,很通俗的话来说就是,我们⽇常⽣活中总会出现在银⾏转账的业务,加⼊A向B转账100元,此时A的账户中应该减少100元,B的账户中增加100元,但是如果在A转完账B还没有接受的时候,服务器出现了故障,⼀般银⾏的系统都会给出交易失败的提⽰,并且A的账户中总⾦额也不会变,那么这就类似⼀个事务。
1.事务是单个逻辑单元⼯作单位执⾏的⼀系列操作 2.多个操作作为整体向系统提交,要么都执⾏,要么都不执⾏ 3.事务时⼀个不可分割的逻辑单元事务的4⼤特性:原⼦性、⼀致性、隔离性、持久性(ACID)下边我就模拟⼀个银⾏转账的事务:⾸先导⼊依赖<!-- https:///artifact/org.springframework/spring-context --><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.1.0.RELEASE</version></dependency><!-- https:///artifact/org.springframework/spring-core --><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>5.1.0.RELEASE</version></dependency><!-- https:///artifact/org.springframework/spring-beans --><dependency><groupId>org.springframework</groupId><artifactId>spring-beans</artifactId><version>5.1.0.RELEASE</version></dependency><!-- https:///artifact/org.springframework/spring-expression --><dependency><groupId>org.springframework</groupId><artifactId>spring-expression</artifactId><version>5.1.0.RELEASE</version></dependency><!--以上4个是spring的核⼼--><!-- https:///artifact/org.aspectj/aspectjweaver --><dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>1.9.2</version></dependency><!-- https:///artifact/org.aspectj/aspectjrt --><dependency><groupId>org.aspectj</groupId><artifactId>aspectjrt</artifactId><version>1.9.2</version></dependency><!--以上两个是aop依赖--><!-- https:///artifact/org.springframework/spring-tx --><dependency><groupId>org.springframework</groupId><artifactId>spring-tx</artifactId><version>5.1.0.RELEASE</version></dependency><!-- https:///artifact/org.springframework/spring-jdbc --><!--spring⾃带的数据库连接依赖--><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.1.0.RELEASE</version></dependency><!-- https:///artifact/mysql/mysql-connector-java --><!--mysql数据库依赖--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.32</version></dependency>dao层接⼝1public interface AccountDao {2void addmonkey();//向表中增加⾦额3void submonkey();//向表中减少⾦额4 }dao层实现类1//dao层实现类需要继承JdbcDaoSupport,这是spring⾃带的数据库操作2public class AccountDaoImpl extends JdbcDaoSupport implements AccountDao {3 @Override4public void addmonkey() {5//id为1的⽤户总⾦额增加1006 String sql="update account set accountmonkey=accountmonkey+100 where accountid=1";7this.getJdbcTemplate().update(sql);8 }910 @Override11public void submonkey() {12//id为2的⽤户总⾦额减少10013 String sql="update account set accountmonkey=accountmonkey-100 where accountid=2";14this.getJdbcTemplate().update(sql);15 }16 }service层接⼝public interface AccountService {void changeMonkey();}service实现类public class AccountServiceImpl implements AccountService {private AccountDao dao;@Overridepublic void changeMonkey() {dao.submonkey();//A先转账给Bint result=5/0;//模拟异常,再调⽤完加钱的时候。
enabletransactionmanagement原理什么是enabletransactionmanagement •enabletransactionmanagement是一个用于开启事务管理功能的选项。
•在软件开发过程中,当需要对多个数据库操作进行组合或者保证一组操作的原子性时,可以开启事务管理。
•使用enabletransactionmanagement可以在程序中灵活地配置和管理事务。
事务管理的意义•事务是指一组数据库操作,要么全部成功执行,要么全部不执行。
•在并发环境下,多个用户同时进行数据库操作,可能会引发一些问题,如数据一致性、并发冲突等。
•事务管理的目的就是提供一种机制来保证多个操作的一致性和隔离性。
事务的ACID特性•ACID是指原子性(Atomicity)、一致性(Consistency)、隔离性(Isolation)和持久性(Durability)。
•原子性指一个事务中的所有操作要么全部成功,要么全部失败。
•一致性指事务在执行前和执行后,数据库始终处于一致的状态。
•隔离性指并发执行的事务之间应该互相隔离,使它们感觉像是在串行执行。
•持久性指一旦事务提交后,其修改操作对数据库是永久性的。
enabletransactionmanagement的配置和使用1.在项目的配置文件中,开启事务管理功能。
2.在需要开启事务的方法或类上添加@Transactional注解。
3.配置事务的一些属性,如事务的传播行为、隔离级别、超时时间等。
配置文件的设置spring:datasource:url: jdbc:username: rootpassword: 123456jpa:hibernate:ddl-auto: updatejackson:date-format: yyyy-MM-dd HH:mm:ssprofiles:active: devmain:allow-bean-definition-overriding: truejpa:properties:hibernate:default_batch_fetch_size: 100show-sql: trueopen-in-view: trueservlet:multipart:enabled: truemax-file-size: 50MBmax-request-size: 50MB方法或类上的注解配置@Servicepublic class UserServiceImpl implements UserService {@Autowiredprivate UserRepository userRepository;@Transactionalpublic User createUser(String username, String passw ord) {User user = new User();user.setUsername(username);user.setPassword(password);return userRepository.save(user);}}事务属性的配置@Servicepublic class UserServiceImpl implements UserService {@Autowiredprivate UserRepository userRepository;@Transactional(propagation = Propagation.REQUIRED, i solation = Isolation.READ_COMMITTED, timeout = 10)public User createUser(String username, String passw ord) {User user = new User();user.setUsername(username);user.setPassword(password);return userRepository.save(user);}}enabletransactionmanagement的工作原理•当一个方法被@Transactional注解修饰时,Spring框架会通过AOP的方式来拦截方法的调用。
Java学习-编程式的事务管理【Java培训】编程式事务提供了TransactionT emplate 模板类,该类可以大大减少事务操作的代码。
因此TransactionT emplate 采用Callback 避免让开发者重复书写其打开事务、提交事务及回滚事务等代码,同时TransactionTemplate 无须书写大量的try..catch 块。
HibernateTemplate 必须提供PlatformTransactionManager 实例。
该实例既可以在代码中手动设置,也可以使用Spring 的依赖注入。
总之,只要获取了PlatformTransactionManager 引用,TransactionTemplate 就可以完成事务操作。
使用TransactionT emplate 不需要显式地开始事务,甚至不需要显式地提交事务。
这些步骤都由模板完成。
但出现异常时,应通过TransactionStatus 的setRollbackOnly 显式回滚事务。
TransactionT emplate 的execute 方法接收一个TransactionCallback 实例。
Callback 也是Spring 的经典设计,用于简化用户操作,下面就帮大家总结了一些TransactionCallback 包含的方法:如下。
•Object dolnTransaction(TransactionStatus status) 。
该方法的方法体就是事务的执行体。
如果事务的执行体没有返回值,则可以使用TransactionCallbackWithoutResultl类的实例。
这是个抽象类,不能直接实例化,只能用于创建匿名内部类。
它也是TransactionCallback 接口的子接口,该抽象类包含一个抽象方法:•void dolnTransactionWithoutResult(TransactionStatus status)该方法与dolnTransaction 的效果非常相似,区别在于该方法没有返回值,即事务执行体无须返回值。
Order Management System 订单管理系统Abstract 摘要This document describes the background design and what results thatwere obtained when devloping the software called PHP Order Manager.PHP Order Manager is a software for helping a small company managetheir orders. This includes entering the orders when they arrive andhandle changes during the production. The system uses MySQL for thedatabase back end and PHP for interfacing the database. PHP OrderManager has great support for modules and has a nice user adminstrationtool.本文档描述了开发PHP 订单管理系统软件的背景,设计,以及该软件所会产生的结果。
PHP 订单管理系统是一个帮助小型企业管理订单的软件。
这包括,订单产生时订单的输入以及订单在生产过程中及时更新信息的输入。
该系统采用了MySQL 数据库以及采用PHP 技术访问MySQL。
PHP 订单管理系统支持模块化,是一款很好的用户管理工具。
1 Introduction 1 简介The project started with a request from DesginaDoors AB DD. DD is asmall company situated in rnskldsvik with fifteen to twenty employees.They manufacture custom made wooden doors to both private personsand companies. Today DD use a paper-based order management systemwhich is very inconvienient for the company because when for example achange is made new papers has to be printed out and be delivered outinto the factory. All the papers are made in Excel but they also have asmall Access database that they don’t use so much because they have to have Access on every computer. DD wanted a better solution for theirorder management system a database with a web based interface thatcould contain all the information that today is in Excel and Access. Themain feature of the wanted system is that you should be able to regísternew orders change existing ones and delete orders that have beencancelled. To be useful the system should also support some kind of userand group management so that the personnel only can access informationthat is relevant to their line of work. The system will also give thecompany benfits becasue it will allow for statistical analysis of the orderintake and the production time. With such a system you could forexample check the time every order spend in each section of the factoryand thereby find slow phases in the production.这个项目是根据DesginaDoors AB(简称DD)公司的需求开发的。
Transaction Management for XML Stored in Relational Database Systems⋆Peter PleshachkovInstitute for System Programming RAS,Russiapeter.pleshachkov@Abstract.Nowadays,modern commercial relational database manage-ment systems(RDBMS)enable functionality to store,query and updateXML data.One of the key problems is efficient handling of concurrentaccess to XML data stored in RDBMS.In this paper,we present an efficient concurrency control method forXML data stored in RDBMS.Our approach is based on Grabs et.al.work on XMLTM,an XML transaction manager built on top of RDBMS.We investigate limitations and drawbacks of XMLTM,and propose solu-tions to overcome them.The paper summarizes our results to date andidentifies directions for future work.The goal of our research is efficient and general transaction manager forconcurrent XML processing in RDBMS.1IntroductionToday a lot of applications use XML to store and exchange data.Their amount is quite significant and continues to grow.To answer new requirements,most commnercial RDBMS vendors extend their products with XML support.Current systems(e.g.MS SQL Server2005) use binary large objects(BLOBS)to store XML documents in a certain internal ers can create special indices on XML documents to speed up queries. The systems enable specialized query languages support such as XQuery/XPath.However,current implementations use internal RDBMS locking for concur-rency control.This approach means that the granularity of locking is the whole XML BLOB,while access is made only to some XML nodes in it.Obviously this creates a bottleneck when concurrent access is an issue.To solve this problem Grabs et.al.[3]proposed to use multilevel transaction management[10].According to this approach,an additional transaction man-ager XMLTM is built on top of RDBMS.It schedules concurrent updates and queries using DGLOCK protocol.XMLTM decomposes XML transaction into a number of small independent transactions over RDBMS.They are called DB transactions.And as XMLTM can commit DB transactions early,the locks on the entire BLOB are released early thereby allowing other transactions waitingfor the locks to proceed.Moreover,DB transactions are run at a lower ANSI isolation level(Read Commited).These factors allow to improve the parallelism of XML transactions.We consider this approach to be the most promising,since XMLTM does not rely on the underlying storage scheme used by relational databases for XML documents.This means that it will work even for native XML databases.Unfortunately there are certain limitations and drawbacks in the Grabs ly:(1)supported query language is a restricted version of XPath, whereas modern RDBMSs support moreflexible and powerful XQuery language, (2)DGLOCK protocol is based on multi-granularity locking scheme[4],which is too restrictive for a wide range of XML-operations and(3)DGLOCK does not guarantee serilizability of produced schedules.Also(4)XMLTM does not sup-port ordered XML and(5)performance of updates degrades due to significant overhead needed to log before-images of updated documents by XMLTM.The goal of our research is to overcome these XMLTM drawbacks and lim-itations and design a more efficient and general transaction manager called SXTM(Semantic XML Transaction Manager)for concurrent XML processingin RDBMS.The key contributions of our research are:–We proposed a locking protocol to schedule XML transactions,which ex-ploits the semantics of XML queries and updates to improve the degree of concurrency in comparison with original DGLOCK protocol.–We introduced a way to reduce a size of log which is needed to guarantee atomicity of XML transactions.The remainder of the paper elaborates our contributions in Section2.In Section3we discuss previous work on concurrency control for XML data.In Sect4we give directions for future work and make conclusions.2Results to Date2.1PreliminariesIn SXTM we use XQuery to query XML documents.To update XML documents we use primitive update operations like insert,delete and rename.It is clear, that any complex update operation may be expressed via these operations.We consider three kinds of insert operations.The operations InsertInto(locpath, constr),InsertAfter(locpath,constr)and InsertBefore(locpath,constr) insert new node defined by constr as the last child,following sibling and preced-ing sibling respectively for each target node defined by locpath.Here Locpath (location path)is the basic operation used both in XQuery queries and update operations.The operation Delete(locpath)removes the target subtrees defined by locpath.The operation Rename(locpath,QName)assigns new name defined by QName to the target nodes defined by locpath.We denote the intermidiate nodes and destination nodes of Locpath as ITM and DST respectively.Below inthis paper,we use II,IA,IB,RN,D and LP to denote InsertInto,InsertAfter, InsertBefore,Rename,Delete and Locpath operations respectively.In the Fig.1we present a sample of XML document Gtree,its DataGuide and DTD.We will use Gtree document in all examples throughout the paper.Fig.1.An XML document GTree,its DataGuide and DTD2.2XDGL2Locking ProtocolIn this section we present a high level overview of new locking protocol called XDGL2.Except for some refinements,the XDGL2protocol is based on our XDGL protocol presented in[8].XDGL2requires transaction to follow the strict two-phase locking protocol (S2PL)[12].According to S2PL,a transaction acquired a lock keeps it until the end.In SXTM we maintain the DataGuide(DG for short)structure for lock-ing purposes rather than the document iself as the document is not physically available.A DG describes every unique label path of a document exaclty once, regardless of the number of times it appears in that document,and encodes no label path that does not appear in the document.Exactly by utilizing DG as a locking structure we abstract from underlying storage scheme used for XML documents in DBMS.Thus,this generalizes the method.To cope with deadlocks we use deadlock detector which periodically builds wait-for graph[11]of the transactions and analyzes it for cycles.When a cycle is found,a victium is selected and aborted.There are two kinds of locks in XDGL2:structural locks and logical locks which we describe in the following subsections.Structural locks–P(pass)lock.This node lock is used by LP operation.It is set on the DG’s nodes which match the ITM nodes of LP.This lock prevents the deletion of ITM nodes by other transactions,but it does not prohibit any insertion of the nodes extending the sequence of ITM nodes(see example1below).–S(share)lock.This node lock is also used by LP operation.It is set on the DG’s nodes which match the DST nodes of LP.This lock prevents any modifications of DST nodes.For example,for query count(/doc/person)S lock is set on node n2(see Fig.1).–SI(shared into)lock.This node lock is used by II operation.It is set on the DG’s nodes which match the target nodes of II.This lock prevents the modification of II’s target nodes and insertion of another nodes into the target nodes by concurrent transactions.The SA(shared after)and SB (shared before)locks are defined in a similar way.–XN(exclusive new)lock.This node lock is used by insert operations.It is set on the DG’s node which matches the newly created nodes.This lock allows passing by the new node,(i.e it compatible with P lock),but other operations(e.g.modidfication)on the node are prohibited.–X(exclisive)lock.This node lock is used by operations which modify internal nodes of the document.This lock prevents any concurrent reads and updates of the node.In our set of update operations this lock is used by RN operation since it renames the target nodes inside the document.It is set on the DG’s nodes which correspond to the RN’s target and new nodes.Note,if we rename the leaf node then we only need to acquire X lock on the RN’s target nodes and XN lock on the new nodes.–ST(shared tree),XT(exclusive tree)locks.The ST(XT)lock is a tree lock.The ST(XT)lock is set on the DG’s node and implicitly locks all its descendants.The ST(XT)lock prevents any updates(reads and updates)in the entire subtree.For example,XT lock is set on target nodes of D operation.–IS(intention shared),IX(intention exclusive)locks.The IS lock must be obtained on each ancestor of the node,which is to be locked in one of the shared modes.It ensures that there are no locks on the coarser granules locking the node in conflicting mode.IX lock is defined in a similar way.To deal with value-based constraints,each structural lock has an annotated value-based predicate1.The XDGL2compatibility matrix for structural locks is shown in the Fig.2.There are no strict incompatibilities in matrix.Symbol CP (check predicates)in matrix means that the requested lock is compatible with granted locks only if conjunction of annotated predicates is not satisfiable.Next we study a couple of examples to illustrate the locking mechanisms2.Example1.Let us consider transactions T1={II(/doc,<person/>)},T2={ II(/doc,<person/>)}and T3={/doc/person/name}.According to XDGL2the following sets of structural locks{n1:(SI,IX),n2:XN},{n1:(SI,IX), n2:XN}and{n1:P,n2:P,n4:ST}must be obtained by transactions T1,T2 and T3respectively.Thus,we obtain that T1,T3and T2,T3can run concurrently whereas T1and T2can not run concurrently due to the conflict of SI locks on node n1.Fig.2.Lock Compatibility MatrixExample2.For transactions T1=D(/doc/person/@age)}and T2={for$v in //person return<name2>{$v/name}</name2>}we need to obtain the sets of structural locks{n1:(IX,P),n2:(IX,P),n3:XT}and{n1:IS,n6:IS, n2:S,n8:S,n4:ST,n10:ST}respectively.Since locks required by T1and T2are compatible,we conclude that T1and T2can be executed concurrently (thus we prevent document order conflict).Note,that DGLOCK from XMLTM does not allow concurrent executon of transactions from examples1and2.Logical Locks Now we turn to the discussion of the logical locks,which are used to prevent phantoms.Let us show how a phantom could appear.Suppose that transaction T1reads all of age attributes in GTree(i.e.T1issued//@age query).In the meantime transaction T2inserts new age attribute into person element with name’John’(see Fig.1).The new age attribute is the phantom for transaction T1.Generally speaking,phantoms can appear when update operation extends the DG3(adds new path to DG)and this modification results in the changing of target nodes of previously executed operations.Thus,we introduce two locks.Thefirst lock is L(logical)lock,which must be set on DG’s node to protect the node’s subtrees in the document from a phantom appearance.A logical lock specifies a set of properties.Essentially,a property is a logical condition on nodes.This lock prohibits the insertion of new nodes,which possess these properties.The second lock is IN(insert new node) lock,which specifies the properties of new node.The update operation,which extends the DG,should obtain the IN lock on each ancestor of the new node.Here we list all possible combinations of properties for L lock:(1)node-name=’name1’(e.g.//person),(2)node-name=’name1’,node-value relop’val1’(e.g.//name[.=’John’]),(3)node-name=’name1’,child-name=’name2’,child-value relop’val1’(e.g.//person[name=’John’]).Here relop is a comparison operation.To check that the new node’s properties do not interfere with the L lock properties,the IN lock should specify three properties of a new node:new-node-parent-name,new-node-name,new-node-value.Thus,L and IN locks are incompatible if one of the following conditions holds:–If IN’s new-node-name equals to a node-name of L lock and L does not contain any other properties(case(1)from the above)4.–If IN’s new-node-name and new-node-value both match appropriate values of L lock consisting of two properties.That is,node-name=new-node-name and new-node-value relop’val1’=#f(case(2)from the above).–If all IN’s properties match three properties of L lock.That is node-name=new-node-parent-name,child-name=new-node-name and new-node-value relop ’val1’=#f(case(3)).If node’s name is a wildcard’*’then it equals to any node-name.DTD-based Concurrency Enhances We already discussed the benefits we got by utilizing the DG for locking.However,there are some drawbacks.The problem with DG is that it lacks the notion of document order.Therefore,the evaluation of ordered-based axes(e.g.preceding-sibling,following-sibling)on DG may result in the lock of unnecessary DG nodes.As a consequence,we can get unnecessary conflicts among transactions.To reduce the number of such conflicts we use DTD,which specifies the document order.For instance,on the basis of the GTree’s DTD information <!ELEMENT person(name,addr,(hobby)*,(child)*)?!>we can resolve the conflict between transactions T1={/doc/person/addr/preceding-sibling::*} and T2={D(/doc/person/hobby)}.Indeed,without DTD information T1must acquire ST lock on all DG’s nodes of level2(n3,n4,n5,n6,n7),whereas T2must obtain XT lock on node n7of level2.Thus,there is a conflict between T1and T2 on node n7.But using DTD we know that preceding sibling of addr element can only be name element,and T1must acquire ST lock only on node n4thereby allowing T2to run concurrently.CorrectnessTheorem1.All schedules of concurrent transactions generated by XDGL2sched-uler are serializable.Formal proof of this theorem is available in[9].2.3Atomicity of XML transactionsDecomposing XML transaction into a number of independent DB transactions, we can no longer implement XML transaction’s abort by RDBMS[10].Only active DB transactions can be rolled back by RDBMS.For this reason,XMLTM logs the before-images of updated XML documents.An abort is implemented by restoring old text value of the document.Since the logging granularity in XMLTM is greater than the locking granularity the cascading aborts are possible.We propose a new way to guarantee atomicity of XML transactions,which allows to reduce the size of log significantly.For clear presentation and becauseof space limitations we consider only insert and delete operations.To undo the insert operations we propose to log reverse operations,which delete the inserted nodes.As a consequence,an extra logging overhead for insert operations is low.This way for II(/doc/person,<name/>)operation we write into the log only D(/doc/person/name[position=last()]).Similarly,for op-eration IB(/doc/person/hobby,<addr/>)we need to log D(/doc/person/addr:: preceding-sibling[position()=1])operation.An undo of D is somewhat more difficult and expensive-we need to log both the before-images of deleted subtrees and their positions in the document.Thus, before executing D operation we need to execute preliminary query,which ex-tracts needed information and then write its results into the log.For instance,forD(/doc/person[name=’John’])the preliminary query is for$node at$posin/doc/person where$node/name=’John’return($node,$pos).Here $node variable is bound with the deleted subtree,whereas$pos defines the posi-tion of the subtree.To undo this D operation we will execute the following query for each$node:IA(/doc/node()[postion()=$pos-1],$node).Note that no extra logging is needed for the last DB transaction since its commit means the end of XML transaction.We use this fact to reduce a signifi-cant logging overhead incured by D operation.We propose to execute D operationin the following way(1)if an operation op in XML transaction preceded by D operation depends on the results of D than execute D before op’s execution,(2) else execute D operation in last DB transaction5.3Concurrency Control for Native XML DBMSs:Related WorkThe protocol developed in[2]relies on the fact that XML is usually accessed by means of XPath query language.They propose to use”path locks”to increase concurrency and provide the best results for XPath queries.Unfortunately,the authors deal with too restrictive subset of XPath.The method presented in[7],proposes a XLP(XPath Locking Protocol) locking protocol,which is based on XPath model and has the features of richer lock modes,refined lock granualrity and lower lock conflict.Another XPath-based protocol was proposed by Choi et al.[1].The protocol assumes that an XML document is modeled as a tree structure.Three versions of XML document are maintained.Concurrency Control is implemented by using read-write check and write-read check.Unfortunately,these checks are very expensive operations. The protocol was limited to theoretical design.Several protocols[5],[6]based on the DOM operations were proposed.The protocols use different kinds of locks to latch nodes on different levels.These seem to workfine for DOM operations,but there is no research done to see whether they could suite well the evaluation of path expressions.Moreover,all these methods require direct access to the XML document, which is not possible in mant cases.4Conclusion and Future WorkThis thesis is centered around the transaction management for XML stored in RDBMSs.The main goal of our research is efficient and general transaction manager for concurrent XML processing in RDBMS.We start with a detailed analysis of existing solutions depicting those as-sumptions,techniques,limitations and drawbacks.In an attempt to eliminate limitations and drawbacks the thesis presents a new XDGL2locking protocol and a new way for logging high level XML-operations to guarantee atomicity of XML transactions.Utilizing DataGuide as a locking structure,we abstract from underlying stor-age scheme used for XML documents in RDBMS.Different types of locks on DataGuide structure are proposed to capture the semantics of XML operations thereby allowing to improve the degree of concurrency in comparison with exist-ing solutions.Unlike previously proposed solutions,our protocol ensures strict serilizability and combines predicate and logical locks to provide protection from phantoms appearance.The paper presents an approach how to reduce the overhead incured by extra logging.We use a combination of logical logging and delayed execution of delete operations,which allows to undo delete operations using RDBMS’s recovery functionality.Finally,the proposed Semantic XML Transaction Manager is primarily being implemented on top of MS SQL Server2005and in our next steps,we concentrate on its comprehensive experimental study.References1. E.H.Choi and T.Kanai.XPath-based Concurrency Control for XML Data.InProc.DEWS2003,2003.2.S.Dekeyser and J.Hidders.Path Locks for XML Document Collaboration.InProc.WISE2002,Singapore,2002.3.T.Grabs,K.Bohm,and H.-J.Schek.XMLTM:Efficient Transaction Managementfor XML Documents.In Proc.ACM CIKM2002,USA,2002.4.J.Gray et al.Granularity of locks in a large shared databases.In Proc.VLDB1975,USA,1975.5.M.Haustein and T.Haerder.Adjustable Transaction Isolation in XML DatabaseManagement Systems.In Proc.XSym2004,LNCS3186,2004.6.S.Helmer,C.-C.Kanne,and G.Moerkotte.Evaluating lock-based protocols forcooperation on XML documents.SIGMOD Record,33(1),2004.7.K.-f.Jea et al.Concurrency Control in XML Document Databases:XPath LockingProtocol.In Proc.ICPADS2002,Taiwan,2002.8.P.Pleshachkov,P.Chardin,S.Kuznetsov.XDGL:XPath-Based Concurrency Con-trol Protocol for XML Data.Proc.BNCOD2005,LNCS3567,Sunderland,UK.9.P.Pleshachkov,P.Chardin,and S.Kuznetsov.A DataGuide-Based ConcurrencyControl Protocol for Cooperation on XML Data.In Proc.ADBIS2005,LNCS 3631,2005.10.G.Weikum.Principles and Realization Strategies of Multilevel Transaction Man-agement.ACM Transactions on Database Systems(TODS),16(1),1991.11.J.Gray and A.Reuter.Transaction Processing:Concepts and Techniques.MorganKaufmann Publishers Inc.,1992.12.K.P.Eswaran et al The notions of consistency and predicate locks in a databasem of ACM,Vol.19,No11,pp.624-633,November1976.。