- /**\r
- * Updates the session factory config file for using this database.\r
- * Writes the datasource property and the dialect property into the session factory.\r
- * @param hibernateHbm2ddlAuto value for the hibernate property hibernate.hbm2dll.auto . If null the properties is not changed. Possible values are 'validate', 'create', 'update' and 'create-drop'.\r
- * @return true if successful.\r
- */\r
- public boolean updateSessionFactory(String hibernateHbm2ddlAuto){\r
- Element root = getRoot(getSessionFactoryInputStream());\r
- if (root == null){\r
- return false;\r
- }\r
- //get sessionFactory bean\r
- Element sessionFactoryBean = getFirstAttributedChild(root, "bean", "id", "sessionFactory");\r
- //sessionFactory must exist \r
- if (sessionFactoryBean == null){\r
- return false;\r
- }\r
- \r
- //set dataSource property\r
- Element dataSourceProperty = getFirstAttributedChild(sessionFactoryBean, "property", "name", "dataSource");\r
- if (dataSourceProperty == null){\r
- dataSourceProperty = insertXmlRefProperty(sessionFactoryBean, "dataSource", getBeanName(this.dataSourceName));\r
- }\r
- Attribute attrRef = dataSourceProperty.getAttribute("ref");\r
- if (attrRef == null){\r
- dataSourceProperty.setAttribute("ref", getBeanName(this.dataSourceName));\r
- }else{\r
- attrRef.setValue(getBeanName(this.dataSourceName));\r
- }\r
- \r
- //set dialect\r
- Element elHibernateProperties = getOrAddChild(sessionFactoryBean, "property", "name", "hibernateProperties");\r
- Element props = getOrAddChild(elHibernateProperties, "props", null, null);\r
- Element elDialectProp = getOrAddChild(props, "prop", "key", "hibernate.dialect");\r
- elDialectProp.setText(this.getDatabaseType().getHibernateDialect());\r
- \r
- //set hibernateHbm2ddlAuto\r
- if (hibernateHbm2ddlAuto != null){\r
- if (hibernateHbm2ddlAuto != "validate" && hibernateHbm2ddlAuto != "create" && hibernateHbm2ddlAuto != "update " && hibernateHbm2ddlAuto != "create-drop" ){\r
- logger.warn("Invalid value " + hibernateHbm2ddlAuto + " for property hibernate.hbm2ddl.auto");\r
- }\r
- Element elHbm2ddlAutoProp = getOrAddChild(props, "prop", "key", "hibernate.hbm2ddl.auto");\r
- elHbm2ddlAutoProp.setText(hibernateHbm2ddlAuto);\r
- }\r
- \r
- //save\r
- saveToXml(root.getDocument(), getSessionFactoryOutputStream() , format );\r
- return true;\r
- }\r
-\r
- \r