List of usage examples for org.hibernate.id PersistentIdentifierGenerator generatorKey
Object generatorKey();
From source file:org.beangle.commons.orm.hibernate.internal.SchemaValidator.java
License:Open Source License
public String validateSchema(Configuration config, Dialect dialect, DatabaseMetadata databaseMetadata) { String defaultCatalog = sessionFactoryBean.getHibernateProperties() .getProperty(Environment.DEFAULT_CATALOG); String defaultSchema = sessionFactoryBean.getHibernateProperties().getProperty(Environment.DEFAULT_SCHEMA); Mapping mapping = config.buildMapping(); Iterator<?> iter = config.getTableMappings(); while (iter.hasNext()) { Table table = (Table) iter.next(); if (table.isPhysicalTable()) { TableMetadata tableInfo = databaseMetadata.getTableMetadata(table.getName(), (table.getSchema() == null) ? defaultSchema : table.getSchema(), (table.getCatalog() == null) ? defaultCatalog : table.getCatalog(), table.isQuoted()); if (tableInfo == null) { reporter.append("Missing table: " + table.getName() + "\n"); } else { validateColumns(table, dialect, mapping, tableInfo); }//from w w w. j av a2 s . c o m } } iter = iterateGenerators(config, dialect); while (iter.hasNext()) { PersistentIdentifierGenerator generator = (PersistentIdentifierGenerator) iter.next(); Object key = generator.generatorKey(); if (!databaseMetadata.isSequence(key) && !databaseMetadata.isTable(key)) { throw new HibernateException("Missing sequence or table: " + key); } } return null; }
From source file:org.n52.sos.ds.datasource.CustomConfiguration.java
License:Open Source License
/** * Copied from//from w w w . ja v a 2s.co m * {@link org.hibernate.cfg.Configuration#iterateGenerators(Dialect)}. */ private Iterator<PersistentIdentifierGenerator> iterateGenerators(final Dialect d, final String c, final String s) throws MappingException { final TreeMap<Object, PersistentIdentifierGenerator> generators = new TreeMap<Object, PersistentIdentifierGenerator>(); for (final PersistentClass pc : classes.values()) { if (!pc.isInherited()) { final IdentifierGenerator ig = pc.getIdentifier() .createIdentifierGenerator(getIdentifierGeneratorFactory(), d, c, s, (RootClass) pc); if (ig instanceof PersistentIdentifierGenerator) { final PersistentIdentifierGenerator pig = (PersistentIdentifierGenerator) ig; generators.put(pig.generatorKey(), pig); } else if (ig instanceof IdentifierGeneratorAggregator) { ((IdentifierGeneratorAggregator) ig).registerPersistentGenerators(generators); } } } for (final Collection collection : collections.values()) { if (collection.isIdentified()) { final IdentifierGenerator ig = ((IdentifierCollection) collection).getIdentifier() .createIdentifierGenerator(getIdentifierGeneratorFactory(), d, c, s, null); if (ig instanceof PersistentIdentifierGenerator) { final PersistentIdentifierGenerator pig = (PersistentIdentifierGenerator) ig; generators.put(pig.generatorKey(), pig); } } } return generators.values().iterator(); }