View Javadoc

1   /*******************************************************************************
2    *  Copyright (c) 2005, 2006 Imola Informatica.
3    *  All rights reserved. This program and the accompanying materials
4    *  are made available under the terms of the LGPL License v2.1
5    *  which accompanies this distribution, and is available at
6    *  http://www.gnu.org/licenses/lgpl.html
7    *******************************************************************************/
8   package it.imolinfo.jbi4cics.messageformat.jdbc;
9   
10  import it.imolinfo.jbi4cics.Logger;
11  import it.imolinfo.jbi4cics.LoggerFactory;
12  import it.imolinfo.jbi4cics.exception.FormatException;
13  import it.imolinfo.jbi4cics.jbi.Messages;
14  import it.imolinfo.jbi4cics.messageformat.FieldDescriptor;
15  import it.imolinfo.jbi4cics.messageformat.MappingDescriptor;
16  
17  import java.util.HashMap;
18  import java.util.Map;
19  
20  public class JdbcStatementDescriptor implements MappingDescriptor{
21  
22    public static final int PREPARED_STATEMENT=0;
23    public static final int CALLABLE_STATEMENT=1;
24    
25    public static final int UPDATE_SQL=0;
26    public static final int SELECT_SQL=1;
27    
28    /**
29     * The logger for this class and its instances.
30     */
31    private static final Logger LOG
32            = LoggerFactory.getLogger(JdbcStatementDescriptor.class);
33    
34    /**
35     * The responsible to translate localized messages.
36     */
37    private static final Messages MESSAGES
38            = Messages.getMessages(JdbcStatementDescriptor.class);
39  
40    
41    private String sql;
42    private int statementType;
43    private int sqlType;
44    private Map<Integer, FieldDescriptor> parameterList=new HashMap<Integer, FieldDescriptor>();
45    private Map<String, Integer> propertyNameParameterIndexMap=new HashMap<String, Integer>();
46    private Class beanClass;
47    
48    
49    public JdbcStatementDescriptor() {
50      super();
51      // TODO Auto-generated constructor stub
52    }  
53    
54    public JdbcParameterDescriptor getParameter(int paramterIndex){
55      return (JdbcParameterDescriptor)parameterList.get(new Integer(paramterIndex));
56    }
57  
58    /**
59     * @return Returns the sql.
60     */
61    public String getSql() {
62      return sql;
63    }
64  
65    /**
66     * @param sql The sql to set.
67     */
68    public void setSql(String sql) {
69      this.sql = sql;
70    }
71  
72    /**
73     * @return Returns the sqlType.
74     */
75    public int getSqlType() {
76      return sqlType;
77    }
78  
79    /**
80     * @param sqlType The sqlType to set.
81     */
82    public void setSqlType(int sqlType) {
83      this.sqlType = sqlType;
84    }
85  
86    /**
87     * @return Returns the statementType.
88     */
89    public int getStatementType() {
90      return statementType;
91    }
92  
93    /**
94     * @param statementType The statementType to set.
95     */
96    public void setStatementType(int statementType) {
97      this.statementType = statementType;
98    }
99  
100   public void addFieldMapping(String propertyName, String fieldName, FieldDescriptor fieldDescriptor) throws FormatException {
101     // TODO Auto-generated method stub
102     
103   }
104   
105   public void addFieldMapping(String propertyName, Integer fieldIndex, FieldDescriptor fieldDescriptor) throws FormatException {
106     if (!(fieldDescriptor instanceof JdbcParameterDescriptor)){
107       LOG.error("CIC001805_Jdbc_parameter_descriptor_not_found", fieldDescriptor.getClass());
108       throw new FormatException(MESSAGES.getString("CIC001805_Jdbc_parameter_descriptor_not_found", fieldDescriptor.getClass()));
109     }     
110     parameterList.put(fieldIndex,fieldDescriptor); 
111     propertyNameParameterIndexMap.put(propertyName,fieldIndex);  
112   }  
113   
114   /**
115    * @return Returns the propertyNameParameterIndexMap.
116    */
117   public Map<String, Integer> getPropertyNameParameterIndexMap() {
118     return propertyNameParameterIndexMap;
119   }
120 
121   public Map<String, FieldDescriptor> getFieldMap() throws FormatException {
122     //TODO gestire questo metodo
123     throw new FormatException(MESSAGES.getString("CIC001800_Not_implemented"));
124   }
125 
126   /**
127    * @return Returns the beanClass.
128    */
129   public Class getBeanClass() {
130     return beanClass;
131   }
132 
133   /**
134    * @param beanClass The beanClass to set.
135    */
136   public void setBeanClass(Class beanClass) {
137     this.beanClass = beanClass;
138   }
139 
140   public void setCodePage(String codePage) {
141     // TODO Auto-generated method stub
142     
143   }  
144     
145 }