1 package org.synchronoss.cpo.cassandra.meta;
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 java.io.Serial;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 import org.synchronoss.cpo.core.CpoException;
29 import org.synchronoss.cpo.core.helper.CpoClassLoader;
30 import org.synchronoss.cpo.core.helper.ExceptionHelper;
31 import org.synchronoss.cpo.core.meta.CpoMetaDescriptor;
32 import org.synchronoss.cpo.core.meta.domain.CpoAttribute;
33
34 /**
35 * CassandraCpoAttribute. A class that includes the Cassandra-specific attributes (map/collection
36 * key and value types) that are additional to the {@link CpoAttribute} attributes.
37 *
38 * @author david berry
39 */
40 public class CassandraCpoAttribute extends CpoAttribute implements java.io.Serializable, Cloneable {
41
42 private static final Logger logger = LoggerFactory.getLogger(CassandraCpoAttribute.class);
43
44 /** Version Id for this class. */
45 @Serial private static final long serialVersionUID = 1L;
46
47 /** The native Cassandra type name of a map attribute's key, e.g. {@code text}. */
48 private String keyType_ = null;
49
50 /** The native Cassandra type name of a map/collection attribute's value. */
51 private String valueType_ = null;
52
53 /** The Java class corresponding to {@link #keyType_}. */
54 private Class<?> keyTypeClass = null;
55
56 /** The Java class corresponding to {@link #valueType_}. */
57 private Class<?> valueTypeClass = null;
58
59 /** Constructs the CassandraCpoAttribute */
60 public CassandraCpoAttribute() {}
61
62 /**
63 * Gets the keytype class name
64 *
65 * @return The keytype class name
66 */
67 public String getKeyType() {
68 return keyType_;
69 }
70
71 /**
72 * Sets the Key Type
73 *
74 * @param keyType The keytype class name
75 */
76 public void setKeyType(String keyType) {
77 this.keyType_ = keyType;
78 }
79
80 /**
81 * Gets the Value Type classname
82 *
83 * @return the Value Type classname
84 */
85 public String getValueType() {
86 return valueType_;
87 }
88
89 /**
90 * Sets the Value Type classname
91 *
92 * @param valueType the Value Type classname
93 */
94 public void setValueType(String valueType) {
95 this.valueType_ = valueType;
96 }
97
98 /**
99 * Sets the Value Type classname
100 *
101 * @return the Value Type classname
102 */
103 public Class<?> getKeyTypeClass() {
104 return keyTypeClass;
105 }
106
107 /**
108 * Sets the Key Type Clazz
109 *
110 * @param keyTypeClass the Key Type Clazz
111 */
112 public void setKeyTypeClass(Class<?> keyTypeClass) {
113 this.keyTypeClass = keyTypeClass;
114 }
115
116 /**
117 * Gets the Value Type Clazz
118 *
119 * @return the Value Type Clazz
120 */
121 public Class<?> getValueTypeClass() {
122 return valueTypeClass;
123 }
124
125 /**
126 * Sets the Value Type Clazz
127 *
128 * @param valueTypeClass the Value Type Clazz
129 */
130 public void setValueTypeClass(Class<?> valueTypeClass) {
131 this.valueTypeClass = valueTypeClass;
132 }
133
134 // private void dumpMethod(Method m) {
135 // logger.debug("========================");
136 // logger.debug("===> Declaring Class: " + m.getDeclaringClass().getName());
137 // logger.debug("===> Method Signature: " + m.toString());
138 // logger.debug("===> Generic Signature: " + m.toGenericString());
139 // logger.debug("===> Method isBridge: " + m.isBridge());
140 // logger.debug("===> Method isSynthetic: " + m.isSynthetic());
141 // logger.debug("========================");
142 // }
143 @Override
144 public void loadRunTimeInfo(CpoMetaDescriptor metaDescriptor, Class<?> metaClass)
145 throws CpoException {
146 super.loadRunTimeInfo(metaDescriptor, metaClass);
147
148 setKeyTypeClass(getTypeClass(metaClass.getName(), getJavaName(), getKeyType(), "KeyType"));
149 setValueTypeClass(
150 getTypeClass(metaClass.getName(), getJavaName(), getValueType(), "ValueType"));
151 }
152
153 /**
154 * Loads, if needed, and returns the Type Clazz for the CpoAttribute
155 *
156 * @param className The classname
157 * @param attributeName The attribute name
158 * @param contextName The context name
159 * @param contextType The context type
160 * @return The Clazz
161 * @throws CpoException An errror occurred
162 */
163 protected Class getTypeClass(
164 String className, String attributeName, String contextName, String contextType)
165 throws CpoException {
166 Class contextClass = null;
167 try {
168 if (contextName != null) {
169 logger.debug(
170 "Loading loading the " + contextType + " Class for " + className + "." + attributeName);
171 contextClass = CpoClassLoader.forName(contextName);
172 }
173 } catch (ClassNotFoundException cnfe) {
174 throw new CpoException(
175 contextType
176 + " class not found: "
177 + contextName
178 + ": "
179 + ExceptionHelper.getLocalizedMessage(cnfe));
180 }
181 return contextClass;
182 }
183
184 @Override
185 protected void initTransformClass(CpoMetaDescriptor metaDescriptor) throws CpoException {
186 super.initTransformClass(metaDescriptor);
187
188 // TODO Revisit this. Initializing the java sql type here. Not sure that this is the right
189 // place.
190 setDataTypeInt(metaDescriptor.getDataTypeInt(getDataType()));
191 }
192 }