List of usage examples for org.hibernate.mapping UniqueKey getColumns
public List<Column> getColumns()
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 www . j av a 2s . co 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.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void createUniqueKeyForColumns(Table table, String columnName, List<Column> keyList) { Collections.reverse(keyList); UniqueKey key = table.getOrCreateUniqueKey("unique_" + columnName); List<?> columns = key.getColumns(); if (columns.isEmpty()) { LOG.debug("create unique key for " + table.getName() + " columns = " + keyList); key.addColumns(keyList.iterator()); }// w w w. j a v a2 s .c o m }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
private static void createUniqueKeyForColumns(Table table, String columnName, List<Column> keyList) { Collections.reverse(keyList); UniqueKey key = table.getOrCreateUniqueKey("unique-" + columnName); List<?> columns = key.getColumns(); if (columns.isEmpty()) { LOG.debug("create unique key for " + table.getName() + " columns = " + keyList); key.addColumns(keyList.iterator()); }/*from www . ja v a2s .c o m*/ }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinderTests.java
License:Apache License
public void testUniqueConstraintGeneration() { DefaultGrailsDomainConfiguration config = getDomainConfig(UNIQUE_PROPERTIES); assertEquals("Tables created", 1, getTableCount(config)); List expectedKeyColumns1 = Arrays .asList(new Column[] { new Column("camel_cased"), new Column("group"), new Column("login") }); List expectedKeyColumns2 = Arrays.asList(new Column[] { new Column("camel_cased"), new Column("group") }); Table mapping = (Table) config.getTableMappings().next(); int cnt = 0;//from ww w .j av a 2 s . c o m boolean found1 = false, found2 = false; for (Iterator i = mapping.getUniqueKeyIterator(); i.hasNext();) { UniqueKey key = (UniqueKey) i.next(); List keyColumns = key.getColumns(); if (keyColumns.equals(expectedKeyColumns1)) { found1 = true; } if (keyColumns.equals(expectedKeyColumns2)) { found2 = true; } cnt++; } assertEquals(2, cnt); assertEquals(true, mapping.getColumn(new Column("employeeID")).isUnique()); assertEquals(true, found1); assertEquals(true, found2); }
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('_'); }//from w w w. j a va2 s . c om 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.teiid.spring.views.ViewBuilder.java
License:Apache License
private void addIndexKeys(org.hibernate.mapping.Table ormTable, Table view, MetadataFactory mf) { Iterator<UniqueKey> keys = ormTable.getUniqueKeyIterator(); while (keys.hasNext()) { UniqueKey uk = keys.next(); List<String> columns = new ArrayList<>(); for (org.hibernate.mapping.Column c : uk.getColumns()) { columns.add(c.getName());/* w w w. j av a 2s .c om*/ } mf.addIndex(uk.getName(), false, columns, view); } Iterator<Index> iit = ormTable.getIndexIterator(); while (iit.hasNext()) { Index idx = iit.next(); List<String> columns = new ArrayList<>(); Iterator<org.hibernate.mapping.Column> it = idx.getColumnIterator(); while (it.hasNext()) { org.hibernate.mapping.Column c = it.next(); columns.add(c.getName()); } mf.addIndex(idx.getName(), true, columns, view); } }