Coverage Report - org.jtheque.primary.services.impl.SimpleDatasService
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleDatasService
0 %
0/33
0 %
0/8
1.188
 
 1  
 package org.jtheque.primary.services.impl;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jtheque.core.managers.persistence.able.DataListener;
 20  
 import org.jtheque.primary.dao.able.IDaoSimpleDatas;
 21  
 import org.jtheque.primary.od.able.SimpleData;
 22  
 import org.jtheque.primary.services.able.ISimpleDataService;
 23  
 import org.springframework.transaction.annotation.Transactional;
 24  
 
 25  
 import java.util.Collection;
 26  
 
 27  
 /**
 28  
  * A simple data service implementation.
 29  
  *
 30  
  * @author Baptiste Wicht
 31  
  */
 32  0
 public final class SimpleDatasService implements ISimpleDataService {
 33  
         private SimpleData defaultSimpleData;
 34  
 
 35  
         private final IDaoSimpleDatas daoSimpleDatas;
 36  
         private final SimpleData.DataType dataType;
 37  
 
 38  
         /**
 39  
          * Construct a new SimpleDatasService.
 40  
          *
 41  
          * @param daoSimpleDatas The dao to use.
 42  
          * @param dataType The data type
 43  
          */
 44  
         public SimpleDatasService(IDaoSimpleDatas daoSimpleDatas, String dataType){
 45  0
                 super();
 46  
 
 47  0
                 this.daoSimpleDatas = daoSimpleDatas;
 48  0
                 this.dataType = SimpleData.DataType.valueOf(dataType);
 49  
 
 50  0
         }
 51  
 
 52  
         @Override
 53  
         public SimpleData getDefaultSimpleData(){
 54  0
                 if (defaultSimpleData == null){
 55  0
                         defaultSimpleData = daoSimpleDatas.getSimpleData("Unknown");
 56  
 
 57  0
                         if (defaultSimpleData == null){
 58  0
                                 createDefaultSimpleData();
 59  
                         }
 60  
                 }
 61  
 
 62  0
                 return defaultSimpleData;
 63  
         }
 64  
 
 65  
         /**
 66  
          * Create the default country.
 67  
          */
 68  
         @Transactional
 69  
         private void createDefaultSimpleData(){
 70  0
                 defaultSimpleData = daoSimpleDatas.createSimpleData();
 71  0
                 defaultSimpleData.setName("Unknown");
 72  0
                 daoSimpleDatas.create(defaultSimpleData);
 73  0
         }
 74  
 
 75  
         @Override
 76  
         @Transactional
 77  
         public void save(SimpleData simpleData){
 78  0
                 daoSimpleDatas.save(simpleData);
 79  0
         }
 80  
 
 81  
         @Override
 82  
         @Transactional
 83  
         public void create(SimpleData simpleData){
 84  0
                 daoSimpleDatas.create(simpleData);
 85  0
         }
 86  
 
 87  
         @Override
 88  
         @Transactional
 89  
         public boolean delete(SimpleData simpleData){
 90  0
                 return daoSimpleDatas.delete(simpleData);
 91  
         }
 92  
 
 93  
         @Override
 94  
         public SimpleData getSimpleData(String name){
 95  0
                 return daoSimpleDatas.getSimpleData(name);
 96  
         }
 97  
 
 98  
         @Override
 99  
         @Transactional
 100  
         public void createAll(Iterable<SimpleData> simpleDatas){
 101  0
                 for (SimpleData simpleData : simpleDatas){
 102  0
                         daoSimpleDatas.create(simpleData);
 103  
                 }
 104  0
         }
 105  
 
 106  
         @Override
 107  
         public boolean exist(SimpleData simpleData){
 108  0
                 return daoSimpleDatas.exist(simpleData);
 109  
         }
 110  
 
 111  
         @Override
 112  
         public SimpleData getEmptySimpleData(){
 113  0
                 return daoSimpleDatas.createSimpleData();
 114  
         }
 115  
 
 116  
         @Override
 117  
         public boolean exist(String name){
 118  0
                 return getSimpleData(name) != null;
 119  
         }
 120  
 
 121  
         @Override
 122  
         public boolean hasNoDatas(){
 123  0
                 return daoSimpleDatas.getSimpleDatas().isEmpty();
 124  
         }
 125  
 
 126  
         @Override
 127  
         public Collection<SimpleData> getDatas(){
 128  0
                 return daoSimpleDatas.getSimpleDatas();
 129  
         }
 130  
 
 131  
         @Override
 132  
         public void addDataListener(DataListener listener){
 133  0
                 daoSimpleDatas.addDataListener(listener);
 134  0
         }
 135  
 
 136  
         @Override
 137  
         @Transactional
 138  
         public void clearAll(){
 139  0
                 daoSimpleDatas.clearAll();
 140  0
         }
 141  
 
 142  
         @Override
 143  
         public String getDataType(){
 144  0
                 return dataType.getDataType();
 145  
         }
 146  
 }