Example usage for org.hibernate HibernateException HibernateException

List of usage examples for org.hibernate HibernateException HibernateException

Introduction

In this page you can find the example usage for org.hibernate HibernateException HibernateException.

Prototype

public HibernateException(Throwable cause) 

Source Link

Document

Constructs a HibernateException using the given message and underlying cause.

Usage

From source file:kr.debop4j.data.hibernate.usertype.WeekOfYearUserType.java

License:Apache License

@Override
public void setPropertyValue(final Object component, final int property, final Object value)
        throws HibernateException {
    Guard.shouldNotBeNull(component, "component");
    YearWeek yw = asYearWeek(component);

    if (property == 0)
        yw.setYear((Integer) Objects.firstNonNull(value, 0));
    else if (property == 1)
        yw.setWeek((Integer) Objects.firstNonNull(value, 0));
    else//  w  w  w  .ja v  a2s .  c o  m
        throw new HibernateException(
                "property index  . 0, 1 ?  . property="
                        + property);
}

From source file:kr.debop4j.data.ogm.test.simpleentity.OgmTestBase.java

License:Apache License

private void rebuildSessionFactory() {
    if (sessions == null) {
        try {//from  w  ww  .  ja  va 2  s .c o  m
            buildConfiguration();
        } catch (Exception e) {
            throw new HibernateException(e);
        }
    }
}

From source file:la.kosmos.app.AliasToBeanNestedMultiLevelResultTransformer.java

@Override
public Object transformTuple(Object[] tuples, String[] aliases) {

    Map<String, Object> nestedObjectsMap = new HashMap<>();

    Object result;/* w w  w .  j a v a  2  s . c  om*/
    try {
        result = resultClass.newInstance();

        if (!initialized) {
            initialized = true;
            initialize(aliases);
        }

        for (int a = 0; a < aliases.length; a++) {

            String alias = aliases[a];
            Object tuple = tuples[a];

            Object baseObject = result;

            int index = alias.lastIndexOf(".");
            if (index > 0) {
                String basePath = alias.substring(0, index);
                baseObject = nestedObjectsMap.get(basePath);
                if (baseObject == null) {
                    baseObject = clazzMap.get(basePath).newInstance();
                    nestedObjectsMap.put(basePath, baseObject);
                }
            }

            settersMap.get(alias).set(baseObject, tuple, null);

        }

        for (Map.Entry<String, Object> entry : nestedObjectsMap.entrySet()) {
            Setter setter = settersMap.get(entry.getKey());
            if (entry.getKey().contains(".")) {

                int index = entry.getKey().lastIndexOf(".");
                String basePath = entry.getKey().substring(0, index);
                Object obj = nestedObjectsMap.get(basePath);

                setter.set(obj, entry.getValue(), null);
            } else {
                setter.set(result, entry.getValue(), null);
            }
        }

    } catch (InstantiationException | IllegalAccessException e) {
        throw new HibernateException("Could not instantiate resultclass: " + resultClass.getName());
    }

    return result;
}

From source file:mitm.common.hibernate.CertificateArrayUserType.java

License:Open Source License

@Override
public Object deepCopy(Object value) throws HibernateException {
    if (value == null) {
        return null;
    }/*from   w  ww  . ja v  a 2s .  c o  m*/

    if (!(value instanceof Certificate[])) {
        throw new IllegalArgumentException("Object is not an array of Certificate.");
    }

    Certificate[] originals = (Certificate[]) value;

    Certificate[] copy = new Certificate[originals.length];

    try {
        for (int i = 0; i < originals.length; i++) {
            copy[i] = cloneCertificate(originals[i]);
        }
    } catch (CertificateException e) {
        throw new HibernateException(e);
    } catch (NoSuchProviderException e) {
        throw new HibernateException(e);
    }

    return copy;
}

From source file:mitm.common.hibernate.CertificateArrayUserType.java

License:Open Source License

@Override
public Object getPropertyValue(Object component, int property) throws HibernateException {
    if (component == null) {
        return null;
    }//w  ww. j av a 2s.c o m

    if (!(component instanceof Certificate[])) {
        throw new IllegalArgumentException("Object is not an array of Certificate.");
    }

    Certificate[] certificates = (Certificate[]) component;

    try {
        switch (property) {
        case CERTIFICATE_ARRAY_COLUMN:
            return toBytes(certificates);
        }
    } catch (CertificateEncodingException e) {
        throw new HibernateException(e);
    }

    return null;
}

From source file:mitm.common.hibernate.CertificateArrayUserType.java

License:Open Source License

@Override
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
        throws HibernateException, SQLException {
    Certificate[] certificates = null;

    byte[] bytes = rs.getBytes(names[CERTIFICATE_ARRAY_COLUMN]);

    if (!rs.wasNull() && bytes != null) {
        Object deserialized = SerializationUtils.deserialize(bytes);

        if (!(deserialized instanceof LinkedList)) {
            throw new IllegalArgumentException("Object is not a LinkedList.");
        }//  ww  w.  j a  v a 2 s .co  m

        try {
            @SuppressWarnings("unchecked")
            List<EncodedCertificate> encodedCertificates = (LinkedList<EncodedCertificate>) deserialized;

            certificates = new Certificate[encodedCertificates.size()];

            for (int i = 0; i < certificates.length; i++) {
                certificates[i] = encodedCertificates.get(i).getCertificate();
            }
        } catch (CertificateException e) {
            throw new HibernateException(e);
        } catch (NoSuchProviderException e) {
            throw new HibernateException(e);
        }
    }

    return certificates;
}

From source file:mitm.common.hibernate.CertificateArrayUserType.java

License:Open Source License

@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
        throws HibernateException, SQLException {
    byte[] encoded = null;

    try {/*ww w  . j  a v a2  s.c om*/
        if (value != null) {
            if (!(value instanceof Certificate[])) {
                throw new IllegalArgumentException("Object is not an array of Certificate.");
            }

            Certificate[] certificates = (Certificate[]) value;

            encoded = toBytes(certificates);
        }
    } catch (CertificateEncodingException e) {
        throw new HibernateException(e);
    }

    Hibernate.BINARY.nullSafeSet(st, encoded, index + CERTIFICATE_ARRAY_COLUMN);
}

From source file:mitm.common.hibernate.CertificateUserType.java

License:Open Source License

@Override
public Object deepCopy(Object value) throws HibernateException {
    if (value == null) {
        return null;
    }//w w  w.  j  a  v  a  2  s.  c om

    if (!(value instanceof Certificate)) {
        throw new IllegalArgumentException("Object is not a Certificate.");
    }

    Certificate original = (Certificate) value;

    Certificate copy = null;

    try {
        byte[] encodedCert = original.getEncoded();

        String certificateType = original.getType();

        CertificateFactory factory = SecurityFactoryFactory.getSecurityFactory()
                .createCertificateFactory(certificateType);

        copy = factory.generateCertificate(new ByteArrayInputStream(encodedCert));
    } catch (CertificateException e) {
        throw new HibernateException(e);
    } catch (NoSuchProviderException e) {
        throw new HibernateException(e);
    }

    return copy;
}

From source file:mitm.common.hibernate.CertificateUserType.java

License:Open Source License

@Override
public Object getPropertyValue(Object component, int property) throws HibernateException {
    if (component == null) {
        return null;
    }//from  w w  w.j  a v  a 2  s.c  o  m

    if (!(component instanceof Certificate)) {
        throw new IllegalArgumentException("Object is not a Certificate.");
    }

    Certificate certificate = (Certificate) component;

    try {
        CertificateInspector inspector = new CertificateInspector(certificate);

        switch (property) {
        case CERTIFICATE_COLUMN:
            return certificate.getEncoded();
        case CERTIFICATE_TYPE_COLUMN:
            return certificate.getType();
        case THUMBPRINT_COLUMN:
            return inspector.getThumbprint();
        }
    } catch (CertificateEncodingException 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.CertificateUserType.java

License:Open Source License

@Override
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
        throws HibernateException, SQLException {
    Certificate certificate = null;

    byte[] encodedCertificate = rs.getBytes(names[CERTIFICATE_COLUMN]);

    if (!rs.wasNull() && encodedCertificate != null) {
        String certificateType = rs.getString(names[CERTIFICATE_TYPE_COLUMN]);

        try {//from   ww w  .j ava  2 s . com
            CertificateFactory factory = SecurityFactoryFactory.getSecurityFactory()
                    .createCertificateFactory(certificateType);

            certificate = factory.generateCertificate(new ByteArrayInputStream(encodedCertificate));
        } catch (CertificateException e) {
            throw new HibernateException(e);
        } catch (NoSuchProviderException e) {
            throw new HibernateException(e);
        }
    }

    return certificate;
}