View Javadoc

1   /*
2    * Copyright (C) 2003-2012 David E. Berry
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2.1 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this library; if not, write to the Free Software
16   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17   *
18   * A copy of the GNU Lesser General Public License may also be found at
19   * http://www.gnu.org/licenses/lgpl.txt
20   */
21  package org.synchronoss.cpo.jdbc;
22  
23  import org.slf4j.*;
24  import org.synchronoss.cpo.CpoException;
25  import org.synchronoss.cpo.jdbc.meta.JdbcCpoMetaDescriptor;
26  import org.synchronoss.cpo.meta.CpoMetaDescriptor;
27  import org.synchronoss.cpo.meta.domain.CpoAttribute;
28  import org.synchronoss.cpo.transform.jdbc.JdbcCpoTransform;
29  
30  import java.lang.reflect.Method;
31  import java.sql.Types;
32  
33  /**
34   * JdbcCpoAttribute. A class that includes the Jdbc specifc attributes that are additional to the CpoAttribute attributes
35   *
36   * @author david berry
37   */
38  public class JdbcCpoAttribute extends CpoAttribute implements java.io.Serializable, java.lang.Cloneable {
39  
40    private static final Logger logger = LoggerFactory.getLogger(JdbcCpoAttribute.class);
41    /**
42     * Version Id for this class.
43     */
44    private static final long serialVersionUID = 1L;
45    private String dbTable_ = null;
46    private String dbColumn_ = null;
47    private int javaSqlType_ = Types.NULL;
48    //Transform attributes
49    private JdbcCpoTransform jdbcTransform = null;
50    private Method transformPSOutMethod = null;
51    private Method transformCSOutMethod = null;
52  
53    public JdbcCpoAttribute() {
54    }
55  
56    public void setDbTable(String dbTable) {
57      dbTable_ = dbTable;
58    }
59  
60    public void setDbColumn(String dbColumn) {
61      dbColumn_ = dbColumn;
62    }
63  
64    public String getDbTable() {
65      return dbTable_;
66    }
67  
68    public String getDbColumn() {
69      return dbColumn_;
70    }
71  
72    protected void setJavaSqlType(int type) {
73      javaSqlType_ = type;
74  
75    }
76  
77    protected int getJavaSqlType() {
78      return this.javaSqlType_;
79    }
80  
81  //  private void dumpMethod(Method m) {
82  //    logger.debug("========================");
83  //    logger.debug("===> Declaring Class: " + m.getDeclaringClass().getName());
84  //    logger.debug("===> Method Signature: " + m.toString());
85  //    logger.debug("===> Generic Signature: " + m.toGenericString());
86  //    logger.debug("===> Method isBridge: " + m.isBridge());
87  //    logger.debug("===> Method isSynthetic: " + m.isSynthetic());
88  //    logger.debug("========================");
89  //  }
90  
91    @Override
92    protected void initTransformClass(CpoMetaDescriptor metaDescriptor) throws CpoException {
93      super.initTransformClass(metaDescriptor);
94      if (getCpoTransform() != null && getCpoTransform() instanceof JdbcCpoTransform) {
95        jdbcTransform = (JdbcCpoTransform) getCpoTransform();
96  
97        for (Method m : findMethods(jdbcTransform.getClass(), TRANSFORM_OUT_NAME, 2, true)) {
98          if (m.getParameterTypes()[0].getName().equals("org.synchronoss.cpo.jdbc.JdbcPreparedStatementFactory")) {
99            transformPSOutMethod = m;
100         } else if (m.getParameterTypes()[0].getName().equals("org.synchronoss.cpo.jdbc.JdbcCallableStatementFactory")) {
101           transformCSOutMethod = m;
102         }
103       }
104     }
105     
106     // TODO Revisit this. Initializing the java sql type here. Not sure that this is the right place.
107     setJavaSqlType(((JdbcCpoMetaDescriptor)metaDescriptor).getJavaSqlType(getDataType()));
108   }
109 }