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 setProperty(USER_PROPERTY, DEF_USER); 051 setProperty(PASSWORD_PROPERTY, DEF_PASSWORD); 052 setProperty(DRIVER_PROPERTY, DRIVER); 053 String url = String.format("jdbc:postgresql://%s:%s/%s", server, port, db); 054 setProperty(URL_PROPERTY, url); 055 setProperty(ID_TYPE_PROPERTY, DEF_ID_TYPE); 056 } 057 058 @Override 059 public void setUp() throws SQLException { 060 super.setUp(); 061 try { 062 Class.forName(DRIVER); 063 } catch (ReflectiveOperationException e) { 064 throw new RuntimeException(e); 065 } 066 setProperties(); 067 Connection connection = DriverManager.getConnection(Framework.getProperty(URL_PROPERTY), 068 Framework.getProperty(USER_PROPERTY), Framework.getProperty(PASSWORD_PROPERTY)); 069 try { 070 doOnAllTables(connection, null, "public", "DROP TABLE \"%s\" CASCADE"); 071 Statement st = connection.createStatement(); 072 executeSql(st, "DROP SEQUENCE IF EXISTS hierarchy_seq"); 073 st.close(); 074 } finally { 075 connection.close(); 076 } 077 } 078 079 @Override 080 public String getDeploymentContrib() { 081 return CONTRIB_XML; 082 } 083 084 @Override 085 public RepositoryDescriptor getRepositoryDescriptor() { 086 RepositoryDescriptor descriptor = new RepositoryDescriptor(); 087 descriptor.setFulltextAnalyzer("french"); 088 descriptor.setPathOptimizationsEnabled(true); 089 descriptor.setAclOptimizationsEnabled(true); 090 descriptor.idType = Framework.getProperty(ID_TYPE_PROPERTY); 091 return descriptor; 092 } 093 094 @Override 095 public boolean supportsClustering() { 096 return true; 097 } 098 099 @Override 100 public boolean supportsSoftDelete() { 101 return true; 102 } 103 104 @Override 105 public boolean supportsSequenceId() { 106 return true; 107 } 108 109 @Override 110 public boolean supportsArrayColumns() { 111 return true; 112 } 113 114}