当前位置: 首页>>代码示例>>Java>>正文


Java Type.nullSafeSet方法代码示例

本文整理汇总了Java中org.hibernate.type.Type.nullSafeSet方法的典型用法代码示例。如果您正苦于以下问题:Java Type.nullSafeSet方法的具体用法?Java Type.nullSafeSet怎么用?Java Type.nullSafeSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.type.Type的用法示例。


在下文中一共展示了Type.nullSafeSet方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: exists

import org.hibernate.type.Type; //导入方法依赖的package包/类
private boolean exists(Serializable key, Object indexOrElement, Type indexOrElementType, String sql, SessionImplementor session) {
	try {
		PreparedStatement st = session.getTransactionCoordinator()
				.getJdbcCoordinator()
				.getStatementPreparer()
				.prepareStatement( sql );
		try {
			getKeyType().nullSafeSet( st, key, 1, session );
			indexOrElementType.nullSafeSet( st, indexOrElement, keyColumnNames.length + 1, session );
			ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st );
			try {
				return rs.next();
			}
			finally {
				session.getTransactionCoordinator().getJdbcCoordinator().release( rs, st );
			}
		}
		catch ( TransientObjectException e ) {
			return false;
		}
		finally {
			session.getTransactionCoordinator().getJdbcCoordinator().release( st );
		}
	}
	catch ( SQLException sqle ) {
		throw getSQLExceptionHelper().convert(
				sqle,
				"could not check row existence: " +
						MessageHelper.collectionInfoString( this, key, getFactory() ),
				sqlSelectSizeString
		);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:AbstractCollectionPersister.java

示例2: getIdByUniqueKey

import org.hibernate.type.Type; //导入方法依赖的package包/类
@Override
public Serializable getIdByUniqueKey(Serializable key, String uniquePropertyName, SessionImplementor session) throws HibernateException {
	if ( LOG.isTraceEnabled() ) {
		LOG.tracef(
				"resolving unique key [%s] to identifier for entity [%s]",
				key,
				getEntityName()
		);
	}

	int propertyIndex = getSubclassPropertyIndex( uniquePropertyName );
	if ( propertyIndex < 0 ) {
		throw new HibernateException(
				"Could not determine Type for property [" + uniquePropertyName + "] on entity [" + getEntityName() + "]"
		);
	}
	Type propertyType = getSubclassPropertyType( propertyIndex );

	try {
		PreparedStatement ps = session.getTransactionCoordinator()
				.getJdbcCoordinator()
				.getStatementPreparer()
				.prepareStatement( generateIdByUniqueKeySelectString( uniquePropertyName ) );
		try {
			propertyType.nullSafeSet( ps, key, 1, session );
			ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( ps );
			try {
				//if there is no resulting row, return null
				if ( !rs.next() ) {
					return null;
				}
				return (Serializable) getIdentifierType().nullSafeGet( rs, getIdentifierAliases(), session, null );
			}
			finally {
				session.getTransactionCoordinator().getJdbcCoordinator().release( rs, ps );
			}
		}
		finally {
			session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
		}
	}
	catch ( SQLException e ) {
		throw getFactory().getSQLExceptionHelper().convert(
				e,
				String.format(
						"could not resolve unique property [%s] to identifier for entity [%s]",
						uniquePropertyName,
						getEntityName()
				),
				getSQLSnapshotSelectString()
		);
	}

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:55,代码来源:AbstractEntityPersister.java

示例3: loadEntityIdByNaturalId

import org.hibernate.type.Type; //导入方法依赖的package包/类
@Override
public Serializable loadEntityIdByNaturalId(
		Object[] naturalIdValues,
		LockOptions lockOptions,
		SessionImplementor session) {
	if ( LOG.isTraceEnabled() ) {
		LOG.tracef(
				"Resolving natural-id [%s] to id : %s ",
				naturalIdValues,
				MessageHelper.infoString( this )
		);
	}

	final boolean[] valueNullness = determineValueNullness( naturalIdValues );
	final String sqlEntityIdByNaturalIdString = determinePkByNaturalIdQuery( valueNullness );

	try {
		PreparedStatement ps = session.getTransactionCoordinator()
				.getJdbcCoordinator()
				.getStatementPreparer()
				.prepareStatement( sqlEntityIdByNaturalIdString );
		try {
			int positions = 1;
			int loop = 0;
			for ( int idPosition : getNaturalIdentifierProperties() ) {
				final Object naturalIdValue = naturalIdValues[loop++];
				if ( naturalIdValue != null ) {
					final Type type = getPropertyTypes()[idPosition];
					type.nullSafeSet( ps, naturalIdValue, positions, session );
					positions += type.getColumnSpan( session.getFactory() );
				}
			}
			ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( ps );
			try {
				// if there is no resulting row, return null
				if ( !rs.next() ) {
					return null;
				}

				return (Serializable) getIdentifierType().hydrate( rs, getIdentifierAliases(), session, null );
			}
			finally {
				session.getTransactionCoordinator().getJdbcCoordinator().release( rs, ps );
			}
		}
		finally {
			session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
		}
	}
	catch ( SQLException e ) {
		throw getFactory().getSQLExceptionHelper().convert(
				e,
				String.format(
						"could not resolve natural-id [%s] to id : %s",
						naturalIdValues,
						MessageHelper.infoString( this )
				),
				sqlEntityIdByNaturalIdString
		);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:62,代码来源:AbstractEntityPersister.java

示例4: bind

import org.hibernate.type.Type; //导入方法依赖的package包/类
/**
 * Bind the appropriate value into the given statement at the specified position.
 *
 * @param statement The statement into which the value should be bound.
 * @param qp The defined values for the current query execution.
 * @param session The session against which the current execution is occuring.
 * @param position The position from which to start binding value(s).
 *
 * @return The number of sql bind positions "eaten" by this bind operation.
 */
@Override
public int bind(PreparedStatement statement, QueryParameters qp, SessionImplementor session, int position) throws SQLException {
	Type type = qp.getPositionalParameterTypes()[hqlPosition];
	Object value = qp.getPositionalParameterValues()[hqlPosition];

	type.nullSafeSet( statement, value, position, session );
	return type.getColumnSpan( session.getFactory() );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:PositionalParameterSpecification.java


注:本文中的org.hibernate.type.Type.nullSafeSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。