1 package org.synchronoss.cpo.jdbc;
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.CpoException;
26 import org.synchronoss.cpo.core.meta.AbstractBindableCpoData;
27 import org.synchronoss.cpo.core.meta.domain.CpoAttribute;
28 import org.synchronoss.cpo.jdbc.meta.JdbcMethodMapEntry;
29 import org.synchronoss.cpo.jdbc.meta.JdbcMethodMapper;
30
31 /**
32 * Base for {@link org.synchronoss.cpo.core.CpoData} implementations backed by a JDBC {@code
33 * Statement} subtype, resolving the {@link JdbcMethodMapEntry} used to bind/read a bound
34 * attribute's value.
35 */
36 public abstract class AbstractStatementCpoData extends AbstractBindableCpoData {
37
38 /**
39 * Creates an instance for the given bound attribute and bind-marker index.
40 *
41 * @param cpoAttribute the attribute this instance moves values for
42 * @param index the bind-marker index within the statement
43 */
44 public AbstractStatementCpoData(CpoAttribute cpoAttribute, int index) {
45 super(cpoAttribute, index);
46 }
47
48 /**
49 * Resolves the {@link JdbcMethodMapEntry} used to move this attribute's value to/from a JDBC
50 * statement.
51 *
52 * @param instanceObject unused; retained for the overriding subclasses' call sites
53 * @return the resolved method map entry
54 * @throws CpoException if no entry can be resolved for the attribute's setter parameter type
55 */
56 protected JdbcMethodMapEntry<?, ?> getJdbcMethodMapEntry(Object instanceObject)
57 throws CpoException {
58 JdbcMethodMapEntry<?, ?> methodMapEntry =
59 JdbcMethodMapper.getJavaSqlMethod(getDataSetterParamType());
60 if (methodMapEntry == null) {
61 if (Object.class.isAssignableFrom(getDataSetterParamType())) {
62 methodMapEntry = JdbcMethodMapper.getJavaSqlMethod(Object.class);
63 }
64 if (methodMapEntry == null) {
65 throw new CpoException(
66 "Error Retrieving Jdbc Method for type: " + getDataSetterParamType().getName());
67 }
68 }
69 switch (methodMapEntry.getMethodType()) {
70 case JdbcMethodMapEntry.METHOD_TYPE_BASIC:
71 case JdbcMethodMapEntry.METHOD_TYPE_OBJECT:
72 case JdbcMethodMapEntry.METHOD_TYPE_STREAM:
73 case JdbcMethodMapEntry.METHOD_TYPE_READER:
74 default:
75 return methodMapEntry;
76 }
77 }
78 }