List of usage examples for org.hibernate.mapping Column DEFAULT_LENGTH
int DEFAULT_LENGTH
To view the source code for org.hibernate.mapping Column DEFAULT_LENGTH.
Click Source Link
From source file:com.amalto.core.storage.hibernate.LiquibaseSchemaAdapter.java
License:Open Source License
private String getColumnType(FieldMetadata current, String columnDataType) { int hibernateTypeCode = 0; TypeMetadata type = MetadataUtils.getSuperConcreteType(current.getType()); Object currentLength = CommonUtil.getSuperTypeMaxLength(current.getType(), current.getType()); Object currentTotalDigits = current.getType().getData(MetadataRepository.DATA_TOTAL_DIGITS); Object currentFractionDigits = current.getType().getData(MetadataRepository.DATA_FRACTION_DIGITS); int length = currentLength == null ? Column.DEFAULT_LENGTH : Integer.parseInt(currentLength.toString()); int precision = currentTotalDigits == null ? Column.DEFAULT_PRECISION : Integer.parseInt(currentTotalDigits.toString()); int scale = currentFractionDigits == null ? Column.DEFAULT_SCALE : Integer.parseInt(currentFractionDigits.toString()); if (type.getName().equals("string")) { //$NON-NLS-1$ hibernateTypeCode = java.sql.Types.VARCHAR; } else if (type.getName().equals("int") || type.getName().equals("short") //$NON-NLS-1$ //$NON-NLS-2$ || type.getName().equals("long") || type.getName().equals("integer")) { //$NON-NLS-1$ //$NON-NLS-2$ hibernateTypeCode = java.sql.Types.INTEGER; } else if (type.getName().equals("boolean")) { //$NON-NLS-1$ hibernateTypeCode = java.sql.Types.BOOLEAN; } else if (type.getName().equals("date") || type.getName().equals("datetime")) { //$NON-NLS-1$ //$NON-NLS-2$ hibernateTypeCode = java.sql.Types.TIMESTAMP; } else if (type.getName().equals("double") || type.getName().equals("float")) { //$NON-NLS-1$ //$NON-NLS-2$ hibernateTypeCode = java.sql.Types.DOUBLE; } else if (type.getName().equals("decimal")) { hibernateTypeCode = java.sql.Types.NUMERIC; }/*from ww w. j av a 2s . com*/ columnDataType = dialect.getTypeName(hibernateTypeCode, length, precision, scale); return columnDataType; }
From source file:com.blazebit.persistence.integration.hibernate.base.HibernateJpaProvider.java
License:Apache License
private String[] getColumnTypeForPropertyType(EntityType<?> entityType, String attributeName, SessionFactoryImplementor sfi, Type propertyType) { if (propertyType instanceof org.hibernate.type.EntityType) { propertyType = ((org.hibernate.type.EntityType) propertyType).getIdentifierOrUniqueKeyType(sfi); }/*from www . jav a 2 s. c om*/ long length = Column.DEFAULT_LENGTH; int precision = Column.DEFAULT_PRECISION; int scale = Column.DEFAULT_SCALE; try { Method m = Type.class.getMethod("dictatedSizes", Mapping.class); Object size = ((Object[]) m.invoke(propertyType, sfi))[0]; length = (long) size.getClass().getMethod("getLength").invoke(size); precision = (int) size.getClass().getMethod("getPrecision").invoke(size); scale = (int) size.getClass().getMethod("getScale").invoke(size); } catch (Exception ex) { LOG.fine("Could not determine the column type of the attribute: " + attributeName + " of the entity: " + entityType.getName()); } return new String[] { sfi.getDialect().getTypeName(propertyType.sqlTypes(sfi)[0], length, precision, scale) }; }
From source file:net.lshift.hibernate.migrations.AlterTableBuilder.java
License:Apache License
private static Column buildColumnDefinition(String name, int sqlType, boolean nullable, Object defaultVal) { return buildColumnDefinition(name, sqlType, Column.DEFAULT_LENGTH, nullable, defaultVal); }
From source file:net.lshift.hibernate.migrations.CreateTableBuilder.java
License:Apache License
public CreateTableBuilder column(String name, int sqlType, boolean nullable) { return column(name, sqlType, Column.DEFAULT_LENGTH, nullable, null); }
From source file:net.lshift.hibernate.migrations.CreateTableBuilder.java
License:Apache License
public CreateTableBuilder column(String name, int sqlType, boolean nullable, Object defaultVal) { return column(name, sqlType, Column.DEFAULT_LENGTH, nullable, defaultVal); }
From source file:org.beangle.orm.hibernate.tool.HbmGenerator.java
License:Open Source License
@SuppressWarnings("unchecked") public void gen(String file) throws Exception { hbconfig = new OverrideConfiguration(); hbconfig.getProperties().put(Environment.DIALECT, new Oracle10gDialect()); ConfigBuilder.build(hbconfig);/* w w w .ja v a 2 s . c om*/ freemarkerConfig = new freemarker.template.Configuration(); freemarkerConfig.setTemplateLoader(new ClassTemplateLoader(getClass(), "/")); Iterator<PersistentClass> iter = hbconfig.getClassMappings(); List<PersistentClass> pcs = CollectUtils.newArrayList(); while (iter.hasNext()) { PersistentClass pc = iter.next(); Class<?> cls = pc.getMappedClass(); Iterator<Property> pi = pc.getPropertyIterator(); // For AnnotationBinder don't set column'length and nullable in ,let's we do it. while (pi.hasNext()) { Property p = pi.next(); if (p.getColumnSpan() != 1) continue; Column column = (Column) p.getColumnIterator().next(); if (column.getLength() == Column.DEFAULT_LENGTH) { Size size = findAnnotation(cls, Size.class, p.getName()); if (null != size) column.setLength(size.max()); } if (column.isNullable()) { NotNull notnull = findAnnotation(cls, NotNull.class, p.getName()); if (null != notnull) column.setNullable(false); } } if (!pc.getClassName().contains(".example.")) pcs.add(pc); } Map<String, Object> data = CollectUtils.newHashMap(); data.put("classes", pcs); data.put("generator", this); Template freemarkerTemplate = freemarkerConfig.getTemplate("/hbm.ftl"); FileWriter fw = new FileWriter("/tmp/hibernate.hbm.xml"); freemarkerTemplate.process(data, fw); }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinderTests.java
License:Apache License
/** * @see GrailsDomainBinder#bindStringColumnConstraints(Column, ConstrainedProperty) *//*from ww w.j av a 2 s. c o m*/ public void testBindStringColumnConstraints() { // Verify that the correct length is set when a maxSize constraint is applied ConstrainedProperty constrainedProperty = getConstrainedStringProperty(); constrainedProperty.applyConstraint(ConstrainedProperty.MAX_SIZE_CONSTRAINT, new Integer(30)); assertColumnLength(constrainedProperty, 30); // Verify that the correct length is set when a size constraint is applied constrainedProperty = getConstrainedStringProperty(); constrainedProperty.applyConstraint(ConstrainedProperty.SIZE_CONSTRAINT, new IntRange(6, 32768)); assertColumnLength(constrainedProperty, 32768); // Verify that the default length remains intact when no size-related constraints are applied constrainedProperty = getConstrainedStringProperty(); assertColumnLength(constrainedProperty, Column.DEFAULT_LENGTH); // Verify that the correct length is set when an inList constraint is applied constrainedProperty = getConstrainedStringProperty(); List validValuesList = Arrays.asList(new String[] { "Groovy", "Java", "C++" }); constrainedProperty.applyConstraint(ConstrainedProperty.IN_LIST_CONSTRAINT, validValuesList); assertColumnLength(constrainedProperty, 6); // Verify that the correct length is set when a maxSize constraint *and* an inList constraint are *both* applied constrainedProperty = getConstrainedStringProperty(); constrainedProperty.applyConstraint(ConstrainedProperty.IN_LIST_CONSTRAINT, validValuesList); constrainedProperty.applyConstraint(ConstrainedProperty.MAX_SIZE_CONSTRAINT, new Integer(30)); assertColumnLength(constrainedProperty, 30); }