-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New major version to work with hibernate 5
- Loading branch information
Bas de Vos
committed
Oct 5, 2015
1 parent
19c31d1
commit 451b7db
Showing
18 changed files
with
125 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...src/main/java/org/jarbframework/utils/orm/hibernate/ConventionImplicitNamingStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.jarbframework.utils.orm.hibernate; | ||
|
||
import org.hibernate.boot.model.naming.Identifier; | ||
import org.hibernate.boot.model.naming.ImplicitForeignKeyNameSource; | ||
import org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl; | ||
|
||
/** | ||
* Naming strategy that describes our mapping between classes and tables. | ||
* | ||
* @author Jeroen van Schagen | ||
*/ | ||
public class ConventionImplicitNamingStrategy extends ImplicitNamingStrategyJpaCompliantImpl { | ||
|
||
private static final String FOREIGN_KEY_SUFFIX = "_id"; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public Identifier determineForeignKeyName(ImplicitForeignKeyNameSource source) { | ||
Identifier identifier = super.determineForeignKeyName(source); | ||
return Identifier.toIdentifier(identifier.getText() + FOREIGN_KEY_SUFFIX, identifier.isQuoted()); | ||
} | ||
|
||
} |
75 changes: 0 additions & 75 deletions
75
jarb-utils/src/main/java/org/jarbframework/utils/orm/hibernate/ConventionNamingStrategy.java
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
...src/main/java/org/jarbframework/utils/orm/hibernate/ConventionPhysicalNamingStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.jarbframework.utils.orm.hibernate; | ||
|
||
import static org.hibernate.boot.model.naming.Identifier.toIdentifier; | ||
|
||
import org.hibernate.boot.model.naming.Identifier; | ||
import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl; | ||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; | ||
|
||
/** | ||
* Physical naming strategy for generic usage. | ||
* | ||
* @author Bas de Vos | ||
*/ | ||
public class ConventionPhysicalNamingStrategy extends PhysicalNamingStrategyStandardImpl { | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) { | ||
return toIdentifier(addUnderscores(name.getText()), name.isQuoted()); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment context) { | ||
return toIdentifier(addUnderscores(name.getText()), name.isQuoted()); | ||
} | ||
|
||
protected static String addUnderscores(String name) { | ||
StringBuilder buffer = new StringBuilder(name.replace('.', '_')); | ||
for (int index = 1; index < buffer.length() - 1; index++) { | ||
if (isSeparator(buffer, index)) { | ||
buffer.insert(index++, '_'); | ||
} | ||
} | ||
return buffer.toString().toLowerCase(); | ||
} | ||
|
||
private static boolean isSeparator(StringBuilder buffer, int index) { | ||
char previous = buffer.charAt(index - 1); | ||
char current = buffer.charAt(index); | ||
return Character.isLowerCase(previous) && Character.isUpperCase(current); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
...ils/src/test/java/org/jarbframework/utils/orm/hibernate/ConventionNamingStrategyTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.