1 package org.synchronoss.cpo.cassandra;
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.transform.CassandraCpoTransform;
26 import org.synchronoss.cpo.core.CpoException;
27 import org.synchronoss.cpo.core.meta.AbstractBindableCpoData;
28 import org.synchronoss.cpo.core.meta.domain.CpoAttribute;
29 import org.synchronoss.cpo.core.transform.CpoTransform;
30
31 /**
32 * Helps manage data transfer between the CPO object and the Cassandra bound statement. Bind values
33 * are actually applied in {@link CassandraBoundStatementFactory#setBindValues}, which builds the
34 * whole value array and binds it in a single {@code PreparedStatement.bind(Object...)} call; this
35 * class only supplies the transform half of the contract (see {@link #transformOut(Object)}), used
36 * to resolve each attribute's value before it goes into that array.
37 *
38 * @author dberry
39 */
40 public class CassandraBoundStatementCpoData extends AbstractBindableCpoData {
41
42 private final CassandraBoundStatementFactory cpoStatementFactory;
43
44 /**
45 * Constructs the CassandraBoundStatementCpoData
46 *
47 * @param cpoStatementFactory The CassandraBoundStatementFactory
48 * @param cpoAttribute The CpoAttribute
49 * @param index The index of the attribute in the bound statement
50 */
51 public CassandraBoundStatementCpoData(
52 CassandraBoundStatementFactory cpoStatementFactory, CpoAttribute cpoAttribute, int index) {
53 super(cpoAttribute, index);
54 this.cpoStatementFactory = cpoStatementFactory;
55 }
56
57 @Override
58 public Object transformOut(Object attributeObject) throws CpoException {
59 Object retObj = attributeObject;
60 CpoTransform cpoTransform = getCpoAttribute().getCpoTransform();
61
62 if (cpoTransform != null) {
63 if (cpoTransform instanceof CassandraCpoTransform) {
64 retObj =
65 ((CassandraCpoTransform) cpoTransform)
66 .transformOut(cpoStatementFactory, attributeObject);
67 } else {
68 retObj = cpoTransform.transformOut(attributeObject);
69 }
70 }
71 return retObj;
72 }
73 }