Dialogue with J2EE developers, the database administrator needs to understand.
If you are an Oracle database administrator working with Java developers, you may have a lot of different views with them. For example, when they want to change the database mode to better store their objects, you may be very surprised; when they discuss WAR and EAR, you may feel very confused. In order to better help you communicate with J2EE developers, let's make a brief introduction to J2EE and see some challenges faced by J2EE developers.
What is J2EE?
Java 2 Platform, Enterprise Edition (J2EE) is an open standard for building and implementing portable, highly scalable enterprise applications. J2EE defines a platform for developing and deploying multi-storey applications. Several suppliers including BEA, IBM, Oracle, and Sun are supported by providing J2EE by providing a J2EE standard. In a non-professional language, the application server acts as an intermediate layer between the user and the database management system, providing a framework for building and deploying an enterprise application.
J2EE consists of several components. Current version J2EE 1.3 includes Java Servlets 2.3, JavaServer Pages (JSP) 1.0, Java Message Services (Java Message Services) 1.0.2, Java Transaction API 1.0, Java Database Connectivity (Java Database Connection, JDBC 2.0, J2EE Connector Architecture (J2EE Connector Architecture) 1.0, Java Naming and Directory Interface (Java Name and Directory Interface, JNDI) and JavaMail 1.2 and other components.
Let us learn more about those technologies interested in database administrators.
JDBC: The entry point of the database
The Java application can connect the database (such as an Oracle Database) using the Java Database Connection (JDBC) application programming interface (API) using the SQL * NET protocol with Oracle Technology. As one of the core J2EE technology, JDBC is used by most J2EE applications, including servlet, JSP, and EJB. JDBC enables application developers to embed SQL statements into their Java code to access and update the database.
Use JDBC to help Java developers connect to Object Examples, and they usually use these object examples to operate on relational databases. Object-oriented examples support to build applications from objects with data and behavior. Relationship Database Technical Support The data is stored in the table via SQL calls and operates in the table.
In order to speed up the J2EE application's database connection speed, the Oracle9i Application Server (Oracle9ias) provides connection sharing features. In the past, developers were hard coded in the application, or packed the attribute file with the application they deployed. JDBC 2.0 Extensions By storing user IDs and passwords in an application server profile, making the application portability. Developers can view DataSource objects and create a connection. This means that as a database administrator, if you want to change a mode user's password, you may have to match the application server administrator to make this change.
There are several different JDBC drivers for different application servers, but as an Oracle database administrator, you may focus primarily for two universal types of drivers: Type IV (or known "thin" driver ) And Type II (that is, well-known Oracle Call Interface "driver or" fat "driver). The thin driver is purely written in Java, collaborates with the JDBC driver class file class12.jar. The fat driver uses the OCI library, running on SQL * NET. Oracle9ias passed the authentication of these type drivers. The OCI driver can take advantage of some high availability extension features in Oracle in Net8 (Oracle's Network Connection Techniques). Oracle9ias not only work with Oracle database, but also certified by third-party databases such as DB2, MS SQLServer and Sybase. You can download the DataDirect JDBC driver capable of connecting Oracle9ias to these databases from the Oracle Technology Website (OTN). Servlet: Alternative for CGI
Unlike the Java Applet downloaded to the browser, the Java Servlet resides on the server, which can be used to access the resources of the server, such as business logic, and the like. The servlet can operate on a database stored in a database or from multiple data sources. As an outstanding server-side web technology, Java Servlet actually replaces the General Gateway Interface (CGI) script because servlets provide better performance and supported by multiple vendors. JSP has improved the Java technology to supplement Java technology by allowing Java code segments to embed Java technology, thereby improving labor division of labor between Web designers and Java programmers. When the user calls, the JSP code can be automatically compiled and converted to Java servlet.
Most agencies build a business application with Servlet and JSP code by using a persistent layer (such as Oracle9IAS Toplink or writing its objects) in the database. As the protector of the database, you should carefully check these Java programmers to use SQL statements used to query and data operations in their programs, and ensure that their SQL statement does not generate serious consequences - for example, performing the production database Most millions of records scanned.
Figure 1: The life cycle of entity beans (see the description in Table 1)
Table 1: Entity Bean method
Method Operation This is a database administrator you mean what ejbload () load bean instance. Usually use a SELECT statement to retrieve lines from the database. ejbcreate () Create a bean instance. Save the bean by inserting a line into the database. EjbPostCreate () Sets the value of the relational domain in the bean. An external keyword domain is usually set using a UPDATE statement. EJBSTORE () Updates the corresponding bean in the database. An entity bean instance is usually updated using a SELECT for Update or UPDATE statement. Findbyxxx () Find beans based on a certain condition. A SELECT statement is usually used to remove (FETCH) or more lines. ejbremove () Delete the bean instance. Remove the corresponding rows from the database table.
EJB: Logic of applications
EJB is an reusable component of the Java application running inside the EJB container, which can be called locally or remote through the Java program or CORBA client. Since EJB is implemented in a container that provides services such as things, persistence, and BEAN access control, developers do not have to develop these services. There are three types of EJB: session beans, entity beans, and messaging beans (Message-Driven Bean, MDB). Session bean describes those business logic that is essentially instantaneous and cannot be surprised by machines or server failures. There are two types of session beans: stateless and stateful. The stateless session bean does not retain any state between the session -, for example, which session makes a stateless session bean a better choice for credit card billing. However, stateful session beans can retain the state between sessions or method calls - so stateful session beans are suitable for describing a business logic for shopping carts. The session bean can connect to a database by using JDBC. Entity Bean: Provide persistence
For database managers, entity beans are attractive and difficult because they are lasting and need an external database (such as Oracle Database). As an alternative to entity beans, some institutions may decide to use a persistent layer (such as Oracle9ias Toplink) or the code to be used to hold data in the database in the database. However, entity Beans is very useful in some cases. For example, an entity bean may indicate an employee record in a group or an employee table in a client table. Entity Beans is also shared between multiple clients. For example, an Employee entity bean can be used by multiple different clients to calculate annual salary or modify employee addresses. EJB server failure can cause a transaction to roll back, but do not destroy entity beans because entity beans are representative of permanent data from the database. The same entity bean can be reconstructed by reading data from a persistent memory. As with database records, entity beans are only identified by its primary keyword. (See the entity bean lifecycle and its methods in Figure 1.)
The EJB specification defines two types of entity beans: beans manage persistence (BMP) beans and beans managed by container management (CMP). For BMP Bean, Bean developers write SQL code in their beans to create, modify, and delete data in your database. So when your Java programmer is using BMP Bean, you must know! You should look at the SQL statement they have to make sure the finder method has an indexed SQL statement - otherwise, you will have to end the full-mete scan using the database speed.
CMP bean requires your great attention. In CMP, the container generates all SQL statements, so you rely on the developer of the application server software to generate the correct SQL statement for you. When the CMP bean is deployed to Oracle9ias, persistent data can be automatically mapped to a specific database table by the container. This may differ from other applications or "containers". For an Oracle database administrator, this may be a problem that needs attention because most application servers (including Oracle9ias) use a proprietary algorithm to generate a table name. This way, you must work with developers to map entity beans to the correct mode.
Bean developers must define primary keywords for the CMP bean in the deployment descriptor and map the bean to the appropriate columns in the basic table. If the primary keyword is not specified for a CMP bean, the container will add a column to the table and use as the primary keyword. Oracle9ias named the column AutoID. If you don't know this, you will be surprised when you find an unnecessary column in your data model. The J2EE container (for example, Oracle9ias) uses its own algorithm to generate a unique value for the column. CMR (container management relationship) is a relationship between developers to create entities and where J2EE application servers manage these relationships. Take two entities of Department and Employees as an example, consider the possible various different relationships therebetween. Their relationship can be 1 pair of 1, 1 to more or more, which can be unidirectional or bidirectional. Oracle9ias manage relationships by using existing external key constraints or a third-party table (well-known binding table). (Multi-to-many relationships can only be managed by binding tables.) By default, the container will generate and name its own table to maintain entity relationships - these tables have some problems with database administrators.
You have to remember that creating entity beans with relationships requires two steps: The first step is created, and the second step is created. If you have a relationship with forced external key, you will have to mark the external key column as "Deferrable" in your database.
Comparison of EJB QL and SQL
EJB QL is a standard query language introduced in J2EE 1.3 for querying CMP Bean. EJB QL is defined by CMP definition entity beans's various Finder and SELECT methods. Developer / Deployers must specify an EJB QL statement in the deployment descriptor of the bean, and the container is usually converted to SQL at runtime. EJB QL is similar to ANSI SQL, but is limited, it lacks support for Date (date) function and ORDER BY clause. See Examples of the EJB QL statement listed in Table 2 and the SQL statements thereof.
Table 2: An EJB QL statement and its corresponding SQL statement
EJB QL statement SQL statement SELECT OBJECT (E) from Employe E WHERE E.EMPNO =? 1Select * from Emp Where Empno = & 1
Contents about business needs to be understood
J2EE Application Server allows EJB transactions to be declarative (application developers do not have to write transaction logic code) or programming. In general, J2EE transactions have long-term existence and will cross users. Like a database transaction, EJB transactions must comply with Acid (Atomic, Consistent, Isolated, And Durable,, ie original, consistent, alone, and resistance). For a declarative EJB transaction (or well known by container management transaction (CMT)), Bean developers must specify transaction attributes. Table 3 lists different types of transaction attributes.
Table 3: Attributes of EJB transactions
Transaction Attribute Description Requirements If there is a transaction, Bean will connect it; otherwise, Bean will start a new transaction. Requiresnew is required When the bean is called, a new transaction will begin. Support (supports) If there is a transaction, Bean will connect to it; otherwise, no new transaction is not started. Not supported (NotSupported) Bean cannot participate in a transaction. Mandatory always requires a transaction; otherwise it will produce an exception. Never (NEVER) If you use this property and call the bean in a transaction context environment, an exception will be generated. J2EE also supports two stages of submission between distributed transactions or resources. Oracle9ias now uses the Oracle9i database as an EJB two-phase submission coordinator and requires a database connection.
J2EE also allows you to specify different isolation levels as EJB according to the information in Table 4.
Table 4: Isolation level of EJB
Isolation Level Description Read Uncommitted) When using this isolation level, if your transaction is executed concurrently with another transaction, and other transactions write data to the database without submitting, then your transaction will be able to read these data. This isolation level is advantageous, but may generate problems such as dirty read, non-repeatable read and false reading (PHANTOM Read). Read Committed) When using this isolation level, your transaction will not read uncommitted data, so you can solve the problem of dirty reading. However, there will be problems such as non-repeatable read and false reading. Repeatable Reads When using this isolation level, no matter when you read the submitted data, it can be ensured that the same value has the same value when the same data is repeated again later. But there will still be a problem with dirty reading. Serializable This isolation level can ensure serialization of all transactions. It avoids all issues, but performance will be reduced.
As mentioned in Table 4, you must decide which one is more important for your organization, performance and data consistency. As a database administrator, you may tend to use the serialized option for data consistency. The EJB isolation mode usually depends on which isolation level is supported by the underlying data source. In the Oracle8i database and the Oracle9i database, the support is the read-committed isolation level and a serializable isolation level.
In addition to the EJB isolation mode, several application servers also provide locking modes for CMP beans concurrently controlled. Table 5 shows different locking modes available in Oracle9ias. These modes are combined with the serialized isolation level and read submitted isolation levels, providing many different concurrent strategies.
Table 5: Control CMP and develop in Oracle9ias
Oracle9IAS Entity Bean Lock Mode Description Optimistic Multiple users can perform entity beans parallel. This mode does not monitor resource contention; therefore, the responsibility for monitoring data consistency is handed over to the database isolation mode. Read-only multiple users can perform entity beans in parallel. The container does not allow any modification of the state of the bean. Pessimistic This mode management resource is not allowed to perform parallelism. Only one user is allowed to perform entity beans at a time.
To get better performance, you want to choose an optic lock mode or read-only lock mode. With message delivery products Oracle9ias can work with messages such as MQ Series, Sonic MQ, and SWIFT MQ. If your developer is using Java, then they may want to use Java Message Service, JMS, JMS is used by Sun, Oracle, and other corporate message product suppliers for enterprise Java standards for enterprise messages. . JMS provides an API for storing and retrieving asynchronous messages, and complements the synchronous communication modes determined by Java Remote Method Invocation, RMI. Oracle's JMS implementation - OracleJMS Provider is based on Advanced Queuing, AQ. Oracle Advanced Queuing (Oracle AQ) stores the message as a database record in the table, which provides the security, recoverability and guarantee of the message. Oracle's JMS implementation is a supercoming of the JMS specification, with an extension that supports AQ administrative operations and other AQ features that are not currently part of the JMS standard. This includes a message delivery gateway that automatically propagates messages to legacy applications (or from legacy application propagation messages). As an Oracle database administrator, using OracleJMS means you have to install and configure Oracle AQ and create the queues and topics used by each application. If you plan to use Oracle AQ that supports Message BEAN (MDB), you must use Oracle9i 9.0.1.4 or 9.2.0.2. For example, if your application requires a topic called Thetopic in Scott mode, you need to do the following: grant Scott Operation Oracle AQ: Grant Execute on sys.dbms_aqadm to scott;
Grant Execute on sys.dbms_aq to scott;
Grant Execute on sys.dbms_aqin to scott;
Grant Execute on sys.dbms_aqjms to scott;
Create queues and topics in the Oracle database, create and start THETTT / TIGER @ mydb;
Begin
DBMS_AQADM.CREATE_QUEUE_TABLE (
Queue_table => 'qt_topic',
Queue_payload_type => 'sys.aq $ _JMS_MESSAGE',
Multiple_consumers => true);
END;
/
EXEC DBMS_AQADM.CREATE_QUEUE
'Topic', 'qt_topic');
EXEC DBMS_AQADM.Add_subscriber
'Topic', sys.aq $ _agent ('MDSub', NULL, NULL);
EXEC DBMS_AQADM.Start_Queue ('Topic');
If Oracle9ias Containers For J2EE (OC4J) is correctly configured correctly (as shown below), now your J2EE application should be able to use the Topic in the Oracle database. From Data-Sources.xml: from $ OC4J_HOME / Config / Application.xml:
Oracle JMS
J2EE Database Tips are useful for the basics of any database tuning to J2EE applications. As a database manager, you know that the first step is to tune the SQL statement. You must find and improve the bad SQL statement that slows down the database running speed. To avoid full table scans, you may have to add more indexes into your application. For CMP Bean, this may be a challenging task because the container generates a SQL statement. In this case, you will have to cooperate with developers to build an index for the Finder / SELECT method with the SQL statement. You can use some open source tools such as P6SPY (www.p6spy.com) to get and record the actual SQL statements generated by your J2EE container's CMP engine. Because most applications using EJB is actually online transaction processing (OLTP), you can use regular database tuning knowledge to tune your database when developers using EJB. As a database administrator, you know that the database SQL processing engine is required to write optimized SQL statements. This is especially true in an expensive transaction processing system. In general, the SQL commands released by the OLTP application perform related lines each time. If an index can point to the exact bank you want, then your Oracle database can make an accurate plan to effectively access those rows through as short paths as possible. When you have a transactional application, it is also very important to tune the red log. Like any Oracle Database Application, you can use the Oracle StatsPack utility to collect databases and session level performance information to tun your database to make it possible to perform EJB applications. To get more details of database tuning, please see "Oracle9i Performance Tuning Guide and Reference, you can get it from OTN. Oracle.com/Documentation). Persistence, the biggest challenge is clearly, for the establishment of J2EE applications, making data lasting one of the biggest challenges. J2EE application developers have several persistent options: They can use JDBC to write persistence logic to build CMP beans in their application code, or use persistence layers such as Oracle9ias Toplink. The cost of building solutions in maintenance is extremely high. It has been placed in Oracle9ias Toplink for many years, and it is almost any situation in persistence. Toplink provides a persistent infrastructure that integrates data from a variety of architectures (including EJB (CMP, and BMP), conventional Java objects, servlets, JSP, session beans, and messaging beans. Toplink allows Java applications to access data as an object stored in a relational database, thereby greatly improving the productivity of developers. Toplink also has features that maximize database hit rate and network traffic and utilization by JDBC and database optimization to enhance application performance. Toplink is to achieve the above features by creating a metadata "Descriptor" (Map) set, which defines how to store objects in a specific database mode. Toplink uses these mappings to dynamically generate the desired SQL statement when running. These metadata descriptors (mapping) are independent of language and database, which can modify them without the need to recoib to the classes they represent. For more information on using Toplink, see.