12.11.2014 Views

web server - Borland Technical Publications

web server - Borland Technical Publications

web server - Borland Technical Publications

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Setting Properties<br />

Automatic table mapping<br />

The <strong>Borland</strong> EJB container has the capability to automatically map Java types defined<br />

in the enterprise bean code to database table types. However, while it may create<br />

these tables automatically, it does not necessarily use the most optimal mapping<br />

approach. In fact, automatically generating these mappings and tables is more of a<br />

convenience for developers.<br />

The <strong>Borland</strong>-generated tables are not optimized for performance. Often, they overuse<br />

database resources. For example, the container maps a Java String field to the<br />

corresponding SQL VARCHAR type. However, the mapping is not sensitive to the actual<br />

length of the Java field, and so it maps all string fields to the maximum VARCHAR length.<br />

Thus, it might map a two-character Java String to a VARCHAR(2000) column.<br />

In a production situation, it is preferable for database administrators (DBA) to create<br />

the tables and do the type mapping. The DBA can override the default mappings and<br />

produce a table optimized for performance and use of database resources.<br />

While all relational databases implement SQL types, there may be significant variations<br />

in how they implement these types. Even when they support SQL types with the same<br />

semantics, they may use different names to identify these types. For example, Oracle<br />

implements a Java boolean as aNUMBER(1,0), while Sybase implements it as a BIT and<br />

DB2 implements it as a SMALLINT.<br />

When the <strong>Borland</strong> EJB Container creates the database tables for your enterprise<br />

beans, it automatically maps entity bean fields and database table columns. The<br />

container must know how to properly specify the SQL types so that it can correctly<br />

create the tables in each supported database. As a result, the EJB Container maps<br />

some Java types differently, depending on the database in use. The following table<br />

shows the mapping for Oracle, Sybase/MSSQL, and DB2:<br />

Java types Oracle Sybase/MSSQL DB2<br />

boolean/Boolean NUMBER(1,0) BITSMALLINT<br />

byte/Byte NUMBER(3,0) TINYINT SMALLINT<br />

char/Character CHAR(1) CHAR(1) CHAR(1)<br />

double/Double NUMBER FLOATFLOAT<br />

float/Float NUMBER REAL REAL<br />

int/Integer NUMBER(10,0) INTINTEGER<br />

long/Long NUMBER(19,0) NUMERIC(19,0) BIGINT<br />

short/Short NUMBER(5,0) SMALLINTSMALLINT<br />

String VARCHAR(2000) TEXT VARCHAR(2000)<br />

java.math.BigDecimal NUMBER(38) DECIMAL(28,28) DECIMAL<br />

byte[] LONG RAW IMAGE BLOB<br />

java.sql.Date DATE DATETIME DATE<br />

java.sql.Time DATE DATETIME TIME<br />

java.sql.Timestamp DATE DATETIME TIMESTAMP<br />

java.util.Date DATE DATETIME TIMESTAMP<br />

java.io.Serializable RAW(2000) IMAGE BLOB<br />

124 BES Developer’s Guide

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!