List of usage examples for org.hibernate TypeMismatchException TypeMismatchException
public TypeMismatchException(String message)
From source file:org.codekaizen.vtj.hibernate3.AbstractValueTypeUserType.java
License:Open Source License
public Object fromXMLString(final String xmlValue) { if (!this.getFactory().isParsable(xmlValue)) { throw new TypeMismatchException("Supplied object must be of type " + this.clazz.getName()); }/* www. j a v a2 s . co m*/ return this.getFactory().parse(xmlValue); }
From source file:org.codekaizen.vtj.hibernate3.AbstractValueTypeUserType.java
License:Open Source License
public String objectToSQLString(final Object value) { if (value == null) { return "IS NULL"; } else if (!(this.clazz.isAssignableFrom(value.getClass()))) { throw new TypeMismatchException("Supplied object must be of type " + this.clazz.getName()); } else {// w w w. j a va 2s .co m return null; } }
From source file:org.codekaizen.vtj.hibernate3.AbstractValueTypeUserType.java
License:Open Source License
public String toXMLString(final Object value) { if (value == null) { return ""; } else if (!(this.clazz.isAssignableFrom(value.getClass()))) { throw new TypeMismatchException("Supplied object must be of type " + this.clazz.getName()); } else {//from w w w.ja v a 2 s . c o m return null; } }
From source file:org.n52.sos.config.sqlite.HibernateTimeInstantType.java
License:Open Source License
@Override protected Time decode(String s) throws HibernateException { try {/*from w w w .j a va 2 s . c o m*/ return decodeTimeInstant(s); } catch (DateTimeParseException e) { throw new TypeMismatchException(String.format("Error while creating Time from %s", s)); } }
From source file:org.n52.sos.config.sqlite.HibernateUriType.java
License:Open Source License
@Override protected URI decode(String s) throws HibernateException { try {/*from w w w . j a v a 2 s .c o m*/ return new URI(s); } catch (URISyntaxException e) { throw new TypeMismatchException(String.format("Error while creating URL from %s", s)); } }
From source file:org.openwms.common.units.UnitUserType.java
License:Open Source License
/** * {@inheritDoc}//from w w w. j a va 2 s.c o m */ @Override public Object getPropertyValue(Object component, int property) { if (component instanceof Piece) { Piece piece = (Piece) component; return property == 0 ? piece.getUnitType() : piece.getMagnitude(); } else if (component instanceof Weight) { Weight weight = (Weight) component; return property == 0 ? weight.getUnitType() : weight.getMagnitude(); } throw new TypeMismatchException("Incompatible type:" + component.getClass()); }
From source file:org.openwms.common.units.UnitUserType.java
License:Open Source License
/** * {@inheritDoc}//from w w w .j a va2 s . co m * <p> * Try to re-assign the value read from the database to some type of Unit. Currently supported types: <ul> <li>Piece</li> * <li>Weight</li> </ul> * * @throws SQLException in case of database errors */ @Override public Object nullSafeGet(ResultSet rs, String[] strings, SessionImplementor sessionImplementor, Object o) throws HibernateException, SQLException { String rs0 = rs.getString(strings[0]); if (rs.wasNull()) { return null; } String[] val = rs0.split("@"); String unitType = val[0]; String unitTypeClass = val[1]; if (Piece.class.getCanonicalName().equals(unitTypeClass)) { int amount = rs.getInt(strings[1]); return new Piece(amount, PieceUnit.valueOf(unitType)); } else if (Weight.class.getCanonicalName().equals(unitTypeClass)) { BigDecimal amount = rs.getBigDecimal(strings[1]); return new Weight(amount, WeightUnit.valueOf(unitType)); } throw new TypeMismatchException("Incompatible type: " + unitTypeClass); }
From source file:org.openwms.common.units.UnitUserType.java
License:Open Source License
/** * {@inheritDoc}/*from w w w . j av a2 s .c o m*/ * <p> * We've to store the concrete classname as well. * * @throws SQLException in case of database errors */ @Override public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor sessionImplementor) throws HibernateException, SQLException { if (value == null) { st.setNull(index, StandardBasicTypes.STRING.sqlType()); st.setNull(index + 1, StandardBasicTypes.STRING.sqlType()); } else { if (value instanceof Piece) { Piece piece = (Piece) value; st.setString(index, piece.getUnitType().toString() + "@" + Piece.class.getCanonicalName()); st.setString(index + 1, piece.getMagnitude().toPlainString()); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Binding '" + piece.getUnitType().toString() + "@" + Piece.class.getCanonicalName() + "' to parameter: " + index); LOGGER.trace( "Binding '" + piece.getMagnitude().toPlainString() + "' to parameter: " + (index + 1)); } } else if (value instanceof Weight) { Weight weight = (Weight) value; st.setString(index, weight.getUnitType().toString() + "@" + Weight.class.getCanonicalName()); st.setString(index + 1, weight.getMagnitude().toPlainString()); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Binding '" + weight.getUnitType().toString() + "@" + Weight.class.getCanonicalName() + "' to parameter: " + index); LOGGER.trace( "Binding '" + weight.getMagnitude().toPlainString() + "' to parameter: " + index + 1); } } else { throw new TypeMismatchException("Incompatible type: " + value.getClass().getCanonicalName()); } } }
From source file:org.openwms.persistence.ext.hibernate.UnitUserType.java
License:Open Source License
/** * {@inheritDoc}//from w w w.j a v a2 s.com * * Try to re-assign the value read from the database to some type of Unit. Currently supported types: * <ul> * <li>Piece</li> * <li>Weight</li> * </ul> * * @throws SQLException * in case of database errors */ @Override public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws SQLException { String rs0 = rs.getString(names[0]); if (rs.wasNull()) { return null; } String[] val = rs0.split("@"); String unitType = val[0]; String unitTypeClass = val[1]; if (Piece.class.getCanonicalName().equals(unitTypeClass)) { int amount = rs.getInt(names[1]); return new Piece(amount, PieceUnit.valueOf(unitType)); } else if (Weight.class.getCanonicalName().equals(unitTypeClass)) { BigDecimal amount = rs.getBigDecimal(names[1]); return new Weight(amount, WeightUnit.valueOf(unitType)); } throw new TypeMismatchException("Incompatible type: " + unitTypeClass); }
From source file:org.openwms.persistence.ext.hibernate.UnitUserType.java
License:Open Source License
/** * {@inheritDoc}/*from w w w . ja va2s . c o m*/ * * We've to store the concrete classname as well. * * @throws SQLException * in case of database errors */ @Override public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws SQLException { if (value == null) { st.setNull(index, StandardBasicTypes.STRING.sqlType()); st.setNull(index + 1, StandardBasicTypes.STRING.sqlType()); } else { if (value instanceof Piece) { Piece piece = (Piece) value; st.setString(index, piece.getUnitType().toString() + "@" + Piece.class.getCanonicalName()); st.setString(index + 1, piece.getMagnitude().toPlainString()); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Binding '" + piece.getUnitType().toString() + "@" + Piece.class.getCanonicalName() + "' to parameter: " + index); LOGGER.trace( "Binding '" + piece.getMagnitude().toPlainString() + "' to parameter: " + (index + 1)); } } else if (value instanceof Weight) { Weight weight = (Weight) value; st.setString(index, weight.getUnitType().toString() + "@" + Weight.class.getCanonicalName()); st.setString(index + 1, weight.getMagnitude().toPlainString()); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Binding '" + weight.getUnitType().toString() + "@" + Weight.class.getCanonicalName() + "' to parameter: " + index); LOGGER.trace( "Binding '" + weight.getMagnitude().toPlainString() + "' to parameter: " + index + 1); } } else { throw new TypeMismatchException("Incompatible type: " + value.getClass().getCanonicalName()); } } }