@Test public void testGetZeroValue() { try { for (final MysqlType mysqlType : MysqlType.values()) { if (mysqlType.isValid()) { assertTrue("Missing mysqlType " + mysqlType, TYPE_TO_ZERO_VALUE_TRANSLATION_TABLE.containsKey(mysqlType)); final MysqlNativeType mnType = new MysqlNativeType(mysqlType); final Object expectedValue = TYPE_TO_ZERO_VALUE_TRANSLATION_TABLE.get(mysqlType); if (expectedValue != null) { assertEquals(expectedValue, mnType.getZeroValue()); } else { new ExpectedExceptionTester() { @Override public void test() throws PEException { mnType.getZeroValue(); } }.assertException(PEException.class); } } } } catch (final Exception e) { failWithStackTrace(e); } }
@Override public Object getZeroValue() throws PEException { switch(mysqlType) { case BIGINT: case BIT: case BOOL: case INT: case SMALLINT: case MEDIUMINT: case TINYINT: case DOUBLE: case DECIMAL: case DOUBLE_PRECISION: case FLOAT: return new Integer(0); case CHAR: case TEXT: case LONGTEXT: case MEDIUMTEXT: case TINYTEXT: case VARCHAR: case BLOB: case LONGBLOB: case ALTLONGBLOB: case MEDIUMBLOB: case ALTMEDIUMBLOB: case TINYBLOB: case ALTTINYBLOB: case VARBINARY: case BINARY: return ""; case DATE: return "0000-00-00"; case TIME: return "00:00:00"; case DATETIME: case TIMESTAMP: return "0000-00-00 00:00:00"; case YEAR: return new Integer(0); default: throw new PEException("No zero value known for type " + mysqlType); } }
MysqlNativeType extends NativeType { @Override public Object getZeroValue() throws PEException { switch(mysqlType) { case BIGINT: case BIT: case BOOL: case INT: case SMALLINT: case MEDIUMINT: case TINYINT: case DOUBLE: case DECIMAL: case DOUBLE_PRECISION: case FLOAT: return new Integer(0); case CHAR: case TEXT: case LONGTEXT: case MEDIUMTEXT: case TINYTEXT: case VARCHAR: case BLOB: case LONGBLOB: case ALTLONGBLOB: case MEDIUMBLOB: case ALTMEDIUMBLOB: case TINYBLOB: case ALTTINYBLOB: case VARBINARY: case BINARY: return ""; case DATE: return "0000-00-00"; case TIME: return "00:00:00"; case DATETIME: case TIMESTAMP: return "0000-00-00 00:00:00"; case YEAR: return new Integer(0); default: throw new PEException("No zero value known for type " + mysqlType); } } }
MysqlNativeType extends NativeType { @Override public Object getZeroValue() throws PEException { switch(mysqlType) { case BIGINT: case BIT: case BOOL: case INT: case SMALLINT: case MEDIUMINT: case TINYINT: case DOUBLE: case DECIMAL: case DOUBLE_PRECISION: case FLOAT: return new Integer(0); case CHAR: case TEXT: case LONGTEXT: case MEDIUMTEXT: case TINYTEXT: case VARCHAR: case BLOB: case LONGBLOB: case ALTLONGBLOB: case MEDIUMBLOB: case ALTMEDIUMBLOB: case TINYBLOB: case ALTTINYBLOB: case VARBINARY: case BINARY: return ""; case DATE: return "0000-00-00"; case TIME: return "00:00:00"; case DATETIME: case TIMESTAMP: return "0000-00-00 00:00:00"; case YEAR: return new Integer(0); default: throw new PEException("No zero value known for type " + mysqlType); } } MysqlNativeType(MysqlType mysqlType); }
MysqlNativeType extends NativeType { @Override public Object getZeroValue() throws PEException { switch(mysqlType) { case BIGINT: case BIT: case BOOL: case INT: case SMALLINT: case MEDIUMINT: case TINYINT: case DOUBLE: case DECIMAL: case DOUBLE_PRECISION: case FLOAT: return new Integer(0); case CHAR: case TEXT: case LONGTEXT: case MEDIUMTEXT: case TINYTEXT: case VARCHAR: case BLOB: case LONGBLOB: case ALTLONGBLOB: case MEDIUMBLOB: case ALTMEDIUMBLOB: case TINYBLOB: case ALTTINYBLOB: case VARBINARY: case BINARY: return ""; case DATE: return "0000-00-00"; case TIME: return "00:00:00"; case DATETIME: case TIMESTAMP: return "0000-00-00 00:00:00"; case YEAR: return new Integer(0); default: throw new PEException("No zero value known for type " + mysqlType); } } MysqlNativeType(MysqlType mysqlType); MysqlType getMysqlType(); byte getCharSet(); void setCharSet(byte charSet); @SuppressWarnings("hiding") MysqlNativeType withCharSet(byte charSet); short getFieldTypeFlags(); void setFieldTypeFlags(short fieldTypeFlags); @SuppressWarnings("hiding") MysqlNativeType withFieldTypeFlags(short fieldTypeFlags); @SuppressWarnings("hiding") MysqlNativeType withFieldTypeFlags(Integer fieldTypeFlags); @Override void setCaseSensitive(boolean caseSensitive); @Override void setUnsignedAttribute(boolean unsignedAttribute); @Override boolean asKeyRequiresPrefix(); @Override Object getZeroValue(); @Override boolean supportsDefaultValue(); @Override boolean isTimestampType(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int getDefaultColumnAttrFlags(); }
MysqlNativeType extends NativeType { @Override public Object getZeroValue() throws PEException { switch(mysqlType) { case BIGINT: case BIT: case BOOL: case INT: case SMALLINT: case MEDIUMINT: case TINYINT: case DOUBLE: case DECIMAL: case DOUBLE_PRECISION: case FLOAT: return new Integer(0); case CHAR: case TEXT: case LONGTEXT: case MEDIUMTEXT: case TINYTEXT: case VARCHAR: case BLOB: case LONGBLOB: case ALTLONGBLOB: case MEDIUMBLOB: case ALTMEDIUMBLOB: case TINYBLOB: case ALTTINYBLOB: case VARBINARY: case BINARY: return ""; case DATE: return "0000-00-00"; case TIME: return "00:00:00"; case DATETIME: case TIMESTAMP: return "0000-00-00 00:00:00"; case YEAR: return new Integer(0); default: throw new PEException("No zero value known for type " + mysqlType); } } MysqlNativeType(MysqlType mysqlType); MysqlType getMysqlType(); byte getCharSet(); void setCharSet(byte charSet); @SuppressWarnings("hiding") MysqlNativeType withCharSet(byte charSet); short getFieldTypeFlags(); void setFieldTypeFlags(short fieldTypeFlags); @SuppressWarnings("hiding") MysqlNativeType withFieldTypeFlags(short fieldTypeFlags); @SuppressWarnings("hiding") MysqlNativeType withFieldTypeFlags(Integer fieldTypeFlags); @Override void setCaseSensitive(boolean caseSensitive); @Override void setUnsignedAttribute(boolean unsignedAttribute); @Override boolean asKeyRequiresPrefix(); @Override Object getZeroValue(); @Override boolean supportsDefaultValue(); @Override boolean isTimestampType(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int getDefaultColumnAttrFlags(); static final String MODIFIER_UNSIGNED; static final String MODIFIER_SIGNED; static final String MODIFIER_ZEROFILL; }