| Method from org.hibernate.id.IdentifierGeneratorFactory Detail: |
public static IdentifierGenerator create(String strategy,
Type type,
Properties params,
Dialect dialect) throws MappingException {
try {
Class clazz = getIdentifierGeneratorClass( strategy, dialect );
IdentifierGenerator idgen = ( IdentifierGenerator ) clazz.newInstance();
if ( idgen instanceof Configurable ) {
( ( Configurable ) idgen ).configure( type, params, dialect );
}
return idgen;
}
catch ( Exception e ) {
throw new MappingException(
"could not instantiate id generator [entity-name=" + params.get(
IdentifierGenerator.ENTITY_NAME
) + "]", e
);
}
}
|
public static Number createNumber(long value,
Class clazz) throws IdentifierGenerationException {
if ( clazz == Long.class ) {
return new Long( value );
}
else if ( clazz == Integer.class ) {
return new Integer( ( int ) value );
}
else if ( clazz == Short.class ) {
return new Short( ( short ) value );
}
else {
throw new IdentifierGenerationException( "this id generator generates long, integer, short" );
}
}
|
public static Serializable get(ResultSet rs,
Type type) throws SQLException, IdentifierGenerationException {
Class clazz = type.getReturnedClass();
if ( clazz == Long.class ) {
return new Long( rs.getLong( 1 ) );
}
else if ( clazz == Integer.class ) {
return new Integer( rs.getInt( 1 ) );
}
else if ( clazz == Short.class ) {
return new Short( rs.getShort( 1 ) );
}
else if ( clazz == String.class ) {
return rs.getString( 1 );
}
else {
throw new IdentifierGenerationException( "this id generator generates long, integer, short or string" );
}
}
|
public static Serializable getGeneratedIdentity(ResultSet rs,
Type type) throws SQLException, HibernateException {
if ( !rs.next() ) {
throw new HibernateException( "The database returned no natively generated identity value" );
}
final Serializable id = IdentifierGeneratorFactory.get( rs, type );
if ( log.isDebugEnabled() ) {
log.debug( "Natively generated identity: " + id );
}
return id;
}
Get the generated identifier when using identity columns |
public static Class getIdentifierGeneratorClass(String strategy,
Dialect dialect) {
Class clazz = ( Class ) GENERATORS.get( strategy );
if ( "native".equals( strategy ) ) {
clazz = dialect.getNativeIdentifierGeneratorClass();
}
try {
if ( clazz == null ) {
clazz = ReflectHelper.classForName( strategy );
}
}
catch ( ClassNotFoundException e ) {
throw new MappingException( "could not interpret id generator strategy: " + strategy );
}
return clazz;
}
|