-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the ability to specify the column name converter to use for SQL…
… column names
- Loading branch information
Showing
7 changed files
with
74 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
10 changes: 10 additions & 0 deletions
10
CPOrm/src/main/java/za/co/cporm/model/naming/ColumnNameConverter.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,10 @@ | ||
package za.co.cporm.model.naming; | ||
|
||
/** | ||
* Created by hennie.brink on 2017/05/04. | ||
*/ | ||
|
||
public interface ColumnNameConverter { | ||
|
||
String convertToSql(String fieldName); | ||
} |
55 changes: 55 additions & 0 deletions
55
CPOrm/src/main/java/za/co/cporm/model/util/DefaultColumnNameConverter.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,55 @@ | ||
package za.co.cporm.model.util; | ||
|
||
import za.co.cporm.model.naming.ColumnNameConverter; | ||
|
||
/** | ||
* Contains common naming utilities to convert strings to SQL formats | ||
*/ | ||
public class DefaultColumnNameConverter implements ColumnNameConverter { | ||
|
||
/** | ||
* Converts the source string to a SQL compatible string. It does this | ||
* by checking for camelcase values, and applying a underscore '_' to whenever one is found. All | ||
* characters are also converted to lower case. | ||
* | ||
* Example: If the provided string is "helloWorld" the resulting string will be "hello_world" | ||
* @param original String to converted | ||
* @return the converted string | ||
*/ | ||
public static String getSQLName(String original){ | ||
|
||
StringBuilder sqlName = new StringBuilder(); | ||
|
||
for (char character : original.toCharArray()) { | ||
|
||
if(Character.isUpperCase(character) && sqlName.length() > 0) sqlName.append("_"); | ||
|
||
sqlName.append(Character.toLowerCase(character)); | ||
} | ||
|
||
return sqlName.toString(); | ||
} | ||
|
||
/** | ||
* Converts the source string to a SQL compatible string. It does this | ||
* by checking for camelcase values, and applying a underscore '_' to whenever one is found. All | ||
* characters are also converted to lower case. | ||
* | ||
* Example: If the provided string is "helloWorld" the resulting string will be "hello_world" | ||
* @param fieldName String to convert | ||
* @return the converted string | ||
*/ | ||
@Override | ||
public String convertToSql(String fieldName) { | ||
StringBuilder sqlName = new StringBuilder(); | ||
|
||
for (char character : fieldName.toCharArray()) { | ||
|
||
if(Character.isUpperCase(character) && sqlName.length() > 0) sqlName.append("_"); | ||
|
||
sqlName.append(Character.toLowerCase(character)); | ||
} | ||
|
||
return sqlName.toString(); | ||
} | ||
} |
30 changes: 0 additions & 30 deletions
30
CPOrm/src/main/java/za/co/cporm/model/util/NamingUtils.java
This file was deleted.
Oops, something went wrong.