/** {@inheritDoc} */ @Override public void setParameter( SqlRuntimeContext runtimeCtx, SqlQuery query, String paramName, Object inputValue, Class<?> inputType, boolean ingoreError) throws SqlRuntimeException { if (logger.isTraceEnabled()) { logger.trace( ">>> setParameter " + getMetaTypes()[0] + ": paramName=" + paramName + ", inputValue=" + inputValue + ", inputType=" + inputType); } if (inputValue == null) { query.setParameter(paramName, null, getProviderSqlNullType()); } else if (inputValue instanceof java.sql.Date) { query.setParameter(paramName, (java.sql.Date) inputValue, getProviderSqlType()); } else if (inputValue instanceof Date) { query.setParameter(paramName, (Date) inputValue, getProviderSqlType()); } else if (ingoreError) { logger.error("Incorrect date " + inputValue + " for " + paramName); } else { throw new SqlRuntimeException("Incorrect date " + inputValue + " for " + paramName); } }
@Override public void setParameter( SqlQuery query, String paramName, Object inputValue, Class<?> inputType, boolean ingoreError) throws SqlRuntimeException { if (inputValue == null) { query.setParameter(paramName, inputValue, Hibernate.STRING); } else { if (inputValue instanceof Collection) { List<String> phoneNumbers = new ArrayList<String>(); for (Iterator iter = ((Collection) inputValue).iterator(); iter.hasNext(); ) { Object o = iter.next(); if (o != null) { if (!(o instanceof PhoneNumber)) { if (ingoreError) { logger.error("Incorrect input value type " + o + ", it should be a PhoneNumber"); continue; } else { throw new SqlRuntimeException( "Incorrect input value type " + o + ", it should be a PhoneNumber"); } } String sPhoneNumber = ((PhoneNumber) o).toString(); } } query.setParameterList(paramName, phoneNumbers.toArray(), Hibernate.STRING); } else { if (!(inputValue instanceof PhoneNumber)) { if (ingoreError) { logger.error( "Incorrect input value type " + inputValue + ", it should be a PhoneNumber"); return; } else { throw new SqlRuntimeException( "Incorrect input value type " + inputValue + ", it should be a PhoneNumber"); } } PhoneNumber phoneNumber = (PhoneNumber) inputValue; String sPhoneNumber = String.format( "%03d-%03d-%04d", phoneNumber.getArea(), phoneNumber.getExch(), phoneNumber.getExt()); query.setParameter(paramName, sPhoneNumber, Hibernate.STRING); } } }
/** {@inheritDoc} */ public void addScalar(SqlQuery query, String dbName, Class<?> attributeType) { query.addScalar(dbName, getProviderSqlType()); }
/** {@inheritDoc} */ @Override public void setParameter( SqlRuntimeContext runtimeCtx, SqlQuery query, String paramName, final Object inputValue, boolean ingoreError, Class<?>... inputTypes) throws SqlRuntimeException { if (logger.isTraceEnabled()) { logger.trace( ">>> setParameter for META type " + this + ": paramName=" + paramName + ", inputValue=" + inputValue + ", inputTypes=" + inputTypes); } if (inputValue == null) { query.setParameter(paramName, inputValue, getProviderSqlType()); } else if (!inputValue.getClass().isEnum()) { if (!(inputValue instanceof Collection)) { if (inputValue instanceof OutValueSetter) { query.setParameter(paramName, inputValue, getProviderSqlType()); } else { error(ingoreError, "Incorrect string based enum " + inputValue + " for " + paramName); return; } } else { List<String> vals = new ArrayList<String>(); for (Iterator iter = ((Collection) inputValue).iterator(); iter.hasNext(); ) { Object val = iter.next(); if (!val.getClass().isEnum()) { error(ingoreError, "Incorrect string based enum item " + val + " for " + paramName); return; } else { Object o = runtimeCtx.getEnumToValue(val); if (o != null && o instanceof String) { vals.add((String) o); } else { error( ingoreError, "Incorrect string based enum item value " + o + " for " + paramName); return; } } } query.setParameterList(paramName, vals.toArray()); } } else { Object o = runtimeCtx.getEnumToValue(inputValue); if (o != null && o instanceof String) { query.setParameter(paramName, (String) o, getProviderSqlType()); } else error( ingoreError, "ENUM_STRING parameter " + paramName + " " + inputValue + " " + inputValue.getClass() + " " + o); } }
/** {@inheritDoc} */ public void addScalar(SqlQuery query, String dbName, Class<?> attributeType) { query.addScalar(dbName, Hibernate.STRING); }