During the analysis design of the software project, we first analyze the data entities, such as determining classes, class member variables, or drawing. Then, the input boxes on the UI interface, text boxes, etc., followed by we will also determine the number and type of the method. These processes are tightly dependent on the stability of the data entity, for example, how many tables we need in the database design, how much each table is, what is the type, etc. But what should I do if this stability loses? The user is very likely to say that I can only determine these fields for my table. Does the project group wait until the user is determined? If the user said that the field changes is my needs, how do I develop? Even if all customers can determine the field, the different customers determined by different customers may not be the same. Since different customers do not have the same demand for fields, the project group sometimes has to be annoying to construct the number of versions of source code. This article is based on Java environment, analyzes and achieves solutions to solve this problem. First, it is pointed out that the J2EE container manages the shortcomings of the persistent entity bean, followed by the skill of implementing this demand with Java, and finally it is realized. 2 Fixed field assumptions and CMP entity bean type mechanisms The CMP entity bean mechanism is also the container management persistence entity bean mechanism. The bean class provided by the provider of the CMP entity bean has an abstract GET / SET method for a persistent field (or attribute). These two methods are the same as the GET / SET method for the properties of ordinary Java Beans. Below is the NAME persistence field of a PersonBean entity bean class. Class Personbean Extends EntityBean {Abstract String GetName (); Abstract String SetName (String vName); String ebjcreate (String Name) {setName (name);}; ------} When deploying, the general deployment tool will generate this class. Subcord, subclasses have probably as follows: Class PersonBeansubclass Extends Personbean {Private: String Name; public: string getName () {return name;} String setName (String vName) {name = vname;} ------ } As for the specific word implementation mechanism, see "Mastering Enterprise JavaBeans Second Edition". The container creates an instance of the subclass. By the comparison of the parent son class, the subclass implements a persistence property of an entity bean through a private field and inherited attribute GET / SET method. The deployment tool is to generate this subclass based on the internal provincial mechanism of Java Bean. Such bean providers only need to specify the abstract accessor function of the persistence field, and other persistence implementations have tool-assisted completion. But we must notice that in order to specify a persistent field, the provider must hardly encode two access methods. Similarly, we note that in order to create an entity bean, we provide a type String parameter for the EJBCREATE method. Such code undoubtedly establishes only only one persistent field of this entity. Similar to the statement below also the statement statement when accessing the database: statement st = conn.createstatement (); st.execuate ("INSERT INTO PERSON (NAME) Value ('john')"); extensive use of similar hypotheses There is a data interaction of ActionForm and HTMLTAG custom labels in the ActionForm and HTMLTAG custom labels in the Struts view - model data exchange. I have said that this assumption is that the fixed field assumes that this hypothesis code implementation mechanism is a CMP entity Bean class mechanism, which is to pay attention to this feature in J2EE.
3 Unexlate field assumptions and scripting language technology fixed fields assumes that the CMP entity bean type mechanism hardcodes the persistence field, the name, number, and type of the field (known as the three attributes of the persistence field) are at least one fixed. It's below, making the work of changing the persistence field inevitably affect the source code, which produces a series of annoying code trees. Unscience field assumptions and scripting language technologies are to separate the three attributes and source code of the persistence field, and ultimately reach the customer to order the purpose of persistence fields. Typical implementation techniques include XML, dynamic compilation technology, metadata technology, dictionary collection technology, etc. These technologies have a common point that does not fix the persistence field, with a ductile field of data containers and a separate analysis code. Analyze the code interpret the persistence field in the data container and finally execute the database operation. Dynamic compilation technology is a transition technology that can dynamically generate source code according to customer configuration, and then compile to generate byte codes in time, deployed into applications. 3.1 XMLXML is a very good data exchange format, which has a good mode definition (DTD), DTD is metadata of the XML document, defining the format and composition of the data in the document. The data name (element name or property name) and data value (element text, or attribute value) are also included in the XML document. In addition, there is a strong XML document analysis and use API, including JAXP, JAXM, etc. JAXP set DOM analysis technology for Simple XML programming interface SAX and node based on event analysis. JAXM is a programming interface that transmits reception and message processing using XML. XSLT can easily turn the XML document into other formats such as HTML, Java source, and so on. 3.2 Dynamic Compilation Technology Use XML to express user configuration information, XSLT converts this information into a corresponding Java source code, then compiles the word pick code in time with java.lang.Compiler class. Of course, you can also generate other auxiliary classes, SQL statements, and more. For details, please refer to http://www.javaworld.com/javaworld/jw-02-2002/jw-0201-XSLT.HTML
3.3 Data Technical Metadata Technologies Put the description of the data in the data dictionary, and the user access the data dictionary to obtain information about the data. The data dictionary can be placed in an XML document or on the database server. After the client is configured, the developer access the data dictionary can get the customer's current persistence field and generate the correct code. 3.4 Dictionary Collection Technology Java's Haxi table and other datagical class set data structures can transfer changes in the method call. Or usually our method call is how many fields in the table, the function of filling the database is generally received, so that the persistence field is hardly encoded into the source code, and the persistence field changes will cause the source code. Dictionary collection technology makes the interface of such a function to be fixed. 4 A simple task for applying the above analysis, refers to how to achieve loosely coupled to the database table field, which proposes a simple task: Be a collection of acquisition personnel information. We have a rough analysis to get a person class, temporarily named Person, but we can't make it. WAF framework is used. See the WAF framework can be found
Http://www-900.ibm.com/developerWorks/cn/java/l-j2eearch/index.shtml
4.1 Design I, Dictionary Collection Technology and Metadata Technology Next Design (Figure 1) (Figure 1) Indicates that the customer issues an HTTP request, the container is positioned to the Person.jsp, this web page is divided into the server section and the client part, the server part is running in the container. Instructions, these instructions will build the client section of the page on the client browser. The client part aggregates (inclusive) an HTML form, the form has a submission button, the customer can click this button to issue a request. Depending on the WAF framework process, we design a class of PersonHtmLAction to process users' submission requests. Below is this key class design instructions: Field: Connection Conn saves the database connection obtained from the container connection pool; HashTable ReqhashnameValue saves the name-value pair extracted from the form submitted by the user; HashTable targethasenametyType saves from the database About Data Table Persight_Table Metadata - Field Name - Type Pair; HashTable FinalHashnameValue saves the name-value pair inserted into the database; function or method: Connect getConnect () Get database linkage from the container connection pool; HashTable getReqHashNameValue () name extracted from the form submitted by the user - the value; Hashtable getTargetHashNameType () obtains metadata about the data from the database table persion_table - field name - type pair; Hashtable getFinalHashNameValue () was filtered off reqHashNameValue fields in accordance targetHashNameType Excessive fields, get the name-value pair that last inserted into the database; Void INSERT () According to the type of TargetHashNameType and the name-value of FinalHashNameValue, the SQL statement is operated. These functions are called by a function perform of the parent class HTMLAction in the WAF framework. Figure 1: Dictionary collection technology and metadata design diagram 2 expressed the loose coupling effect of this design. The first place between the form and the processing class, and the data transfer between them makes full use of the Haxi Dictionary. Direct benefits is that we can develop custom forms to let customers customize their application's input interface, and customers can increase the various input elements to forms without affecting the processing classes in the background. The second place is between the processing class and the database table, and the data transfer between them fully utilizes metadata information in the database, and the direct benefit of achieving the tool we can develop customized data sheets to customize the most fields of the data sheet. Customers can increase or modify the fields but do not affect the processing class. 4.2 Design II, XML Technology, Haxi Technology and Metadata Design (Figure 3) Different from Figure II, we add JMS technology inside the control layer, using XML as the data exchange format. The class of XMLPersonhtmLAction handles the user's submission request, and Personmdb inserts the data into the database. Below is the two key class design descriptions: XMLPERSONHTMLACTION class function or method: String getReqXML () call getParameters () gets the client's submission data, generates an XML document; void sendxml () generates a temporary queue as a feedback queue of the message, using The JMS API sends the XML document returned by getReqxml as a JMS message.