@Test public void testFindBySqlDataType() { try { String[][] data = { { String.valueOf(Types.BIT), "BIT" }, { String.valueOf(Types.TINYINT), "TINYINT" }, { String.valueOf(Types.SMALLINT), "SMALLINT" }, { String.valueOf(Types.INTEGER), "INTEGER" }, { String.valueOf(Types.BIGINT), "BIGINT" }, { String.valueOf(Types.REAL), "FLOAT" }, { String.valueOf(Types.DOUBLE), "DOUBLE" }, { String.valueOf(Types.DECIMAL), "DECIMAL" }, { String.valueOf(Types.CHAR), "CHAR" }, { String.valueOf(Types.VARCHAR), "VARCHAR" }, { String.valueOf(Types.DATE), "DATE" }, { String.valueOf(Types.TIME), "TIME" }, { String.valueOf(Types.TIMESTAMP), "DATETIME" }, { String.valueOf(Types.BINARY), "BINARY" }, { String.valueOf(Types.VARBINARY), "VARBINARY" }, { String.valueOf(Types.NULL), "NULL" }, }; MysqlNativeTypeCatalog mntCatalog = new MysqlNativeTypeCatalog(); mntCatalog.load(); for (String[] rec : data) { int sqlType = Integer.valueOf(rec[0]); String mysqlTypeStr = rec[1]; MysqlNativeType mysqlNativeType = (MysqlNativeType) mntCatalog.findType(sqlType, true); MysqlNativeType expectedMnType = (MysqlNativeType) mntCatalog.findType(mysqlTypeStr, true); assertEquals("Sql type " + sqlType + " should map to correct mysqlType", expectedMnType, mysqlNativeType); } } catch (Exception e) { failWithStackTrace(e); } }
@Override public MysqlNativeType findType(final MyFieldType mft, final int flags, final long maxLength, final boolean except) throws PEException { MyFieldDataKind dataKind = null; if (mft.isBinaryFlagDependent()) { final boolean keepText = (flags & MysqlNativeConstants.FLDPKT_FLAG_BINARY) == 0; if (keepText) { dataKind = MyFieldDataKind.TEXT; } else { dataKind = MyFieldDataKind.BINARY; } } else { dataKind = MyFieldDataKind.ANY; } final NativeType type = findSmallestSuitableType(mft.getByteValue(), dataKind, maxLength, (maxLength == 0) ? Collections.<NativeType> singleton(PARAMETER) : Collections.EMPTY_SET); if (type == null) { throw new PECodingException("Cannot find native type for field type " + mft + " with flags " + flags + " and length " + maxLength); } return (MysqlNativeType) type; }
MysqlNativeTypeCatalog extends NativeTypeCatalog { @Override public MysqlNativeType findType(final MyFieldType mft, final int flags, final long maxLength, final boolean except) throws PEException { MyFieldDataKind dataKind = null; if (mft.isBinaryFlagDependent()) { final boolean keepText = (flags & MysqlNativeConstants.FLDPKT_FLAG_BINARY) == 0; if (keepText) { dataKind = MyFieldDataKind.TEXT; } else { dataKind = MyFieldDataKind.BINARY; } } else { dataKind = MyFieldDataKind.ANY; } final NativeType type = findSmallestSuitableType(mft.getByteValue(), dataKind, maxLength, (maxLength == 0) ? Collections.<NativeType> singleton(PARAMETER) : Collections.EMPTY_SET); if (type == null) { throw new PECodingException("Cannot find native type for field type " + mft + " with flags " + flags + " and length " + maxLength); } return (MysqlNativeType) type; } }
MysqlNativeTypeCatalog extends NativeTypeCatalog { @Override public MysqlNativeType findType(final MyFieldType mft, final int flags, final long maxLength, final boolean except) throws PEException { MyFieldDataKind dataKind = null; if (mft.isBinaryFlagDependent()) { final boolean keepText = (flags & MysqlNativeConstants.FLDPKT_FLAG_BINARY) == 0; if (keepText) { dataKind = MyFieldDataKind.TEXT; } else { dataKind = MyFieldDataKind.BINARY; } } else { dataKind = MyFieldDataKind.ANY; } final NativeType type = findSmallestSuitableType(mft.getByteValue(), dataKind, maxLength, (maxLength == 0) ? Collections.<NativeType> singleton(PARAMETER) : Collections.EMPTY_SET); if (type == null) { throw new PECodingException("Cannot find native type for field type " + mft + " with flags " + flags + " and length " + maxLength); } return (MysqlNativeType) type; }  }
MysqlNativeTypeCatalog extends NativeTypeCatalog { @Override public MysqlNativeType findType(final MyFieldType mft, final int flags, final long maxLength, final boolean except) throws PEException { MyFieldDataKind dataKind = null; if (mft.isBinaryFlagDependent()) { final boolean keepText = (flags & MysqlNativeConstants.FLDPKT_FLAG_BINARY) == 0; if (keepText) { dataKind = MyFieldDataKind.TEXT; } else { dataKind = MyFieldDataKind.BINARY; } } else { dataKind = MyFieldDataKind.ANY; } final NativeType type = findSmallestSuitableType(mft.getByteValue(), dataKind, maxLength, (maxLength == 0) ? Collections.<NativeType> singleton(PARAMETER) : Collections.EMPTY_SET); if (type == null) { throw new PECodingException("Cannot find native type for field type " + mft + " with flags " + flags + " and length " + maxLength); } return (MysqlNativeType) type; }  @Override MysqlNativeType findType(final MyFieldType mft, final int flags, final long maxLength, final boolean except); }
MysqlNativeTypeCatalog extends NativeTypeCatalog { @Override public MysqlNativeType findType(final MyFieldType mft, final int flags, final long maxLength, final boolean except) throws PEException { MyFieldDataKind dataKind = null; if (mft.isBinaryFlagDependent()) { final boolean keepText = (flags & MysqlNativeConstants.FLDPKT_FLAG_BINARY) == 0; if (keepText) { dataKind = MyFieldDataKind.TEXT; } else { dataKind = MyFieldDataKind.BINARY; } } else { dataKind = MyFieldDataKind.ANY; } final NativeType type = findSmallestSuitableType(mft.getByteValue(), dataKind, maxLength, (maxLength == 0) ? Collections.<NativeType> singleton(PARAMETER) : Collections.EMPTY_SET); if (type == null) { throw new PECodingException("Cannot find native type for field type " + mft + " with flags " + flags + " and length " + maxLength); } return (MysqlNativeType) type; }  @Override MysqlNativeType findType(final MyFieldType mft, final int flags, final long maxLength, final boolean except);  }