View Javadoc
1 /* ====================================================================
2 * License:
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. The end-user documentation included with the redistribution,
17 * if any, must include the following acknowledgment:
18 * "This product includes software developed by
19 * Robert Half International (http://www.rhi.com/)."
20 * Alternately, this acknowledgment may appear in the software itself,
21 * if and wherever such third-party acknowledgments normally appear.
22 *
23 * 4. The names "Parc", "RHI", and "Robert Half International" must
24 * not be used to endorse or promote products derived from this
25 * software without prior written permission. For written
26 * permission, please contact pete.mckinstry@rhi.com.
27 *
28 * 5. Products derived from this software may not be called "PARC",
29 * nor may "PARC" appear in their name, without prior written
30 * permission of Robert Half International.
31 *
32 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
33 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
34 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
36 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
37 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
38 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
39 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
40 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
41 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
42 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 * SUCH DAMAGE.
44 * ====================================================================
45 *
46 */
47 package com.rhi.architecture.parc.adapter.jdo;
48
49 import com.rhi.architecture.config.ConfigurationException;
50 import com.rhi.architecture.logging.LogUtil;
51 import com.rhi.architecture.logging.Logger;
52 import com.rhi.architecture.parc.ProcessingException;
53 import com.rhi.architecture.parc.adapter.AbstractInputAdapter;
54 import com.rhi.architecture.resource.InitializationException;
55
56 import java.util.ArrayList;
57 import java.util.Collection;
58 import java.util.Properties;
59
60 import org.exolab.castor.jdo.Database;
61 import org.exolab.castor.jdo.DatabaseNotFoundException;
62 import org.exolab.castor.jdo.JDO;
63 import org.exolab.castor.jdo.OQLQuery;
64 import org.exolab.castor.jdo.PersistenceException;
65 import org.exolab.castor.jdo.QueryException;
66 import org.exolab.castor.jdo.QueryResults;
67 import org.exolab.castor.jdo.TransactionNotInProgressException;
68
69 /***
70 * Castor JDO based InputAdapter.
71 *
72 * @author Pete McKinstry
73 * @copyright 2002, Robert Half Int'l., Inc. All rights reserved.
74 *
75 * @since 1.0
76 */
77 public class JDOInputAdapter extends AbstractInputAdapter {
78
79 private static Logger log = null;
80
81 // Castor objects
82 private static Database db;
83
84 // the OQL to pull the data for processing.
85 private static String query;
86
87 /***
88 * Perform any resource initialization.
89 * @param props
90 * @throws InitializationException
91 * @since 1.0
92 */
93 public void init(Properties props) throws InitializationException {
94 super.init(props);
95
96 try {
97 log = LogUtil.getLogger();
98 }
99 catch (ConfigurationException e) {
100 throw new InitializationException(e.toString());
101 }
102
103 log.debug("init");
104 try {
105 JDO jdo = new JDO();
106 jdo.setConfiguration(props.getProperty("jdo_db_config_file"));
107 jdo.setDatabaseName(props.getProperty("jdo_db_name"));
108 db = jdo.getDatabase();
109 query = props.getProperty("jdo_query");
110 }
111 catch (DatabaseNotFoundException dnfe) {
112 throw new InitializationException(dnfe.toString());
113 }
114 catch (PersistenceException pe) {
115 throw new InitializationException(pe.toString());
116 }
117
118 }
119
120 /***
121 * Push a dummy set of records into the pipeline.
122 *
123 * @return Collection
124 * @throws ProcessingException
125 *
126 * @since 1.0
127 */
128 protected Collection loadBatch() throws ProcessingException {
129 log.debug("loadRecords()");
130 ArrayList list = new ArrayList();
131
132 try {
133 db.begin();
134
135 if (log.isDebugEnabled()) {
136 log.debug("query = " + getQuery());
137 }
138
139 OQLQuery selectOql = db.getOQLQuery(getQuery());
140 QueryResults rs = selectOql.execute();
141 while (rs.hasMore()) {
142 list.add(rs.next());
143 }
144
145 db.commit();
146 db.close();
147 }
148 catch (TransactionNotInProgressException te) {
149 throw new ProcessingException(te.toString());
150 }
151 catch (QueryException qe) {
152 throw new ProcessingException(qe.toString());
153 }
154 catch (PersistenceException pe) {
155 throw new ProcessingException(pe.toString());
156 }
157 return list;
158 }
159
160 /***
161 * Return a String representing the OQL query that should
162 * be used to retrieve records to process. In the simple
163 * case, this class can be used as is, and the OQL is
164 * specified in the application properties file. However,
165 * if a more complex OQL string is required, this is
166 * overridable.
167 *
168 * @return The OQL to execute.
169 *
170 * @since 1.0
171 */
172 protected String getQuery() {
173 return JDOInputAdapter.query;
174 }
175
176 }
This page was automatically generated by Maven