View Javadoc
1   package org.synchronoss.cpo.jdbc.exporter;
2   
3   /*-
4    * [[
5    * jdbc
6    * ==
7    * Copyright (C) 2003 - 2026 Exaxis LLC, Synchronoss Technologies Inc
8    * ==
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   *
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Lesser Public License for more details.
18   *
19   * You should have received a copy of the GNU General Lesser Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22   * ]]
23   */
24  
25  import org.synchronoss.cpo.core.exporter.CoreMetaXmlObjectExporter;
26  import org.synchronoss.cpo.core.exporter.MetaXmlObjectExporter;
27  import org.synchronoss.cpo.core.meta.CpoMetaDescriptor;
28  import org.synchronoss.cpo.core.meta.domain.CpoArgument;
29  import org.synchronoss.cpo.core.meta.domain.CpoAttribute;
30  import org.synchronoss.cpo.cpometa.CtJdbcArgument;
31  import org.synchronoss.cpo.cpometa.CtJdbcAttribute;
32  import org.synchronoss.cpo.cpometa.ObjectFactory;
33  import org.synchronoss.cpo.cpometa.StArgumentScope;
34  import org.synchronoss.cpo.jdbc.JdbcCpoArgument;
35  import org.synchronoss.cpo.jdbc.JdbcCpoAttribute;
36  
37  /**
38   * XmlObject exporter for jdbc meta objects
39   *
40   * @author Michael Bellomo
41   * @since 4/18/12
42   */
43  public class JdbcMetaXmlObjectExporter extends CoreMetaXmlObjectExporter
44      implements MetaXmlObjectExporter {
45  
46    protected ObjectFactory objectFactory = new ObjectFactory();
47  
48    /**
49     * Constructs a JdbcMetaXmlObjectExporter object.
50     *
51     * @param metaDescriptor - The meta descriptor to export
52     */
53    public JdbcMetaXmlObjectExporter(CpoMetaDescriptor metaDescriptor) {
54      super(metaDescriptor);
55    }
56  
57    @Override
58    public void visit(CpoAttribute cpoAttribute) {
59  
60      // shouldn't happen, but if what we got wasn't a JdbcAttribute...
61      if (!(cpoAttribute instanceof JdbcCpoAttribute)) {
62        super.visit(cpoAttribute);
63        return;
64      }
65  
66      JdbcCpoAttribute jdbcAttribute = (JdbcCpoAttribute) cpoAttribute;
67  
68      if (currentCtClass != null) {
69  
70        // CtClass.addNewCpoAttribute() can't be used here because it returns a CtAttribute, not a
71        // CtJdbcAttribute
72        CtJdbcAttribute ctJdbcAttribute = new CtJdbcAttribute();
73        var jaxbElement = objectFactory.createJdbcAttribute(ctJdbcAttribute);
74        // add it to the class
75        currentCtClass.getCpoAttribute().add(jaxbElement);
76  
77        ctJdbcAttribute.setJavaName(jdbcAttribute.getJavaName());
78        ctJdbcAttribute.setJavaType(jdbcAttribute.getJavaType());
79        ctJdbcAttribute.setDataName(jdbcAttribute.getDataName());
80        ctJdbcAttribute.setDataType(jdbcAttribute.getDataType());
81  
82        if (jdbcAttribute.getTransformClassName() != null
83            && !jdbcAttribute.getTransformClassName().isEmpty()) {
84          ctJdbcAttribute.setTransformClass(jdbcAttribute.getTransformClassName());
85        }
86  
87        if (jdbcAttribute.getDescription() != null && !jdbcAttribute.getDescription().isEmpty()) {
88          ctJdbcAttribute.setDescription(jdbcAttribute.getDescription());
89        }
90  
91        if (jdbcAttribute.getDbTable() != null && !jdbcAttribute.getDbTable().isEmpty()) {
92          ctJdbcAttribute.setDbTable(jdbcAttribute.getDbTable());
93        }
94  
95        if (jdbcAttribute.getDbColumn() != null && !jdbcAttribute.getDbColumn().isEmpty()) {
96          ctJdbcAttribute.setDbColumn(jdbcAttribute.getDbColumn());
97        }
98      }
99    }
100 
101   @Override
102   public void visit(CpoArgument cpoArgument) {
103 
104     // shouldn't happen, but if what we got wasn't a JdbcArgument...
105     if (!(cpoArgument instanceof JdbcCpoArgument)) {
106       super.visit(cpoArgument);
107       return;
108     }
109 
110     JdbcCpoArgument jdbcArgument = (JdbcCpoArgument) cpoArgument;
111 
112     if (currentCtFunction != null) {
113 
114       // CtFunction.addNewCpoArgument() can't be used here because it returns a CtArgument, not a
115       // CtJdbcArgument
116       CtJdbcArgument ctJdbcArgument = new CtJdbcArgument();
117       var jaxbElement = objectFactory.createJdbcArgument(ctJdbcArgument);
118       currentCtFunction.getCpoArgument().add(jaxbElement);
119 
120       ctJdbcArgument.setAttributeName(jdbcArgument.getName());
121 
122       if (jdbcArgument.getDescription() != null && !jdbcArgument.getDescription().isEmpty()) {
123         ctJdbcArgument.setDescription(jdbcArgument.getDescription());
124       }
125 
126       if (jdbcArgument.isInParameter() && jdbcArgument.isOutParameter()) {
127         ctJdbcArgument.setScope(StArgumentScope.BOTH);
128       } else if (jdbcArgument.isInParameter()) {
129         ctJdbcArgument.setScope(StArgumentScope.IN);
130       } else if (jdbcArgument.isOutParameter()) {
131         ctJdbcArgument.setScope(StArgumentScope.OUT);
132       }
133 
134       if (jdbcArgument.getTypeInfo() != null && !jdbcArgument.getTypeInfo().isEmpty()) {
135         ctJdbcArgument.setTypeInfo(jdbcArgument.getTypeInfo());
136       }
137     }
138   }
139 }