Coverage Report - org.jtheque.core.managers.schema.AbstractSchema
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractSchema
0 %
0/28
0 %
0/24
3.667
 
 1  
 package org.jtheque.core.managers.schema;
 2  
 
 3  
 import org.jtheque.core.managers.Managers;
 4  
 import org.jtheque.core.managers.properties.IPropertiesManager;
 5  
 import org.jtheque.core.utils.CoreUtils;
 6  
 import org.jtheque.utils.Constants;
 7  
 import org.jtheque.utils.StringUtils;
 8  
 import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
 9  
 
 10  
 /*
 11  
  * This file is part of JTheque.
 12  
  *            
 13  
  * JTheque is free software: you can redistribute it and/or modify
 14  
  * it under the terms of the GNU General Public License as published by
 15  
  * the Free Software Foundation, either version 3 of the License. 
 16  
  *
 17  
  * JTheque is distributed in the hope that it will be useful,
 18  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 19  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 20  
  * GNU General Public License for more details.
 21  
  *
 22  
  * You should have received a copy of the GNU General Public License
 23  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 24  
  */
 25  
 
 26  
 /**
 27  
  * An abstract schema. The only thing this abstract class do is implementing the compareTo() method to ensure for
 28  
  * good order in collections.
 29  
  *
 30  
  * @author Baptiste Wicht
 31  
  */
 32  0
 public abstract class AbstractSchema implements Schema {
 33  
     private SimpleJdbcTemplate jdbcTemplate;
 34  
 
 35  
     /**
 36  
      * Return the jdbc template to execute JDBC request.
 37  
      *
 38  
      * @return The jdbc template.
 39  
      */
 40  
     public SimpleJdbcTemplate getJdbcTemplate(){
 41  0
         if(jdbcTemplate == null){
 42  0
             jdbcTemplate = CoreUtils.getBean("jdbcTemplate");
 43  
         }
 44  
 
 45  0
         return jdbcTemplate;
 46  
     }
 47  
 
 48  
     /**
 49  
      * Update the the database executing the specified request.
 50  
      *
 51  
      * @param request The request to execute.
 52  
      * @param args The args to give to the request. 
 53  
      */
 54  
     public void update(String request, Object... args){
 55  0
         getJdbcTemplate().update(request, args);
 56  0
     }
 57  
 
 58  
     @Override
 59  
     public final int compareTo(Schema other) {
 60  0
         boolean hasDependency = StringUtils.isNotEmpty(getDependencies());
 61  0
         boolean hasOtherDependency = StringUtils.isNotEmpty(other.getDependencies());
 62  
 
 63  0
         if (hasDependency && !hasOtherDependency) {
 64  0
             return 1;
 65  0
         } else if (!hasDependency && hasOtherDependency) {
 66  0
             return -1;
 67  0
         } else if(hasDependency && hasOtherDependency){
 68  0
             for (String dependency : other.getDependencies()) {
 69  0
                 if (dependency.equals(getId())) {//The other depends on me
 70  0
                     return -1;
 71  
                 }
 72  
             }
 73  
 
 74  0
             for (String dependency : getDependencies()) {
 75  0
                 if (dependency.equals(other.getId())) {//I depends on the other
 76  0
                     return 1;
 77  
                 }
 78  
             }
 79  
         }
 80  
 
 81  0
         return 0;
 82  
     }
 83  
 
 84  
     @Override
 85  
     public int hashCode() {
 86  0
         int hash = Constants.HASH_CODE_START;
 87  
         
 88  0
         hash = Constants.HASH_CODE_PRIME * hash + getVersion().hashCode();
 89  0
         hash = Constants.HASH_CODE_PRIME * hash + getId().hashCode();
 90  
         
 91  0
         for(String dependency : getDependencies()){
 92  0
             hash = Constants.HASH_CODE_PRIME * hash + dependency.hashCode();
 93  
         }
 94  
         
 95  0
         return hash;
 96  
     }
 97  
 
 98  
     @Override
 99  
     public boolean equals(Object obj) {
 100  0
         return Managers.getManager(IPropertiesManager.class).areEquals(this, obj, "id", "version");
 101  
     }
 102  
 
 103  
     @Override
 104  
     public final String toString() {
 105  0
         return getId() + ':' + getVersion();
 106  
     }
 107  
 }