Project

General

Profile

Download (2.2 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.cdm.database.types;
11

    
12
import org.hibernate.dialect.Dialect;
13
import org.hibernate.dialect.MySQL5MyISAMUtf8Dialect;
14

    
15
import eu.etaxonomy.cdm.database.ICdmDataSource;
16

    
17

    
18
/**
19
 * @author a.mueller
20
 *
21
 */
22
public class MariaDbDatabaseType extends DatabaseTypeBase {
23

    
24
	//typeName
25
	protected String typeName = "MariaDB";
26

    
27
	//class
28
	protected String classString = "com.mariadb.jdbc.Driver";
29

    
30
	//url
31
    protected String urlString = "jdbc:mariadb://";
32

    
33
    //port
34
    private final int defaultPort = 3306;
35

    
36
    private static String dbSeparator = "/";
37

    
38
    //hibernate dialect
39
    // see #3371 (switch cdm to MySQL InnoDB)
40
//    private Dialect hibernateDialect = new MySQL5InnoDBUtf8Dialect();
41
    //MariaDB specific dialect starts with hibernate 5.2.8 only
42
//    https://stackoverflow.com/questions/37066024/what-is-the-mariadb-dialect-class-name-for-hibernate
43
    private Dialect hibernateDialect = new MySQL5MyISAMUtf8Dialect();
44

    
45
    //connection String
46
	@Override
47
    public String getConnectionString(ICdmDataSource ds, int port){
48
        return urlString + ds.getServer() + ":" + port + dbSeparator + ds.getDatabase() + "?useUnicode=true&characterEncoding=utf8" + "&zeroDateTimeBehavior=convertToNull";
49
        //return urlString + ds.getServer() + ":" + port + "/" + ds.getDatabase() + "?useUnicode=true&characterEncoding=utf8&connectionCollation=utf8_general_ci&characterSetResults=utf8&jdbcCompliantTruncation=false";
50
    }
51

    
52
    @Override
53
    public String getDatabaseNameByConnectionString(String connectionString){
54
    	String result;
55
    	result = getDatabasePartOfConnectionString(connectionString, dbSeparator);
56
    	if(result == null) {
57
    		return null;
58
    	}
59
    	int posParams = result.indexOf("?");
60
    	if (posParams != -1){
61
    		result = result.substring(0, posParams);
62
    	}
63
     	return result;
64
    }
65

    
66
    /**
67
     * Constructor
68
     */
69
    public MariaDbDatabaseType() {
70
    	init (typeName, classString, urlString, defaultPort,  hibernateDialect );
71
	}
72
}
(5-5/14)