r673 - in nuiton-jpa: . nuiton-jpa-api nuiton-jpa-api/src nuiton-jpa-api/src/main/java/org/nuiton/jpa/api nuiton-jpa-api/src/test nuiton-jpa-hibernate nuiton-jpa-hibernate/src nuiton-jpa-hibernate/src/main nuiton-jpa-hibernate/src/main/java nuiton-jpa-hibernate/src/main/java/org nuiton-jpa-hibernate/src/main/java/org/nuiton nuiton-jpa-hibernate/src/main/java/org/nuiton/jpa nuiton-jpa-hibernate/src/main/java/org/nuiton/jpa/hibernate nuiton-jpa-hibernate/src/test nuiton-jpa-hibernate/src/tes
Author: bleny Date: 2013-06-20 17:01:45 +0200 (Thu, 20 Jun 2013) New Revision: 673 Url: http://nuiton.org/projects/sandbox/repository/revisions/673 Log: introduce nuiton-jpa-hibernate module, moving HibernateUtil inside it, introduce OracleCompliantImprovedNamingStrategy Added: nuiton-jpa/nuiton-jpa-api/src/test/ nuiton-jpa/nuiton-jpa-api/src/test/java/ nuiton-jpa/nuiton-jpa-hibernate/ nuiton-jpa/nuiton-jpa-hibernate/LICENSE.txt nuiton-jpa/nuiton-jpa-hibernate/README.txt nuiton-jpa/nuiton-jpa-hibernate/changelog.txt nuiton-jpa/nuiton-jpa-hibernate/pom.xml nuiton-jpa/nuiton-jpa-hibernate/src/ nuiton-jpa/nuiton-jpa-hibernate/src/main/ nuiton-jpa/nuiton-jpa-hibernate/src/main/java/ nuiton-jpa/nuiton-jpa-hibernate/src/main/java/org/ nuiton-jpa/nuiton-jpa-hibernate/src/main/java/org/nuiton/ nuiton-jpa/nuiton-jpa-hibernate/src/main/java/org/nuiton/jpa/ nuiton-jpa/nuiton-jpa-hibernate/src/main/java/org/nuiton/jpa/hibernate/ nuiton-jpa/nuiton-jpa-hibernate/src/main/java/org/nuiton/jpa/hibernate/HibernateUtil.java nuiton-jpa/nuiton-jpa-hibernate/src/main/java/org/nuiton/jpa/hibernate/OracleCompliantImprovedNamingStrategy.java nuiton-jpa/nuiton-jpa-hibernate/src/test/ nuiton-jpa/nuiton-jpa-hibernate/src/test/java/ nuiton-jpa/nuiton-jpa-hibernate/src/test/java/org/ nuiton-jpa/nuiton-jpa-hibernate/src/test/java/org/nuiton/ nuiton-jpa/nuiton-jpa-hibernate/src/test/java/org/nuiton/jpa/ nuiton-jpa/nuiton-jpa-hibernate/src/test/java/org/nuiton/jpa/hibernate/ nuiton-jpa/nuiton-jpa-hibernate/src/test/java/org/nuiton/jpa/hibernate/OracleCompliantImprovedNamingStrategyTest.java Removed: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/hibernate/ Modified: nuiton-jpa/nuiton-jpa-api/pom.xml nuiton-jpa/nuiton-jpa-junit/pom.xml nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java nuiton-jpa/pom.xml Modified: nuiton-jpa/nuiton-jpa-api/pom.xml =================================================================== --- nuiton-jpa/nuiton-jpa-api/pom.xml 2013-06-19 07:57:46 UTC (rev 672) +++ nuiton-jpa/nuiton-jpa-api/pom.xml 2013-06-20 15:01:45 UTC (rev 673) @@ -22,16 +22,6 @@ </dependency> <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-core</artifactId> - </dependency> - - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-entitymanager</artifactId> - </dependency> - - <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> Property changes on: nuiton-jpa/nuiton-jpa-hibernate ___________________________________________________________________ Added: svn:ignore + target *.iml Added: nuiton-jpa/nuiton-jpa-hibernate/LICENSE.txt =================================================================== --- nuiton-jpa/nuiton-jpa-hibernate/LICENSE.txt (rev 0) +++ nuiton-jpa/nuiton-jpa-hibernate/LICENSE.txt 2013-06-20 15:01:45 UTC (rev 673) @@ -0,0 +1,166 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. + Added: nuiton-jpa/nuiton-jpa-hibernate/README.txt =================================================================== Added: nuiton-jpa/nuiton-jpa-hibernate/changelog.txt =================================================================== Added: nuiton-jpa/nuiton-jpa-hibernate/pom.xml =================================================================== --- nuiton-jpa/nuiton-jpa-hibernate/pom.xml (rev 0) +++ nuiton-jpa/nuiton-jpa-hibernate/pom.xml 2013-06-20 15:01:45 UTC (rev 673) @@ -0,0 +1,61 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-jpa</artifactId> + <version>0.1-SNAPSHOT</version> + </parent> + + <groupId>org.nuiton.jpa</groupId> + <artifactId>nuiton-jpa-hibernate</artifactId> + + <name>Nuiton Jpa :: Hibernate</name> + + <dependencies> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-core</artifactId> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-entitymanager</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + </dependency> + + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + </dependency> + + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + </dependency> + + </dependencies> + + <build> + + + </build> + +</project> Copied: nuiton-jpa/nuiton-jpa-hibernate/src/main/java/org/nuiton/jpa/hibernate/HibernateUtil.java (from rev 672, nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/hibernate/HibernateUtil.java) =================================================================== --- nuiton-jpa/nuiton-jpa-hibernate/src/main/java/org/nuiton/jpa/hibernate/HibernateUtil.java (rev 0) +++ nuiton-jpa/nuiton-jpa-hibernate/src/main/java/org/nuiton/jpa/hibernate/HibernateUtil.java 2013-06-20 15:01:45 UTC (rev 673) @@ -0,0 +1,159 @@ +package org.nuiton.jpa.hibernate; + +/* + * #%L + * nuiton-jpa-api + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.apache.commons.lang3.SystemUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.Environment; +import org.hibernate.ejb.AvailableSettings; +import org.hibernate.ejb.EntityManagerFactoryImpl; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.service.internal.SessionFactoryServiceRegistryImpl; +import org.hibernate.tool.hbm2ddl.SchemaExport; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; +import java.io.File; +import java.lang.reflect.Field; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public class HibernateUtil { + + private static final Log log = LogFactory.getLog(HibernateUtil.class); + + protected static final Map<String, String> HIBERNATE_H2_CONFIG; + + public static final String HBM2DDL_AUTO_VALIDATE = "validate"; + + public static final String HBM2DDL_AUTO_CREATE_DROP = "create-drop"; + + public static final String HBM2DDL_AUTO_CREATE = "create"; + + public static final String HBM2DDL_AUTO_UPDATE = "update"; + + static { + + Map<String, String> hibernateH2Config = new HashMap<String, String>(); + + hibernateH2Config.put(AvailableSettings.JDBC_DRIVER, org.h2.Driver.class.getName()); + hibernateH2Config.put(AvailableSettings.JDBC_USER, "sa"); + hibernateH2Config.put(AvailableSettings.JDBC_PASSWORD, ""); + hibernateH2Config.put(Environment.DIALECT, org.hibernate.dialect.H2Dialect.class.getName()); + hibernateH2Config.put(Environment.HBM2DDL_AUTO, HBM2DDL_AUTO_UPDATE); + + HIBERNATE_H2_CONFIG = Collections.unmodifiableMap(hibernateH2Config); + + } + + private HibernateUtil() { + } + + public static EntityManagerFactory createTempEntityManagerFactory(String persistenceUnitName, String context) { + + EntityManagerFactory tempEntityManagerFactory = + createTempEntityManagerFactory( + persistenceUnitName, + context, Collections.<String, String>emptyMap()); + + return tempEntityManagerFactory; + + } + + public static EntityManagerFactory createTempEntityManagerFactory(String persistenceUnitName, String context, Map<String, String> jpaParameters) { + + Map<String, String> allJpaParameters = new HashMap<String, String>(); + + allJpaParameters.putAll(jpaParameters); + + allJpaParameters.putAll(HIBERNATE_H2_CONFIG); + + File tempDirFile = SystemUtils.getJavaIoTmpDir(); + + File databaseFile = new File(tempDirFile, context); + + String h2dataPath = databaseFile.getAbsolutePath() + File.separator + "h2data"; + + String jdbcUrl = "jdbc:h2:file:" + h2dataPath; + + allJpaParameters.put(AvailableSettings.JDBC_URL, jdbcUrl); + + if (log.isTraceEnabled()) { + log.trace("will store H2 data in " + h2dataPath); + log.trace("allJpaParameters = " + allJpaParameters); + } + + if (log.isDebugEnabled()) { + log.debug("jdbc url is\n" + jdbcUrl); + } + + EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(persistenceUnitName, allJpaParameters); + + return entityManagerFactory; + + } + + public static void cleanDatabase(EntityManager entityManager) { + + if (log.isInfoEnabled()) { + log.info("will clean database"); + } + + ServiceRegistry serviceRegistry = + ((EntityManagerFactoryImpl) entityManager.getEntityManagerFactory()) + .getSessionFactory().getServiceRegistry(); + + Configuration configuration = null; + try { + Field configurationField = SessionFactoryServiceRegistryImpl.class.getDeclaredField("configuration"); + configurationField.setAccessible(true); + configuration = (Configuration) configurationField.get(serviceRegistry); + } catch (IllegalAccessException e) { + if (log.isErrorEnabled()) { + log.error("should not occur", e); + } + } catch (NoSuchFieldException e) { + if (log.isErrorEnabled()) { + log.error("should not occur", e); + } + } + + SchemaExport schemaExport = new SchemaExport(serviceRegistry, configuration); + + schemaExport.setHaltOnError(true); + + // drop + schemaExport.execute(true, true, true, false); + + // create + schemaExport.execute(true, true, false, true); + + } + +} \ No newline at end of file Property changes on: nuiton-jpa/nuiton-jpa-hibernate/src/main/java/org/nuiton/jpa/hibernate/HibernateUtil.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: nuiton-jpa/nuiton-jpa-hibernate/src/main/java/org/nuiton/jpa/hibernate/OracleCompliantImprovedNamingStrategy.java =================================================================== --- nuiton-jpa/nuiton-jpa-hibernate/src/main/java/org/nuiton/jpa/hibernate/OracleCompliantImprovedNamingStrategy.java (rev 0) +++ nuiton-jpa/nuiton-jpa-hibernate/src/main/java/org/nuiton/jpa/hibernate/OracleCompliantImprovedNamingStrategy.java 2013-06-20 15:01:45 UTC (rev 673) @@ -0,0 +1,122 @@ +package org.nuiton.jpa.hibernate; + +import com.google.common.base.Joiner; +import com.google.common.base.Splitter; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; +import org.hibernate.cfg.ImprovedNamingStrategy; +import org.hibernate.cfg.NamingStrategy; + +import java.util.List; +import java.util.Map; + +/** + * Oracle doesn't support table names and columns names longer than 30 characters. + * + * This naming strategy solve the issue. <strong>This is not safe, since reducing + * the name can lead to collisions according to your classes and their attributes names + * </strong> + * + */ +public class OracleCompliantImprovedNamingStrategy extends ImprovedNamingStrategy implements NamingStrategy { + + /** + * Arbitrary value fixed by Oracle. + * + * @link http://stackoverflow.com/questions/8701479/table-name-with-more-than-30-char... + */ + protected static final int MAXIMUM_IDENTIFIER_LENGTH = 30; + + protected Map<String, String> cache = Maps.newConcurrentMap(); + + /** + * Given an identifier, return a similar identifier but no longer + * than MAXIMUM_IDENTIFIER_LENGTH. Some characters are removed + * at the end of each part of the identifier. + * + * Any given identifier shorter than MAXIMUM_IDENTIFIER_LENGTH + * will be returned as it. + * + * @param value a string that may contain some underscores + * @return a string that looks like given value but without + * removed characters in order to make the total + * length lower than MAXIMUM_IDENTIFIER_LENGTH + */ + protected String getShortenedIdentifier(String value) { + String reducedValue = value; + if (value.length() > MAXIMUM_IDENTIFIER_LENGTH) { + reducedValue = cache.get(value); + if (reducedValue == null) { + reducedValue = shortenIdentifier(value); + cache.put(value, reducedValue); + } + } + return reducedValue; + } + + protected String shortenIdentifier(String identifier) { + Iterable <String> split = Splitter.on('_').split(identifier); + int numberOfElements = Iterables.size(split); + int numberOfUnderscores = numberOfElements - 1; + int acceptedLengthForAnElement = (MAXIMUM_IDENTIFIER_LENGTH - numberOfUnderscores) / numberOfElements; + List<String> reducedElements = Lists.newLinkedList(); + for (String element : split) { + reducedElements.add(StringUtils.left(element, acceptedLengthForAnElement)); + } + String reducedIdentifier = Joiner.on('_').join(reducedElements); + return reducedIdentifier; + } + + @Override + public String classToTableName(String className) { + return getShortenedIdentifier(super.classToTableName(className)); + } + + @Override + public String propertyToColumnName(String propertyName) { + return getShortenedIdentifier(super.propertyToColumnName(propertyName)); + } + + @Override + public String tableName(String tableName) { + return getShortenedIdentifier(super.tableName(tableName)); + } + + @Override + public String columnName(String columnName) { + return getShortenedIdentifier(super.columnName(columnName)); + } + + @Override + public String collectionTableName(String ownerEntity, String ownerEntityTable, String associatedEntity, String associatedEntityTable, String propertyName) { + return getShortenedIdentifier(super.collectionTableName(ownerEntity, ownerEntityTable, associatedEntity, associatedEntityTable, propertyName)); + } + + @Override + public String joinKeyColumnName(String joinedColumn, String joinedTable) { + return getShortenedIdentifier(super.joinKeyColumnName(joinedColumn, joinedTable)); + } + + @Override + public String foreignKeyColumnName(String propertyName, String propertyEntityName, String propertyTableName, String referencedColumnName) { + return getShortenedIdentifier(super.foreignKeyColumnName(propertyName, propertyEntityName, propertyTableName, referencedColumnName)); + } + + @Override + public String logicalColumnName(String columnName, String propertyName) { + return getShortenedIdentifier(super.logicalColumnName(columnName, propertyName)); + } + + @Override + public String logicalCollectionTableName(String tableName, String ownerEntityTable, String associatedEntityTable, String propertyName) { + return getShortenedIdentifier(super.logicalCollectionTableName(tableName, ownerEntityTable, associatedEntityTable, propertyName)); + } + + @Override + public String logicalCollectionColumnName(String columnName, String propertyName, String referencedColumn) { + return getShortenedIdentifier(super.logicalCollectionColumnName(columnName, propertyName, referencedColumn)); + } + +} Added: nuiton-jpa/nuiton-jpa-hibernate/src/test/java/org/nuiton/jpa/hibernate/OracleCompliantImprovedNamingStrategyTest.java =================================================================== --- nuiton-jpa/nuiton-jpa-hibernate/src/test/java/org/nuiton/jpa/hibernate/OracleCompliantImprovedNamingStrategyTest.java (rev 0) +++ nuiton-jpa/nuiton-jpa-hibernate/src/test/java/org/nuiton/jpa/hibernate/OracleCompliantImprovedNamingStrategyTest.java 2013-06-20 15:01:45 UTC (rev 673) @@ -0,0 +1,82 @@ +package org.nuiton.jpa.hibernate; + +import org.apache.commons.lang3.StringUtils; +import org.junit.Assert; +import org.junit.Test; + +public class OracleCompliantImprovedNamingStrategyTest { + + protected OracleCompliantImprovedNamingStrategy oracleCompliantImprovedNamingStrategy = new OracleCompliantImprovedNamingStrategy(); + + @Test + public void testNamingStrategy() { + + String className = getLongValue("LONG_CLASS_NAME_"); + + String ownerEntity = getLongValue("LONG_OWNER_ENTITY_"); + + String ownerEntityTable = getLongValue("LONG_OWNER_ENTITY_TABLE_"); + + String associatedEntity = getLongValue("LONG_ASSOCIATED_ENTITY_"); + + String associatedEntityTable = getLongValue("LONG_ASSOCIATED_ENTITY_TABLE_"); + + String propertyName = getLongValue("LONG_PROPERTY_NAME_"); + + String tableName = getLongValue("LONG_TABLE_NAME_"); + + String columnName = getLongValue("LONG_COLUMN_NAME_"); + + String propertyEntityName = getLongValue("LONG_PROPERTY_ENTITY_NAME"); + + String propertyTableName = getLongValue("LONG_PROPERTY_TABLE_NAME"); + + String referencedColumnName = getLongValue("LONG_REFERENCED_COLUMN_NAME"); + + String referencedColumn = getLongValue("LONG_REFERENCED_COLUMN"); + + String joinedColumn = getLongValue("LONG_JOINED_COLUMN"); + + String joinedTable = getLongValue("LONG_JOINED_TABLE"); + + check(oracleCompliantImprovedNamingStrategy.classToTableName(className)); + + check(oracleCompliantImprovedNamingStrategy.classToTableName("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")); + + check(oracleCompliantImprovedNamingStrategy.collectionTableName(ownerEntity, ownerEntityTable, associatedEntity, associatedEntityTable, propertyName)); + + check(oracleCompliantImprovedNamingStrategy.logicalCollectionTableName(tableName, ownerEntityTable, associatedEntityTable, propertyName)); + + check(oracleCompliantImprovedNamingStrategy.columnName(columnName)); + + check(oracleCompliantImprovedNamingStrategy.tableName(tableName)); + + check(oracleCompliantImprovedNamingStrategy.foreignKeyColumnName(propertyName, propertyEntityName, propertyTableName, referencedColumnName)); + + check(oracleCompliantImprovedNamingStrategy.propertyToColumnName(propertyName)); + + check(oracleCompliantImprovedNamingStrategy.logicalCollectionColumnName(columnName, propertyName, referencedColumn)); + + check(oracleCompliantImprovedNamingStrategy.logicalColumnName(columnName, propertyName)); + + check(oracleCompliantImprovedNamingStrategy.joinKeyColumnName(joinedColumn, joinedTable)); + + } + + protected void check(String reducedValue) { + + Assert.assertFalse( + "'" + reducedValue + "' length (" + reducedValue.length() + ") is too long", + reducedValue.length() > oracleCompliantImprovedNamingStrategy.MAXIMUM_IDENTIFIER_LENGTH); + + Assert.assertFalse(reducedValue.startsWith("_")); + + Assert.assertFalse(reducedValue.endsWith("_")); + + } + + protected String getLongValue(String value) { + return StringUtils.rightPad(value, 50, "LONG"); + } + +} Modified: nuiton-jpa/nuiton-jpa-junit/pom.xml =================================================================== --- nuiton-jpa/nuiton-jpa-junit/pom.xml 2013-06-19 07:57:46 UTC (rev 672) +++ nuiton-jpa/nuiton-jpa-junit/pom.xml 2013-06-20 15:01:45 UTC (rev 673) @@ -16,9 +16,10 @@ <dependencies> + <!-- fixme bleny 20/06/2013 we shouldn't rely on a particular implemetation of JPA --> <dependency> <groupId>${project.groupId}</groupId> - <artifactId>nuiton-jpa-api</artifactId> + <artifactId>nuiton-jpa-hibernate</artifactId> <version>${project.version}</version> </dependency> Modified: nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java =================================================================== --- nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java 2013-06-19 07:57:46 UTC (rev 672) +++ nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java 2013-06-20 15:01:45 UTC (rev 673) @@ -29,7 +29,7 @@ import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; -import org.nuiton.jpa.api.hibernate.HibernateUtil; +import org.nuiton.jpa.hibernate.HibernateUtil; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; Modified: nuiton-jpa/pom.xml =================================================================== --- nuiton-jpa/pom.xml 2013-06-19 07:57:46 UTC (rev 672) +++ nuiton-jpa/pom.xml 2013-06-20 15:01:45 UTC (rev 673) @@ -47,6 +47,7 @@ <modules> <module>nuiton-jpa-api</module> + <module>nuiton-jpa-hibernate</module> <module>nuiton-jpa-junit</module> <module>nuiton-jpa-templates</module> </modules> @@ -161,9 +162,9 @@ <artifactId>maven-site-plugin</artifactId> <dependencies> <dependency> - <groupId>org.nuiton.jrst</groupId> - <artifactId>doxia-module-jrst</artifactId> - <version>${jrstPluginVersion}</version> + <groupId>org.apache.maven.doxia</groupId> + <artifactId>doxia-module-markdown</artifactId> + <version>1.3</version> </dependency> </dependencies> </plugin>
participants (1)
-
bleny@users.nuiton.org