ForeignKeyCannotBeComparedToPrimaryKey.java

  1. /*
  2.  * Copyright 2014 Gregory Graham.
  3.  *
  4.  * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
  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 nz.co.gregs.dbvolution.exceptions;

  17. import nz.co.gregs.dbvolution.internal.properties.PropertyWrapper;
  18. import nz.co.gregs.dbvolution.query.RowDefinition;

  19. /**
  20.  * Thrown when there is a mismatch between the datatype of a DBRow's primary key
  21.  * and another's foreign key reference to it.
  22.  *
  23.  * <p>
  24.  * That is to say a DBPrimaryKey field has been declared as, for instance,
  25.  * DBInteger but the DBForeignKey elsewhere is associated with a, for instance,
  26.  * DBString.
  27.  *
  28.  * <p>
  29.  * Generally this means the foreign key field needs to be changed to the correct
  30.  * datatype.
  31.  *
  32.  * <p style="color: #F90;">Support DBvolution at
  33.  * <a href="http://patreon.com/dbvolution" target=new>Patreon</a></p>
  34.  *
  35.  * @author Gregory Graham
  36.  */
  37. public class ForeignKeyCannotBeComparedToPrimaryKey extends DBRuntimeException {

  38.     private static final long serialVersionUID = 1L;

  39.     /**
  40.      * Thrown when there is a mismatch between the datatype of a DBRow's primary
  41.      * key and another's foreign key reference to it.
  42.      *
  43.      * @param ex ex
  44.      * @param targetPK targetPK
  45.      * @param source source
  46.      * @param target target
  47.      * @param sourceFK sourceFK
  48.      */
  49.     public ForeignKeyCannotBeComparedToPrimaryKey(Exception ex, RowDefinition source, PropertyWrapper<?, ?, ?> sourceFK, RowDefinition target, PropertyWrapper<?, ?, ?> targetPK) {
  50.         super("Unable To Construct An Expression Representing The Foreign Key Relationship From "
  51.                 + source.getClass().getSimpleName() + ":" + sourceFK.javaName()
  52.                 + " To " + target.getClass().getSimpleName() + ":" + targetPK.javaName() + ": Check that the 2 fields have similar and comparable datatypes or remove the @DBForeignKey annotation",
  53.                 ex);
  54.     }

  55. }