+/*
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.argeo.slc.jcr.dao;
import java.util.ArrayList;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.Workspace;
import javax.jcr.query.Query;
-import javax.jcr.query.QueryManager;
import javax.jcr.query.QueryResult;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.argeo.jcr.BeanNodeMapper;
import org.argeo.jcr.JcrUtils;
import org.argeo.slc.SlcException;
import org.argeo.slc.dao.process.SlcExecutionDao;
import org.argeo.slc.process.SlcExecution;
import org.argeo.slc.process.SlcExecutionStep;
-public class SlcExecutionDaoJcr implements SlcExecutionDao {
+public class SlcExecutionDaoJcr extends AbstractSlcJcrDao implements
+ SlcExecutionDao {
private final static Log log = LogFactory.getLog(SlcExecutionDaoJcr.class);
- private Session session;
- private Workspace workspace;
- private QueryManager queryManager;
-
- private BeanNodeMapper beanNodeMapper = new BeanNodeMapper();
-
- public void init() {
- try {
- workspace = session.getWorkspace();
- queryManager = workspace.getQueryManager();
- } catch (RepositoryException e) {
- throw new SlcException("Cannot initialize DAO", e);
- }
- }
public void addSteps(String slcExecutionId,
List<SlcExecutionStep> additionalSteps) {
}
public void create(SlcExecution slcExecution) {
- if (log.isDebugEnabled())
- log.debug("create");
-
try {
- beanNodeMapper.save(getSession(), basePath(slcExecution),
- slcExecution);
- session.save();
- } catch (Exception e) {
- throw new SlcException("Cannot import " + slcExecution, e);
+ nodeMapper.save(getSession(), basePath(slcExecution), slcExecution);
+ getSession().save();
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot create slcExecution" + slcExecution,
+ e);
}
}
Calendar cal = new GregorianCalendar();
cal.setTime(new Date());
// cal.setTime(slcExecution.getStartDate());
- return "/slc/processes/" + slcExecution.getHost().replace('.', '/')
- + '/' + JcrUtils.dateAsPath(cal) + "process";
+ String host = slcExecution.getHost();
+ if (host == null)
+ host = "UNKOWNHOST";
+ return "/slc/processes/" + JcrUtils.hostAsPath(host) + '/'
+ + JcrUtils.dateAsPath(cal) + "process";
}
public SlcExecution getSlcExecution(String uuid) {
- if (log.isDebugEnabled())
- log.debug("getSlcExecution");
-
- try {
- // TODO: optimize query
- String queryString = "//process[@uuid='" + uuid + "']";
- Query query = queryManager.createQuery(queryString, Query.XPATH);
- Node node = JcrUtils.querySingleNode(query);
- if (node == null)
- return null;
- return (SlcExecution) beanNodeMapper.nodeToBean(node);
- } catch (Exception e) {
- throw new SlcException("Cannot load SLC execution " + uuid, e);
- }
+ // TODO: optimize query
+ String queryString = "//process[@uuid='" + uuid + "']";
+ Query query = createQuery(queryString, Query.XPATH);
+ Node node = JcrUtils.querySingleNode(query);
+ if (node == null)
+ return null;
+ return (SlcExecution) nodeMapper.load(node);
}
public List<SlcExecution> listSlcExecutions() {
- if (log.isDebugEnabled())
- log.debug("listSlcExecutions");
-
List<SlcExecution> res = new ArrayList<SlcExecution>();
// TODO: optimize query
String queryString = "//process";
try {
- Query query = queryManager.createQuery(queryString, Query.XPATH);
+ Query query = createQuery(queryString, Query.XPATH);
QueryResult qr = query.execute();
NodeIterator iterator = qr.getNodes();
while (iterator.hasNext()) {
Node node = iterator.nextNode();
- SlcExecution slcExecution = (SlcExecution) beanNodeMapper
- .nodeToBean(node);
+ SlcExecution slcExecution = (SlcExecution) nodeMapper
+ .load(node);
res.add(slcExecution);
}
return res;
- } catch (Exception e) {
+ } catch (RepositoryException e) {
throw new SlcException("Cannot list SLC executions", e);
}
}
}
public void update(SlcExecution slcExecution) {
- if (log.isDebugEnabled())
- log.debug("update");
-
// TODO: optimize query
String queryString = "//process[@uuid='" + slcExecution.getUuid()
+ "']";
try {
- Query query = queryManager.createQuery(queryString, Query.XPATH);
+ Query query = createQuery(queryString, Query.XPATH);
Node node = JcrUtils.querySingleNode(query);
- beanNodeMapper.update(node, slcExecution);
- session.save();
- } catch (Exception e) {
+ nodeMapper.update(node, slcExecution);
+ getSession().save();
+ } catch (RepositoryException e) {
throw new SlcException("Cannot update " + slcExecution, e);
}
}
- public void setSession(Session session) {
- this.session = session;
- }
-
- protected Session getSession() {
- return session;
+ public List<SlcExecutionStep> tailSteps(String slcExecutionId,
+ Integer nbrOfSteps) {
+ log.error("Method not implemented, returning an empty list.");
+ return new ArrayList<SlcExecutionStep>();
}
- public void setBeanNodeMapper(BeanNodeMapper beanNodeMapper) {
- this.beanNodeMapper = beanNodeMapper;
+ public List<SlcExecutionStep> tailSteps(String slcExecutionId,
+ String slcExecutionStepId) {
+ log.error("Method not implemented, returning an empty list.");
+ return new ArrayList<SlcExecutionStep>();
}
}