Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2011 The Kuali Foundation Licensed under the Educational Community 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.osedu.org/licenses/ECL-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.kuali.common.impex.model.util;
 
 
 public class DifferenceUtils {
     public static final String LABEL_SEPARATOR = ": ";
     public static final String FOUND_IN_LABEL = "FOUND IN: ";
     public static final String NOT_FOUND_IN_LABEL = "NOT FOUND IN: ";
     public static final String DOT = ".";
     public static final String COMMA = ".";
     public static final String SPACE = " ";
     public static final String NOT_EQUAL_SEPARATOR = " != ";
     public static final String OPEN_PAREN = "(";
     public static final String CLOSE_PAREN = ")";
 
     static String buildDifferenceToken(String labelSchemaDifference difference) {
         StringBuilder sb = new StringBuilder();
 
         sb.append(label);
         sb.append();
         sb.append(buildSchema1Token(difference));
         sb.append();
         sb.append(buildSchema2Token(difference));
 
         return sb.toString();
     }
 
     public static String buildTable1DifferenceToken(TableDifference t) {
         StringBuilder sb = new StringBuilder();
         sb.append(t.getTable1().getName());
 
         if (t instanceof ColumnDifference) {
             ColumnDifference c = (ColumnDifferencet;
             sb.append();
             sb.append(c.getColumn1().getName());
             switch (c.getType()) {
                 case : {
                     sb.append(parenWrapToken(c.getColumn1().getColumnDataType().toString()));
                     break;
                 }
                 case : {
                     sb.append(parenWrapToken(buildTypeSizeToken(c.getColumn1().getTypeSize())));
                     break;
                 }
             }
         }
         else if (t instanceof IndexDifference) {
             IndexDifference i = (IndexDifferencet;
             sb.append();
             sb.append(i.getIndex1().getName());
         }
         else if (t instanceof UniqueConstraintDifference) {
             UniqueConstraintDifference u = (UniqueConstraintDifferencet;
             sb.append();
             sb.append(u.getUnique1().getName());
         }
 
         return sb.toString();
     }
 
     public static String buildSchema1Token(SchemaDifference difference) {
         StringBuilder sb = new StringBuilder();
         sb.append(difference.getSchema1().getName());
         sb.append();
         if (difference instanceof TableDifference) {
             sb.append(buildTable1DifferenceToken((TableDifferencedifference));
         }
 
         if(difference instanceof ViewDifference) {
             sb.append(((ViewDifferencedifference).getView1().getName());
         }
 
         if(difference instanceof ForeignKeyDifference) {
             sb.append(((ForeignKeyDifferencedifference).getForeignKey1().getName());
         }
 
        if (difference instanceof SequenceDifference) {
            sb.append(((SequenceDifferencedifference).getSequence1().getName());
        }
        return sb.toString();
    }
    public static String buildSchema2Token(SchemaDifference difference) {
        StringBuilder sb = new StringBuilder();
        sb.append(difference.getSchema2().getName());
        sb.append();
        if (difference instanceof TableDifference) {
            sb.append(buildTable2DifferenceToken((TableDifferencedifference));
        }
        if(difference instanceof ViewDifference) {
            sb.append(((ViewDifferencedifference).getView2().getName());
        }
        if(difference instanceof ForeignKeyDifference) {
            sb.append(((ForeignKeyDifferencedifference).getForeignKey2().getName());
        }
        if (difference instanceof SequenceDifference) {
            sb.append(((SequenceDifferencedifference).getSequence2().getName());
        }
        return sb.toString();
    }
    public static String buildTable2DifferenceToken(TableDifference t) {
        StringBuilder sb = new StringBuilder();
        sb.append(t.getTable2().getName());
        if (t instanceof ColumnDifference) {
            ColumnDifference c = (ColumnDifferencet;
            sb.append();
            sb.append(c.getColumn2().getName());
            switch (c.getType()) {
                case : {
                    sb.append(parenWrapToken(c.getColumn2().getColumnDataType().toString()));
                    break;
                }
                case : {
                    sb.append(parenWrapToken(buildTypeSizeToken(c.getColumn2().getTypeSize())));
                    break;
                }
            }
        }
        else if (t instanceof IndexDifference) {
            IndexDifference i = (IndexDifferencet;
            sb.append();
            sb.append(i.getIndex2().getName());
        }
        else if (t instanceof UniqueConstraintDifference) {
            UniqueConstraintDifference u = (UniqueConstraintDifferencet;
            sb.append();
            sb.append(u.getUnique2().getName());
        }
        return sb.toString();
    }
    public static String buildMissingElementToken(String typeLabelString foundTokenString notFoundToken) {
        StringBuilder sb = new StringBuilder();
        sb.append(typeLabel);
        sb.append();
        sb.append();
        sb.append();
        sb.append(foundToken);
        sb.append();
        sb.append();
        sb.append(notFoundToken);
        return sb.toString();
    }
    public static String parenWrapToken(String s) {
        return  +  +  + s +  +  + ;
    }
    public static String buildTypeSizeToken(TypeSize typeSize) {
        String typeSizeString = "";
        if (typeSize != null) {
            typeSizeString = typeSize.getSize().toString();
            if (typeSize.isScaleSet()) {
                typeSizeString +=  + typeSize.getScale();
            }
        }
        return typeSizeString;
    }
New to GrepCode? Check out our FAQ X