/** * The main method. * * @param args * the arguments * @throws Exception * the exception */ public static void main(String[] args) throws Exception { Properties props = new Properties(); props.setProperty("separator", ""); IdentifierGenerator gen = new UIDGenerator(); ((Configurable) gen).configure(Hibernate.STRING, props, null); IdentifierGenerator gen2 = new UIDGenerator(); ((Configurable) gen2).configure(Hibernate.STRING, props, null); for (int i = 0; i < 10; i++) { String id = (String) gen.generate(null, gen); System.out.println(id); String id2 = (String) gen2.generate(null, gen2); System.out.println(id2); } }
public IdentifierGenerator createIdentifierGenerator(String strategy, Type type, Properties config) { try { Class clazz = getIdentifierGeneratorClass( strategy ); CustomGenerator identifierGenerator = ( CustomGenerator ) 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 ); } }
@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 String generateUniqueContentFolderID() { IdentifierGenerator uuidGen = new UUIDGenerator(); ((Configurable) uuidGen).configure(StringType.INSTANCE, new Properties(), null); // lowercase to resolve OS issues return ((String) uuidGen.generate(null, null)).toLowerCase(); }
/** * Generates the unique key used for the forgot password request * * @return a unique key * @throws FileUtilException * @throws IOException */ public static String generateUniqueKey() { Properties props = new Properties(); IdentifierGenerator uuidGen = new UUIDGenerator(); ((Configurable) uuidGen).configure(StringType.INSTANCE, props, null); return ((String) uuidGen.generate(null, null)).toLowerCase(); }
public void configure(Type type, Properties params, Dialect d) throws MappingException { if (getGenerator() instanceof Configurable) { if (params.getProperty("schema") == null && sDefaultSchema != null) params.setProperty("schema", sDefaultSchema); if (params.get("identifier_normalizer") == null && sNormalizer != null) params.put("identifier_normalizer", sNormalizer); ((Configurable)getGenerator()).configure(type, params, d); } }