Project

General

Profile

« Previous | Next » 

Revision 7920febf

Added by Andreas Müller about 5 years ago

ref #8118 added MariaDbDatabaseType

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/DatabaseTypeEnum.java
22 22
import eu.etaxonomy.cdm.database.types.H2DatabaseType;
23 23
import eu.etaxonomy.cdm.database.types.HSqlDbDatabaseType;
24 24
import eu.etaxonomy.cdm.database.types.IDatabaseType;
25
import eu.etaxonomy.cdm.database.types.MariaDbDatabaseType;
25 26
import eu.etaxonomy.cdm.database.types.MySQLDatabaseType;
26 27
import eu.etaxonomy.cdm.database.types.OdbcDatabaseType;
27 28
import eu.etaxonomy.cdm.database.types.OracleDatabaseType;
......
47 48
	H2(9),
48 49
	SqlServer2008(10),
49 50
    SqlServer2012(11),
51
    MariaDB(12),  //not yet tested
50 52
    ;
51 53

  
52 54
//	/**
......
83 85
                this.dbType = new SqlServer2008DatabaseType(); break;
84 86
            case 11:
85 87
                this.dbType = new SqlServer2012DatabaseType(); break;
88
            case 12:
89
                this.dbType = new MariaDbDatabaseType(); break;
86 90
            default:
87
                //TODO Exception
91
                throw new RuntimeException("Database type not handled");
88 92
        }
89 93
	}
90 94

  
......
250 254
        }
251 255
        if (product.toLowerCase().matches("\\.*mysql\\.*")){
252 256
            return MySQL;
257
        }else if (product.toLowerCase().matches("\\.*mariadb\\.*")) {
258
            return MariaDB;
253 259
        }else if (product.toLowerCase().matches("\\.*hsqldb\\.*")) {
254 260
            return HSqlDb;
255 261
        }else if (product.toLowerCase().matches("\\.*oracle\\.*")) {
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/types/MariaDbDatabaseType.java
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
}

Also available in: Unified diff