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.meta.CpoMetaDescriptor;
26  import org.synchronoss.cpo.meta.domain.CpoAttribute;
27  import org.synchronoss.cpo.transform.jdbc.JdbcCpoTransform;
28  
29  import java.lang.reflect.Method;
30  
31  /**
32   * JdbcCpoAttribute. A class that includes the Jdbc specifc attributes that are additional to the CpoAttribute attributes
33   *
34   * @author david berry
35   */
36  public class JdbcCpoAttribute extends CpoAttribute implements java.io.Serializable, java.lang.Cloneable {
37  
38    private static final Logger logger = LoggerFactory.getLogger(JdbcCpoAttribute.class);
39    /**
40     * Version Id for this class.
41     */
42    private static final long serialVersionUID = 1L;
43    private String dbTable_ = null;
44    private String dbColumn_ = null;
45    //Transform attributes
46    private JdbcCpoTransform jdbcTransform = null;
47    private Method transformPSOutMethod = null;
48    private Method transformCSOutMethod = null;
49  
50    public JdbcCpoAttribute() {
51    }
52  
53    public void setDbTable(String dbTable) {
54      dbTable_ = dbTable;
55    }
56  
57    public void setDbColumn(String dbColumn) {
58      dbColumn_ = dbColumn;
59    }
60  
61    public String getDbTable() {
62      return dbTable_;
63    }
64  
65    public String getDbColumn() {
66      return dbColumn_;
67    }
68  
69  //  private void dumpMethod(Method m) {
70  //    logger.debug("========================");
71  //    logger.debug("===> Declaring Class: " + m.getDeclaringClass().getName());
72  //    logger.debug("===> Method Signature: " + m.toString());
73  //    logger.debug("===> Generic Signature: " + m.toGenericString());
74  //    logger.debug("===> Method isBridge: " + m.isBridge());
75  //    logger.debug("===> Method isSynthetic: " + m.isSynthetic());
76  //    logger.debug("========================");
77  //  }
78  
79    @Override
80    protected void initTransformClass(CpoMetaDescriptor metaDescriptor) throws CpoException {
81      super.initTransformClass(metaDescriptor);
82      if (getCpoTransform() != null && getCpoTransform() instanceof JdbcCpoTransform) {
83        jdbcTransform = (JdbcCpoTransform) getCpoTransform();
84  
85        for (Method m : findMethods(jdbcTransform.getClass(), TRANSFORM_OUT_NAME, 2, true)) {
86          if (m.getParameterTypes()[0].getName().equals("org.synchronoss.cpo.jdbc.JdbcPreparedStatementFactory")) {
87            transformPSOutMethod = m;
88          } else if (m.getParameterTypes()[0].getName().equals("org.synchronoss.cpo.jdbc.JdbcCallableStatementFactory")) {
89            transformCSOutMethod = m;
90          }
91        }
92      }
93  
94      // TODO Revisit this. Initializing the java sql type here. Not sure that this is the right place.
95      setDataTypeInt(metaDescriptor.getDataTypeInt(getDataType()));
96    }
97  }