List of usage examples for org.hibernate.mapping Column Column
public Column(String columnName)
From source file:net.lshift.hibernate.migrations.CreateTableBuilder.java
License:Apache License
public PrimaryKey getPrimaryKey() { PrimaryKey result = new PrimaryKey(); for (String pk : primaryKeys) result.addColumn(new Column(pk)); return result; }
From source file:org.apereo.portal.tools.dbloader.TableXmlHandler.java
License:Apache License
@Override public void endElement(String uri, String localName, String name) throws SAXException { if ("table".equals(name)) { for (final Column column : this.currentColumns.values()) { this.currentTable.addColumn(column); }// ww w. j a v a2 s . c o m if (this.primaryKey != null) { this.currentTable.setPrimaryKey(this.primaryKey); } this.tables.put(this.currentTable.getName(), this.currentTable); this.tableColumnTypes.put(this.currentTable.getName(), this.currentColumnTypes); this.primaryKey = null; this.currentColumns = null; this.currentColumnTypes = null; this.currentTable = null; } else if ("column".equals(name)) { this.currentColumns.put(this.currentColumn.getName(), this.currentColumn); this.currentColumn = null; } else if ("name".equals(name)) { final String itemName = this.chars.toString().trim(); if (this.currentIndex != null) { this.currentIndex.setName(itemName); } else if (this.currentUnique != null) { this.currentUnique.setName(itemName); } else if (this.currentTable == null) { this.currentTable = new Table(itemName); } else if (this.currentColumn == null) { this.currentColumn = new Column(itemName); } } else if ("type".equals(name)) { final String sqlTypeName = this.chars.toString().trim(); final int sqlType = this.getSqlType(sqlTypeName); this.currentColumnTypes.put(this.currentColumn.getName(), sqlType); final String hibType = this.getHibernateType(sqlType); final SimpleValue value = new SimpleValue(this.mappings, this.currentTable); value.setTypeName(hibType); this.currentColumn.setValue(value); } else if ("param".equals(name)) { final String param = this.chars.toString().trim(); final Integer length = Integer.valueOf(param); this.currentColumn.setLength(length); } else if ("primary-key".equals(name)) { final String columnName = this.chars.toString().trim(); if (this.primaryKey == null) { this.primaryKey = new PrimaryKey(); } final Column column = this.currentColumns.get(columnName); this.primaryKey.addColumn(column); } else if ("not-null".equals(name)) { final String columnName = this.chars.toString().trim(); final Column column = this.currentColumns.get(columnName); column.setNullable(false); } else if ("column-ref".equals(name)) { final String columnName = this.chars.toString().trim(); final Column column = this.currentColumns.get(columnName); if (this.currentIndex != null) { this.currentIndex.addColumn(column); } else if (this.currentUnique != null) { this.currentUnique.addColumn(column); } } else if ("index".equals(name)) { this.currentTable.addIndex(this.currentIndex); this.currentIndex = null; } else if ("unique".equals(name)) { this.currentTable.addUniqueKey(this.currentUnique); this.currentUnique = null; } else if ("key".equals(name)) { this.logger.warn("the 'key' element is ignored, use the table level 'primary-key' element instead"); } this.chars = null; }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void createKeyForProps(GrailsDomainClassProperty grailsProp, String path, Table table, String columnName, List<?> propertyNames, String sessionFactoryBeanName) { List<Column> keyList = new ArrayList<Column>(); keyList.add(new Column(columnName)); for (Iterator<?> i = propertyNames.iterator(); i.hasNext();) { String propertyName = (String) i.next(); GrailsDomainClassProperty otherProp = grailsProp.getDomainClass().getPropertyByName(propertyName); String otherColumnName = getColumnNameForPropertyAndPath(otherProp, path, null, sessionFactoryBeanName); keyList.add(new Column(otherColumnName)); }/*from w w w.jav a 2s .co m*/ createUniqueKeyForColumns(table, columnName, keyList); }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
private static void createKeyForProps(GrailsDomainClassProperty grailsProp, String path, Table table, String columnName, List<?> propertyNames, String sessionFactoryBeanName) { List<Column> keyList = new ArrayList<Column>(); keyList.add(new Column(columnName)); for (Iterator<?> i = propertyNames.iterator(); i.hasNext();) { String propertyName = (String) i.next(); GrailsDomainClassProperty otherProp = grailsProp.getDomainClass().getPropertyByName(propertyName); String otherColumnName = getColumnNameForPropertyAndPath(otherProp, path, null, sessionFactoryBeanName); keyList.add(new Column(otherColumnName)); }// ww w. j a v a 2 s . c o m createUniqueKeyForColumns(table, columnName, keyList); }
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 a v a2s.co 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.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinderTests.java
License:Apache License
private void assertColumnNotNullable(String tablename, String columnName, DefaultGrailsDomainConfiguration config) { Table table = getTableMapping(tablename, config); assertTrue(table.getName() + "." + columnName + " is not nullable", !table.getColumn(new Column(columnName)).isNullable()); }
From source file:org.eclipse.emf.teneo.hibernate.HbDataStore.java
License:Open Source License
protected void addContainerMappingToPC(PersistentClass pc) { if (log.isDebugEnabled()) { log.debug("Adding eContainer and econtainerfeatureid properties to " + pc.getClassName()); }//from w ww. ja v a 2 s . co m final EContainerFeaturePersistenceStrategy featurePersistenceStrategy = getPersistenceOptions() .getEContainerFeaturePersistenceStrategy(); final Property eContainer = new Property(); eContainer.setName(HbConstants.PROPERTY_ECONTAINER); eContainer.setMetaAttributes(new HashMap<Object, Object>()); eContainer.setNodeName(eContainer.getName()); eContainer.setPropertyAccessorName(EContainerAccessor.class.getName()); final SimpleValue sv = new SimpleValue(getMappings(), pc.getTable()); sv.setTypeName(EContainerUserType.class.getName()); final Column eccColumn = new Column(getPersistenceOptions().getSQLColumnNamePrefix() + getPersistenceOptions().getEContainerClassColumn()); sv.addColumn(checkColumnExists(pc.getTable(), eccColumn)); final Column ecColumn = new Column( getPersistenceOptions().getSQLColumnNamePrefix() + getPersistenceOptions().getEContainerColumn()); sv.addColumn(checkColumnExists(pc.getTable(), ecColumn)); eContainer.setValue(sv); pc.addProperty(eContainer); if (featurePersistenceStrategy.equals(EContainerFeaturePersistenceStrategy.FEATUREID) || featurePersistenceStrategy.equals(EContainerFeaturePersistenceStrategy.BOTH)) { final Property ecFID = new Property(); ecFID.setName(HbConstants.PROPERTY_ECONTAINER_FEATURE_ID); ecFID.setMetaAttributes(new HashMap<Object, Object>()); ecFID.setNodeName(ecFID.getName()); ecFID.setPropertyAccessorName(EContainerFeatureIDAccessor.class.getName()); final SimpleValue svfid = new SimpleValue(getMappings(), pc.getTable()); svfid.setTypeName("integer"); final Column ecfColumn = new Column( getPersistenceOptions().getSQLColumnNamePrefix() + HbConstants.COLUMN_ECONTAINER_FEATUREID); svfid.addColumn(checkColumnExists(pc.getTable(), ecfColumn)); ecFID.setValue(svfid); pc.addProperty(ecFID); } if (featurePersistenceStrategy.equals(EContainerFeaturePersistenceStrategy.FEATURENAME) || featurePersistenceStrategy.equals(EContainerFeaturePersistenceStrategy.BOTH)) { final Property ecFID = new Property(); ecFID.setName(HbConstants.PROPERTY_ECONTAINER_FEATURE_NAME); ecFID.setMetaAttributes(new HashMap<Object, Object>()); ecFID.setNodeName(ecFID.getName()); ecFID.setPropertyAccessorName(NewEContainerFeatureIDPropertyHandler.class.getName()); final SimpleValue svfid = new SimpleValue(getMappings(), pc.getTable()); svfid.setTypeName(EContainerFeatureIDUserType.class.getName()); final Column ecfColumn = new Column(getPersistenceOptions().getSQLColumnNamePrefix() + getPersistenceOptions().getEContainerFeatureNameColumn()); ecfColumn.setLength(getEContainerFeatureNameColumnLength()); svfid.addColumn(checkColumnExists(pc.getTable(), ecfColumn)); ecFID.setValue(svfid); pc.addProperty(ecFID); } }
From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void createKeyForProps(PersistentProperty grailsProp, String path, Table table, String columnName, List<?> propertyNames, String sessionFactoryBeanName) { List<Column> keyList = new ArrayList<Column>(); keyList.add(new Column(columnName)); for (Object po : propertyNames) { String propertyName = (String) po; PersistentProperty otherProp = grailsProp.getOwner().getPropertyByName(propertyName); String otherColumnName = getColumnNameForPropertyAndPath(otherProp, path, null, sessionFactoryBeanName); keyList.add(new Column(otherColumnName)); }//from w ww. ja va2s. com createUniqueKeyForColumns(table, columnName, keyList); }
From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
protected void createKeyForProps(PersistentProperty grailsProp, String path, Table table, String columnName, List<?> propertyNames, String sessionFactoryBeanName) { List<Column> keyList = new ArrayList<Column>(); keyList.add(new Column(columnName)); for (Iterator<?> i = propertyNames.iterator(); i.hasNext();) { String propertyName = (String) i.next(); PersistentProperty otherProp = grailsProp.getOwner().getPropertyByName(propertyName); String otherColumnName = getColumnNameForPropertyAndPath(otherProp, path, null, sessionFactoryBeanName); keyList.add(new Column(otherColumnName)); }/*from w w w . jav a 2s . c o m*/ createUniqueKeyForColumns(table, columnName, keyList); }
From source file:org.ligoj.bootstrap.core.dao.ImplicitNamingStrategyNiceJpaImpl.java
License:MIT License
protected List<Column> toColumns(final List<Identifier> identifiers) { return identifiers.stream().map(column -> new Column(column.getText())).collect(Collectors.toList()); }