Coverage Summary for Class: SQLProfile (com.acciente.oacc.sql)

Class Method, % Line, %
SQLProfile 72.7% (8/ 11) 59.1% (26/ 44)
SQLProfile$Builder 100% (9/ 9) 100% (17/ 17)
total 85% (17/ 20) 70.5% (43/ 61)


1 /* 2  * Copyright 2009-2018, Acciente LLC 3  * 4  * Acciente LLC licenses this file to you under the 5  * Apache License, Version 2.0 (the "License"); you 6  * may not use this file except in compliance with the 7  * License. You may obtain a copy of the License at 8  * 9  * http://www.apache.org/licenses/LICENSE-2.0 10  * 11  * Unless required by applicable law or agreed to in 12  * writing, software distributed under the License is 13  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES 14  * OR CONDITIONS OF ANY KIND, either express or implied. 15  * See the License for the specific language governing 16  * permissions and limitations under the License. 17  */ 18 package com.acciente.oacc.sql; 19  20 import java.io.Serializable; 21 import java.util.LinkedHashMap; 22 import java.util.Map; 23  24 public class SQLProfile implements Serializable { 25  private static final long serialVersionUID = 1L; 26  27  public static final SQLProfile DB2_10_5_RECURSIVE; 28  public static final SQLProfile DB2_10_5_NON_RECURSIVE; 29  public static final SQLProfile Oracle_11_2_RECURSIVE; 30  public static final SQLProfile Oracle_11_2_NON_RECURSIVE; 31  public static final SQLProfile PostgreSQL_9_3_RECURSIVE; 32  public static final SQLProfile PostgreSQL_9_3_NON_RECURSIVE; 33  public static final SQLProfile SQLServer_12_0_RECURSIVE; 34  public static final SQLProfile SQLServer_12_0_NON_RECURSIVE; 35  public static final SQLProfile SQLite_3_8_RECURSIVE; 36  public static final SQLProfile SQLite_3_8_NON_RECURSIVE; 37  public static final SQLProfile MySQL_5_6_NON_RECURSIVE; 38  public static final SQLProfile HSQLDB_2_3_NON_RECURSIVE; 39  40  static { 41  DB2_10_5_RECURSIVE = new Builder("DB2_10_5_RECURSIVE") 42  .sqlDialect(SQLDialect.DB2_10_5) 43  .recursiveCTEEnabled(true) 44  .recursiveDeleteEnabled(false) 45  .sequenceEnabled(true) 46  .build(); 47  48  DB2_10_5_NON_RECURSIVE = new Builder("DB2_10_5_NON_RECURSIVE") 49  .sqlDialect(SQLDialect.DB2_10_5) 50  .recursiveCTEEnabled(false) 51  .recursiveDeleteEnabled(false) 52  .sequenceEnabled(true) 53  .build(); 54  55  Oracle_11_2_RECURSIVE = new Builder("Oracle_11_2_RECURSIVE") 56  .sqlDialect(SQLDialect.Oracle_11_2) 57  .recursiveCTEEnabled(true) 58  .recursiveDeleteEnabled(true) 59  .sequenceEnabled(true) 60  .build(); 61  62  Oracle_11_2_NON_RECURSIVE = new Builder("Oracle_11_2_NON_RECURSIVE") 63  .sqlDialect(SQLDialect.Oracle_11_2) 64  .recursiveCTEEnabled(false) 65  .recursiveDeleteEnabled(false) 66  .sequenceEnabled(true) 67  .build(); 68  69  PostgreSQL_9_3_RECURSIVE = new Builder("PostgreSQL_9_3_RECURSIVE") 70  .sqlDialect(SQLDialect.PostgreSQL_9_3) 71  .recursiveCTEEnabled(true) 72  .recursiveDeleteEnabled(true) 73  .sequenceEnabled(true) 74  .build(); 75  76  PostgreSQL_9_3_NON_RECURSIVE = new Builder("PostgreSQL_9_3_NON_RECURSIVE") 77  .sqlDialect(SQLDialect.PostgreSQL_9_3) 78  .recursiveCTEEnabled(false) 79  .recursiveDeleteEnabled(false) 80  .sequenceEnabled(true) 81  .build(); 82  83  SQLServer_12_0_RECURSIVE = new Builder("SQLServer_12_0_RECURSIVE") 84  .sqlDialect(SQLDialect.SQLServer_12_0) 85  .recursiveCTEEnabled(true) 86  .recursiveDeleteEnabled(true) 87  .sequenceEnabled(true) 88  .build(); 89  90  SQLServer_12_0_NON_RECURSIVE = new Builder("SQLServer_12_0_NON_RECURSIVE") 91  .sqlDialect(SQLDialect.SQLServer_12_0) 92  .recursiveCTEEnabled(false) 93  .recursiveDeleteEnabled(false) 94  .sequenceEnabled(true) 95  .build(); 96  97  SQLite_3_8_RECURSIVE = new Builder("SQLite_3_8_RECURSIVE") 98  .sqlDialect(SQLDialect.SQLite_3_8) 99  .recursiveCTEEnabled(true) 100  .recursiveDeleteEnabled(true) 101  .sequenceEnabled(false) 102  .build(); 103  104  SQLite_3_8_NON_RECURSIVE = new Builder("SQLite_3_8_NON_RECURSIVE") 105  .sqlDialect(SQLDialect.SQLite_3_8) 106  .recursiveCTEEnabled(false) 107  .recursiveDeleteEnabled(false) 108  .sequenceEnabled(false) 109  .build(); 110  111  MySQL_5_6_NON_RECURSIVE = new Builder("MySQL_5_6_NON_RECURSIVE") 112  .sqlDialect(SQLDialect.MySQL_5_6) 113  .recursiveCTEEnabled(false) 114  .recursiveDeleteEnabled(false) 115  .sequenceEnabled(false) 116  .build(); 117  118  HSQLDB_2_3_NON_RECURSIVE = new Builder("HSQLDB_2_3_NON_RECURSIVE") 119  .sqlDialect(SQLDialect.HSQLDB_2_3) 120  .recursiveCTEEnabled(false) 121  .recursiveDeleteEnabled(false) 122  .sequenceEnabled(true) 123  .build(); 124  } 125  126  public static String nameOf(SQLProfile sqlProfile) { 127  return sqlProfile.name; 128  } 129  130  public static SQLProfile valueOf(String name) { 131  return Builder.valueOf(name); 132  } 133  134  // attributes of the SQLProfile 135  private final String name; 136  private final SQLDialect sqlDialect; 137  private final boolean recursiveCTEEnabled; 138  private final boolean recursiveDeleteEnabled; 139  private final boolean sequenceEnabled; 140  141  private SQLProfile(Builder builder) { 142  this.name = builder.name; 143  this.sqlDialect = builder.sqlDialect; 144  this.recursiveCTEEnabled = builder.recursiveCTEEnabled; 145  this.recursiveDeleteEnabled = builder.recursiveDeleteEnabled; 146  this.sequenceEnabled = builder.sequenceEnabled; 147  } 148  149  public SQLDialect getSqlDialect() { 150  return sqlDialect; 151  } 152  153  public boolean isRecursiveCTEEnabled() { 154  return recursiveCTEEnabled; 155  } 156  157  public boolean isRecursiveDeleteEnabled() { 158  return recursiveDeleteEnabled; 159  } 160  161  public boolean isSequenceEnabled() { 162  return sequenceEnabled; 163  } 164  165  @Override 166  public boolean equals(Object o) { 167  if (this == o) { 168  return true; 169  } 170  if (o == null || getClass() != o.getClass()) { 171  return false; 172  } 173  174  SQLProfile that = (SQLProfile) o; 175  176  if (recursiveCTEEnabled != that.recursiveCTEEnabled) { 177  return false; 178  } 179  if (recursiveDeleteEnabled != that.recursiveDeleteEnabled) { 180  return false; 181  } 182  if (sequenceEnabled != that.sequenceEnabled) { 183  return false; 184  } 185  return sqlDialect == that.sqlDialect; 186  } 187  188  @Override 189  public int hashCode() { 190  int result = sqlDialect.hashCode(); 191  result = 31 * result + (recursiveCTEEnabled ? 1 : 0); 192  result = 31 * result + (recursiveDeleteEnabled ? 1 : 0); 193  result = 31 * result + (sequenceEnabled ? 1 : 0); 194  return result; 195  } 196  197  // private builder, also maintains mapping by name 198  private static class Builder { 199  // a map of all the SQLProfile values defined here keyed by their associated name 200  private static final Map<String, SQLProfile> sqlProfilesByName = new LinkedHashMap<>(); 201  202  private final String name; 203  204  private SQLDialect sqlDialect; 205  private boolean recursiveCTEEnabled; 206  private boolean recursiveDeleteEnabled; 207  private boolean sequenceEnabled; 208  209  private static SQLProfile valueOf(String name) { 210  return sqlProfilesByName.get(name); 211  } 212  213  private Builder(String name) { 214  this.name = name; 215  } 216  217  private Builder sqlDialect(SQLDialect sqlDialect) { 218  this.sqlDialect = sqlDialect; 219  return this; 220  } 221  222  private Builder recursiveCTEEnabled(boolean recursiveCTEEnabled) { 223  this.recursiveCTEEnabled = recursiveCTEEnabled; 224  return this; 225  } 226  227  private Builder recursiveDeleteEnabled(boolean recursiveDeleteEnabled) { 228  this.recursiveDeleteEnabled = recursiveDeleteEnabled; 229  return this; 230  } 231  232  private Builder sequenceEnabled(boolean sequenceEnabled) { 233  this.sequenceEnabled = sequenceEnabled; 234  return this; 235  } 236  237  private SQLProfile build() { 238  SQLProfile sqlProfile = new SQLProfile(this); 239  sqlProfilesByName.put(name, sqlProfile); 240  return sqlProfile; 241  } 242  } 243 }