wordpress 文章前空格seo与sem的区别
news/
2025/9/24 5:17:46/
文章来源:
wordpress 文章前空格,seo与sem的区别,网络公司企业网站源码,做商城网站一般用什么ddl hibernate不久前#xff0c;我必须使用内存数据库。 该活动与集成测试有关。 如您所知#xff0c;通常将内存数据库用于集成测试。 造成这种情况的原因有很多#xff1a;可移植性#xff0c;良好的环境基础结构#xff0c;高性能#xff0c;原始数据库的一致性。 问… ddl hibernate 不久前我必须使用内存数据库。 该活动与集成测试有关。 如您所知通常将内存数据库用于集成测试。 造成这种情况的原因有很多可移植性良好的环境基础结构高性能原始数据库的一致性。 问题在于将生产DDL架构压入测试内存数据库。 第一个是MySQL 第二个是HSQLDB 。 MySQL的语法不同于HSQL语法。 因此如果不进行适当的转换就不可能将MySQL表模式导入HSQLDB。 坦白说我已经花了很多时间在寻找一些解决方案这将有助于我在HSQL中导入MySQL DDL模式 。 结果不是我想要的那么好。 所有解决方案都是商业化的或非自动化的例如替换HSQL上所有MySQL特定的代码。 幸运的是我的项目使用Hibernate作为JPA实现。 所有实体都装饰有适当的Hibernate注释。 正如您将进一步看到的那样这对于MySQL模式的转换将非常有帮助。 Hibernate提供了基于DDL生成实体的机制反之亦然。 因此任何使用Hibernate注释修饰的实体都可以使用Hibernate支持的DB语言来表示为表模式。 这是一个解决我的问题的类 public class SchemaTranslator {private Configuration config null;public SchemaTranslator() {config new Configuration();}public SchemaTranslator setDialect(String dialect) {config.setProperty(AvailableSettings.DIALECT, dialect);return this;}/*** Method determines classes which will be used for DDL generation. * param annotatedClasses - entities annotated with Hibernate annotations.*/public SchemaTranslator addAnnotatedClasses(Class[] annotatedClasses) {for (Class clazz : annotatedClasses)config.addAnnotatedClass(clazz);return this;}/*** Method performs translation of entities in table schemas.* It generates CREATE and DELETE scripts for the Hibernate entities.* Current implementation involves usage of {link #write(FileOutputStream, String[], Formatter)} method.* param outputStream - stream will be used for *.sql file creation.* throws IOException*/public SchemaTranslator translate(FileOutputStream outputStream) throws IOException {Dialect requiredDialect Dialect.getDialect(config.getProperties());String[] query null;query config.generateDropSchemaScript(requiredDialect);write(outputStream, query, FormatStyle.DDL.getFormatter());query config.generateSchemaCreationScript(requiredDialect);write(outputStream, query, FormatStyle.DDL.getFormatter());return this;}/*** Method writes line by line DDL scripts in the output stream.* Also each line logs in the console.* throws IOException*/private void write(FileOutputStream outputStream, String[] lines, Formatter formatter) throws IOException {String tempStr null;for (String line : lines) {tempStr formatter.format(line);;System.out.println(tempStr);outputStream.write(tempStr.getBytes());}}public static void main(String[] args) throws IOException {SchemaTranslator translator new SchemaTranslator();Class[] entityClasses {Smartphone.class};translator.setDialect(org.hibernate.dialect.HSQLDialect).addAnnotatedClasses(entityClasses).translate(new FileOutputStream(new File(db-schema.sql)));}} 上面的代码非常冗长但我对此进行了评论。 因此我希望它或多或少容易理解。 整个应用程序的代码可以在GitHub上找到 。 SchemaTranslator类在项目结构中具有以下位置 / src / test / java / com / mobapp / test / util / 借助此类您可以将您的实体采用到Hibernate支持的任何必需数据库中。 祝好运 参考 Hibernate我们的JCG合作伙伴 Alexey Zvolinskiy在Fruzenshtein的注释博客中生成了DDL Schema 。 翻译自: https://www.javacodegeeks.com/2014/01/hibernate-ddl-schema-generation.htmlddl hibernate
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/914937.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!