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.cassandra.exporter;
22  
23  import org.synchronoss.cpo.cassandra.cpoCassandraMeta.CtCassandraArgument;
24  import org.synchronoss.cpo.cassandra.cpoCassandraMeta.CtCassandraAttribute;
25  import org.synchronoss.cpo.cassandra.meta.CassandraCpoAttribute;
26  import org.synchronoss.cpo.core.cpoCoreMeta.CtArgument;
27  import org.synchronoss.cpo.core.cpoCoreMeta.CtAttribute;
28  import org.synchronoss.cpo.exporter.CoreMetaXmlObjectExporter;
29  import org.synchronoss.cpo.exporter.MetaXmlObjectExporter;
30  import org.synchronoss.cpo.meta.CpoMetaDescriptor;
31  import org.synchronoss.cpo.meta.domain.CpoArgument;
32  import org.synchronoss.cpo.meta.domain.CpoAttribute;
33  
34  /**
35   * Created with IntelliJ IDEA.
36   * User: dberry
37   * Date: 9/10/13
38   * Time: 08:13 AM
39   * To change this template use File | Settings | File Templates.
40   */
41  public class CassandraMetaXmlObjectExporter extends CoreMetaXmlObjectExporter implements MetaXmlObjectExporter {
42    public CassandraMetaXmlObjectExporter(CpoMetaDescriptor metaDescriptor) {
43      super(metaDescriptor);
44    }
45  
46    @Override
47    public void visit(CpoAttribute cpoAttribute) {
48  
49      // shouldn't happen, but if what we got wasn't a JdbcAttribute...
50      if (!(cpoAttribute instanceof CassandraCpoAttribute)) {
51        super.visit(cpoAttribute);
52        return;
53      }
54  
55      CassandraCpoAttribute cassAttribute = (CassandraCpoAttribute) cpoAttribute;
56  
57      if (currentCtClass != null) {
58  
59        // CtClass.addNewCpoAttribute() can't be used here because it returns a CtAttribute, not a CtJdbcAttribute
60        CtCassandraAttribute ctCassandraAttribute = CtCassandraAttribute.Factory.newInstance();
61  
62        ctCassandraAttribute.setJavaName(cassAttribute.getJavaName());
63        ctCassandraAttribute.setJavaType(cassAttribute.getJavaType());
64        ctCassandraAttribute.setDataName(cassAttribute.getDataName());
65        ctCassandraAttribute.setDataType(cassAttribute.getDataType());
66  
67        if (cassAttribute.getTransformClassName() != null && cassAttribute.getTransformClassName().length() > 0) {
68          ctCassandraAttribute.setTransformClass(cassAttribute.getTransformClassName());
69        }
70  
71        if (cassAttribute.getDescription() != null && cassAttribute.getDescription().length() > 0) {
72          ctCassandraAttribute.setDescription(cassAttribute.getDescription());
73        }
74  
75        // add it to the class
76        CtAttribute ctAttribute = currentCtClass.addNewCpoAttribute();
77        ctAttribute.set(ctCassandraAttribute);
78      }
79    }
80  
81    @Override
82    public void visit(CpoArgument cpoArgument) {
83  
84      if (currentCtFunction != null) {
85  
86        // CtFunction.addNewCpoArgument() can't be used here because it returns a CtArgument, not a CtJdbcArgument
87        CtCassandraArgument ctCassandraArgument = CtCassandraArgument.Factory.newInstance();
88  
89        ctCassandraArgument.setAttributeName(cpoArgument.getAttributeName());
90  
91        if (cpoArgument.getDescription() != null && cpoArgument.getDescription().length() > 0) {
92          ctCassandraArgument.setDescription(cpoArgument.getDescription());
93        }
94  
95        CtArgument ctArgument = currentCtFunction.addNewCpoArgument();
96        ctArgument.set(ctCassandraArgument);
97      }
98    }
99  
100 }