public IdentitySchema(Configuration configuration) { this.configuration = configuration; this.properties = configuration.getProperties(); this.dialect = Dialect.getDialect(properties); try { // get the mapping field via reflection :-( Field mappingField = Configuration.class.getDeclaredField("mapping"); mappingField.setAccessible(true); this.mapping = (Mapping) mappingField.get(configuration); } catch (Exception e) { throw new RuntimeException("couldn't get the hibernate mapping", e); } }
public static void toJSON(ConfigurationAdmin admin, Writer osw, String filter) throws Exception { Configuration[] list = admin.listConfigurations(filter); Encoder encoder = codec.enc().to(osw); Protocol p = new Protocol(); p.version = 1; p.date = new Date(); p.size = list.length; encoder.put(p).append('\n'); if (list != null) for (Configuration c : list) { Dictionary<String, Object> d = c.getProperties(); Export export = new Export(); export.values = new HashMap<String, Object>(); export.factoryPid = c.getFactoryPid(); export.pid = c.getPid(); for (Enumeration<String> e = d.keys(); e.hasMoreElements(); ) { String k = e.nextElement(); Object v = d.get(k); if (!(v instanceof String)) { if (export.types == null) export.types = new HashMap<String, Type>(); Type type = new Type(); Class<?> clazz = v.getClass(); if (v instanceof Collection) { Collection<?> coll = (Collection<?>) v; clazz = String.class; if (coll.size() > 0) type.vectorOf = shortName(coll.iterator().next().getClass()); else type.vectorOf = shortName(String.class); } else if (v.getClass().isArray()) { type.arrayOf = shortName(clazz.getComponentType()); } else type.scalar = shortName(v.getClass()); export.types.put(k, type); } export.values.put(k, v); } encoder.mark().put(export); // encoder.put(encoder.digest()); encoder.append('\n'); } osw.flush(); }
public static ServiceRegistry getDefaultServiceRegistry(Configuration configuration) { ServiceRegistry registry = cache.get(configuration); if (registry == null) { Properties properties = new Properties(); properties.putAll(configuration.getProperties()); Environment.verifyProperties(properties); ConfigurationHelper.resolvePlaceHolders(properties); registry = new org.hibernate.service.ServiceRegistryBuilder(properties).buildServiceRegistry(); cache.put(configuration, registry); } return registry; }
static { try { // Create the SessionFactory from hibernate.cfg.xml Configuration configuration = new Configuration(); configuration.configure(); serviceRegistry = new ServiceRegistryBuilder() .applySettings(configuration.getProperties()) .buildServiceRegistry(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); } catch (Throwable ex) { System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } }
/** Writes the given configuration to the given file. */ public static void write(Configuration config, String file) throws IOException { FileOutputStream fos = new FileOutputStream(file); XMLPrettyPrinter pp = new XMLPrettyPrinter(fos); pp.startDocument(); pp.startElement("duke", null); // FIXME: here we should write the objects, but that's not // possible with the current API. we don't need that for the // genetic algorithm at the moment, but it would be useful. pp.startElement("schema", null); writeElement(pp, "threshold", "" + config.getThreshold()); if (config.getMaybeThreshold() != 0.0) writeElement(pp, "maybe-threshold", "" + config.getMaybeThreshold()); for (Property p : config.getProperties()) writeProperty(pp, p); pp.endElement("schema"); String dbclass = config.getDatabase(false).getClass().getName(); AttributeListImpl atts = new AttributeListImpl(); atts.addAttribute("class", "CDATA", dbclass); pp.startElement("database", atts); pp.endElement("database"); if (config.isDeduplicationMode()) for (DataSource src : config.getDataSources()) writeDataSource(pp, src); else { pp.startElement("group", null); for (DataSource src : config.getDataSources(1)) writeDataSource(pp, src); pp.endElement("group"); pp.startElement("group", null); for (DataSource src : config.getDataSources(2)) writeDataSource(pp, src); pp.endElement("group"); } pp.endElement("duke"); pp.endDocument(); fos.close(); }
public static Configuration clone(final Configuration configuration) { return fromProperties(configuration.getProperties()); }
Configuration(final Configuration configuration) { this(configuration.getProperties()); }