List of usage examples for org.hibernate.cfg Configuration addFile
public Configuration addFile(File xmlFile) throws MappingException
From source file:com.mg.framework.service.HibernateListenerInjectorImpl.java
License:Open Source License
public void injectListeners(ObjectName objectName, Configuration configuration) throws DeploymentException { configuration.setListener("pre-insert", new PreInsertEventListener() { public boolean onPreInsert(PreInsertEvent event) { Object entity = event.getEntity(); if (!(entity instanceof PersistentObject)) return false; setGlobalAttributes((PersistentObject) entity, event.getState(), event.getPersister().getPropertyNames()); EntityInterceptorManagerLocator.locate().invokeOnPrePersistInterceptor((PersistentObject) entity); setUpdatedAttributes((PersistentObject) entity, event.getState(), event.getPersister()); return false; }//from w ww. j a va 2 s. com }); configuration.setListener("post-insert", new PostInsertEventListener() { public void onPostInsert(PostInsertEvent event) { Object entity = event.getEntity(); if (!(entity instanceof PersistentObject)) return; EntityInterceptorManagerLocator.locate().invokeOnPostPersistInterceptor((PersistentObject) entity); } }); configuration.setListener("post-commit-insert", new PostInsertEventListener() { public void onPostInsert(PostInsertEvent event) { DatabaseAuditServiceLocator.locate().auditCreate(event); Object entity = event.getEntity(); if (!(entity instanceof PersistentObject)) return; EntityInterceptorManagerLocator.locate() .invokeOnPostCommitPersistInterceptor((PersistentObject) entity); } }); configuration.setListener("pre-delete", new PreDeleteEventListener() { public boolean onPreDelete(PreDeleteEvent event) { Object entity = event.getEntity(); if (!(entity instanceof PersistentObject)) return false; EntityInterceptorManagerLocator.locate().invokeOnPreRemoveInterceptor((PersistentObject) entity); return false; } }); configuration.setListener("post-delete", new PostDeleteEventListener() { public void onPostDelete(PostDeleteEvent event) { Object entity = event.getEntity(); if (!(entity instanceof PersistentObject)) return; EntityInterceptorManagerLocator.locate().invokeOnPostRemoveInterceptor((PersistentObject) entity); } }); configuration.setListener("post-commit-delete", new PostDeleteEventListener() { public void onPostDelete(PostDeleteEvent event) { DatabaseAuditServiceLocator.locate().auditRemove(event); Object entity = event.getEntity(); if (!(entity instanceof PersistentObject)) return; EntityInterceptorManagerLocator.locate() .invokeOnPostCommitRemoveInterceptor((PersistentObject) entity); } }); configuration.setListener("pre-update", new PreUpdateEventListener() { public boolean onPreUpdate(PreUpdateEvent event) { Object entity = event.getEntity(); if (!(entity instanceof PersistentObject)) return false; setGlobalAttributes((PersistentObject) entity, event.getState(), event.getPersister().getPropertyNames()); EntityInterceptorManagerLocator.locate().invokeOnPreUpdateInterceptor((PersistentObject) entity, createAttributesMap(event.getPersister().getPropertyNames(), event.getOldState())); setUpdatedAttributes((PersistentObject) entity, event.getState(), event.getPersister()); return false; } }); configuration.setListener("post-update", new PostUpdateEventListener() { public void onPostUpdate(PostUpdateEvent event) { Object entity = event.getEntity(); if (!(entity instanceof PersistentObject)) return; EntityInterceptorManagerLocator.locate().invokeOnPostUpdateInterceptor((PersistentObject) entity, createAttributesMap(event.getPersister().getPropertyNames(), event.getOldState())); setUpdatedAttributes((PersistentObject) entity, event.getState(), event.getPersister()); } }); configuration.setListener("post-commit-update", new PostUpdateEventListener() { public void onPostUpdate(PostUpdateEvent event) { DatabaseAuditServiceLocator.locate().auditModify(event); Object entity = event.getEntity(); if (!(entity instanceof PersistentObject)) return; EntityInterceptorManagerLocator.locate().invokeOnPostCommitUpdateInterceptor( (PersistentObject) entity, createAttributesMap(event.getPersister().getPropertyNames(), event.getOldState())); } }); configuration.setListener("post-load", new PostLoadEventListener() { public void onPostLoad(PostLoadEvent event) { Object entity = event.getEntity(); if (!(entity instanceof PersistentObject)) return; EntityInterceptorManagerLocator.locate().invokeOnPostLoadInterceptor((PersistentObject) entity); } }); //load workaround for http://issues.m-g.ru/bugzilla/show_bug.cgi?id=4413 try { File workaround = new File(ServerConfigLocator.locate().getServerHomeDir().getAbsolutePath() .concat("/mg-custom/patches/workaround_MBSA-4413.hbm.xml")); configuration.addFile(workaround); logger.info("Install patch MBSA-4413"); } catch (Exception e) { logger.error("Install patch MBSA-4413 failed", e); } //load workaround for http://issues.m-g.ru/bugzilla/show_bug.cgi?id=4866 try { HibernateMBean service = (HibernateMBean) MBeanProxyExt.create(HibernateMBean.class, objectName); String dialect = service.getDialect(); Class<?> dialectClass = ServerUtils.loadClass(dialect); //? ?? ? Firebird Interbase if (org.hibernate.dialect.InterbaseDialect.class.isAssignableFrom(dialectClass)) { File workaround = new File(ServerConfigLocator.locate().getServerHomeDir().getAbsolutePath() .concat("/mg-custom/patches/workaround_MBSA-4866.hbm.xml")); configuration.addFile(workaround); logger.info("Install patch MBSA-4866"); } } catch (Exception e) { logger.error("Install patch MBSA-4866 failed", e); } //setup global tenant filter Map<String, Object> paramTypes = new HashMap<String, Object>(); paramTypes.put("sysClientId", new IntegerType()); configuration.addFilterDefinition( new FilterDefinition("__mg_tenantFilter", "CLIENT_ID = :sysClientId", paramTypes)); }
From source file:com.mg.jet.birt.report.data.oda.ejbql.HibernateUtil.java
License:Open Source License
public static synchronized void buildConfig(String hibfile, String mapdir, Configuration cfg) throws HibernateException, IOException, Exception { Bundle hibbundle = Platform.getBundle("com.mg.jet.birt.report.data.oda.ejbql"); //?? ?//from w w w. j av a 2 s .c om File cfgDir = new File(mapdir); if (cfgDir != null) { if (cfgDir.isDirectory()) cfg.addDirectory(cfgDir); else if (cfgDir.length() > 0) cfg.addJar(cfgDir); } URL hibfiles = FileLocator.find(hibbundle, new Path(CommonConstant.HIBERNATE_CLASSES), null); URL hibURL = FileLocator.resolve(hibfiles); File hibDirectory = new File(hibURL.getPath()); // ? ? , ? ?? ? File[] files = hibDirectory.listFiles(); if (files != null) for (int i = 0; i < files.length; i++) { if (!files[i].isDirectory() && files[i].getName().startsWith("mg.") && files[i].getName().endsWith(".hbm.xml")) { cfg.addFile(files[i]); } } // ? MBSA // loadMBSADatawarehouse(cfg); File mbsaData = new File(hibURL.getPath().concat(CommonConstant.DATAWAREHOUSE)); if (mbsaData.isFile()) cfg.addJar(mbsaData); cfg.addDirectory(hibDirectory); File cfgFile = new File(hibfile); if (cfgFile != null && cfgFile.length() > 0) { cfg.configure(cfgFile); } else { File configFile = new File(hibURL.getPath() + CommonConstant.DATAWAREHOUSE_CFG_FILE); cfg.configure(configFile); } return; }
From source file:com.mysema.query.jpa.codegen.HibernateDomainExporterTest.java
License:Apache License
@Test public void Execute_MyEntity() throws IOException { FileUtils.delete(new File("target/gen6")); File myEntity = new File("src/test/resources/entity.hbm.xml"); Configuration config = new Configuration(); config.addFile(myEntity); HibernateDomainExporter exporter = new HibernateDomainExporter("Q", new File("target/gen6"), config); exporter.execute();//w ww. j a v a2s . co m File targetFile = new File("target/gen6/com/mysema/query/jpa/codegen/QMyEntity.java"); assertContains(targetFile, "StringPath pk1", "StringPath pk2", "StringPath prop1"); }
From source file:com.mysema.query.jpa.codegen.HibernateDomainExporterTest.java
License:Apache License
@Test public void Execute_Contact() throws IOException { FileUtils.delete(new File("target/gen1")); File contact = new File("src/test/resources/contact.hbm.xml"); Configuration config = new Configuration(); config.addFile(contact); HibernateDomainExporter exporter = new HibernateDomainExporter("Q", new File("target/gen1"), config); exporter.execute();//from w w w .ja va 2s. co m File targetFile = new File("target/gen1/com/mysema/query/jpa/domain2/QContact.java"); assertContains(targetFile, "StringPath email", "StringPath firstName", "NumberPath<Long> id", "StringPath lastName"); }
From source file:com.mysema.query.jpa.codegen.HibernateDomainExporterTest.java
License:Apache License
@Test public void Execute_Contact_with_Suffix() throws IOException { FileUtils.delete(new File("target/gen1")); File contact = new File("src/test/resources/contact.hbm.xml"); Configuration config = new Configuration(); config.addFile(contact); HibernateDomainExporter exporter = new HibernateDomainExporter("", "Type", new File("target/gen1"), config); exporter.execute();/*from w ww.j a va2 s . c om*/ File targetFile = new File("target/gen1/com/mysema/query/jpa/domain2/ContactType.java"); assertContains(targetFile, "StringPath email", "StringPath firstName", "NumberPath<Long> id", "StringPath lastName"); }
From source file:com.mysema.query.jpa.codegen.HibernateDomainExporterTest.java
License:Apache License
@Test public void Execute_Contact2() throws IOException { FileUtils.delete(new File("target/gen2")); File contact = new File("src/test/resources/contact2.hbm.xml"); Configuration config = new Configuration(); config.addFile(contact); HibernateDomainExporter exporter = new HibernateDomainExporter("Q", new File("target/gen2"), config); exporter.execute();/*www. ja v a2 s. c o m*/ File targetFile = new File("target/gen2/com/mysema/query/jpa/domain2/QContact.java"); assertContains(targetFile, "StringPath email", "StringPath firstName", "NumberPath<Long> id", "StringPath lastName"); }
From source file:com.mysema.query.jpa.codegen.HibernateDomainExporterTest.java
License:Apache License
@Test public void Execute_Store() throws IOException { FileUtils.delete(new File("target/gen5")); File contact = new File("src/test/resources/store.hbm.xml"); Configuration config = new Configuration(); config.addFile(contact); HibernateDomainExporter exporter = new HibernateDomainExporter("Q", new File("target/gen5"), config); exporter.execute();/*from w ww . j av a 2 s . c om*/ File targetFile = new File("target/gen5/com/mysema/query/jpa/domain3/QStore.java"); assertContains(targetFile, "StringPath code", "StringPath address"); targetFile = new File("target/gen5/com/mysema/query/jpa/domain3/QHardwareStore.java"); assertContains(targetFile, "StringPath code = _super.code;", "StringPath address"); }
From source file:com.mysema.query.jpa.codegen.JPADomainExporterTest.java
License:Apache License
@Test @Ignore // FIXME/*w w w .j a v a 2s . c o m*/ public void Execute_MyEntity() throws IOException { FileUtils.delete(new File("target/jpagen6")); File myEntity = new File("src/test/resources/entity.hbm.xml"); Configuration config = new Configuration(); config.addFile(myEntity); JPADomainExporter exporter = new JPADomainExporter("Q", new File("target/jpagen6"), convert(config)); exporter.execute(); File targetFile = new File("target/jpagen6/com/mysema/query/jpa/codegen/QMyEntity.java"); assertContains(targetFile, "StringPath pk1", "StringPath pk2", "StringPath prop1"); }
From source file:com.mysema.query.jpa.codegen.JPADomainExporterTest.java
License:Apache License
@Test public void Execute_Contact() throws IOException { FileUtils.delete(new File("target/jpagen1")); File contact = new File("src/test/resources/contact.hbm.xml"); Configuration config = new Configuration(); config.addFile(contact); JPADomainExporter exporter = new JPADomainExporter("Q", new File("target/jpagen1"), convert(config)); exporter.execute();/* w w w . j a va 2s . c o m*/ File targetFile = new File("target/jpagen1/com/mysema/query/jpa/domain2/QContact.java"); assertContains(targetFile, "StringPath email", "StringPath firstName", "NumberPath<Long> id", "StringPath lastName"); }
From source file:com.mysema.query.jpa.codegen.JPADomainExporterTest.java
License:Apache License
@Test public void Execute_Contact_with_Suffix() throws IOException { FileUtils.delete(new File("target/jpagen1")); File contact = new File("src/test/resources/contact.hbm.xml"); Configuration config = new Configuration(); config.addFile(contact); JPADomainExporter exporter = new JPADomainExporter("", "Type", new File("target/jpagen1"), convert(config)); exporter.execute();/*from w w w . ja v a2 s . c o m*/ File targetFile = new File("target/jpagen1/com/mysema/query/jpa/domain2/ContactType.java"); assertContains(targetFile, "StringPath email", "StringPath firstName", "NumberPath<Long> id", "StringPath lastName"); }