List of usage examples for org.hibernate HibernateException HibernateException
public HibernateException(Throwable cause)
From source file:mitm.common.hibernate.X509CRLUserType.java
License:Open Source License
@Override public Object deepCopy(Object value) throws HibernateException { if (value == null) { return null; }//from ww w .j ava 2 s. c o m if (!(value instanceof X509CRL)) { throw new IllegalArgumentException("Object is not a X509CRL."); } X509CRL original = (X509CRL) value; X509CRL copy = null; try { byte[] encodedCRL = original.getEncoded(); CertificateFactory factory = SecurityFactoryFactory.getSecurityFactory() .createCertificateFactory("X.509"); copy = (X509CRL) factory.generateCRL(new ByteArrayInputStream(encodedCRL)); } catch (CertificateException e) { throw new HibernateException(e); } catch (CRLException e) { throw new HibernateException(e); } catch (NoSuchProviderException e) { throw new HibernateException(e); } return copy; }
From source file:mitm.common.hibernate.X509CRLUserType.java
License:Open Source License
@Override public Object getPropertyValue(Object component, int property) throws HibernateException { if (component == null) { return null; }/* w w w .ja v a2s . c o m*/ if (!(component instanceof X509CRL)) { throw new IllegalArgumentException("Object is not a X509CRL."); } X509CRL crl = (X509CRL) component; try { byte[] encodedCRL = null; /* * Encoding the CRL can be time and memory consuming. We will therefore * encode it once and use it for thumbprint as well */ if (property == CRL_COLUMN || property == THUMBPRINT_COLUMN) { encodedCRL = crl.getEncoded(); } switch (property) { case ISSUER_COLUMN: return X509CRLInspector.getIssuerCanonical(crl); case NEXT_UPDATE_COLUMN: return crl.getNextUpdate(); case THIS_UPDATE_COLUMN: return crl.getThisUpdate(); case CRL_NUMBER_COLUMN: return BigIntegerUtils.hexEncode(X509CRLInspector.getCRLNumber(crl)); case CRL_COLUMN: return encodedCRL; case THUMBPRINT_COLUMN: return X509CRLInspector.getThumbprint(encodedCRL); } } catch (CRLException e) { throw new HibernateException(e); } catch (IOException e) { throw new HibernateException(e); } catch (NoSuchAlgorithmException e) { throw new HibernateException(e); } catch (NoSuchProviderException e) { throw new HibernateException(e); } return null; }
From source file:mitm.common.hibernate.X509CRLUserType.java
License:Open Source License
@Override public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { X509CRL crl = null;/*from ww w .j a v a2 s . com*/ byte[] encodedCRL = rs.getBytes(names[CRL_COLUMN]); if (!rs.wasNull() && encodedCRL != null) { try { CertificateFactory factory = SecurityFactoryFactory.getSecurityFactory() .createCertificateFactory("X.509"); crl = (X509CRL) factory.generateCRL(new ByteArrayInputStream(encodedCRL)); } catch (CertificateException e) { throw new HibernateException(e); } catch (NoSuchProviderException e) { throw new HibernateException(e); } catch (CRLException e) { throw new HibernateException(e); } } return crl; }
From source file:mitm.common.hibernate.X509CRLUserType.java
License:Open Source License
@Override public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { try {//from www . j a va 2 s . co m String issuer = null; Date nextUpdate = null; Date thisUpdate = null; String crlNumber = null; byte[] encodedCRL = null; String thumbprint = null; if (value != null) { if (!(value instanceof X509CRL)) { throw new IllegalArgumentException("Object is not a X509CRL."); } X509CRL crl = (X509CRL) value; issuer = X509CRLInspector.getIssuerCanonical(crl); nextUpdate = crl.getNextUpdate(); thisUpdate = crl.getThisUpdate(); crlNumber = BigIntegerUtils.hexEncode(X509CRLInspector.getCRLNumber(crl)); encodedCRL = crl.getEncoded(); thumbprint = X509CRLInspector.getThumbprint(encodedCRL); } Hibernate.STRING.nullSafeSet(st, issuer, index + ISSUER_COLUMN); Hibernate.TIMESTAMP.nullSafeSet(st, nextUpdate, index + NEXT_UPDATE_COLUMN); Hibernate.TIMESTAMP.nullSafeSet(st, thisUpdate, index + THIS_UPDATE_COLUMN); Hibernate.STRING.nullSafeSet(st, crlNumber, index + CRL_NUMBER_COLUMN); Hibernate.BINARY.nullSafeSet(st, encodedCRL, index + CRL_COLUMN); Hibernate.STRING.nullSafeSet(st, thumbprint, index + THUMBPRINT_COLUMN); } catch (IOException e) { throw new HibernateException(e); } catch (CRLException e) { throw new HibernateException(e); } catch (NoSuchAlgorithmException e) { throw new HibernateException(e); } catch (NoSuchProviderException e) { throw new HibernateException(e); } }
From source file:modelo.departamento.DepartamentoCDU.java
License:Open Source License
/** * * @param codigo/*from w w w . j a v a 2 s . c o m*/ * @return * @throws HibernateException */ @Override public int bajaDepartamento(Depart codigo) throws HibernateException { if (exists(codigo.getDeptNo())) { return delete(codigo); } else { throw new HibernateException("El departamento a dar de baja no existe."); } }
From source file:modelo.departamento.DepartamentoCDU.java
License:Open Source License
/** * * @param depart//from w ww .ja va 2 s. c o m * @return * @throws HibernateException */ @Override public boolean altaDepartamento(Depart depart) throws HibernateException { byte codigo = depart.getDeptNo(); if (!exists(codigo)) { return create(depart) > 0; } else { throw new HibernateException("El departamento con codigo " + (int) codigo + " ya existe."); } }
From source file:modelo.empleado.EmpleadoCDU.java
License:Open Source License
/** * * @param codigo/* w ww.ja v a 2s . co m*/ * @return * @throws HibernateException */ @Override public int bajaEmpleado(Emple emple) throws HibernateException { if (exists(emple.getEmpNo())) { return delete(emple); } else { throw new HibernateException("El empleado a dar de baja no existe."); } }
From source file:modelo.empleado.EmpleadoCDU.java
License:Open Source License
/** * * @param emple//w w w. j a v a 2s .c o m * @return * @throws HibernateException */ @Override public boolean altaEmpleado(Emple emple) throws HibernateException { short codigo = emple.getEmpNo(); if (!exists(codigo)) { return create(emple) > 0; } else { throw new HibernateException("El empleado con codigo " + codigo + " ya existe."); } }
From source file:net.awired.generic.jpa.helper.HibernateEnumAdapter.java
License:Apache License
private T findEnumValue(Integer id) { for (T enumValue : values()) { if (enumValue.getId().equals(id)) { return enumValue; }/* www . j av a2 s .c o m*/ } throw new HibernateException("Cannot find '" + clazz.getName() + "' with id '" + id + "'"); }
From source file:net.commerce.zocalo.currency.CurrencyToken.java
License:Open Source License
public CashBank lookupCashBank(Session session) throws HibernateException { Criteria bankCriterion = session.createCriteria(CashBank.class); bankCriterion.add(Expression.eq("id", id())); List tokens = bankCriterion.list(); if (tokens.size() == 1) { return (CashBank) tokens.get(0); } else {// w w w . jav a 2 s .com throw new HibernateException("no unique root bank"); } }