Coverage Report - org.kuali.rice.ksb.impl.registry.ServiceRegistryDaoOjb
 
Classes in this File Line Coverage Branch Coverage Complexity
ServiceRegistryDaoOjb
0%
0/39
0%
0/2
1.462
ServiceRegistryDaoOjb$1
0%
0/13
0%
0/2
1.462
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl1.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.ksb.impl.registry;
 17  
 
 18  
 import java.sql.Connection;
 19  
 import java.sql.PreparedStatement;
 20  
 import java.sql.SQLException;
 21  
 import java.util.List;
 22  
 
 23  
 import javax.xml.namespace.QName;
 24  
 
 25  
 import org.apache.ojb.broker.PersistenceBroker;
 26  
 import org.apache.ojb.broker.query.Criteria;
 27  
 import org.apache.ojb.broker.query.QueryByCriteria;
 28  
 import org.kuali.rice.ksb.api.registry.ServiceEndpointStatus;
 29  
 import org.springmodules.orm.ojb.PersistenceBrokerCallback;
 30  
 import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
 31  
 
 32  
 /**
 33  
  * An OJB dao implementation of the {@link ServiceRegistryDao}. 
 34  
  * 
 35  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 36  
  *
 37  
  */
 38  0
 public class ServiceRegistryDaoOjb extends PersistenceBrokerDaoSupport implements ServiceRegistryDao {
 39  
 
 40  
         @Override
 41  
         public ServiceInfoBo getServiceInfo(String serviceId) {
 42  0
                 Criteria crit = new Criteria();
 43  0
                 crit.addEqualTo("serviceId", serviceId);
 44  0
                 return (ServiceInfoBo)getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(ServiceInfoBo.class, crit));
 45  
         }
 46  
 
 47  
         @Override
 48  
         public List<ServiceInfoBo> getOnlineServiceInfosByName(QName serviceName) {
 49  0
                 Criteria crit = new Criteria();
 50  0
                 crit.addEqualTo("serviceName", serviceName.toString());
 51  0
                 crit.addEqualTo("statusCode", ServiceEndpointStatus.ONLINE.getCode());
 52  0
                 return (List<ServiceInfoBo>)getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ServiceInfoBo.class, crit));
 53  
         }
 54  
 
 55  
         @Override
 56  
         public List<ServiceInfoBo> getAllOnlineServiceInfos() {
 57  0
                 Criteria crit = new Criteria();
 58  0
                 crit.addEqualTo("statusCode", ServiceEndpointStatus.ONLINE.getCode());
 59  0
                 return (List<ServiceInfoBo>)getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ServiceInfoBo.class, crit));
 60  
         }
 61  
         
 62  
         @Override
 63  
         public List<ServiceInfoBo> getAllServiceInfos() {
 64  0
                 Criteria crit = new Criteria();
 65  0
                 return (List<ServiceInfoBo>)getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ServiceInfoBo.class, crit));
 66  
         }
 67  
 
 68  
         @Override
 69  
         public List<ServiceInfoBo> getAllServiceInfosForInstance(String instanceId) {
 70  0
                 Criteria crit = new Criteria();
 71  0
                 crit.addEqualTo("instanceId", instanceId);
 72  0
                 return (List<ServiceInfoBo>)getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ServiceInfoBo.class, crit));
 73  
         }
 74  
         
 75  
         @Override
 76  
         public ServiceDescriptorBo getServiceDescriptor(String serviceDescriptorId) {
 77  0
                 Criteria crit = new Criteria();
 78  0
                 crit.addEqualTo("id", serviceDescriptorId);
 79  0
                 return (ServiceDescriptorBo)getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(ServiceDescriptorBo.class, crit));
 80  
         }
 81  
 
 82  
         @Override
 83  
         public ServiceDescriptorBo saveServiceDescriptor(ServiceDescriptorBo serviceDescriptor) {
 84  0
                 getPersistenceBrokerTemplate().store(serviceDescriptor);
 85  0
                 return serviceDescriptor;
 86  
         }
 87  
 
 88  
         @Override
 89  
         public ServiceInfoBo saveServiceInfo(ServiceInfoBo serviceInfo) {
 90  0
                 getPersistenceBrokerTemplate().store(serviceInfo);
 91  0
                 return serviceInfo;
 92  
         }
 93  
 
 94  
         @Override
 95  
         public void removeServiceInfo(String serviceId) {
 96  0
                 Criteria crit = new Criteria();
 97  0
                 crit.addEqualTo("serviceId", serviceId);
 98  0
                 getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(ServiceInfoBo.class, crit));
 99  0
         }
 100  
 
 101  
         @Override
 102  
         public void removeServiceDescriptor(String serviceDescriptorId) {
 103  0
                 Criteria crit = new Criteria();
 104  0
                 crit.addEqualTo("id", serviceDescriptorId);
 105  0
                 getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(ServiceDescriptorBo.class, crit));
 106  0
         }
 107  
 
 108  
         @Override
 109  
         public boolean updateStatus(String serviceId, String statusCode) {
 110  0
                 ServiceInfoBo serviceInfoBo = getServiceInfo(serviceId);
 111  0
                 if (serviceInfoBo == null) {
 112  0
                         return false;
 113  
                 }
 114  0
                 serviceInfoBo.setStatusCode(statusCode);
 115  0
                 saveServiceInfo(serviceInfoBo);
 116  0
                 return true;
 117  
         }
 118  
 
 119  
         private static final String UPDATE_STATUS_FOR_INSTANCE_ID = "update KRSB_SVC_DEF_T set STAT_CD=? where INSTN_ID=?";
 120  
         @Override
 121  
         public void updateStatusForInstanceId(final String instanceId, final String statusCode) {
 122  0
                 getPersistenceBrokerTemplate().execute(new PersistenceBrokerCallback() {
 123  
                         @Override
 124  
                         public Object doInPersistenceBroker(PersistenceBroker broker) {
 125  0
                                 PreparedStatement preparedStatement = null;
 126  
                                 try {
 127  0
                                         Connection connection = broker.serviceConnectionManager().getConnection();
 128  0
                                         preparedStatement = connection.prepareStatement(UPDATE_STATUS_FOR_INSTANCE_ID);
 129  0
                                         preparedStatement.setString(1, statusCode);
 130  0
                                         preparedStatement.setString(2, instanceId);
 131  0
                                         preparedStatement.executeUpdate();
 132  0
                                 } catch (Exception e) {
 133  0
                                         throw new RuntimeException("Failed to update status for instance id", e);
 134  
                                 } finally {
 135  0
                                         if (preparedStatement != null) {
 136  
                                                 try {
 137  0
                                                         preparedStatement.close();
 138  0
                                                 } catch (SQLException e) {}
 139  
                                         }
 140  
                                 }
 141  0
                                 return null;
 142  
                         }
 143  
                 });
 144  0
         }
 145  
 
 146  
 }