List of usage examples for org.hibernate HibernateException HibernateException
public HibernateException(String message, Throwable cause)
From source file:br.com.tcc.common.support.GenericEnumUserType.java
/** * {@inheritDoc}/*from w ww. j a v a 2s . co m*/ * @param parameters * {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public void setParameterValues(Properties parameters) { String enumClassName = parameters.getProperty(ENUM_CLASS_PARAM_NAME); try { enumClass = (Class<? extends Enum<?>>) Class.forName(enumClassName).asSubclass(Enum.class); } catch (ClassNotFoundException cfne) { throw new HibernateException((new StringBuilder()).append("Enum class named '").append(enumClass) .append("'not found").toString(), cfne); } String identifierMethodName = parameters.getProperty(IDENTIFIER_METHOD_PARAM_NAME, DEFAULT_IDENTIFIER_METHOD_NAME); try { identifierMethod = enumClass.getMethod(identifierMethodName, new Class[FIRST_ITEM]); identifierType = identifierMethod.getReturnType(); } catch (NoSuchMethodException e) { throw new HibernateException((new StringBuilder()).append(MSG_NO_METHOD_NAMED) .append(identifierMethodName).append(MSG_FOUND).toString(), e); } catch (SecurityException e) { throw new HibernateException((new StringBuilder()).append(MSG_NO_METHOD_NAMED) .append(identifierMethodName).append(MSG_FOUND).toString(), e); } TypeResolver tr = new TypeResolver(); type = (AbstractSingleColumnStandardBasicType) tr.basic(identifierType.getName()); if (type == null) { throw new HibernateException((new StringBuilder()).append("Unsupported identifier type ") .append(identifierType.getName()).toString()); } sqlTypes = new int[] { type.sqlType() }; String valueOfMethodName = parameters.getProperty(VALUE_OF_METHOD_PARAM_NAME, DEFAULT_VALUE_OF_METHOD_NAME); try { valueOfMethod = enumClass.getMethod(valueOfMethodName, new Class[] { identifierType }); } catch (NoSuchMethodException e) { throw new HibernateException((new StringBuilder()).append(MSG_NO_METHOD_NAMED).append(valueOfMethodName) .append(MSG_FOUND).toString(), e); } catch (SecurityException e) { throw new HibernateException((new StringBuilder()).append(MSG_NO_METHOD_NAMED).append(valueOfMethodName) .append(MSG_FOUND).toString(), e); } }
From source file:br.com.tcc.common.support.GenericEnumUserType.java
/** * {@inheritDoc}/*from w w w.j a v a2 s .c o m*/ * @param rs * {@inheritDoc} * @param names * {@inheritDoc} * @param owner * {@inheritDoc} * @return {@inheritDoc} */ @Override public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor si, Object owner) throws SQLException { Object identifier = type.get(rs, names[FIRST_ITEM], si); if (identifier == null) { return null; } try { return valueOfMethod.invoke(enumClass, new Object[] { identifier }); } catch (IllegalAccessException e) { throw new HibernateException( (new StringBuilder()).append(MSG_INVOKE_METHOD).append(valueOfMethod.getName()).append(MSG_OF) .append(MSG_ENUM_CLASS).append(enumClass).append(MSG_SINGLE_QUOTE).toString(), e); } catch (InvocationTargetException e) { throw new HibernateException( (new StringBuilder()).append(MSG_INVOKE_METHOD).append(valueOfMethod.getName()).append(MSG_OF) .append(MSG_ENUM_CLASS).append(enumClass).append(MSG_SINGLE_QUOTE).toString(), e); } catch (IllegalArgumentException e) { throw new HibernateException( (new StringBuilder()).append(MSG_INVOKE_METHOD).append(valueOfMethod.getName()).append(MSG_OF) .append(MSG_ENUM_CLASS).append(enumClass).append(MSG_SINGLE_QUOTE).toString(), e); } }
From source file:br.com.tcc.common.support.GenericEnumUserType.java
/** * {@inheritDoc}//from w ww .j a va2 s . c om * @param st * {@inheritDoc} * @param value * {@inheritDoc} * @param index * {@inheritDoc} * @throws SQLException * {@inheritDoc} */ @Override public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor si) throws SQLException { try { if (value == null) { st.setNull(index, type.sqlType()); } else { Object identifier = identifierMethod.invoke(value, new Object[FIRST_ITEM]); type.set(st, identifier, index, si); } } catch (IllegalAccessException e) { throw new HibernateException((new StringBuilder()).append(MSG_INVOKE_IDENT_METHOD) .append(identifierMethod.getName()).append(MSG_OF).append(MSG_ENUM_CLASS).append(enumClass) .append(MSG_SINGLE_QUOTE).toString(), e); } catch (InvocationTargetException e) { throw new HibernateException((new StringBuilder()).append(MSG_INVOKE_IDENT_METHOD) .append(identifierMethod.getName()).append(MSG_OF).append(MSG_ENUM_CLASS).append(enumClass) .append(MSG_SINGLE_QUOTE).toString(), e); } catch (IllegalArgumentException e) { throw new HibernateException((new StringBuilder()).append(MSG_INVOKE_IDENT_METHOD) .append(identifierMethod.getName()).append(MSG_OF).append(MSG_ENUM_CLASS).append(enumClass) .append(MSG_SINGLE_QUOTE).toString(), e); } }
From source file:br.com.uktech.multitenantschema.multitenant.ConfigurableMultiTenantConnectionProvider.java
License:Open Source License
@Override public Connection getConnection(String tenantIdentifier) throws SQLException { final Connection connection = getAnyConnection(); try {/*from w ww .j ava 2 s .c om*/ connection.createStatement().execute("SET search_path TO '" + tenantIdentifier + "', 'public'"); } catch (final SQLException e) { throw new HibernateException("Error trying to alter schema [" + tenantIdentifier + "]", e); } return connection; }
From source file:br.com.uktech.multitenantschema.multitenant.ConfigurableMultiTenantConnectionProvider.java
License:Open Source License
@Override public void releaseConnection(String tenantIdentifier, Connection connection) throws SQLException { try {//from w w w .j a v a2s . co m connection.createStatement().execute("SET SCHEMA 'public'"); } catch (final SQLException e) { throw new HibernateException("Error trying to alter schema [public]", e); } finally { this.releaseAnyConnection(connection); } }
From source file:ccc.plugins.persistence.hibernate.EnumUserType.java
License:Open Source License
/** {@inheritDoc} */ @SuppressWarnings("unchecked") // Class class doesn't support generics @Override//from w ww. j a v a 2s.c o m public void setParameterValues(final Properties parameters) { final String enumClassName = parameters.getProperty(PROPERTY_TYPE); try { _enumClass = (Class<T>) Class.forName(enumClassName); } catch (final Exception cnfe) { throw new HibernateException("Enum class not found: " + enumClassName, cnfe); } }
From source file:ch.algotrader.hibernate.HibernateEnumType.java
License:Open Source License
/** * @see org.hibernate.usertype.ParameterizedType#setParameterValues(java.util.Properties) *//* ww w.ja v a 2s. c o m*/ @Override @SuppressWarnings({ "unchecked", "rawtypes" }) public void setParameterValues(Properties parameters) { final String enumClassName = parameters.getProperty("enumClassName"); try { //noinspection unchecked this.enumClass = (Class<Enum>) Class.forName(enumClassName); } catch (ClassNotFoundException cnfe) { throw new HibernateException("Enum class not found", cnfe); } }
From source file:ch.silviowangler.dox.hibernate.AmountOfMoneyType.java
License:Apache License
@Override public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { String value = (String) StandardBasicTypes.STRING.nullSafeGet(rs, names, session, owner); if (value == null) { return null; }//from w w w . j a va 2s . com String[] tokens = value.split(" "); assert tokens.length == 2 : "Wrong token size"; DecimalFormat df = new DecimalFormat(); df.setParseBigDecimal(true); final BigDecimal amount; try { amount = (BigDecimal) df.parse(tokens[1]); return new AmountOfMoney(Currency.getInstance(tokens[0]), amount); } catch (ParseException e) { throw new HibernateException("", e); } }
From source file:clases.ContactoAnotDAO.java
private void manejaExcepcion(HibernateException he) throws HibernateException { tx.rollback();//from ww w . j av a 2 s. c o m throw new HibernateException("Ocurri un error en la capa de acceso a datos", he); }
From source file:com.abiquo.abiserver.business.hibernate.pojohb.userType.GenericEnumUserType.java
License:Open Source License
public void setParameterValues(Properties parameters) { String enumClassName = parameters.getProperty("enumClass"); try {/*w w w .j a va 2s . c o m*/ enumClass = Class.forName(enumClassName).asSubclass(Enum.class); } catch (ClassNotFoundException cfne) { throw new HibernateException("Enum class not found", cfne); } String identifierMethodName = parameters.getProperty("identifierMethod", DEFAULT_IDENTIFIER_METHOD_NAME); try { identifierMethod = enumClass.getMethod(identifierMethodName, new Class[0]); identifierType = identifierMethod.getReturnType(); } catch (Exception e) { throw new HibernateException("Failed to obtain identifier method", e); } type = (NullableType) TypeFactory.basic(identifierType.getName()); if (type == null) throw new HibernateException("Unsupported identifier type " + identifierType.getName()); sqlTypes = new int[] { type.sqlType() }; String valueOfMethodName = parameters.getProperty("valueOfMethod", DEFAULT_VALUE_OF_METHOD_NAME); try { valueOfMethod = enumClass.getMethod(valueOfMethodName, new Class[] { identifierType }); } catch (Exception e) { throw new HibernateException("Failed to obtain valueOf method", e); } }