001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Florent Guillaume 018 */ 019 020package org.nuxeo.ecm.core.storage.sql; 021 022import java.sql.Connection; 023import java.sql.DriverManager; 024import java.sql.SQLException; 025import java.sql.Statement; 026 027import org.nuxeo.runtime.api.Framework; 028 029/** 030 * @author Florent Guillaume 031 */ 032public class DatabasePostgreSQL extends DatabaseHelper { 033 034 private static final String DEF_SERVER = "localhost"; 035 036 private static final String DEF_PORT = "5432"; 037 038 private static final String DEF_USER = "nuxeo"; 039 040 private static final String DEF_PASSWORD = "nuxeo"; 041 042 private static final String CONTRIB_XML = "OSGI-INF/test-repo-repository-postgresql-contrib.xml"; 043 044 private static final String DRIVER = "org.postgresql.Driver"; 045 046 protected void setProperties() { 047 String db = setProperty(DATABASE_PROPERTY, databaseName); 048 String server = setProperty(SERVER_PROPERTY, DEF_SERVER); 049 String port = setProperty(PORT_PROPERTY, DEF_PORT); 050 String user = setProperty(USER_PROPERTY, DEF_USER); 051 String password = setProperty(PASSWORD_PROPERTY, DEF_PASSWORD); 052 // for sql directory tests 053 String driver = setProperty(DRIVER_PROPERTY, DRIVER); 054 String url = String.format("jdbc:postgresql://%s:%s/%s", server, port, db); 055 setProperty(URL_PROPERTY, url); 056 setProperty(ID_TYPE_PROPERTY, DEF_ID_TYPE); 057 } 058 059 @Override 060 public void setUp() throws SQLException { 061 super.setUp(); 062 try { 063 Class.forName(DRIVER); 064 } catch (ReflectiveOperationException e) { 065 throw new RuntimeException(e); 066 } 067 setProperties(); 068 Connection connection = DriverManager.getConnection(Framework.getProperty(URL_PROPERTY), 069 Framework.getProperty(USER_PROPERTY), Framework.getProperty(PASSWORD_PROPERTY)); 070 try { 071 doOnAllTables(connection, null, "public", "DROP TABLE \"%s\" CASCADE"); 072 Statement st = connection.createStatement(); 073 executeSql(st, "DROP SEQUENCE IF EXISTS hierarchy_seq"); 074 st.close(); 075 } finally { 076 connection.close(); 077 } 078 } 079 080 @Override 081 public String getDeploymentContrib() { 082 return CONTRIB_XML; 083 } 084 085 @Override 086 public RepositoryDescriptor getRepositoryDescriptor() { 087 RepositoryDescriptor descriptor = new RepositoryDescriptor(); 088 descriptor.setFulltextAnalyzer("french"); 089 descriptor.setPathOptimizationsEnabled(true); 090 descriptor.setAclOptimizationsEnabled(true); 091 descriptor.idType = Framework.getProperty(ID_TYPE_PROPERTY); 092 return descriptor; 093 } 094 095 @Override 096 public boolean supportsClustering() { 097 return true; 098 } 099 100 @Override 101 public boolean supportsSoftDelete() { 102 return true; 103 } 104 105 @Override 106 public boolean supportsSequenceId() { 107 return true; 108 } 109 110 @Override 111 public boolean supportsArrayColumns() { 112 return true; 113 } 114 115}