JDO + JSP2.0 Development Web Application Wizard - Configuration

zhaozj2021-02-17  36

JDO JSP2.0 Development Web Application Wizard - Configuration

This article will mainly introduce the application development process of current popular JDO specifications. For simplicity, JSP 2.0 will be used to develop the development of the page part, because its JSP EL can greatly simplify the development of the page, save debugging time, and increase the readability of the page.

Previously, I have published an article on the use of JDO development database applications, which is just a database-based simple text mode, just to express the principles and basic processes of JDO development, now this article will be more Pay attention to practicality, to the readers of interest to the use of JDO to develop the development process of currently popular Web-based three-layer structure database applications.

Before starting development, we need to build a development environment first. Here first explains the third-party product for development.

1 system environment

1.1 mysql and its JDBC driver

The web application we develop is a database-oriented, of course, a bottom-level database support. We use the free database product MySQL as the underlying relational database.

On the {www.mysql.com}, download the latest version 4.0.16, we download the 19M size Zip package that does not have the installer, we will get this to the C: / directory to form a C: / mysql-4.0.16 directory (using in the future), then run /bin/winmysqladmin.exe, so that the mysql service is installed onto the unit and started.

The next development is based on Java, we also need to download the latest JDBC driver on www.mysql.com: 3.0.9. We will download the ZIP package solution, where the mysql-connector-java-3.0.9-stable-bin.jar file in the mysql-connector-java-3.0.9-stable / directory is the JDBC driver JAR we need. Document. For convenience, it can be renamed the mysql.jar file and put it in a directory for use.

To test the connection of MySQL JDBC, you can download a Database Delivery tool specially facing JDBC: Squirrelsql, its URL is: {http://squirrel-sql.sourceforge.net}. This is a free software. Note There are two questions when connecting mySQL:

1. The database is available directly with the "Test" library that comes with Mysql installation, no username and password. Some custom MySQL installations set the username to "root" or "sa". If the empty user name is not connected, you can try "root" or "sa".

2. In order to be able to use Chinese, you need to set the parameters using the GBK character set in the JDBC URL connected to MySQL: JDBC: mysql: // localhost / test? Useunicode = true & characterencoding = GBK

1.2 JDO and JDogenie products

JDO is the core of this article as a data object packaging layer we developed a web application. To configure the JDO environment as simple as possible and fastest, we use the simplest easy-to-play JDogenie as JDO Implementation. In addition to achieving standard JDO specifications, this product has the following characteristics related to our development process:

1. Integrated graphics configuration interface Workbench, basically implement all configuration functions

2. In the collection frame, support java.util.list. This is an optional JDO feature.

3. Supports two-way relationships of automatic maintenance. This is also the characteristics of JDO2.0 will join, and there is currently no other JDO products to do. 4. Support ANT integration, you can run the ANT script in its integrated configuration interface to compile, class enhancements, etc.

5. Supports the size () method of the query result set, returns the number of accurate eligible total records. (This method will return 0 or INTEGER.MAX_VALUE in some JDO products, which is allowed by the JDO specification.)

Let's go to JDogenie's website {www.jdogenie.com} to download the current latest version: 2.2.0beta7, is a zip package that is unlocked into a directory. We assume that this is unmarkable into a c: /jdogenie-2.2.0beta7/ directory, in the future, we use to replace C: /jdogenie-2.2.0Beta7/ directory.

In addition, after downloading JDogenie, you need to apply for a trial License. According to the page prompt, we need to fill your own mailbox, and some other information, after submitting the application, will send an email with attachment, this attachment is Trial license The file name is: jdogenie.license, pay attention to this attachment file must be saved with mail client programs (such as Outlook Express or Foxmail), many netizens saved this attachment through IE browser mailbox mail mailbox mail mailbox When this file is changed, it cannot be used.

Before running JDogenie, we need to install JDK in the system, recommend the latest JDK1.4.2. After installing JDK, set up a jdogenie required environment variable: Java_Home, which points to the root directory of the installed JDK, such as: c: /jdk1.4.2/. This variable is also required in the JSP server RESIN that will be mentioned below.

After setting up JDK, we run /workbench.bat directly, enter the JDogenie's integrated configuration environment, as shown below:

Briefly introduce this interface:

1. Top is a menu and toolbar

2. On the left is JDO-based workspace (individual responsibilities may use different workspaces), in turn:

a) Tree diagram This can see the internal properties of classes and classes, which is convenient for setting. However, it is generally not used.

b) UML class zone This can display the relationship between the data class

c) Class and class attribute list area, and the main work area here lists the various JDO related configurations of the data classes used in this project, the main configuration work is also completed in this area.

d) The database creation area is used to convert the object model to the SQL of the corresponding database built table, and generate a database structure.

e) The query area, the work area that is important when maintaining maintenance after application is running, and can perform JDOQL queries here, and can perform attribute changes to the objects in the query result set. After submit, the data in the database will update data after the changed data. . You can also perform SQL operation here, such as a class adds an attribute, executes a SQL operation that adds a field to the table.

f) The remote console is mainly connected to the remote JDogenie engine and observes the workspace of the server health. Which jdoql and generated SQL have been run how many times, the average occupation time is how much in order to optimize (such as add index) , Improve query code, etc.)

3. The bottom is a status bar. When an operation is wrong, the status bar will display the latest error description with red, click the first button on the right side of the status bar to view detailed error messages. The status bar shows how much memory occupies the current JDogenie table, if it is found that too many memory is occupied, it is estimated that there are too many garbage objects, you can click on the rightmost garbage collection button for memory release. 1.3 Ant: Java Batch Tool

As a batch tool in Java development (similar to Make tools in C / C , it is mainly used for compilation, environmental settings, file organizations, etc.), ANT is one of the biggest contributions to the Java world, now has become Java. Domestic batch depends on facts. About Ant's introduction article is a lot, you can find a lot in {www.9cbs.net}, not more introduced here. Let's go to Ant's website {http://ant.apache.org} Download the latest version: 1.5.4, download is a zip package, unword to a directory. Here, it is assumed to unlock to the C: / Apache-Ant-1.5.4 / directory, and below is used instead of the C: /Apache-ant-1.5.4 directory.

Note that some HTTP proxy has filtering some scripts on the {http://ant.apache.org/} home page, causing some users to see content when they may access this page, at this time, you can directly access {http: // Ant.apache.org/bindownload.cgi} to download Ant1.5.4.

In order to pass the DOS command line processing directly, we recommend configuring the path environment variable in the system, add the / bin / directory to it so that you can enter "Ant" to run directly in the command line status " /lib/ant.bat "command.

Ant is a Java-developed product, which is also based on the Java_Home environment variable mentioned earlier. Ant uses it to find JDK, thus running the ANT batch script prepared by the user.

Now Ant is installed, let's open JDogenie, configure an integration with Ant: Select menu "FileàWorkBench Settings ...", perform JDoGenie's environment configuration interface, we set up the path to the inlet program Ant.bat in which Ant is set, as shown :

Here, the author's Ant is installed in the D: / Bak / Ant directory, readers need to set their own /bin/ant.bat path according to their own actual situation. Other settings are recommended.

1.4 JSP and RESIN server

For easy understanding, this article will write JSP pages in JSP 2.0 standard, JSP2.0 define a very useful data output method: JSP EL (JSP Expression Language), can pass standard JavaBean getxxxxxx () / isxxx ( ) And setXXX () to implement the output of Java object data, and JSP2.0 also incorporate a set of tag libraries: JSTL, containing many commonly used JSP page processing mechanisms, such as loops, conditional display, and so on. About the function introduction of JSP2.0, you can also search for "JSP 2.0" related articles on {www.9cbs.net}.

At present, JSP2.0 specification has not been officially introduced, still in the proposedFinalDraft-3 stage, but will be officially released soon. Support JSP2.0 servers have Tomcat5, Resin3, etc. For convenience, easy maintenance purposes, we use RESIN to make JSP servers. First to the RESIN website {www.caucho.com}, upload the latest version 3.0.4. Download now is a zip package that is unlocked to a directory. Assuming that we solve the contents in the package to form a C: / Resin-3.0.4 / directory, we will use to represent the "C: / Resin-3.0.4" directory. After completing the above work, we entered the / bin directory, run the httpd.exe program, you can see the RESIN server started. If you want to install the RESIN as a service, you can use httpd.exe -install installation and use NET Start Resin to launch the Resin service. However, in order to facilitate the output log of the RESIN server, we do not recommend installing resin for system services, and it is recommended to run httpd.exe to launch RESIN directly. The RESIN server has the following features:

1. Automatic detection of web applications and updates to monitor the subdirectory of / WebApps /, can dynamically release or cancel a web application, you can also monitor web-inf / web.xml of a web application. Update to move the application

2. Automatically compile update Java files, if resin detects a Java source file under an application's web-inf / class, it will automatically compile this file.

3. Detect the JSP file update, if a JSP page is updated, RESIN recombines it. (This function is mostly the JSP server)

After Run, we open the Internet Explorer browser, enter: {http: // localhost: 8080 /}, you can see the main page of Resin, indicating that RESIN has been successfully run, as shown:

2 web application: forum

In the following two chapters, we will experience the development and maintenance process of a forum project, from the original very simple demand, to development, run, then experience a series of demand changes and function improvements, come and see using JDO How to achieve the rapid development and maintenance of the software and the application of the application. Moreover, it also involves some old problems such as the development of traditional JDBC development (such as string field length limits).

2.1 Preparation Work

Before starting development, we must first figure out some basic concepts and establish a corresponding operating environment by J2EE for web applications.

2.1.1 Knowing the development process of JDO on JDO development processes, some of the previous articles and online materials have also been detailed, here is simply repeated:

First write the class representing the data object, compile the generated .class file, and write metadata that describes the saving details of each attribute in this class: .jdo file, then enhance the .class file according to the .jdo file, this The data class can be called through the JDO API in the code. The illustration is as follows:

2.1.2 Establish an application directory structure in accordance with WebApp specification in J2EE

In order to reduce the integrated configuration with RESIN, we put the forum application directly in / WebApps / under the establishment of a subdirectory named BBS. This way, you can access this web application by adding "/ BBS /" behind the server address. In the BBS directory, we build a "web-inf" subdirectory according to the J2EE specification, and then build two subdirectories "Classes" and "lib" in Web-INF, and support MySQL JDBC's support for mysql.jar and JDogenie The jdogenie.jar and jta.jar under the jdogenie> / lib / directory are copied to this / WebApps / BBS / Web-INF / LIB directory, as a third-party component dependent on this application, and will /license/jdogenie.license file is copied to the / webapps / bbs / web-inf / class of. These configurations are integrated into the BBS application.

Next, we start determining the package structure of the Java class for the BBS application. Simply put, we put the source files in the "JDobbs" package, that is, the Java source code involved in this app will begin with "package jdobbs;".

After these catalogs are built, we get the following directory structure:

Let's put a index.jsp file in the BBS directory:

jdo bbs on $ {pagecontext.request.servername} </ title></p> <p>Your present location: <b> JDO BBS Home </ b></p> <p><h3> Welcome to JDOBBS! </ h3></p> <p><p> This system uses JDO JSP 2.0 to complete <P></p> <p><p> Your browser type is: $ {header ['user-agent']}</p> <p><p> Your IP address is: $ {pageContext.Request.RemoteAddr}</p> <p>Then start RESIN to see the effect:</p> <p>it is good! Now our first JSP page has been completed. "$ {PageContext.Request.servername}", "$ {pageContext.request.servername}", "$ {pageContext.Request.RemoteAdddr}" is defined in JSP2.0. JSP EL expression.</p> <p>2.1.3 Tools for processing JDO resources: jdobbs.sys</p> <p>Let's first write a very critical tool class: jdobbs.sys, this class is responsible for handling some basic JDO storage managers get transactions in terms of transactions. Regarding each of these details, you can use a large article (for details, see {http://www.jdocentral.com/index.php?s=8bf08748EA2B95FE52E0D25C7A489732 &CT=SF=11}), Here is the simplicity of simplicity, just describe the goals of this tool class: 1. Ensure that all business logic methods in the server threads for each JSP page request share the same Javax.jdo.PersistenceManager unless explicitly closes the current PersistenceManager in the middle of the process. This will be implemented in java.lang.threadlocal interface</p> <p>2. Ensure that each page request is completed, the JDO resources involved in the process request are all released (ie the PersistenceManager that is closed). This will use the Javax.Servlet.filter interface to implement us to see the Sys.java source code below:</p> <p>Package JDOBBS;</p> <p>Import javax.jdo. *;</p> <p>Import javax.servlet. *;</p> <p>Import java.io. *;</p> <p>Import java.util. *;</p> <p>Public Class Sys Extends Threadlocal Implements Filter {</p> <p>/ ** Get the persistenceManagerFactory * /</p> <p>Public Static PersistenceManagerFactory PMF () {</p> <p>IF (PMF == NULL) {</p> <p>Properties P = new profment ();</p> <p>InputStream is = sys.class.getResourceceAsStream ("/ jdobbs.jdogenie");</p> <p>Try {</p> <p>p.Load (IS);</p> <p>} catch (ioException ex) {</p> <p>Throw new runtimeException ("Initialization PersistenceManagerFactory when configuring the configuration file reading!", EX);</p> <p>}</p> <p>PMF = JDOHELPER.GETPERSISISTENCEMANAGERFACTORY (P);</p> <p>}</p> <p>Return PMF;</p> <p>}</p> <p>/ ** Get the PersistenceManager</p> <p>* By using the ThreadLocal object, the same PM object will be returned each time the method is called in the same thread.</p> <p>* /</p> <p>Public Static PersistenceManager PM () {</p> <p>IF (threadlocal == null) {</p> <p>Threadlocal = new sys ();</p> <p>}</p> <p>Return (persistencemanager) threadlocal.get ();</p> <p>}</p> <p>/ ** Used to release the JDO resources used in this thread</p> <p>* @return has unfinished Transaction, which is convenient for background log difference records</p> <p>* /</p> <p>Public static boolean cleanupResource () {</p> <p>Return threadlocal! = null && threadlocal.cleanup ();</p> <p>}</p> <p>Private static persistenceManagerFactory PMF;</p> <p>/ / ============== The following is the related method of Threadlocal ======================================================================================================================================================================================================================</p> <p>Private static sys threadlocal; // A controller for ensuring only the same thread only accesss the same PM object</p> <p>/ **</p> <p>* Get a PersistenceManager associated with the current thread</p> <p>* @Return's object of a PersistenceManager type, the caller needs to force to convert a type.</p> <p>* /</p> <p>Public Object get () {</p> <p>PersistenceManager PM = (persistenceManager) Super.get ();</p> <p>IF (PM == null || pm.isclosed ()) {</p> <p>PM = PMF (). getPersistenceManager ();</p> <p>Set (PM);</p> <p>}</p> <p>Return PM;}</p> <p>/ **</p> <p>* Release all JDO resources related to this thread</p> <p>* @return has unfinished Transaction, which is convenient for background log difference records</p> <p>* /</p> <p>Public boolean cleanup () {</p> <p>PersistenceManager PM = (persistenceManager) Super.get ();</p> <p>IF (PM == Null) Return False;</p> <p>IF (pm.isclosed ()) {</p> <p>Set (null); return false;</p> <p>}</p> <p>Boolean tsactive = false;</p> <p>Try {</p> <p>Transaction ts = pm.currenttransaction ();</p> <p>Tsactive = ts.isactive ();</p> <p>IF (tsactive) ts.rollback ();</p> <p>} finally {</p> <p>set (null);</p> <p>PM.Close ();</p> <p>}</p> <p>Return Tsactive;</p> <p>}</p> <p>/ / ============= Or above is the related method of threadlocal ===============</p> <p>/ / ============= The following is the relevant method of the JSP filter ===============</p> <p>Public void init (FilterConfig P0) THROWS servletexception {}</p> <p>Public void destroy () {}</p> <p>/ ** JSP page (servlet) The filter method is used for JSP execution, and the JDO resource used is detected and released. * /</p> <p>Public Void Dofilter (ServletRequest Req, ServletResponse Res, Filterchain</p> <p>FC) throws servletexception, ioException {</p> <p>Try {</p> <p>fc.dofilter (Req, RES);</p> <p>} finally {</p> <p>CleanupResource ();</p> <p>}</p> <p>}</p> <p>/ / ============= or more is the relevant method of JSP filter ===============</p> <p>}</p> <p>Simply put, this class provides a static PM () method, you can get a JDO storage manager PersistenceManager, which will be the most used in the later code.</p> <p>The SYS. PMF () is used to obtain the PersistenceManagerFactory, which is used in this method: jdobbs.jdogenie, this file is the JDogen's configuration file we want to generate, that is, the application configuration file will be generated in Workbench, where Includes database connection addresses, users, password information, and some performance adjustment settings. This profile jdobbs.jdogenie will be placed in the BBS / Web-INF / CLASSES / directory for program read.</p> <p>This SYS class uses the servlet's filtering interface to ensure that the JDO resources related to each JSP are completed. Therefore, when compiling this class, be sure to include servlet2.4's support pack in ClassPath, this package is "<RESIN> /LIB/J2SDK-24.jar" file. For the convenience of compiling and performing other work, we write an ANT script as a tool for performing various batch (including compilation). 2.1.4 Configuring a JSP filter</p> <p>In order to take effect in front of the JSP Filter, we need to configure it into our web application, say it is to create (or change) BBS / web-inf / web.xml file, let's change the file, see Source code: Web.xml</p> <p><web-app></p> <p><filter></p> <p><filter-name> jdo_resource_clener </ filter-name></p> <p><filter-class> jdobbs.sys </ filter-class></p> <p></ filter></p> <p><filter-mapping></p> <p><filter-name> jdo_resource_clener </ filter-name></p> <p><url-pattern> / * </ url-pattern></p> <p></ filter-mapping></p> <p></ web-app></p> <p>This content ensures that each JSP page request is processed, the sys.cleanup () method will be executed to detect and clear the JDO resources used.</p> <p>2.1.5 ANT script</p> <p>According to the standard of Ant, we write a script called "build.xml", and for the convenience of configuration, we put this file in the BBS / Web-INF / directory.</p> <p>Let's take a look at the source code of this Ant script: build.xml</p> <p><Project name = "jdobbs" default = "enhance"></p> <p><Property Name = "resin" location = "d: /resin-3.0.4" /></p> <p><Path ID = "CP"></p> <p><Pathelement Path = "$ {rate} /lib/jsdk-24.jar" /></p> <p><PATHELEMENT PATH = "Classes" /></p> <p><fileset dir = "lib" incrudes = "*. jar" /></p> <p></ path></p> <p><target name = "compile"></p> <p><javac srcdir = "classes" classpathref = "cp" debug = "true" /></p> <p></ target></p> <p><target name = "enhance" debnds = "compile" description = "enhance the compiled class"></p> <p><taskdef resource = "jdogenie.tasks" ClassPathref = "cp" /></p> <p><jdo-enhance project = "$ {ant.project.name} .jdogenie" Outputdir = "classes" /> </ target></p> <p></ provject></p> <p>After putting this file in the BBS / Web-INF / directory, we turn on a DOS command line window and enter the directory, run: "Ant Compile", will see the following results:</p> <p>D: /RESIN-3.0.4/webapps/bbs/web-inf> ant compile</p> <p>Buildfile: build.xml</p> <p>Compile:</p> <p>[Javac] Compiling 1 Source File to D: /RESIN-3.0.4/webapps/bbs/web-inf/classes</p> <p>Build Successful</p> <p>Total Time: 2 Seconds</p> <p>D: /RESIN-3.0.4/webapps/bbs/web-inf></p> <p>This result indicates that our Ant script has been successfully run. If you see the result:</p> <p>'Ant' is not internal or external command, nor is it a running program</p> <p>Or batch files.</p> <p>Then, your ANT is not configured (for example, if you open the DOS window, you can change the system's path environment variable), which is resolved by the ANT installation and configuration in this area.</p> <p>The content of the script is not explained here, please refer to the help of Ant. Here only shows: "Enhance" batch is defined in jdogenie.jar in jdogenie.jar, using a "JDO-Enhance" task, which is used to enhance class code.</p> <p>Ok, these preparations have been conducted, and there is no error in confident that the above work, we will access the home page again from the browser, and the result is exactly the same as the first home page, in line with expectations.</p> <p>Next, we can start real JDO analysis and design.</p> <p>2.2 Functional requirements</p> <p>Our initial demand is simple, that is, let users can communicate in this system, posted, reply, simply, can say this is a message. We want to achieve the following goals: 1. When a netizen enters the homepage, the system lists all the topics in the current order, and is nestled from near to far.</p> <p>2. Netizens can publish new topics in the posted form below the homepage, including title and content</p> <p>3. Other netizens Click on a title in the post list of the homepage to read this topic, including all posts. All posts are arranged in the subject of the subject in time order</p> <p>4. You can reply to this topic in the posts theme details page.</p> <p>5. Each netizen issues a topic or post, the system needs to record the client IP address when the post is published.</p> <p>6. The system provides an advanced search function that allows users to search for time, theme title, content or reply content, IP search topic</p> <p>2.3 Analysis, data object model and JDO integration</p> <p>Through the analysis of the needs, we found that the information that needs to be stored in the system is the topic or reply submitted by netizens. The subject and reply need to record the IP address of the netizen posted, there is text content, but the two are slightly different, the theme can have a title, but the reply does not need (the purpose is to make a reply), another, a reply The post must be directed to one theme.</p> <p>From the object-oriented point of view, we will pack the above data into the following object models:</p> <p>(After we will see how this picture is made out)</p> <p>2.3.1 Write a data class source code</p> <p>We write a base class according to the commonality of the post: POST (post), represents all themes and reply, have several basic properties with posts. And the subject class we use Topic to inherit from POST; There is a pair of multi-relationships between topics and replies, reflecting on Topic.Replies and Reply.topic properties. For JSP EL in JSP2.0, we give each property plus getter / setter (Many IDE tools). Let's take a look at the source code of these three files (note, put it in web-inf / classs / jdobbs / directory):</p> <p>Post-post.java:</p> <p>Package JDOBBS;</p> <p>Import java.util. *;</p> <p>/ **</p> <p>* Posts published by netizens, including topics and reply</p> <p>* /</p> <p>Public class pos {</p> <p>/ ** Post content * /</p> <p>String content;</p> <p>/ ** Lead content * /</p> <p>Int length;</p> <p>/ ** Posted by the IP address of the client machine * /</p> <p>String IP;</p> <p>/ ** Published this post * /</p> <p>Date PostTime;</p> <p>Public string getContent () {</p> <p>Return Content;</p> <p>}</p> <p>Public void setContent (string value) {</p> <p>CONTENT = Value;</p> <p>}</p> <p>Public int getLength () {</p> <p>Return Length;</p> <p>}</p> <p>Public void setLength (int value) {</p> <p>Length = value;</p> <p>}</p> <p>Public String getip () {</p> <p>Return IP;</p> <p>}</p> <p>Public void setip (string value) {</p> <p>IP = Value;</p> <p>}</p> <p>Public Date getPostTime () {</p> <p>Return PostTime;</p> <p>}</p> <p>Public void setposttime (date value) {</p> <p>Posttime = value;</p> <p>}</p> <p>}</p> <p>Topic Topic.java:</p> <p>Package JDOBBS;</p> <p>Import java.util. *;</p> <p>/ **</p> <p>* Topic</p> <p>* /</p> <p>Public class topic extends post {</p> <p>/ ** Title * /</p> <p>String Title;</p> <p>/** Replies */</p> <p>Int replycount;</p> <p>/ ** All replies * /</p> <p>List replies;</p> <p>/ ** Last update, that is, the last reply time * /</p> <p>Date lastupdate;</p> <p>Public string gettitle () {</p> <p>Return Title;</p> <p>}</p> <p>Public void settitle (string value) {</p> <p>Title = Value;</p> <p>}</p> <p>Public int getReplyCount () {</p> <p>Return replycount;</p> <p>}</p> <p>Public void setReplyCount (int value) {</p> <p>replycount = Value;</p> <p>}</p> <p>Public List getReplies () {</p> <p>Return replies;</p> <p>}</p> <p>Public void setReplies (List value) {</p> <p>Replies = value;</p> <p>}</p> <p>Public Date getLastupdate () {</p> <p>Return LaseTupdate;</p> <p>}</p> <p>Public void setlastupdate (date value) {lastupdate = value;</p> <p>}</p> <p>}</p> <p>Reply to reply.java:</p> <p>Package JDOBBS;</p> <p>/ **</p> <p>* Reply</p> <p>* /</p> <p>Public class reply extends post {</p> <p>/ ** Reply to the topic * /</p> <p>Topic Topic;</p> <p>Public Topic Gettopic () {</p> <p>Return Topic;</p> <p>}</p> <p>Public void settopic (Topic Value) {</p> <p>Topic = Value;</p> <p>}</p> <p>}</p> <p>In order to use the JDogenie tool below to configure the JDO environment, let's run the compilation task in the directory where build.xml is located: Ant Compile, compile these classes.</p> <p>2.3.2 Configuring JDoGenie to automatically create system.jdo metadata files, automatically build databases, etc.</p> <p>Next, we use JDogenie to implement this object model. Note that this step is very important!</p> <p>We entered the <jdogenie> / directory, run Workbench.bat, start our JDO trip. In the main window, we create a new JDogenie project through the menu "FileàNew Project ..." (this project is actually a JDogenIE configuration file), in the project file dialog box, we choose <resin> / webapps / bbs / web- INF / CLASSES / directory, and enter the project name in the file name input field (that is, the name of the configuration file): "JDOBBS.JDoGENIE", pay attention, please enter the full file name. Figure:</p> <p>After clicking OK, we will see a dialog box for project configuration settings. The configuration item is listed on the left side of this configuration dialog box, and the configuration content is performed. Note that "Project" and "Datastore" with a directory icon are also a configuration item. We will configure the necessary information item by item in this dialog:</p> <p>1. The first appears is the Project property setting, the top of the Project item, in this item, we select the "Non-Transactional Read" check box, so you can use the transaction directly through the Storage Manager (PersistenceManager) to access the database. Object. Figure:</p> <p>2. Next is an integrated configuration of Ant, the purpose is to facilitate calling Ant to complete the compilation and enhancement of the data class directly in the workbench. We need to enter the path where Ant.bat and build.xml are called. Figure:</p> <p>Of course, we can also always call Ant in the command line, which only needs to select "disable Ant" in the figure.</p> <p>3. ClassPath settings. Here you need to add the root path of the data class and the JDBC package of MySQL, as shown:</p> <p>4. Specify the metadata file. According to the requirements of the JDO specification, the data classes that need to be stored (also known as metadata or descriptors) must be used in. JDO. We choose the SYSTEM.JDO file under the ClassPath root to describe all data classes that need to be stored in this system. First select "JDO Meta Data Files" on the left of the configuration dialog, the following dialog box appears:</p> <p>Click the button "New" to create a system.jdo file in web-inf / class, as shown in the figure:</p> <p>Click the "Save" button back to the Configuration dialog:</p> <p>5. The remaining configuration items in the "Project" part are mainly used for adjustments such as performance optimization, and we will not consider it. Now click on the "Datastore" item, enter the database connection information configuration item, as shown: Click the "Choose" button, select the MySQL type database, and then enter the connection to the native mysql database in the URL bar: "JDBC: mysql: / / localhost / test? useunicode = true & characterencoding = GBK ", the GBK setting in this URL guarantees that mysql processing in Chinese will not garble. After configuration, the interface is as follows:</p> <p>Now, we can click the "TEST" button below to detect if the database can connect (before this, check if mysql has been run). If you can't connect, please check if the previous configuration is correct (IRL is added in the ClassPath configuration, whether the URL is entered correctly)</p> <p>So far, several of the "Datastore" section can be ignored, and directly click on the bottom "OK" button to close the configuration dialog. At this time, an empty interface is as shown in the figure:</p> <p>Here, briefly introduce the interface of JDogenie, a few big buttons on the left, representing the functions of all aspects (previously introduced), from top to bottom: class, class diagram, class list, database structure, JDO query And remote console. These features will be described later.</p> <p>We now add the data class written in front to the project, this step will generate the .jdo metadata file required in the JDO specification. In the first half of the top half of the above interface, click Right-click, select "Add Classes ..." in the pop-up menu, then the system lists the .class class files found from the ClassPath, we choose three: POST , Topic, Reply:</p> <p>After determining, the system prompts which metadata file and lists the "System.jdo" file created earlier. Click "OK" directly. We will see the main window to become the following:</p> <p>The fourth button "jdo metadata compile" on the toolbar turns red, indicating ambiguity in the information in system.jdo, click on this button to see the details:</p> <p>It turns out that the system does not know the element type of the Replies list (list) in the Topic class. In the main window, in the primary window of the interface, click Right click on the REPLIES attribute line, select "Field Properties ... ", Enter the dialog box for the Replies property setting, in the dialog, we need to set two items: first, select the JDobbs.Reply class in" element type ", indicating the element of the reply object; second item, Select "Topic" in "Inverse Field", indicating that Topic.Replies and reply.topic are a pair of two-way relationships, and the changes on any side affect the other side. Figure:</p> <p>After setting up, click the "" button in this dialog to close it. Now in the main window, the fourth button on the toolbar has become green (), indicating that the metadata has no problem. We save the project: "File-> Save", now you can enhance our data classes. Select the fifth button "BuildàCompile & Enhance" or click on the toolbar "", we will see the information successfully compiled and enhanced: Below we need to establish a corresponding data table for our data classes, we click on the left Big Button "Database Schema Operations ...", the system will list the data table structure required by the current data class. Here we only see a table, because our three classes are inheritance relationships, JDogenie is inherited. Use the same table to indicate. We select the menu "buildàrecreate schema" to generate this table structure in the database (if you change the class later, you can no longer be rebuilt, and you need to use the ALTER TABLE SQL statement in the JDO query area "Quelies" to solve it, otherwise Lost data):</p> <p>The above series of configuration processes are the process of our integration JDO. At first glance, it seems that the configuration is very complicated. In fact, the series can be completed soon, understanding the principle of JDO, it will feel very simple. In the future, this JDogenie's workbench Workbench.bat is our work environment. After we change the source code, we only need to click on the compile button here "", you can compile and enhance the latest source file. If you add more data classes, you only need to add new classes to your project (ie in the metadata) in this workstore.</p> <p>Finally, we recall the data class diagrams mentioned earlier, which is actually generated in the workbench of JDogenie. We click on the big button "Class and E / R DIAGRAGRAMS" to enter the class diagram area, right-click in the window, select "Choose Classes ...", add all the data classes to the map, will see containing POST, Topic, reply three classes of class, with a slightly adjustable position, you can get the previous class diagram, as shown:</p> <p>Ok, the above introduction is the many details of the JDogenie's workbench map open, in fact, we have not involved in the core part of JDO development: API's use. However, I believe that after the above introduction, the reader has a relatively comprehensive understanding of JDogenie implemented as a JDO. However, for JDO development, different products have different configuration tools and configuration operations, each with features, such as Kodojdo's database is configurable to synchronize with the data type model during runtime, this is deeply Developers love. It is grateful that JDogenie will soon be added this very favorable to rapid development and maintenance.</p> <p>Before we started the real JDO development trip, let's take a break, review the servers of the various levels mentioned earlier, including databases, JSP servers, JDO products, and more. In the "development articles" of this article, the readers will uncover the mystery of JDO, so that the readers see every detail in the development process ...</p> <p>The copyright of this article belongs to the author, but welcome to reprint, the premise is to indicate the source and the original. In addition, welcome to some of my articles in my column, and make valuable comments!</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-29863.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="29863" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.064</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'XD1kQrcpQh0tYrPPpjUPePnWwgR3Oz75RabiHjxd_2FBFQje8EZpRk8Tw69f5MGSQtkAxUOR9WZKeqhif73G7y9w_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>