001: // $Id: TestOracle.java 7 2007-08-17 19:32:18Z jcamaia $
002:
003: package net.sf.persist.tests.oracle;
004:
005: import java.io.InputStream;
006: import java.io.Reader;
007: import java.math.BigDecimal;
008: import java.sql.SQLException;
009:
010: import net.sf.persist.tests.common.TestSimple;
011: import net.sf.persist.tests.framework.BeanMap;
012: import net.sf.persist.tests.framework.BeanTest;
013: import net.sf.persist.tests.framework.FieldMap;
014:
015: import org.junit.Test;
016:
017: public class TestOracle extends TestSimple {
018:
019: public String getProperties() {
020: return "net/sf/persist/tests/oracle/oracle.properties";
021: }
022:
023: // several tests are inherited from net.sf.persist.tests.common.TestSimple
024:
025: @Test
026: public void testStringTypes() throws SQLException {
027:
028: Class[] characterTypes = new Class[] { Character.class,
029: char.class, String.class };
030: Class[] stringTypes = new Class[] { String.class, char[].class,
031: Character[].class };
032: Class[] clobTypes = new Class[] { String.class, char[].class,
033: Character[].class, Reader.class };
034:
035: // oracle doesn't support queries by clob, long or nclob
036: BeanMap beanMap = new BeanMap("StringTypes").addField(
037: new FieldMap("longCol").setTypes(stringTypes).setSize(
038: 32).setSupportsQueryByValue(false)).addField(
039: new FieldMap("char1Col").setTypes(characterTypes)
040: .setSize(1)).addField(
041: new FieldMap("nchar1Col").setTypes(characterTypes)
042: .setSize(1)).addField(
043: new FieldMap("charCol").setTypes(stringTypes).setSize(
044: 255)).addField(
045: new FieldMap("ncharCol").setTypes(stringTypes).setSize(
046: 255)).addField(
047: new FieldMap("nvarchar2Col").setTypes(stringTypes)
048: .setSize(255)).addField(
049: new FieldMap("varchar2Col").setTypes(stringTypes)
050: .setSize(255)).addField(
051: new FieldMap("clobCol").setTypes(clobTypes).setSize(
052: 16384).setSupportsQueryByValue(false))
053: .addField(
054: new FieldMap("nclobCol").setTypes(clobTypes)
055: .setSize(16384)
056: .setSupportsQueryByValue(false));
057:
058: BeanTest.test(persist, beanMap);
059: }
060:
061: @Test
062: public void testNumericTypes() throws SQLException {
063:
064: Class[] longTypes = new Class[] { Long.class, long.class };
065: Class[] doubleTypes = new Class[] { Double.class, double.class,
066: BigDecimal.class };
067: Class[] floatTypes = new Class[] { Float.class, float.class,
068: Double.class, double.class, BigDecimal.class };
069:
070: BeanMap beanMap = new BeanMap("NumericTypes").addField(
071: new FieldMap("numberCol").setTypes(longTypes))
072: .addField(
073: new FieldMap("binaryFloatCol").setTypes(
074: floatTypes).setBoundaries(0, 9999))
075: .addField(
076: new FieldMap("binaryDoubleCol").setTypes(
077: doubleTypes).setBoundaries(0, 9999));
078:
079: BeanTest.test(persist, beanMap);
080: }
081:
082: @Test
083: public void testDatetimeTypes() throws SQLException {
084:
085: BeanMap beanMap = new BeanMap("DatetimeTypes").addField(
086: new FieldMap("dateCol").setTypes(java.sql.Date.class)) // oracle is picky about Date when used in queries
087: .addField(
088: new FieldMap("timestampCol").setTypes(
089: java.sql.Timestamp.class,
090: java.util.Date.class));
091:
092: BeanTest.test(persist, beanMap);
093: }
094:
095: @Test
096: public void testBinaryTypes() throws SQLException {
097:
098: Class[] binaryTypes = new Class[] { byte[].class, Byte[].class };
099: Class[] blobTypes = new Class[] { byte[].class, Byte[].class,
100: InputStream.class };
101:
102: // by default, oracle can't bind more than 4000 bytes to lob/long columns in a single statement
103: // oracle doesn't support queries by long_raw or blob columns
104: // only blobs support InputStream types
105: BeanMap beanMap = new BeanMap("BinaryTypes").addField(
106: new FieldMap("rawCol").setTypes(binaryTypes).setSize(
107: 1024)).addField(
108: new FieldMap("longRawCol").setTypes(binaryTypes)
109: .setSize(1024).setSupportsQueryByValue(false))
110: .addField(
111: new FieldMap("blobCol").setTypes(blobTypes)
112: .setSize(1024).setSupportsQueryByValue(
113: false));
114:
115: BeanTest.test(persist, beanMap);
116: }
117:
118: }
|