private void checkInitialized() { if ( value == null ) { throw new IdentifierGenerationException( "integral holder was not initialized" ); } }
public BasicHolder(Class exactType) { this.exactType = exactType; if ( exactType != Long.class && exactType != Integer.class && exactType != Short.class ) { throw new IdentifierGenerationException( "Invalid type for basic integral holder : " + exactType ); } }
private void checkInitialized() { if ( value == Long.MIN_VALUE ) { throw new IdentifierGenerationException( "integral holder was not initialized" ); } }
private void checkInitialized() { if ( value == null ) { throw new IdentifierGenerationException( "integral holder was not initialized" ); } }
public static long extractLong(IntegralDataTypeHolder holder) { if ( holder.getClass() == BasicHolder.class ) { ( (BasicHolder) holder ).checkInitialized(); return ( (BasicHolder) holder ).value; } else if ( holder.getClass() == BigIntegerHolder.class ) { ( (BigIntegerHolder) holder ).checkInitialized(); return ( (BigIntegerHolder) holder ).value.longValue(); } else if ( holder.getClass() == BigDecimalHolder.class ) { ( (BigDecimalHolder) holder ).checkInitialized(); return ( (BigDecimalHolder) holder ).value.longValue(); } throw new IdentifierGenerationException( "Unknown IntegralDataTypeHolder impl [" + holder + "]" ); }
public static BigDecimal extractBigDecimal(IntegralDataTypeHolder holder) { if ( holder.getClass() == BasicHolder.class ) { ( (BasicHolder) holder ).checkInitialized(); return BigDecimal.valueOf( ( (BasicHolder) holder ).value ); } else if ( holder.getClass() == BigIntegerHolder.class ) { ( (BigIntegerHolder) holder ).checkInitialized(); return new BigDecimal( ( (BigIntegerHolder) holder ).value ); } else if ( holder.getClass() == BigDecimalHolder.class ) { ( (BigDecimalHolder) holder ).checkInitialized(); // scale should already be set... return ( (BigDecimalHolder) holder ).value; } throw new IdentifierGenerationException( "Unknown IntegralDataTypeHolder impl [" + holder + "]" ); }
public static BigInteger extractBigInteger(IntegralDataTypeHolder holder) { if ( holder.getClass() == BasicHolder.class ) { ( (BasicHolder) holder ).checkInitialized(); return BigInteger.valueOf( ( (BasicHolder) holder ).value ); } else if ( holder.getClass() == BigIntegerHolder.class ) { ( (BigIntegerHolder) holder ).checkInitialized(); return ( (BigIntegerHolder) holder ).value; } else if ( holder.getClass() == BigDecimalHolder.class ) { ( (BigDecimalHolder) holder ).checkInitialized(); // scale should already be set... return ( (BigDecimalHolder) holder ).value.toBigInteger(); } throw new IdentifierGenerationException( "Unknown IntegralDataTypeHolder impl [" + holder + "]" ); }
/** * Wrap the given value in the given Java numeric class. * * @param value The primitive value to wrap. * @param clazz The Java numeric type in which to wrap the value. * * @return The wrapped type. * * @throws IdentifierGenerationException Indicates an unhandled 'clazz'. * @deprecated Use the {@link #getIntegralDataTypeHolder holders} instead. */ @Deprecated public static Number createNumber(long value, Class clazz) throws IdentifierGenerationException { if ( clazz == Long.class ) { return value; } else if ( clazz == Integer.class ) { return (int) value; } else if ( clazz == Short.class ) { return (short) value; } else { throw new IdentifierGenerationException( "unrecognized id type : " + clazz.getName() ); } }
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() ); } }
public Serializable generate(SharedSessionContractImplementor session, Object obj) throws HibernateException { //TODO: cache the persister, this shows up in yourkit final Serializable id = session.getEntityPersister( entityName, obj ).getIdentifier( obj, session ); if ( id == null ) { throw new IdentifierGenerationException( "ids for this class must be manually assigned before calling save(): " + entityName ); } return id; }
protected Serializable getResult( SharedSessionContractImplementor session, ResultSet rs, Object entity) throws SQLException { if ( !rs.next() ) { throw new IdentifierGenerationException( "the inserted row could not be located by the unique key: " + uniqueKeyPropertyName ); } return (Serializable) idType.nullSafeGet( rs, persister.getRootTableKeyColumnNames(), session, entity ); } }
private static String determineNameOfPropertyToUse(PostInsertIdentityPersister persister, String supplied) { if ( supplied != null ) { return supplied; } int[] naturalIdPropertyIndices = persister.getNaturalIdentifierProperties(); if ( naturalIdPropertyIndices == null ) { throw new IdentifierGenerationException( "no natural-id property defined; need to specify [key] in " + "generator parameters" ); } if ( naturalIdPropertyIndices.length > 1 ) { throw new IdentifierGenerationException( "select generator does not currently support composite " + "natural-id properties; need to specify [key] in generator parameters" ); } if ( persister.getEntityMetamodel().isNaturalIdentifierInsertGenerated() ) { throw new IdentifierGenerationException( "natural-id also defined as insert-generated; need to specify [key] " + "in generator parameters" ); } return persister.getPropertyNames()[naturalIdPropertyIndices[0]]; }
public static IntegralDataTypeHolder getIntegralDataTypeHolder(Class integralType) { if ( integralType == Long.class || integralType == Integer.class || integralType == Short.class ) { return new BasicHolder( integralType ); } else if ( integralType == BigInteger.class ) { return new BigIntegerHolder(); } else if ( integralType == BigDecimal.class ) { return new BigDecimalHolder(); } else { throw new IdentifierGenerationException( "Unknown integral data type for ids : " + integralType.getName() ); } }
throw new IdentifierGenerationException( "unrecognized id type : " + type.getName() + " -> " + clazz.getName() );
Serializable generatedId = persister.getIdentifierGenerator().generate( source, entity ); if ( generatedId == null ) { throw new IdentifierGenerationException( "null id generated for:" + entity.getClass() );
Object associatedObject = persister.getPropertyValue( object, propertyName ); if ( associatedObject == null ) { throw new IdentifierGenerationException( "attempted to assign id from null one-to-one property [" + getRole() + "]" );
private void checkInitialized() { if ( value == null ) { throw new IdentifierGenerationException( "integral holder was not initialized" ); } }
public BasicHolder(Class exactType) { this.exactType = exactType; if ( exactType != Long.class && exactType != Integer.class && exactType != Short.class ) { throw new IdentifierGenerationException( "Invalid type for basic integral holder : " + exactType ); } }
public Serializable generate(SessionImplementor session, Object obj) throws HibernateException { if (obj instanceof PersistentCollection) throw new IdentifierGenerationException( "Illegal use of assigned id generation for a toplevel collection" ); final Serializable id = session.getEntityPersister( entityName, obj ).getIdentifier( obj, session.getEntityMode() ); if (id==null) throw new IdentifierGenerationException( "ids for this class must be manually assigned before calling save(): " + obj.getClass().getName() ); return id; }
public Serializable generate(SessionImplementor session, Object obj) throws HibernateException { final Serializable id = session.getEntityPersister( entityName, obj ) //TODO: cache the persister, this shows up in yourkit .getIdentifier( obj, session.getEntityMode() ); if (id==null) { throw new IdentifierGenerationException( "ids for this class must be manually assigned before calling save(): " + entityName ); } return id; }