@Override public IdentifierGenerator createIdentifierGenerator(String strategy, Type type, Properties config) { try { Class clazz = getIdentifierGeneratorClass( strategy ); IdentifierGenerator identifierGenerator = ( IdentifierGenerator ) clazz.newInstance(); if ( identifierGenerator instanceof Configurable ) { ( ( Configurable ) identifierGenerator ).configure( type, config, serviceRegistry ); } return identifierGenerator; } catch ( Exception e ) { final String entityName = config.getProperty( IdentifierGenerator.ENTITY_NAME ); throw new MappingException( String.format( "Could not instantiate id generator [entity-name=%s]", entityName ), e ); } }
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", e); } }
@Override public IdentifierGenerator createIdentifierGenerator(String strategy, Type type, Properties config) { try { Class clazz = getIdentifierGeneratorClass( strategy ); IdentifierGenerator identifierGenerator = ( IdentifierGenerator ) clazz.newInstance(); if ( identifierGenerator instanceof Configurable ) { ( ( Configurable ) identifierGenerator ).configure( type, config, dialect ); } return identifierGenerator; } catch ( Exception e ) { final String entityName = config.getProperty( IdentifierGenerator.ENTITY_NAME ); throw new MappingException( String.format( "Could not instantiate id generator [entity-name=%s]", entityName ), e ); } }
public static void main( String[] args ) throws Exception { Properties props = new Properties(); props.setProperty("separator", "/"); IdentifierGenerator gen = new UUIDHexGenerator(); ( (Configurable) gen ).configure(Hibernate.STRING, props, null); IdentifierGenerator gen2 = new UUIDHexGenerator(); ( (Configurable) gen2 ).configure(Hibernate.STRING, props, null); for ( int i=0; i<10; i++) { String id = (String) gen.generate(null, null); System.out.println(id); String id2 = (String) gen2.generate(null, null); System.out.println(id2); } }
@Override public IdentifierGenerator createIdentifierGenerator(String strategy, Type type, Properties config) { try { Class clazz = getIdentifierGeneratorClass( strategy ); IdentifierGenerator identifierGenerator = ( IdentifierGenerator ) clazz.newInstance(); if ( identifierGenerator instanceof Configurable ) { ( ( Configurable ) identifierGenerator ).configure( type, config, dialect ); } return identifierGenerator; } catch ( Exception e ) { final String entityName = config.getProperty( IdentifierGenerator.ENTITY_NAME ); throw new MappingException( String.format( "Could not instantiate id generator [entity-name=%s]", entityName ), e ); } }
public static void main( String[] args ) throws Exception { Properties props = new Properties(); props.setProperty("separator", "/"); IdentifierGenerator gen = new UUIDHexGenerator(); ( (Configurable) gen ).configure(Hibernate.STRING, props, null); IdentifierGenerator gen2 = new UUIDHexGenerator(); ( (Configurable) gen2 ).configure(Hibernate.STRING, props, null); for ( int i=0; i<10; i++) { String id = (String) gen.generate(null, null); System.out.println(id); String id2 = (String) gen2.generate(null, null); System.out.println(id2); } }
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", e); } }
@Override public IdentifierGenerator createIdentifierGenerator(String strategy, JavaTypeDescriptor type, Properties config) { try { Class clazz = getIdentifierGeneratorClass( strategy ); IdentifierGenerator identifierGenerator = ( IdentifierGenerator ) clazz.newInstance(); if ( identifierGenerator instanceof Configurable ) { ( ( Configurable ) identifierGenerator ).configure( type, config, serviceRegistry ); } return identifierGenerator; } catch ( Exception e ) { final String entityName = config.getProperty( IdentifierGenerator.ENTITY_NAME ); throw new MappingException( String.format( "Could not instantiate id generator [entity-name=%s]", entityName ), e ); } }
public void configure(Type type, Properties params, Dialect dialect) throws MappingException { Class generatorClass = null; if (dialect.supportsSequences()) { __log.debug("Using SequenceHiLoGenerator"); generatorClass = SequenceHiLoGenerator.class; } else { generatorClass = TableHiLoGenerator.class; __log.debug("Using native dialect generator " + generatorClass); } IdentifierGenerator g = null; try { g = (IdentifierGenerator) generatorClass.newInstance(); } catch (Exception e) { throw new MappingException("", e); } if (g instanceof Configurable) ((Configurable) g).configure(type, params, dialect); this._proxy = g; } }
@Override public void configure(final Type type, final Properties params, final Dialect d) throws MappingException { if (!(generator instanceof org.hibernate.id.Configurable)) { throw new NotImplementedException("org.hibernate.id.Configurable not implemented on " + generator.getClass().getName()); } try { ((org.hibernate.id.Configurable) generator).configure( TypeV5Adapter.adapt(sessionFactory, type), params, sessionFactory.getServiceRegistry()); } catch (final PersistenceException ex) { throw (MappingException) HibernateExceptionAdapter.adapt(ex); } }
public void configure(Type type, Properties params, Dialect d) throws MappingException { if (_log.isDebugEnabled()) _log.debug("Configuring ComboGenerator for dialect [" + d + "]"); HQDialect hqDialect = (HQDialect)d; if (hqDialect.usesSequenceGenerator()) { _delegate = new SequenceGenerator(); } else { _delegate = new HQMultipleHiLoPerTableGenerator(); // Table containing the sequences params.put(HQMultipleHiLoPerTableGenerator.ID_TABLE, "HQ_SEQUENCE"); // Name of the column containing the 'sequence' name params.put(HQMultipleHiLoPerTableGenerator.PK_COLUMN_NAME, "seq_name"); // Name of the column containing the value for the sequence params.put(HQMultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME, "seq_val"); // How many IDs do we increment and cache? params.put(HQMultipleHiLoPerTableGenerator.MAX_LO, "100"); // What is the initial 'hi' value? params.put(HQMultipleHiLoPerTableGenerator.INITIAL_HI, "100"); } ((Configurable)_delegate).configure(type, params, d); }