List of usage examples for org.hibernate HibernateException HibernateException
public HibernateException(String message, Throwable cause)
From source file:com.netradius.hibernate.support.BCryptUserType.java
License:Apache License
/** * {@inheritDoc}/*from w w w .j a va 2s . c o m*/ */ public void setParameterValues(final Properties properties) { if (properties != null) { String tmp = properties.getProperty(PARAM_CHARSET); if (tmp != null) { try { charset = Charset.forName(tmp); } catch (IllegalCharsetNameException x) { throw new HibernateException("Unsupported character set " + tmp + ": " + x.getMessage(), x); } catch (UnsupportedCharsetException x) { throw new HibernateException("Unsupported character set " + tmp + ": " + x.getMessage(), x); } } } if (charset == null) { charset = DEFAULT_CHARSET; } }
From source file:com.netradius.hibernate.support.EncryptedUserType.java
License:Apache License
/** * {@inheritDoc}//from w ww .java 2 s .c o m */ public void nullSafeSet(final PreparedStatement ps, final Object o, final int index, final SessionImplementor impl) throws HibernateException, SQLException { try { if (o == null) { ps.setNull(index, SQL_TYPE); } else { ps.setBytes(index, doFinal(getCipher(Cipher.ENCRYPT_MODE), (byte[]) o)); } } catch (GeneralSecurityException x) { throw new HibernateException("Failed to set encrypted value: " + x.getMessage(), x); } }
From source file:com.netradius.hibernate.support.EncryptedUserType.java
License:Apache License
/** * Preforms the encryption or decryption of the data. * * @param cipher the cipher to use/*from www. jav a2s. com*/ * @param data the data to encrypt or decrypt * @return the encrypted or decrypted data */ protected byte[] doFinal(final Cipher cipher, final byte[] data) { try { return cipher.doFinal(data); } catch (IllegalBlockSizeException x) { throw new HibernateException("Invalid block size for transformation: " + x.getMessage(), x); } catch (BadPaddingException x) { throw new HibernateException("Data is not padded properly for transformation: " + x.getMessage(), x); } }
From source file:com.netradius.hibernate.support.MessageDigestUserType.java
License:Apache License
/** * {@inheritDoc}/* www .j a v a 2 s . com*/ */ public void setParameterValues(final Properties properties) { if (properties != null) { algorithm = properties.getProperty(PARAM_ALGORITHM); provider = properties.getProperty(PARAM_PROVIDER); String tmp = properties.getProperty(PARAM_CHARSET); if (tmp != null) { try { charset = Charset.forName(tmp); } catch (IllegalCharsetNameException x) { throw new HibernateException("Unsupported character set " + tmp + ": " + x.getMessage(), x); } catch (UnsupportedCharsetException x) { throw new HibernateException("Unsupported character set " + tmp + ": " + x.getMessage(), x); } } encoding = properties.getProperty(PARAM_ENCODING); } if (algorithm == null) { algorithm = DEFAULT_ALGORITHM; } if (charset == null) { charset = DEFAULT_CHARSET; } if (encoding == null) { encoding = DEFAULT_ENCODING; } }
From source file:com.netradius.hibernate.support.MessageDigestUserType.java
License:Apache License
/** * {@inheritDoc}/*from w w w . j a va 2 s . co m*/ */ protected byte[] digest(final byte[] data) { try { final MessageDigest md = provider == null ? MessageDigest.getInstance(algorithm) : MessageDigest.getInstance(algorithm, provider); return md.digest(data); } catch (NoSuchAlgorithmException x) { final StringBuilder sb = new StringBuilder("Failed to find message digest algorithm ") .append(algorithm); if (provider != null) { sb.append(" in provider ").append(provider); } sb.append(": ").append(x.getMessage()); throw new HibernateException(sb.toString(), x); } catch (NoSuchProviderException x) { throw new HibernateException( "Failed to find message digest provider " + provider + ": " + x.getMessage(), x); } }
From source file:com.netxforge.oss2.model.OnmsSeverityUserType.java
License:Open Source License
public void nullSafeSet(final PreparedStatement st, final Object value, final int index) throws HibernateException, SQLException { if (value == null) { st.setInt(index, 1);//w ww .j a v a 2s. co m } else if (value instanceof OnmsSeverity) { st.setInt(index, ((OnmsSeverity) value).getId()); } else if (value instanceof String) { try { st.setInt(index, Integer.parseInt((String) value)); } catch (final IllegalArgumentException e) { throw new HibernateException("unable to set severity " + value, e); } } }
From source file:com.npower.dm.hibernate.management.HibernateSessionFactory.java
License:Open Source License
private void initSessionFactory() throws HibernateException { synchronized (initialized) { if (initialized.booleanValue() == false) { try { config.setProperties(this.loadProperties()); config.configure(CONFIG_FILE_LOCATION); sessionFactory = config.buildSessionFactory(); initialized = new Boolean(true); } catch (IOException e) { System.err.println("%%%% Error Creating SessionFactory %%%%"); DMUtil.print(Thread.currentThread().getContextClassLoader()); e.printStackTrace();//from www .ja v a 2 s .c om log.fatal("%%%% Error Creating SessionFactory %%%%", e); throw new HibernateException("Error Creating SessionFactory", e); } catch (HibernateException e) { System.err.println("%%%% Error Creating SessionFactory %%%%"); DMUtil.print(Thread.currentThread().getContextClassLoader()); e.printStackTrace(); log.fatal("%%%% Error Creating SessionFactory %%%%", e); throw e; } catch (Exception e) { System.err.println("%%%% Error Creating SessionFactory %%%%"); DMUtil.print(Thread.currentThread().getContextClassLoader()); e.printStackTrace(); log.fatal("%%%% Error Creating SessionFactory %%%%", e); throw new HibernateException("Error Creating SessionFactory", e); } } } }
From source file:com.opengamma.util.db.hibernate.types.enums.EnumType.java
License:Open Source License
@SuppressWarnings("unchecked") public void setParameterValues(Properties parameters) { String enumClassName = parameters.getProperty("enum"); try {//from w ww .ja v a2 s . c o m _enumClass = (Class<T>) Class.forName(enumClassName).asSubclass(Enum.class); } catch (ClassNotFoundException cnfe) { throw new HibernateException("Enum class not found", cnfe); } setDefaultValue(parameters.getProperty("defaultValue")); }
From source file:com.opengamma.util.db.hibernate.types.enums.StringValuedEnumType.java
License:Open Source License
@SuppressWarnings("unchecked") public void setParameterValues(Properties parameters) { String enumClassName = parameters.getProperty("enum"); try {// w w w . ja va 2 s .co m _enumClass = (Class<T>) Class.forName(enumClassName).asSubclass(Enum.class) .asSubclass(StringValuedEnum.class); //Validates the class but does not eliminate the cast } catch (ClassNotFoundException cnfe) { throw new HibernateException("Enum class not found", cnfe); } setDefaultValue(parameters.getProperty("defaultValue")); }
From source file:com.processpuzzle.persistence.domain.EnumUserType.java
License:Open Source License
public void setParameterValues(Properties parameters) { String targetClassName = parameters.getProperty("targetClass"); try {/* w w w .j a v a 2 s . co m*/ targetClass = Class.forName(targetClassName); } catch (ClassNotFoundException e) { throw new HibernateException("Class " + targetClassName + " not found ", e); } }