List of usage examples for org.hibernate.mapping Column getLength
public int getLength()
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void linkValueUsingAColumnCopy(GrailsDomainClassProperty prop, Column column, DependantValue key) { Column mappingColumn = new Column(); mappingColumn.setName(column.getName()); mappingColumn.setLength(column.getLength()); mappingColumn.setNullable(prop.isOptional()); mappingColumn.setSqlType(column.getSqlType()); mappingColumn.setValue(key);//from w w w . j a va 2 s .c om key.addColumn(mappingColumn); key.getTable().addColumn(mappingColumn); }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
private static void linkValueUsingAColumnCopy(GrailsDomainClassProperty prop, Column column, DependantValue key) {/*from w w w. j a v a 2 s. c om*/ Column mappingColumn = new Column(); mappingColumn.setName(column.getName()); mappingColumn.setLength(column.getLength()); mappingColumn.setNullable(prop.isOptional()); mappingColumn.setSqlType(column.getSqlType()); mappingColumn.setValue(key); key.addColumn(mappingColumn); key.getTable().addColumn(mappingColumn); }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinderTests.java
License:Apache License
private void assertColumnLength(ConstrainedProperty constrainedProperty, int expectedLength) { Column column = new Column(); GrailsDomainBinder.bindStringColumnConstraints(column, constrainedProperty); assertEquals(expectedLength, column.getLength()); }
From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void linkValueUsingAColumnCopy(PersistentProperty prop, Column column, DependantValue key) { Column mappingColumn = new Column(); mappingColumn.setName(column.getName()); mappingColumn.setLength(column.getLength()); mappingColumn.setNullable(prop.isNullable()); mappingColumn.setSqlType(column.getSqlType()); mappingColumn.setValue(key);//from w w w . j av a2s .c o m key.addColumn(mappingColumn); key.getTable().addColumn(mappingColumn); }
From source file:org.jdbcluster.template.hibernate.HibernateConfiguration.java
License:Apache License
/** * calculated the max length of an attribute of type String * @param c Cluster that holds the attribute * @param attributeName name of the attribute * @return max allowed length of the attribute *//* w ww .jav a2 s .c o m*/ public int getLenthOfStringAttribute(ICluster c, String attributeName) { Assert.notNull(c, "c may not be null"); Assert.notNull(attributeName, "attributeName may not be null"); PersistentClass pc = cfg.getClassMapping(c.getDaoClass().getName()); if (pc == null) throw new ConfigurationException( "Persistent Dao Class from Cluster " + c.getClass().getName() + " is not Hibernate configured"); Property p = pc.getProperty(attributeName); if (p == null) throw new ConfigurationException( "Property " + attributeName + " in cluster " + c.getClass().getName() + " not found"); Iterator<Column> i = (Iterator<Column>) p.getValue().getColumnIterator(); Column column = i.next(); return column.getLength(); }
From source file:org.projectforge.database.HibernateUtils.java
License:Open Source License
private Integer internalGetPropertyMaxLength(final String entityName, final String propertyName) { Integer length = columnLengthMap.get(getKey(entityName, propertyName)); if (length != null) { return length; }/* ww w . ja v a 2s.c o m*/ if (columnLengthFailedSet.contains(getKey(entityName, propertyName)) == true) { return null; } final PersistentClass persistentClass = configuration.getClassMapping(entityName); if (persistentClass == null) { final String msg = "Could not find persistent class for entityName '" + entityName + "' (OK for non hibernate objects)."; if (entityName.endsWith("DO") == true) { log.error(msg); } else { log.info(msg); } putFailedEntry(entityName, propertyName); return null; } Column column = persistentClass.getTable().getColumn(new Column(propertyName)); if (column == null) { // OK, may be the database name of the column differs, e. g. if a different name is set via @Column(name = "..."). Property property = null; try { property = persistentClass.getProperty(propertyName); } catch (final MappingException ex) { if (TEST_MODE == false) { log.error(ex.getMessage(), ex); } else { log.info("***** TESTMODE: property '" + propertyName + "' not found (OK in test mode)."); } putFailedEntry(entityName, propertyName); return null; } final Iterator<?> it = property.getColumnIterator(); if (it.hasNext() == true) { column = (Column) it.next(); if (it.hasNext() == true) { putFailedEntry(entityName, propertyName); throw new UnsupportedOperationException("Multiple columns for selected entity '" + entityName + "' with name '" + propertyName + "' not predictable, aborting."); } } } if (column == null) { log.error("Could not find column for entity '" + entityName + "' with name '" + propertyName + "'."); return null; } length = column.getLength(); columnLengthMap.put(entityName + "#" + propertyName, length); return length; }
From source file:org.sparkcommerce.openadmin.server.dao.provider.metadata.DefaultFieldMetadataProvider.java
License:Apache License
@Override public FieldProviderResponse addMetadataFromMappingData( AddMetadataFromMappingDataRequest addMetadataFromMappingDataRequest, FieldMetadata metadata) { BasicFieldMetadata fieldMetadata = (BasicFieldMetadata) metadata; fieldMetadata.setFieldType(addMetadataFromMappingDataRequest.getType()); fieldMetadata.setSecondaryType(addMetadataFromMappingDataRequest.getSecondaryType()); if (addMetadataFromMappingDataRequest.getRequestedEntityType() != null && !addMetadataFromMappingDataRequest.getRequestedEntityType().isCollectionType()) { Column column = null; for (Property property : addMetadataFromMappingDataRequest.getComponentProperties()) { if (property.getName().equals(addMetadataFromMappingDataRequest.getPropertyName())) { Object columnObject = property.getColumnIterator().next(); if (columnObject instanceof Column) { column = (Column) columnObject; }// www . ja v a2s.c o m break; } } if (column != null) { fieldMetadata.setLength(column.getLength()); fieldMetadata.setScale(column.getScale()); fieldMetadata.setPrecision(column.getPrecision()); fieldMetadata.setRequired(!column.isNullable()); fieldMetadata.setUnique(column.isUnique()); } fieldMetadata.setForeignKeyCollection(false); } else { fieldMetadata.setForeignKeyCollection(true); } fieldMetadata.setMutable(true); fieldMetadata.setMergedPropertyType(addMetadataFromMappingDataRequest.getMergedPropertyType()); if (SupportedFieldType.BROADLEAF_ENUMERATION.equals(addMetadataFromMappingDataRequest.getType())) { try { setupSparkEnumeration(fieldMetadata.getSparkEnumeration(), fieldMetadata, addMetadataFromMappingDataRequest.getDynamicEntityDao()); } catch (Exception e) { throw new RuntimeException(e); } } return FieldProviderResponse.HANDLED; }
From source file:org.squale.jraf.provider.persistence.hibernate.MetaDataImpl.java
License:Open Source License
/** * Retourne la longueur de la colonne ou sera stocke columnName de la classe clazz * @param clazz Classe voulue/*from w w w.j a v a2 s. c o m*/ * @param columnName nom de la colonne * @return la longueur de la colonne si elle existe * @throws JrafConfigException si la colonne est pas touv ou si le mode introspection n'est pas actif */ public int getColumnMaxSize(Class clazz, String columnName) throws JrafConfigException { if (getConfiguration() == null) { throw new JrafConfigException("L'introspection n'est pas active"); } //Cette mthode ne prend plus en paramtre un type Class plutt un String. PersistentClass persistentClass = configuration.getClassMapping(clazz.getName()); Table table = persistentClass.getTable(); Column column = getColumn(table, columnName); if (column == null) throw new JrafConfigException("Column non trouve : " + columnName); return column.getLength(); }
From source file:org.unitime.timetable.backup.SessionRestore.java
License:Open Source License
public void create(TableData.Table table) throws InstantiationException, IllegalAccessException, DocumentException { ClassMetadata metadata = iHibSessionFactory.getClassMetadata(table.getName()); if (metadata == null) return;/* w w w.j a v a 2 s.c om*/ PersistentClass mapping = _RootDAO.getConfiguration().getClassMapping(table.getName()); Map<String, Integer> lengths = new HashMap<String, Integer>(); for (String property : metadata.getPropertyNames()) { Type type = metadata.getPropertyType(property); if (type instanceof StringType) for (Iterator<?> i = mapping.getProperty(property).getColumnIterator(); i.hasNext();) { Object o = i.next(); if (o instanceof Column) { Column column = (Column) o; lengths.put(property, column.getLength()); } break; } } iProgress.setPhase(metadata.getEntityName().substring(metadata.getEntityName().lastIndexOf('.') + 1) + " [" + table.getRecordCount() + "]", table.getRecordCount()); for (TableData.Record record : table.getRecordList()) { iProgress.incProgress(); Object object = metadata.getMappedClass().newInstance(); for (String property : metadata.getPropertyNames()) { TableData.Element element = null; for (TableData.Element e : record.getElementList()) if (e.getName().equals(property)) { element = e; break; } if (element == null) continue; Object value = null; Type type = metadata.getPropertyType(property); if (type instanceof PrimitiveType) { if (type instanceof BooleanType) { value = new Boolean("true".equals(element.getValue(0))); } else if (type instanceof ByteType) { value = Byte.valueOf(element.getValue(0)); } else if (type instanceof CharacterType) { value = Character.valueOf(element.getValue(0).charAt(0)); } else if (type instanceof DoubleType) { value = Double.valueOf(element.getValue(0)); } else if (type instanceof FloatType) { value = Float.valueOf(element.getValue(0)); } else if (type instanceof IntegerType) { value = Integer.valueOf(element.getValue(0)); } else if (type instanceof LongType) { value = Long.valueOf(element.getValue(0)); } else if (type instanceof ShortType) { value = Short.valueOf(element.getValue(0)); } } else if (type instanceof DateType) { try { value = new SimpleDateFormat("dd MMMM yyyy", Localization.getJavaLocale()) .parse(element.getValue(0)); } catch (ParseException e) { value = new DateType().fromStringValue(element.getValue(0)); } } else if (type instanceof TimestampType) { value = new TimestampType().fromStringValue(element.getValue(0)); } else if (type instanceof StringType) { value = element.getValue(0); Integer len = lengths.get(property); if (len != null && value.toString().length() > len) { message("Value is too long, truncated (property " + metadata.getEntityName() + "." + property + ", length " + len + ")", record.getId()); value = value.toString().substring(0, len); } } else if (type instanceof BinaryType) { value = ByteString.copyFromUtf8(element.getValue(0)).toByteArray(); } else if (type instanceof CustomType && type.getReturnedClass().equals(Document.class)) { value = new SAXReader().read(new StringReader(element.getValue(0))); } else if (type instanceof EntityType) { } else if (type instanceof CollectionType) { } else { message("Unknown type " + type.getClass().getName() + " (property " + metadata.getEntityName() + "." + property + ", class " + type.getReturnedClass() + ")", record.getId()); } if (value != null) metadata.setPropertyValue(object, property, value); } add(new Entity(metadata, record, object, record.getId())); } }
From source file:org.zht.framework.service.impl.BaseServiceImpl.java
License:Apache License
private String checkLenth(M m) { // final PersistentClass clazz = factory.getConfiguration().getClassMapping(m.getClass().getName()); if (clazz == null) { throw new ServiceLogicalException("[]???"); }/* w w w . j av a2s . co m*/ // final Table table = clazz.getTable(); // if(table==null){ // throw new ServiceLogicalException("[]???"); // } @SuppressWarnings("unchecked") final Iterator<Property> iterator = clazz.getPropertyIterator(); if (iterator == null) { throw new ServiceLogicalException( "[]???"); } // MethodAccess access = MethodAccess.get(m.getClass()); while (iterator.hasNext()) { Property property = iterator.next(); if ("id".equals(property.getName())) { continue; } Iterator<?> columnIterator = property.getColumnIterator(); if (columnIterator.hasNext()) { Column column = (Column) columnIterator.next(); int lenth = column.getLength(); Object value = (Object) access.invoke(m, "get" + ZStrUtil.toUpCaseFirst(property.getName())); if (value != null) { if (value instanceof java.lang.String) { if (lenth < (((java.lang.String) value).length())) { return (" [" + property.getName() + "] ??"); } } } } } return null; }