org.hibernate.type.Type.sqlTypes()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(124)

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

Type.sqlTypes介绍

[英]Return the SQL type codes for the columns mapped by this type. The codes are defined on java.sql.Types.
[中]返回此类型映射的列的SQL类型代码。这些代码是在java上定义的。sql。类型。

代码示例

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

@Override
public int[] sqlTypes(Mapping mapping) throws MappingException {
  return underlyingType.sqlTypes( mapping );
}

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

public int[] sqlTypes(Mapping mapping) throws MappingException {
  return baseType.sqlTypes(mapping);
}

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

@Override
public int[] sqlTypes(Mapping mapping) throws MappingException {
  return ArrayHelper.join( discriminatorType.sqlTypes( mapping ), identifierType.sqlTypes( mapping ) );
}

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

@Override
public int[] sqlTypes(Mapping mapping) throws MappingException {
  //Not called at runtime so doesn't matter if its slow :)
  int[] sqlTypes = new int[getColumnSpan( mapping )];
  int n = 0;
  for ( int i = 0; i < propertySpan; i++ ) {
    int[] subtypes = propertyTypes[i].sqlTypes( mapping );
    for ( int subtype : subtypes ) {
      sqlTypes[n++] = subtype;
    }
  }
  return sqlTypes;
}

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

@Override
public int[] sqlTypes(Mapping mapping) throws MappingException {
  return requireIdentifierOrUniqueKeyType( mapping ).sqlTypes( mapping );
}

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

public int[] sqlTypes(Mapping mapping) throws MappingException {
  return super.getIdentifierOrUniqueKeyType( mapping ).sqlTypes( mapping );
}

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

protected final int determineJdbcTypeCode(Type firstArgumentType, SessionFactoryImplementor factory) throws QueryException {
  try {
    final int[] jdbcTypeCodes = firstArgumentType.sqlTypes( factory );
    if ( jdbcTypeCodes.length != 1 ) {
      throw new QueryException( "multiple-column type in avg()" );
    }
    return jdbcTypeCodes[0];
  }
  catch ( MappingException me ) {
    throw new QueryException( me );
  }
}

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

@Override
public int[] sqlTypes(Mapping mapping) throws MappingException {
  int[] result = new int[getColumnSpan( mapping )];
  int n = 0;
  for ( Type type : userType.getPropertyTypes() ) {
    for ( int sqlType : type.sqlTypes( mapping ) ) {
      result[n++] = sqlType;
    }
  }
  return result;
}

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

protected final int determineJdbcTypeCode(Type type, Mapping mapping) throws QueryException {
  try {
    final int[] jdbcTypeCodes = type.sqlTypes( mapping );
    if ( jdbcTypeCodes.length != 1 ) {
      throw new QueryException( "multiple-column type in sum()" );
    }
    return jdbcTypeCodes[0];
  }
  catch ( MappingException me ) {
    throw new QueryException( me );
  }
}

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

@Override
public int[] getSqlTypes() {
  if ( mode == ParameterMode.REF_CURSOR ) {
    // we could use the Types#REF_CURSOR added in Java 8, but that would require requiring Java 8...
    throw new IllegalStateException( "REF_CURSOR parameters do not have a SQL/JDBC type" );
  }
  return determineHibernateType().sqlTypes( procedureCall.getSession().getFactory() );
}

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

@Override
public void setHibernateType(Type expectedType) {
  super.setHibernateType( expectedType );
  if ( mode == ParameterMode.REF_CURSOR ) {
    sqlTypes = new int[] { Types.REF_CURSOR };
  }
  else {
    if ( expectedType == null ) {
      throw new IllegalArgumentException( "Type cannot be null" );
    }
    else {
      sqlTypes = expectedType.sqlTypes( procedureCall.getSession().getFactory() );
    }
  }
}

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

@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
  final String[] columns = criteriaQuery.findColumns( propertyName, criteria );
  final Type type = criteriaQuery.getTypeUsingProjection( criteria, propertyName );
  final StringBuilder fragment = new StringBuilder();
  if ( columns.length > 1 ) {
    fragment.append( '(' );
  }
  final SessionFactoryImplementor factory = criteriaQuery.getFactory();
  final int[] sqlTypes = type.sqlTypes( factory );
  for ( int i = 0; i < columns.length; i++ ) {
    final boolean lower = ignoreCase && (sqlTypes[i] == Types.VARCHAR || sqlTypes[i] == Types.CHAR || 
        sqlTypes[i] == Types.NVARCHAR || sqlTypes[i] == Types.NCHAR);
    if ( lower ) {
      fragment.append( factory.getDialect().getLowercaseFunction() ).append( '(' );
    }
    fragment.append( columns[i] );
    if ( lower ) {
      fragment.append( ')' );
    }
    fragment.append( getOp() ).append( "?" );
    if ( i < columns.length - 1 ) {
      fragment.append( " and " );
    }
  }
  if ( columns.length > 1 ) {
    fragment.append( ')' );
  }
  return fragment.toString();
}

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

@Override
public String render(Type columnType, List args, SessionFactoryImplementor factory) throws QueryException {
  if ( args.size()!=2 ) {
    throw new QueryException( "cast() requires two arguments; found : " + args.size() );
  }
  final String type = (String) args.get( 1 );
  final int[] sqlTypeCodes = factory.getTypeResolver().heuristicType( type ).sqlTypes( factory );
  if ( sqlTypeCodes.length!=1 ) {
    throw new QueryException("invalid Hibernate type for cast()");
  }
  String sqlType = factory.getDialect().getCastTypeName( sqlTypeCodes[0] );
  if ( sqlType == null ) {
    //TODO: never reached, since getExplicitHibernateTypeName() actually throws an exception!
    sqlType = type;
  }
  return "cast(" + args.get( 0 ) + " as " + sqlType + ')';
}

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

/**
 * Determine whether the two types are "assignment compatible".
 *
 * @param target The type defined in the into-clause.
 * @param source The type defined in the select clause.
 *
 * @return True if they are assignment compatible.
 */
private boolean areCompatible(Type target, Type source) {
  if ( target.equals( source ) ) {
    // if the types report logical equivalence, return true...
    return true;
  }
  // otherwise, doAfterTransactionCompletion a "deep equivalence" check...
  if ( !target.getReturnedClass().isAssignableFrom( source.getReturnedClass() ) ) {
    return false;
  }
  int[] targetDatatypes = target.sqlTypes( getSessionFactoryHelper().getFactory() );
  int[] sourceDatatypes = source.sqlTypes( getSessionFactoryHelper().getFactory() );
  if ( targetDatatypes.length != sourceDatatypes.length ) {
    return false;
  }
  for ( int i = 0; i < targetDatatypes.length; i++ ) {
    if ( !areSqlTypesCompatible( targetDatatypes[i], sourceDatatypes[i] ) ) {
      return false;
    }
  }
  return true;
}

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

public int getSqlTypeCode(Mapping mapping) throws MappingException {
  org.hibernate.type.Type type = getValue().getType();
  try {
    int sqlTypeCode = type.sqlTypes( mapping )[getTypeIndex()];
    if ( getSqlTypeCode() != null && getSqlTypeCode() != sqlTypeCode ) {
      throw new MappingException( "SQLType code's does not match. mapped as " + sqlTypeCode + " but is " + getSqlTypeCode() );
    }
    return sqlTypeCode;
  }
  catch (Exception e) {
    throw new MappingException(
        "Could not determine type for column " +
            name +
            " of type " +
            type.getClass().getName() +
            ": " +
            e.getClass().getName(),
        e
    );
  }
}

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

final Type type = criteriaQuery.getTypeUsingProjection( criteria, propertyName );
final SessionFactoryImplementor factory = criteriaQuery.getFactory();
final int[] sqlTypes = type.sqlTypes( factory );

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

public String getIdentitySelectString() {
  //TODO: cache this in an instvar
  return getFactory().getDialect().getIdentityColumnSupport()
      .getIdentitySelectString(
          getTableName( 0 ),
          getKeyColumns( 0 )[0],
          getIdentifierType().sqlTypes( getFactory() )[0]
      );
}

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

final int[] sqlTypes = hibernateType.sqlTypes( procedureCall.getSession().getFactory() );

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

case TIMESTAMP: {
  typeToUse = CalendarType.INSTANCE;
  sqlTypesToUse = typeToUse.sqlTypes( procedureCall.getSession().getFactory() );
  break;
  sqlTypesToUse = typeToUse.sqlTypes( procedureCall.getSession().getFactory() );
  break;
  sqlTypesToUse = typeToUse.sqlTypes( procedureCall.getSession().getFactory() );
  break;

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

@Test
@TestForIssue( jiraKey = "HHH-9599")
public void basicTest() {
  StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
  try {
    Metadata metadata = new MetadataSources( ssr ).addAnnotatedClass( TestEntity.class ).buildMetadata();
    ( (MetadataImpl) metadata ).validate();
    final PersistentClass entityBinding = metadata.getEntityBinding( TestEntity.class.getName() );
    if(metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect
        || metadata.getDatabase().getDialect() instanceof DB2Dialect){
      // See issue HHH-10693 for PostgreSQL, HHH-12753 for DB2
      assertEquals(
          Types.VARCHAR,
          entityBinding.getProperty( "name" ).getType().sqlTypes( metadata )[0]
      );
    }else {
      assertEquals(
          Types.NVARCHAR,
          entityBinding.getProperty( "name" ).getType().sqlTypes( metadata )[0]
      );
    }
  }
  finally {
    StandardServiceRegistryBuilder.destroy( ssr );
  }
}

相关文章