View Javadoc
1   package org.synchronoss.cpo.cassandra.exporter;
2   
3   /*-
4    * [[
5    * cassandra
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.cassandra.meta.CassandraCpoAttribute;
26  import org.synchronoss.cpo.core.exporter.CoreMetaXmlObjectExporter;
27  import org.synchronoss.cpo.core.exporter.MetaXmlObjectExporter;
28  import org.synchronoss.cpo.core.meta.CpoMetaDescriptor;
29  import org.synchronoss.cpo.core.meta.domain.CpoArgument;
30  import org.synchronoss.cpo.core.meta.domain.CpoAttribute;
31  import org.synchronoss.cpo.cpometa.CtCassandraArgument;
32  import org.synchronoss.cpo.cpometa.CtCassandraAttribute;
33  import org.synchronoss.cpo.cpometa.ObjectFactory;
34  
35  /**
36   * Exports the Cassandra metadata
37   *
38   * @author dberry
39   */
40  public class CassandraMetaXmlObjectExporter extends CoreMetaXmlObjectExporter
41      implements MetaXmlObjectExporter {
42  
43    private final ObjectFactory objectFactory = new ObjectFactory();
44  
45    /**
46     * Constructs the CassandraMetaXmlObjectExporter
47     *
48     * @param metaDescriptor The descriptor to export
49     */
50    public CassandraMetaXmlObjectExporter(CpoMetaDescriptor metaDescriptor) {
51      super(metaDescriptor);
52    }
53  
54    @Override
55    public void visit(CpoAttribute cpoAttribute) {
56  
57      // shouldn't happen, but if what we got wasn't a CassandraCpoAttribute...
58      if (!(cpoAttribute instanceof CassandraCpoAttribute)) {
59        super.visit(cpoAttribute);
60        return;
61      }
62  
63      CassandraCpoAttribute cassAttribute = (CassandraCpoAttribute) cpoAttribute;
64  
65      if (currentCtClass != null) {
66  
67        // CtClass.addNewCpoAttribute() can't be used here because it returns a CtAttribute, not a
68        // CtCassandraAttribute
69        CtCassandraAttribute ctCassandraAttribute = new CtCassandraAttribute();
70  
71        ctCassandraAttribute.setJavaName(cassAttribute.getJavaName());
72        ctCassandraAttribute.setJavaType(cassAttribute.getJavaType());
73        ctCassandraAttribute.setDataName(cassAttribute.getDataName());
74        ctCassandraAttribute.setDataType(cassAttribute.getDataType());
75  
76        if (cassAttribute.getTransformClassName() != null
77            && !cassAttribute.getTransformClassName().isEmpty()) {
78          ctCassandraAttribute.setTransformClass(cassAttribute.getTransformClassName());
79        }
80  
81        if (cassAttribute.getDescription() != null && !cassAttribute.getDescription().isEmpty()) {
82          ctCassandraAttribute.setDescription(cassAttribute.getDescription());
83        }
84  
85        if (cassAttribute.getKeyType() != null && !cassAttribute.getKeyType().isEmpty()) {
86          ctCassandraAttribute.setKeyType(cassAttribute.getKeyType());
87        }
88  
89        if (cassAttribute.getValueType() != null && !cassAttribute.getValueType().isEmpty()) {
90          ctCassandraAttribute.setValueType(cassAttribute.getValueType());
91        }
92  
93        // add it to the class
94        currentCtClass
95            .getCpoAttribute()
96            .add(objectFactory.createCassandraAttribute(ctCassandraAttribute));
97      }
98    }
99  
100   @Override
101   public void visit(CpoArgument cpoArgument) {
102 
103     if (currentCtFunction != null) {
104 
105       // CtFunction.addNewCpoArgument() can't be used here because it returns a CtArgument, not a
106       // ctCassandraArgument
107       CtCassandraArgument ctCassandraArgument = new CtCassandraArgument();
108 
109       ctCassandraArgument.setAttributeName(cpoArgument.getName());
110 
111       if (cpoArgument.getDescription() != null && !cpoArgument.getDescription().isEmpty()) {
112         ctCassandraArgument.setDescription(cpoArgument.getDescription());
113       }
114 
115       currentCtFunction
116           .getCpoArgument()
117           .add(objectFactory.createCassandraArgument(ctCassandraArgument));
118     }
119   }
120 }