X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=runtime%2Forg.argeo.slc.support.jcr%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fjcr%2Fdao%2FSlcAgentDescriptorDaoJcr.java;h=863dfb93c8e6fbae8cad48a46719bbe34e7e629b;hb=74904a755b5b344238eafa798419b80c5e74f7ed;hp=14c838aa7001eac9cf14eb8aad55dc6806e16f05;hpb=b554c0910f6ddce935ceea5f99d399fe23af6f58;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/dao/SlcAgentDescriptorDaoJcr.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/dao/SlcAgentDescriptorDaoJcr.java index 14c838aa7..863dfb93c 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/dao/SlcAgentDescriptorDaoJcr.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/dao/SlcAgentDescriptorDaoJcr.java @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * 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; @@ -5,6 +20,7 @@ import java.util.List; import javax.jcr.Node; import javax.jcr.NodeIterator; +import javax.jcr.RepositoryException; import javax.jcr.query.Query; import org.apache.commons.logging.Log; @@ -24,30 +40,26 @@ public class SlcAgentDescriptorDaoJcr extends AbstractSlcJcrDao implements nodeMapper.save(getSession(), basePath(slcAgentDescriptor), slcAgentDescriptor); getSession().save(); - } catch (Exception e) { + } catch (RepositoryException e) { throw new SlcException("Cannot import " + slcAgentDescriptor, e); } } public SlcAgentDescriptor getAgentDescriptor(String agentId) { - try { - // TODO: optimize query - String queryString = "//agent[@uuid='" + agentId + "']"; - Query query = queryManager.createQuery(queryString, Query.XPATH); - Node node = JcrUtils.querySingleNode(query); - if (node == null) - return null; - return (SlcAgentDescriptor) nodeMapper.load(node); - } catch (Exception e) { - throw new SlcException("Cannot load Agent Descriptor" + agentId, e); - } + // TODO: optimize query + String queryString = "//agent[@uuid='" + agentId + "']"; + Query query = createQuery(queryString, Query.XPATH); + Node node = JcrUtils.querySingleNode(query); + if (node == null) + return null; + return (SlcAgentDescriptor) nodeMapper.load(node); } public void delete(SlcAgentDescriptor slcAgentDescriptor) { try { String queryString = "//agent[@uuid='" + slcAgentDescriptor.getUuid() + "']"; - Query query = queryManager.createQuery(queryString, Query.XPATH); + Query query = createQuery(queryString, Query.XPATH); Node node = JcrUtils.querySingleNode(query); if (node != null) { node.remove(); @@ -55,7 +67,7 @@ public class SlcAgentDescriptorDaoJcr extends AbstractSlcJcrDao implements } else log.warn("No node found for agent descriptor: " + slcAgentDescriptor); - } catch (Exception e) { + } catch (RepositoryException e) { throw new SlcException("Cannot delete " + slcAgentDescriptor, e); } @@ -65,11 +77,11 @@ public class SlcAgentDescriptorDaoJcr extends AbstractSlcJcrDao implements try { // TODO: optimize query String queryString = "//agent[@uuid='" + agentId + "']"; - Query query = queryManager.createQuery(queryString, Query.XPATH); + Query query = createQuery(queryString, Query.XPATH); Node node = JcrUtils.querySingleNode(query); if (node != null) node.remove(); - } catch (Exception e) { + } catch (RepositoryException e) { throw new SlcException("Cannot find AgentDescriptor" + agentId, e); } @@ -78,7 +90,7 @@ public class SlcAgentDescriptorDaoJcr extends AbstractSlcJcrDao implements public List listSlcAgentDescriptors() { try { String queryString = "//agent"; - Query query = queryManager.createQuery(queryString, Query.XPATH); + Query query = createQuery(queryString, Query.XPATH); List listSad = new ArrayList();