Example usage for org.hibernate.mapping UniqueKey getTable

List of usage examples for org.hibernate.mapping UniqueKey getTable

Introduction

In this page you can find the example usage for org.hibernate.mapping UniqueKey getTable.

Prototype

public Table getTable() 

Source Link

Usage

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

protected void setUniqueName(UniqueKey uk) {
    StringBuilder sb = new StringBuilder(uk.getTable().getName()).append('_');
    for (Object col : uk.getColumns()) {
        sb.append(((Column) col).getName()).append('_');
    }/*from w  ww.j  a  v  a 2 s .c  o  m*/

    MessageDigest md;
    try {
        md = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }
    try {
        md.update(sb.toString().getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }

    String name = "UK" + new BigInteger(1, md.digest()).toString(16);
    if (name.length() > 30) {
        // Oracle has a 30-char limit
        name = name.substring(0, 30);
    }

    uk.setName(name);
}

From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

protected void setGeneratedUniqueName(UniqueKey uk) {
    StringBuilder sb = new StringBuilder(uk.getTable().getName()).append('_');
    for (Object col : uk.getColumns()) {
        sb.append(((Column) col).getName()).append('_');
    }/*  w ww. java  2s  .c  o  m*/

    MessageDigest md;
    try {
        md = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }
    try {
        md.update(sb.toString().getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }

    String name = "UK" + new BigInteger(1, md.digest()).toString(16);
    if (name.length() > 30) {
        // Oracle has a 30-char limit
        name = name.substring(0, 30);
    }

    uk.setName(name);
}