List of usage examples for org.hibernate.mapping UniqueKey addColumns
public void addColumns(Iterator columnIterator)
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void bindNaturalIdentifier(Table table, Mapping mapping, PersistentClass persistentClass) { Object o = mapping != null ? mapping.getIdentity() : null; if (!(o instanceof Identity)) { return;/*ww w . j a v a 2 s .c om*/ } Identity identity = (Identity) o; final NaturalId naturalId = identity.getNatural(); if (naturalId == null || naturalId.getPropertyNames().isEmpty()) { return; } UniqueKey uk = new UniqueKey(); uk.setTable(table); boolean mutable = naturalId.isMutable(); for (String propertyName : naturalId.getPropertyNames()) { Property property = persistentClass.getProperty(propertyName); property.setNaturalIdentifier(true); if (!mutable) property.setUpdateable(false); uk.addColumns(property.getColumnIterator()); } setUniqueName(uk); table.addUniqueKey(uk); }
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 .ja v a 2s . c om*/ }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
private static void bindNaturalIdentifier(Table table, Mapping mapping, PersistentClass persistentClass) { Object o = mapping != null ? mapping.getIdentity() : null; if (o instanceof Identity) { Identity identity = (Identity) o; final NaturalId naturalId = identity.getNatural(); if (naturalId != null && !naturalId.getPropertyNames().isEmpty()) { UniqueKey uk = new UniqueKey(); uk.setName("_UniqueKey"); uk.setTable(table);//from w w w .ja v a 2 s.c o m boolean mutable = naturalId.isMutable(); for (String propertyName : naturalId.getPropertyNames()) { Property property = persistentClass.getProperty(propertyName); property.setNaturalIdentifier(true); if (!mutable) property.setUpdateable(false); uk.addColumns(property.getColumnIterator()); } table.addUniqueKey(uk); } } }
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()); }/* w w w. j a va2 s . c om*/ }
From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void bindNaturalIdentifier(Table table, Mapping mapping, PersistentClass persistentClass) { Object o = mapping != null ? mapping.getIdentity() : null; if (!(o instanceof Identity)) { return;//w w w . jav a 2 s .co m } Identity identity = (Identity) o; final NaturalId naturalId = identity.getNatural(); if (naturalId == null || naturalId.getPropertyNames().isEmpty()) { return; } UniqueKey uk = new UniqueKey(); uk.setTable(table); boolean mutable = naturalId.isMutable(); for (String propertyName : naturalId.getPropertyNames()) { Property property = persistentClass.getProperty(propertyName); property.setNaturalIdentifier(true); if (!mutable) property.setUpdateable(false); uk.addColumns(property.getColumnIterator()); } setGeneratedUniqueName(uk); table.addUniqueKey(uk); }
From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void createUniqueKeyForColumns(Table table, String columnName, List<Column> columns) { Collections.reverse(columns); UniqueKey uk = new UniqueKey(); uk.setTable(table);//from w w w. j a v a 2 s .co m uk.addColumns(columns.iterator()); if (LOG.isDebugEnabled()) { LOG.debug("create unique key for " + table.getName() + " columns = " + columns); } setGeneratedUniqueName(uk); table.addUniqueKey(uk); }