Java Code Examples for org.hibernate.type.Type#getName()

The following examples show how to use org.hibernate.type.Type#getName() . 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: IdentifierGeneratorHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static Serializable extractIdentifier(ResultSet rs, String identifier, Type type, Class clazz)
		throws SQLException {
	if ( clazz == Long.class ) {
		return rs.getLong( identifier );
	}
	else if ( clazz == Integer.class ) {
		return rs.getInt( identifier );
	}
	else if ( clazz == Short.class ) {
		return rs.getShort( identifier );
	}
	else if ( clazz == String.class ) {
		return rs.getString( identifier );
	}
	else if ( clazz == BigInteger.class ) {
		return rs.getBigDecimal( identifier ).setScale( 0, BigDecimal.ROUND_UNNECESSARY ).toBigInteger();
	}
	else if ( clazz == BigDecimal.class ) {
		return rs.getBigDecimal( identifier ).setScale( 0, BigDecimal.ROUND_UNNECESSARY );
	}
	else {
		throw new IdentifierGenerationException(
				"unrecognized id type : " + type.getName() + " -> " + clazz.getName()
		);
	}
}
 
Example 2
Source File: BinaryLogicOperatorNode.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected final void mutateRowValueConstructorSyntaxesIfNecessary(Type lhsType, Type rhsType) {
	// TODO : this really needs to be delayed until after we definitively know all node types
	// where this is currently a problem is parameters for which where we cannot unequivocally
	// resolve an expected type
	SessionFactoryImplementor sessionFactory = getSessionFactoryHelper().getFactory();
	if ( lhsType != null && rhsType != null ) {
		int lhsColumnSpan = getColumnSpan( lhsType, sessionFactory );
		if ( lhsColumnSpan != getColumnSpan( rhsType, sessionFactory ) ) {
			throw new TypeMismatchException(
					"left and right hand sides of a binary logic operator were incompatibile [" +
							lhsType.getName() + " : " + rhsType.getName() + "]"
			);
		}
		if ( lhsColumnSpan > 1 ) {
			// for dialects which are known to not support ANSI-SQL row-value-constructor syntax,
			// we should mutate the tree.
			if ( !sessionFactory.getDialect().supportsRowValueConstructorSyntax() ) {
				mutateRowValueConstructorSyntax( lhsColumnSpan );
			}
		}
	}
}
 
Example 3
Source File: BinaryLogicOperatorNode.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected final void mutateRowValueConstructorSyntaxesIfNecessary(Type lhsType, Type rhsType) {
	// TODO : this really needs to be delayed unitl after we definitively know all node types
	// where this is currently a problem is parameters for which where we cannot unequivocally
	// resolve an expected type
	SessionFactoryImplementor sessionFactory = getSessionFactoryHelper().getFactory();
	if ( lhsType != null && rhsType != null ) {
		int lhsColumnSpan = lhsType.getColumnSpan( sessionFactory );
		if ( lhsColumnSpan != rhsType.getColumnSpan( sessionFactory ) ) {
			throw new TypeMismatchException(
					"left and right hand sides of a binary logic operator were incompatibile [" +
					lhsType.getName() + " : "+ rhsType.getName() + "]"
			);
		}
		if ( lhsColumnSpan > 1 ) {
			// for dialects which are known to not support ANSI-SQL row-value-constructor syntax,
			// we should mutate the tree.
			if ( !sessionFactory.getDialect().supportsRowValueConstructorSyntax() ) {
				mutateRowValueConstructorSyntax( lhsColumnSpan );
			}
		}
	}
}
 
Example 4
Source File: HibernateMetadataExtractor.java    From mPaaS with Apache License 2.0 5 votes vote down vote up
/**
 * 转换HBM的类型
 */
private String formatHbmType(Type type) {
    String typeName = type.getName();
    if (typeName.indexOf(DOT) > -1) {
        return typeName;
    }
    String metaType = HBMTYPES.get(typeName);
    if (metaType != null) {
        return metaType;
    }
    return StringHelper.join(Character.toUpperCase(typeName.charAt(0)),
            typeName.substring(1));
}
 
Example 5
Source File: CriteriaQueryRenderingContext.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String getCastType(Class javaType) {
	Type hibernateType = typeResolver.heuristicType( javaType.getName() );
	if ( hibernateType == null ) {
		throw new IllegalArgumentException(
				"Could not convert java type [" + javaType.getName() + "] to Hibernate type"
		);
	}
	return hibernateType.getName();
}
 
Example 6
Source File: AbstractScrollableResults.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private Object throwInvalidColumnTypeException(
		int i,
		Type type,
		Type returnType) throws HibernateException {
	throw new HibernateException(
			"incompatible column types: " +
					type.getName() +
					", " +
					returnType.getName()
	);
}
 
Example 7
Source File: AbstractScrollableResults.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Object throwInvalidColumnTypeException(
        int i,
        Type type,
        Type returnType) throws HibernateException {
	throw new HibernateException( 
			"incompatible column types: " + 
			type.getName() + 
			", " + 
			returnType.getName() 
	);
}
 
Example 8
Source File: IgnitePropertyHelper.java    From hibernate-ogm-ignite with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
	 * Returns the {@link PropertyIdentifier} for the given property path.
	 *
	 * In passing, it creates all the necessary aliases for embedded/associations.
	 *
	 * @param path the path to the property
	 * @param targetEntityType the type of the entity
	 * @return the {@link PropertyIdentifier}
	 */
	PropertyIdentifier getPropertyIdentifier(PropertyPath path, String targetEntityType) {
		// we analyze the property path to find all the associations/embedded
		// which are in the way and create proper aliases for them

		List<String> propertyPath = path.getNodeNamesWithoutAlias();
		String entityAlias;
		boolean isLastElementAssociation = true;
		if ( path.getFirstNode().isAlias() ) {
			entityAlias = path.getFirstNode().getName();
		}
		else {
			entityAlias = findAliasForType( targetEntityType );
		}
		String propertyEntityType = entityNameByAlias.get( entityAlias );
		if ( propertyEntityType == null ) {
			propertyEntityType = targetEntityType;
		}

		String propertyAlias = entityAlias;
		String propertyName;

		List<String> currentPropertyPath = new ArrayList<>();
		List<String> lastAssociationPath = new ArrayList<>();

		OgmEntityPersister currentPersister = getPersister( propertyEntityType );
		OgmEntityPersister predPersister = currentPersister;
		String predJoinAlias = entityAlias;

		for ( String property : propertyPath ) {
			currentPropertyPath.add( property );
			Type currentPropertyType = getPropertyType( propertyEntityType, Collections.singletonList( property ) );

			if ( currentPropertyType.isAssociationType() ) {
				propertyEntityType = currentPropertyType.getName();
				currentPersister = getPersister( propertyEntityType );
				AssociationType associationPropertyType = (AssociationType) currentPropertyType;
				Joinable associatedJoinable = associationPropertyType.getAssociatedJoinable( getSessionFactory() );
				if ( associatedJoinable.isCollection()
					&& ( (OgmCollectionPersister) associatedJoinable ).getType().isComponentType() ) {
					// we have a collection of embedded
					throw new NotYetImplementedException( "Query with collection of embeddables" );
//					propertyAlias = aliasResolver.createAliasForEmbedded( entityAlias, currentPropertyPath, optionalMatch );
				}
				else {
					// last in path? - no need for join
					if ( currentPropertyPath.size() == propertyPath.size() ) {
						propertyName = getColumnName( predPersister.getEntityType().getName(),
							Collections.singletonList( property ) );
						return new PropertyIdentifier( predJoinAlias, propertyName );
					}
					// else, we register an implicit join
					lastAssociationPath.add( property );
					throw new NotYetImplementedException( "Query on associated property" );
					// predPersister = currentPersister;
					// isLastElementAssociation = true;
				}
			}
			else if ( currentPropertyType.isComponentType()
				&& !isIdProperty( currentPersister, propertyPath.subList( lastAssociationPath.size(), propertyPath.size() ) ) ) {
				// we are in the embedded case and the embedded is not the id of the entity (the id is stored as normal
				// properties)
				String embeddedProperty = String.join( ".", propertyPath.subList( lastAssociationPath.size(), propertyPath.size() ) );
				String[] columns = currentPersister.getPropertyColumnNames( embeddedProperty );
				if ( columns.length > 1 ) {
					throw new NotYetImplementedException( "Query with composite-ID association" );
				}
				return new PropertyIdentifier( propertyAlias, columns[0] );
			}
			else {
				isLastElementAssociation = false;
			}
		}

		if ( isLastElementAssociation ) {
			// even the last element is an association, we need to find a suitable identifier property
			propertyName = getPersister( propertyEntityType ).getIdentifierPropertyName();
		}
		else {
			// the last element is a property so we can build the rest with this property
			propertyName = getColumnName( propertyEntityType, propertyPath.subList( lastAssociationPath.size(), propertyPath.size() ) );
		}
		return new PropertyIdentifier( predJoinAlias, propertyName );
	}