org.hibernate.mapping.Column.getLength()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(137)

本文整理了Java中org.hibernate.mapping.Column.getLength()方法的一些代码示例,展示了Column.getLength()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Column.getLength()方法的具体详情如下:
包路径:org.hibernate.mapping.Column
类名称:Column
方法名:getLength

Column.getLength介绍

暂无

代码示例

代码示例来源:origin: hibernate/hibernate-orm

public String getSqlType(Dialect dialect, Mapping mapping) throws HibernateException {
  if ( sqlType == null ) {
    sqlType = dialect.getTypeName( getSqlTypeCode( mapping ), getLength(), getPrecision(), getScale() );
  }
  return sqlType;
}

代码示例来源:origin: hibernate/hibernate-orm

private void alignColumns(Table referencedTable) {
  final int referencedPkColumnSpan = referencedTable.getPrimaryKey().getColumnSpan();
  if ( referencedPkColumnSpan != getColumnSpan() ) {
    StringBuilder sb = new StringBuilder();
    sb.append( "Foreign key (" ).append( getName() ).append( ":" )
        .append( getTable().getName() )
        .append( " [" );
    appendColumns( sb, getColumnIterator() );
    sb.append( "])" )
        .append( ") must have same number of columns as the referenced primary key (" )
        .append( referencedTable.getName() )
        .append( " [" );
    appendColumns( sb, referencedTable.getPrimaryKey().getColumnIterator() );
    sb.append( "])" );
    throw new MappingException( sb.toString() );
  }
  Iterator fkCols = getColumnIterator();
  Iterator pkCols = referencedTable.getPrimaryKey().getColumnIterator();
  while ( pkCols.hasNext() ) {
    ( (Column) fkCols.next() ).setLength( ( (Column) pkCols.next() ).getLength() );
  }
}

代码示例来源:origin: hibernate/hibernate-orm

private void applyComponentColumnSizeValueToJoinColumn(Column column, Ejb3JoinColumn joinColumn) {
  Column mappingColumn = joinColumn.getMappingColumn();
  mappingColumn.setLength( column.getLength() );
  mappingColumn.setPrecision( column.getPrecision() );
  mappingColumn.setScale( column.getScale() );
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testApplyOnIdColumn() throws Exception {
  PersistentClass classMapping = metadata().getEntityBinding( Tv.class.getName() );
  Column serialColumn = (Column) classMapping.getIdentifierProperty().getColumnIterator().next();
  assertEquals( "Validator annotation not applied on ids", 2, serialColumn.getLength() );
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testBasicDDL() {
  PersistentClass classMapping = metadata().getEntityBinding( Address.class.getName() );
  Column stateColumn = (Column) classMapping.getProperty( "state" ).getColumnIterator().next();
  assertEquals( stateColumn.getLength(), 3 );
  Column zipColumn = (Column) classMapping.getProperty( "zip" ).getColumnIterator().next();
  assertEquals( zipColumn.getLength(), 5 );
  assertFalse( zipColumn.isNullable() );
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
@TestForIssue( jiraKey = "HHH-5281" )
public void testLengthConstraint() throws Exception {
  PersistentClass classMapping = metadata().getEntityBinding( Tv.class.getName() );
  Column modelColumn = (Column) classMapping.getProperty( "model" ).getColumnIterator().next();
  assertEquals( modelColumn.getLength(), 5 );
}

代码示例来源:origin: hibernate/hibernate-orm

/**
 * Adds <code>column</code> element with the following attributes (unless empty): <code>name</code>,
 * <code>length</code>, <code>scale</code>, <code>precision</code>, <code>sql-type</code>, <code>read</code>
 * and <code>write</code>.
 *
 * @param anyMapping Parent element.
 * @param column Column descriptor.
 */
public static void addColumn(Element anyMapping, Column column) {
  addColumn(
      anyMapping,
      column.getName(),
      column.getLength(),
      column.getScale(),
      column.getPrecision(),
      column.getSqlType(),
      column.getCustomRead(),
      column.getCustomWrite(),
      column.isQuoted()
  );
}

代码示例来源:origin: hibernate/hibernate-orm

/**
 * used for mappedBy cases
 */
public void linkValueUsingAColumnCopy(Column column, SimpleValue value) {
  initMappingColumn(
      //column.getName(),
      column.getQuotedName(),
      null, column.getLength(),
      column.getPrecision(),
      column.getScale(),
      getMappingColumn().isNullable(),
      column.getSqlType(),
      getMappingColumn().isUnique(),
      false //We do copy no strategy here
  );
  linkWithValue( value );
}

代码示例来源:origin: hibernate/hibernate-orm

/**
 * Called to apply column definitions from the referenced FK column to this column.
 *
 * @param column the referenced column.
 */
public void overrideFromReferencedColumnIfNecessary(org.hibernate.mapping.Column column) {
  if (getMappingColumn() != null) {
    // columnDefinition can also be specified using @JoinColumn, hence we have to check
    // whether it is set or not
    if ( StringHelper.isEmpty( sqlType ) ) {
      sqlType = column.getSqlType();
      getMappingColumn().setSqlType( sqlType );
    }
    // these properties can only be applied on the referenced column - we can just take them over
    getMappingColumn().setLength(column.getLength());
    getMappingColumn().setPrecision(column.getPrecision());
    getMappingColumn().setScale(column.getScale());
  }
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

fieldMetadata.setLength(column.getLength());
fieldMetadata.setScale(column.getScale());
fieldMetadata.setPrecision(column.getPrecision());

代码示例来源:origin: hibernate/hibernate-orm

public void linkValueUsingDefaultColumnNaming(
    Column referencedColumn,
    PersistentClass referencedEntity,
    SimpleValue value) {
  String logicalReferencedColumn = getBuildingContext().getMetadataCollector().getLogicalColumnName(
      referencedEntity.getTable(),
      referencedColumn.getQuotedName()
  );
  String columnName = buildDefaultColumnName( referencedEntity, logicalReferencedColumn );
  //yuk side effect on an implicit column
  setLogicalColumnName( columnName );
  setReferencedColumn( logicalReferencedColumn );
  initMappingColumn(
      columnName,
      null, referencedColumn.getLength(),
      referencedColumn.getPrecision(),
      referencedColumn.getScale(),
      getMappingColumn() != null ? getMappingColumn().isNullable() : false,
      referencedColumn.getSqlType(),
      getMappingColumn() != null ? getMappingColumn().isUnique() : false,
      false
  );
  linkWithValue( value );
}

代码示例来源:origin: hibernate/hibernate-orm

Column column = (Column) mappedByColumns.next();
Column copy = new Column();
copy.setLength( column.getLength() );
copy.setScale( column.getScale() );
copy.setValue( key );

代码示例来源:origin: hibernate/hibernate-orm

@Test
  @FailureExpected( jiraKey = "HHH-9089" )
  public void testEnumTypeInterpretation() {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();

    try {
      final Metadata metadata = new MetadataSources( ssr )
          .addAnnotatedClass( Customer.class )
          .buildMetadata();

      PersistentClass classMetadata = metadata.getEntityBinding( Customer.class.getName() );
      Property investmentsProperty = classMetadata.getProperty( "investments" );
      Collection investmentsValue = (Collection) investmentsProperty.getValue();
      Component investmentMetadata = (Component) investmentsValue.getElement();
      Value descriptionValue = investmentMetadata.getProperty( "description" ).getValue();
      assertEquals( 1, descriptionValue.getColumnSpan() );
      Column selectable = (Column) descriptionValue.getColumnIterator().next();
      assertEquals( 500, selectable.getLength() );
      Component amountMetadata = (Component) investmentMetadata.getProperty( "amount" ).getValue();
      SimpleValue currencyMetadata = (SimpleValue) amountMetadata.getProperty( "currency" ).getValue();
      CustomType currencyType = (CustomType) currencyMetadata.getType();
      int[] currencySqlTypes = currencyType.sqlTypes( metadata );
      assertEquals( 1, currencySqlTypes.length );
      assertJdbcTypeCode( Types.VARCHAR, currencySqlTypes[0] );
    }
    finally {
      StandardServiceRegistryBuilder.destroy( ssr );
    }
  }
}

代码示例来源:origin: hibernate/hibernate-orm

assertEquals( 1, descriptionValue.getColumnSpan() );
Column selectable = (Column) descriptionValue.getColumnIterator().next();
assertEquals( 500, selectable.getLength() );
Component amountMetadata = (Component) investmentMetadata.getProperty( "amount" ).getValue();
SimpleValue currencyMetadata = (SimpleValue) amountMetadata.getProperty( "currency" ).getValue();

代码示例来源:origin: openmrs/openmrs-core

@Override
public int getMaximumPropertyLength(Class<? extends OpenmrsObject> aClass, String fieldName) {
  if (configuration == null) {
    HibernateSessionFactoryBean sessionFactoryBean = (HibernateSessionFactoryBean) applicationContext
        .getBean("&sessionFactory");
    configuration = sessionFactoryBean.getConfiguration();
  }
  
  PersistentClass persistentClass = configuration.getClassMapping(aClass.getName().split("_")[0]);
  if (persistentClass == null) {
    throw new APIException("Couldn't find a class in the hibernate configuration named: " + aClass.getName());
  } else {
    int fieldLength;
    try {
      fieldLength = ((Column) persistentClass.getProperty(fieldName).getColumnIterator().next()).getLength();
    }
    catch (Exception e) {
      log.debug("Could not determine maximum length", e);
      return -1;
    }
    return fieldLength;
  }
}

代码示例来源:origin: hibernate/hibernate-orm

Column column = (Column) otherSideJoinKeyColumns.next();
Column copy = new Column();
copy.setLength( column.getLength() );
copy.setScale( column.getScale() );
copy.setValue( manyToOne );

代码示例来源:origin: org.hibernate/hibernate-annotations

/**
 * used for mappedBy cases
 */
public void linkValueUsingAColumnCopy(Column column, SimpleValue value) {
  initMappingColumn(
      //column.getName(),
      column.getQuotedName(),
      null, column.getLength(),
      column.getPrecision(),
      column.getScale(),
      getMappingColumn().isNullable(),
      column.getSqlType(),
      getMappingColumn().isUnique(),
      false //We do copy no strategy here
  );
  linkWithValue( value );
}

代码示例来源:origin: org.hibernate/hibernate-annotations

/**
 * Called to apply column definitions from the referenced FK column to this column.
 * 
 * @param column the referenced column.
 */
public void overrideFromReferencedColumnIfNecessary(org.hibernate.mapping.Column column) {
  
  if (getMappingColumn() != null) {
    // columnDefinition can also be specified using @JoinColumn, hence we have to check
    // whether it is set or not
    if ( StringHelper.isEmpty( sqlType ) ) {
      sqlType = column.getSqlType();
      getMappingColumn().setSqlType( sqlType );
    }
    // these properties can only be applied on the referenced column - we can just take them over
    getMappingColumn().setLength(column.getLength());
    getMappingColumn().setPrecision(column.getPrecision());
    getMappingColumn().setScale(column.getScale());
  }
}

代码示例来源:origin: org.hibernate/hibernate-annotations

public void linkValueUsingDefaultColumnNaming(
    Column referencedColumn, PersistentClass referencedEntity, SimpleValue value
) {
  String columnName;
  String logicalReferencedColumn = getMappings().getLogicalColumnName(
      referencedColumn.getQuotedName(), referencedEntity.getTable()
  );
  columnName = buildDefaultColumnName( referencedEntity, logicalReferencedColumn );
  //yuk side effect on an implicit column
  setLogicalColumnName( columnName );
  setReferencedColumn( logicalReferencedColumn );
  initMappingColumn(
      columnName,
      null, referencedColumn.getLength(),
      referencedColumn.getPrecision(),
      referencedColumn.getScale(),
      getMappingColumn() != null ? getMappingColumn().isNullable() : false,
      referencedColumn.getSqlType(),
      getMappingColumn() != null ? getMappingColumn().isUnique() : false,
      false
  );
  linkWithValue( value );
}

代码示例来源:origin: org.hibernate/hibernate-annotations

Column column = (Column) mappedByColumns.next();
Column copy = new Column();
copy.setLength( column.getLength() );
copy.setScale( column.getScale() );
copy.setValue( key );

相关文章