Java Code Examples for org.hibernate.mapping.Property#getColumnIterator()
The following examples show how to use
org.hibernate.mapping.Property#getColumnIterator() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeSafeActivator.java From lams with GNU General Public License v2.0 | 6 votes |
private static void applyMin(Property property, ConstraintDescriptor<?> descriptor, Dialect dialect) { if ( Min.class.equals( descriptor.getAnnotation().annotationType() ) ) { @SuppressWarnings("unchecked") ConstraintDescriptor<Min> minConstraint = (ConstraintDescriptor<Min>) descriptor; long min = minConstraint.getAnnotation().value(); @SuppressWarnings("unchecked") final Iterator<Selectable> itor = property.getColumnIterator(); if ( itor.hasNext() ) { final Selectable selectable = itor.next(); if ( Column.class.isInstance( selectable ) ) { Column col = (Column) selectable; String checkConstraint = col.getQuotedName(dialect) + ">=" + min; applySQLCheck( col, checkConstraint ); } } } }
Example 2
Source File: TypeSafeActivator.java From lams with GNU General Public License v2.0 | 6 votes |
private static void applyMax(Property property, ConstraintDescriptor<?> descriptor, Dialect dialect) { if ( Max.class.equals( descriptor.getAnnotation().annotationType() ) ) { @SuppressWarnings("unchecked") ConstraintDescriptor<Max> maxConstraint = (ConstraintDescriptor<Max>) descriptor; long max = maxConstraint.getAnnotation().value(); @SuppressWarnings("unchecked") final Iterator<Selectable> itor = property.getColumnIterator(); if ( itor.hasNext() ) { final Selectable selectable = itor.next(); if ( Column.class.isInstance( selectable ) ) { Column col = (Column) selectable; String checkConstraint = col.getQuotedName( dialect ) + "<=" + max; applySQLCheck( col, checkConstraint ); } } } }
Example 3
Source File: TypeSafeActivator.java From lams with GNU General Public License v2.0 | 6 votes |
private static void applyDigits(Property property, ConstraintDescriptor<?> descriptor) { if ( Digits.class.equals( descriptor.getAnnotation().annotationType() ) ) { @SuppressWarnings("unchecked") ConstraintDescriptor<Digits> digitsConstraint = (ConstraintDescriptor<Digits>) descriptor; int integerDigits = digitsConstraint.getAnnotation().integer(); int fractionalDigits = digitsConstraint.getAnnotation().fraction(); @SuppressWarnings("unchecked") final Iterator<Selectable> itor = property.getColumnIterator(); if ( itor.hasNext() ) { final Selectable selectable = itor.next(); if ( Column.class.isInstance( selectable ) ) { Column col = (Column) selectable; col.setPrecision( integerDigits + fractionalDigits ); col.setScale( fractionalDigits ); } } } }
Example 4
Source File: TypeSafeActivator.java From lams with GNU General Public License v2.0 | 6 votes |
private static void applySize(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) { if ( Size.class.equals( descriptor.getAnnotation().annotationType() ) && String.class.equals( propertyDescriptor.getElementClass() ) ) { @SuppressWarnings("unchecked") ConstraintDescriptor<Size> sizeConstraint = (ConstraintDescriptor<Size>) descriptor; int max = sizeConstraint.getAnnotation().max(); @SuppressWarnings("unchecked") final Iterator<Selectable> itor = property.getColumnIterator(); if ( itor.hasNext() ) { final Selectable selectable = itor.next(); Column col = (Column) selectable; if ( max < Integer.MAX_VALUE ) { col.setLength( max ); } } } }
Example 5
Source File: TypeSafeActivator.java From lams with GNU General Public License v2.0 | 6 votes |
private static void applyLength(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) { if ( "org.hibernate.validator.constraints.Length".equals( descriptor.getAnnotation().annotationType().getName() ) && String.class.equals( propertyDescriptor.getElementClass() ) ) { @SuppressWarnings("unchecked") int max = (Integer) descriptor.getAttributes().get( "max" ); @SuppressWarnings("unchecked") final Iterator<Selectable> itor = property.getColumnIterator(); if ( itor.hasNext() ) { final Selectable selectable = itor.next(); if ( Column.class.isInstance( selectable ) ) { Column col = (Column) selectable; if ( max < Integer.MAX_VALUE ) { col.setLength( max ); } } } } }
Example 6
Source File: MetadataTest.java From high-performance-java-persistence with Apache License 2.0 | 6 votes |
@Test public void testEntityToDatabaseBindingMetadata() { Metadata metadata = MetadataExtractorIntegrator.INSTANCE.getMetadata(); for ( PersistentClass persistentClass : metadata.getEntityBindings()) { Table table = persistentClass.getTable(); LOGGER.info( "Entity: {} is mapped to table: {}", persistentClass.getClassName(), table.getName() ); for(Iterator propertyIterator = persistentClass.getPropertyIterator(); propertyIterator.hasNext(); ) { Property property = (Property) propertyIterator.next(); for(Iterator columnIterator = property.getColumnIterator(); columnIterator.hasNext(); ) { Column column = (Column) columnIterator.next(); LOGGER.info( "Property: {} is mapped on table column: {} of type: {}", property.getName(), column.getName(), column.getSqlType() ); } } } }
Example 7
Source File: TypeSafeActivator.java From lams with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") private static boolean applyNotNull(Property property, ConstraintDescriptor<?> descriptor) { boolean hasNotNull = false; if ( NotNull.class.equals( descriptor.getAnnotation().annotationType() ) ) { // single table inheritance should not be forced to null due to shared state if ( !( property.getPersistentClass() instanceof SingleTableSubclass ) ) { //composite should not add not-null on all columns if ( !property.isComposite() ) { final Iterator<Selectable> itr = property.getColumnIterator(); while ( itr.hasNext() ) { final Selectable selectable = itr.next(); if ( Column.class.isInstance( selectable ) ) { Column.class.cast( selectable ).setNullable( false ); } else { LOG.debugf( "@NotNull was applied to attribute [%s] which is defined (at least partially) " + "by formula(s); formula portions will be skipped", property.getName() ); } } } } hasNotNull = true; } return hasNotNull; }
Example 8
Source File: BinderHelper.java From lams with GNU General Public License v2.0 | 5 votes |
private static void matchColumnsByProperty(Property property, Map<Column, Set<Property>> columnsToProperty) { if ( property == null ) { return; } if ( "noop".equals( property.getPropertyAccessorName() ) || "embedded".equals( property.getPropertyAccessorName() ) ) { return; } // FIXME cannot use subproperties becasue the caller needs top level properties // if ( property.isComposite() ) { // Iterator subProperties = ( (Component) property.getValue() ).getPropertyIterator(); // while ( subProperties.hasNext() ) { // matchColumnsByProperty( (Property) subProperties.next(), columnsToProperty ); // } // } else { Iterator columnIt = property.getColumnIterator(); while ( columnIt.hasNext() ) { //can be a Formula so we don't cast Object column = columnIt.next(); //noinspection SuspiciousMethodCalls if ( columnsToProperty.containsKey( column ) ) { columnsToProperty.get( column ).add( property ); } } } }
Example 9
Source File: MapBinder.java From lams with GNU General Public License v2.0 | 5 votes |
private boolean propertyIteratorContainsColumn(Iterator propertyIterator, Column column) { for ( Iterator it = propertyIterator; it.hasNext(); ) { final Property property = (Property) it.next(); for ( Iterator<Selectable> selectableIterator = property.getColumnIterator(); selectableIterator.hasNext(); ) { final Selectable selectable = selectableIterator.next(); if ( column.equals( selectable ) ) { final Column iteratedColumn = (Column) selectable; if ( column.getValue().getTable().equals( iteratedColumn.getValue().getTable() ) ) { return true; } } } } return false; }
Example 10
Source File: AbstractEntityPersister.java From lams with GNU General Public License v2.0 | 5 votes |
private void internalInitSubclassPropertyAliasesMap(String path, Iterator propertyIterator) { while ( propertyIterator.hasNext() ) { Property prop = (Property) propertyIterator.next(); String propname = path == null ? prop.getName() : path + "." + prop.getName(); if ( prop.isComposite() ) { Component component = (Component) prop.getValue(); Iterator compProps = component.getPropertyIterator(); internalInitSubclassPropertyAliasesMap( propname, compProps ); } else { String[] aliases = new String[prop.getColumnSpan()]; String[] cols = new String[prop.getColumnSpan()]; Iterator colIter = prop.getColumnIterator(); int l = 0; while ( colIter.hasNext() ) { Selectable thing = (Selectable) colIter.next(); aliases[l] = thing.getAlias( getFactory().getDialect(), prop.getValue().getTable() ); cols[l] = thing.getText( getFactory().getDialect() ); // TODO: skip formulas? l++; } subclassPropertyAliases.put( propname, aliases ); subclassPropertyColumnNames.put( propname, cols ); } } }
Example 11
Source File: AbstractEntityPersister.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
private void internalInitSubclassPropertyAliasesMap(String path, Iterator propertyIterator) { while ( propertyIterator.hasNext() ) { Property prop = ( Property ) propertyIterator.next(); String propname = path == null ? prop.getName() : path + "." + prop.getName(); if ( prop.isComposite() ) { Component component = ( Component ) prop.getValue(); Iterator compProps = component.getPropertyIterator(); internalInitSubclassPropertyAliasesMap( propname, compProps ); } else { String[] aliases = new String[prop.getColumnSpan()]; String[] cols = new String[prop.getColumnSpan()]; Iterator colIter = prop.getColumnIterator(); int l = 0; while ( colIter.hasNext() ) { Selectable thing = ( Selectable ) colIter.next(); aliases[l] = thing.getAlias( getFactory().getDialect(), prop.getValue().getTable() ); cols[l] = thing.getText( getFactory().getDialect() ); // TODO: skip formulas? l++; } subclassPropertyAliases.put( propname, aliases ); subclassPropertyColumnNames.put( propname, cols ); } } }
Example 12
Source File: AbstractDBUnitHibernateMemoryTest.java From livingdoc-confluence with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") protected String[] getColumnNames(Class<?> peristentClass, String[] includedFields) throws MappingException { Collection<String> columns = new ArrayList<String>(); for (int i = 0; i < includedFields.length; i++) { String propertyName = includedFields[i]; Property property = getMapping(peristentClass).getProperty(propertyName); for (Iterator<Column> it = property.getColumnIterator(); it.hasNext(); ) { Column col = it.next(); columns.add(col.getName()); } } return columns.toArray(new String[columns.size()]); }
Example 13
Source File: HibernateUtil.java From unitime with Apache License 2.0 | 5 votes |
public static void fixSchemaInFormulas(Configuration cfg) throws ClassNotFoundException { cfg.buildMappings(); Class dialect = Class.forName(cfg.getProperty("dialect")); String schema = cfg.getProperty("default_schema"); for (Iterator i=cfg.getClassMappings();i.hasNext();) { PersistentClass pc = (PersistentClass)i.next(); for (Iterator j=pc.getPropertyIterator();j.hasNext();) { Property p = (Property)j.next(); for (Iterator k=p.getColumnIterator();k.hasNext();) { Selectable c = (Selectable)k.next(); if (c instanceof Formula) { Formula f = (Formula)c; boolean updated = false; if (schema != null && f.getFormula() != null && f.getFormula().indexOf("%SCHEMA%")>=0) { f.setFormula(f.getFormula().replaceAll("%SCHEMA%", schema)); sLog.debug("Schema updated in "+pc.getClassName()+"."+p.getName()+" to "+f.getFormula()); } if (f.getFormula()!=null && (f.getFormula().indexOf("%TRUE%")>=0 || f.getFormula().indexOf("%FALSE%")>=0)) { if (isPostgress(dialect)) { f.setFormula(f.getFormula().replaceAll("%TRUE%", "'t'").replaceAll("%FALSE%", "'f'")); } else { f.setFormula(f.getFormula().replaceAll("%TRUE%", "1").replaceAll("%FALSE%", "0")); } } if (updated) sLog.debug("Schema updated in "+pc.getClassName()+"."+p.getName()+" to "+f.getFormula()); } } } } }
Example 14
Source File: ModelBinder.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public void process() { log.debugf( "Binding natural-id UniqueKey for entity : " + entityBinding.getEntityName() ); final List<Identifier> columnNames = new ArrayList<Identifier>(); final UniqueKey uk = new UniqueKey(); uk.setTable( entityBinding.getTable() ); for ( Property attributeBinding : attributeBindings ) { final Iterator itr = attributeBinding.getColumnIterator(); while ( itr.hasNext() ) { final Object selectable = itr.next(); if ( Column.class.isInstance( selectable ) ) { final Column column = (Column) selectable; uk.addColumn( column ); columnNames.add( mappingDocument.getMetadataCollector().getDatabase().toIdentifier( column.getQuotedName() ) ); } } uk.addColumns( attributeBinding.getColumnIterator() ); } final Identifier ukName = mappingDocument.getBuildingOptions().getImplicitNamingStrategy().determineUniqueKeyName( new ImplicitUniqueKeyNameSource() { @Override public Identifier getTableName() { return entityBinding.getTable().getNameIdentifier(); } @Override public List<Identifier> getColumnNames() { return columnNames; } @Override public MetadataBuildingContext getBuildingContext() { return mappingDocument; } @Override public Identifier getUserProvidedIdentifier() { return uk.getName() != null ? Identifier.toIdentifier( uk.getName() ) : null; } } ); uk.setName( ukName.render( mappingDocument.getMetadataCollector().getDatabase().getDialect() ) ); entityBinding.getTable().addUniqueKey( uk ); }