當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。