001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Florent Guillaume 011 */ 012 013package org.nuxeo.ecm.core.storage.sql; 014 015import java.sql.Connection; 016import java.sql.DriverManager; 017import java.util.HashMap; 018import java.util.Map; 019 020import org.nuxeo.runtime.api.Framework; 021 022/** 023 * @author Florent Guillaume 024 */ 025public class DatabaseMySQL extends DatabaseHelper { 026 027 public static DatabaseHelper INSTANCE = new DatabaseMySQL(); 028 029 private static final String DEF_URL = "jdbc:mysql://localhost:3306/nuxeojunittests"; 030 031 private static final String DEF_USER = "nuxeo"; 032 033 private static final String DEF_PASSWORD = "nuxeo"; 034 035 private static final String CONTRIB_XML = "OSGI-INF/test-repo-repository-mysql-contrib.xml"; 036 037 private static final String DRIVER = "com.mysql.jdbc.Driver"; 038 039 private void setProperties() { 040 Framework.getProperties().setProperty(REPOSITORY_PROPERTY, repositoryName); 041 setProperty(URL_PROPERTY, DEF_URL); 042 setProperty(USER_PROPERTY, DEF_USER); 043 setProperty(PASSWORD_PROPERTY, DEF_PASSWORD); 044 setProperty(DRIVER_PROPERTY, DRIVER); 045 } 046 047 @Override 048 public void setUp() throws Exception { 049 super.setUp(); 050 Class.forName(DRIVER); 051 setProperties(); 052 Connection connection = DriverManager.getConnection(Framework.getProperty(URL_PROPERTY), 053 Framework.getProperty(USER_PROPERTY), Framework.getProperty(PASSWORD_PROPERTY)); 054 doOnAllTables(connection, null, null, "DROP TABLE `%s` CASCADE"); 055 connection.close(); 056 } 057 058 @Override 059 public String getDeploymentContrib() { 060 return CONTRIB_XML; 061 } 062 063 @Override 064 public RepositoryDescriptor getRepositoryDescriptor() { 065 RepositoryDescriptor descriptor = new RepositoryDescriptor(); 066 descriptor.xaDataSourceName = "com.mysql.jdbc.jdbc2.optional.MysqlXADataSource"; 067 Map<String, String> properties = new HashMap<String, String>(); 068 properties.put("URL", Framework.getProperty(URL_PROPERTY)); 069 properties.put("User", Framework.getProperty(USER_PROPERTY)); 070 properties.put("Password", Framework.getProperty(PASSWORD_PROPERTY)); 071 descriptor.properties = properties; 072 return descriptor; 073 } 074 075 @Override 076 public boolean hasSubSecondResolution() { 077 return false; 078 } 079 080 @Override 081 public int getRecursiveRemovalDepthLimit() { 082 // Stupid MySQL limitations: 083 // "Cascading operations may not be nested more than 15 levels deep." 084 // "Currently, triggers are not activated by cascaded foreign key 085 // actions." 086 // Use a bit less that 15 to cater for complex properties 087 return 13; 088 } 089 090 @Override 091 public boolean supportsClustering() { 092 return true; 093 } 094 095}