001package io.ebean.config.dbplatform.mysql;
002
003import io.ebean.config.dbplatform.DbPlatformType;
004
005/**
006 * Support for blob, mediumblob or longblob selection based on the deployment
007 * length.
008 * <p>
009 * If no deployment length is defined longblob is used.
010 * </p>
011 */
012public class MySqlBlob extends DbPlatformType {
013
014  private static final int POWER_2_16 = 65536;
015  private static final int POWER_2_24 = 16777216;
016
017  public MySqlBlob() {
018    super("blob");
019  }
020
021  @Override
022  public String renderType(int deployLength, int deployScale) {
023
024    if (deployLength >= POWER_2_24) {
025      return "longblob";
026    }
027    if (deployLength >= POWER_2_16) {
028      return "mediumblob";
029    }
030    if (deployLength < 1) {
031      // length not explicitly defined
032      return "longblob";
033    }
034    return "blob";
035  }
036
037}