View Javadoc
1   package org.melati.poem.test;
2   
3   import java.sql.PreparedStatement;
4   import java.sql.ResultSet;
5   import java.sql.SQLException;
6   import java.sql.Types;
7   
8   import org.melati.poem.AccessPoemException;
9   import org.melati.poem.AtomPoemType;
10  import org.melati.poem.ColumnInfo;
11  import org.melati.poem.NullTypeMismatchPoemException;
12  import org.melati.poem.ParsingPoemException;
13  import org.melati.poem.SQLPoemType;
14  import org.melati.poem.TypeMismatchPoemException;
15  import org.melati.poem.ValidationPoemException;
16  import org.melati.poem.dbms.Dbms;
17  
18  /**
19   * A PoemType which throws an exception when used. 
20   * @author timp
21   * @since 3 February 2007
22   *
23   */
24  public class SqlExceptionPoemType extends AtomPoemType<Integer> {
25  
26    /**
27     * Constructor.
28     * 
29     * @param nullable
30     *          whether nullable or not
31     */
32    public SqlExceptionPoemType(boolean nullable) {
33      super(Types.INTEGER, "INT", nullable);
34    }
35  
36    /**
37     * {@inheritDoc}
38     * 
39     * @see org.melati.poem.BasePoemType#_assertValidRaw(java.lang.Object)
40     */
41    protected void _assertValidRaw(Object raw) throws ValidationPoemException {
42      if (raw == null)
43        throw new NullTypeMismatchPoemException(this);
44      if (! (raw instanceof Integer))
45        throw new TypeMismatchPoemException(raw, this);
46    }
47  
48    /**
49     * {@inheritDoc}
50     * 
51     * @see org.melati.poem.BasePoemType#_canRepresent(org.melati.poem.SQLPoemType)
52     */
53    protected boolean _canRepresent(SQLPoemType<?> other) {
54      return false;
55    }
56  
57    /**
58     * {@inheritDoc}
59     * 
60     * @see org.melati.poem.BasePoemType#_getRaw(java.sql.ResultSet, int)
61     */
62    protected Integer _getRaw(ResultSet rs, int col) throws SQLException {
63      throw new SQLException("Dummy");
64    }
65  
66    /**
67     * {@inheritDoc}
68     * 
69     * @see org.melati.poem.BasePoemType#_rawOfString(java.lang.String)
70     */
71    protected Integer _rawOfString(String string) throws ParsingPoemException {
72      
73      return new Integer(string);
74    }
75  
76    /**
77     * {@inheritDoc}
78     * 
79     * @see org.melati.poem.BasePoemType#_saveColumnInfo(org.melati.poem.ColumnInfo)
80     */
81    protected void _saveColumnInfo(ColumnInfo info) throws AccessPoemException {
82  
83    }
84  
85    /**
86     * {@inheritDoc}
87     * 
88     * @see org.melati.poem.BasePoemType#_setRaw(java.sql.PreparedStatement, int,
89     *      java.lang.Object)
90     */
91    protected void _setRaw(PreparedStatement ps, int col, Object raw)
92        throws SQLException {
93      throw new SQLException("Dummy");
94  
95    }
96  
97    /**
98     * {@inheritDoc}
99     * 
100    * @see org.melati.poem.SQLType#sqlDefaultValue
101    */
102   public String sqlDefaultValue(Dbms dbms) {
103     return "1";
104   }
105 
106   /**
107    * {@inheritDoc}
108    * 
109    * @see org.melati.poem.PoemType#toDsdType()
110    */
111   public String toDsdType() {
112     return null;
113   }
114 
115 }