Project

General

Profile

Task #1207 » IdmMsSQLNamingStrategy.java

Ondřej Kopr, 08/13/2018 10:48 AM

 
1
package eu.bcvsolutions.idm.core.config;
2

    
3
import java.io.Serializable;
4

    
5
import org.apache.commons.lang3.StringUtils;
6
import org.hibernate.cfg.ImprovedNamingStrategy;
7
import org.hibernate.cfg.NamingStrategy;
8

    
9
/**
10
 * Naming strategy for MsSQL. All names are in uppercase
11
 *
12
 * @author Ondrej Kopr <kopr@xyxy.cz>
13
 *
14
 */
15
public class IdmMsSQLNamingStrategy extends ImprovedNamingStrategy implements NamingStrategy, Serializable {
16

    
17
	private static final long serialVersionUID = 1L;
18

    
19
	@Override
20
	public String classToTableName(String className) {
21
		return toUpperCase(super.classToTableName(className));
22
	}
23

    
24
	@Override
25
	public String collectionTableName(String ownerEntity, String ownerEntityTable, String associatedEntity,
26
			String associatedEntityTable, String propertyName) {
27
		return toUpperCase(super.collectionTableName(ownerEntity, ownerEntityTable, associatedEntity, associatedEntityTable,
28
				propertyName));
29
	}
30

    
31
	@Override
32
	public String columnName(String columnName) {
33
		return toUpperCase(super.columnName(columnName));
34
	}
35

    
36
	@Override
37
	public String foreignKeyColumnName(String propertyName, String propertyEntityName, String propertyTableName,
38
			String referencedColumnName) {
39
		return toUpperCase(super.foreignKeyColumnName(propertyName, propertyEntityName, propertyTableName, referencedColumnName));
40
	}
41

    
42
	@Override
43
	public String joinKeyColumnName(String joinedColumn, String joinedTable) {
44
		return toUpperCase(super.joinKeyColumnName(joinedColumn, joinedTable));
45
	}
46

    
47
	@Override
48
	public String logicalCollectionColumnName(String columnName, String propertyName, String referencedColumn) {
49
		return toUpperCase(super.logicalCollectionColumnName(columnName, propertyName, referencedColumn));
50
	}
51

    
52
	@Override
53
	public String logicalCollectionTableName(String tableName, String ownerEntityTable, String associatedEntityTable,
54
			String propertyName) {
55
		return toUpperCase(super.logicalCollectionTableName(tableName, ownerEntityTable, associatedEntityTable, propertyName));
56
	}
57

    
58
	@Override
59
	public String logicalColumnName(String columnName, String propertyName) {
60
		return toUpperCase(super.logicalColumnName(columnName, propertyName));
61
	}
62

    
63
	@Override
64
	public String propertyToColumnName(String propertyName) {
65
		return toUpperCase(super.propertyToColumnName(propertyName));
66
	}
67

    
68
	@Override
69
	public String tableName(String tableName) {
70
		return toUpperCase(super.tableName(tableName));
71
	}
72

    
73
	/**
74
	 * Save uppercase string
75
	 *
76
	 * @param name
77
	 * @return
78
	 */
79
	protected static String toUpperCase(String name) {
80
		if (StringUtils.isNotEmpty(name)) {
81
			return name.toUpperCase();
82
		}
83
		return name;
84
	}
85
}
    (1-1/1)