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 public static DatabaseHelper INSTANCE = new DatabasePostgreSQL(); 035 036 private static final String DEF_SERVER = "localhost"; 037 038 private static final String DEF_PORT = "5432"; 039 040 private static final String DEF_USER = "nuxeo"; 041 042 private static final String DEF_PASSWORD = "nuxeo"; 043 044 private static final String CONTRIB_XML = "OSGI-INF/test-repo-repository-postgresql-contrib.xml"; 045 046 private static final String DRIVER = "org.postgresql.Driver"; 047 048 protected void setProperties() { 049 String db = setProperty(DATABASE_PROPERTY, databaseName); 050 String server = setProperty(SERVER_PROPERTY, DEF_SERVER); 051 String port = setProperty(PORT_PROPERTY, DEF_PORT); 052 String user = setProperty(USER_PROPERTY, DEF_USER); 053 String password = setProperty(PASSWORD_PROPERTY, DEF_PASSWORD); 054 // for sql directory tests 055 String driver = setProperty(DRIVER_PROPERTY, DRIVER); 056 String url = String.format("jdbc:postgresql://%s:%s/%s", server, port, db); 057 setProperty(URL_PROPERTY, url); 058 setProperty(ID_TYPE_PROPERTY, DEF_ID_TYPE); 059 } 060 061 @Override 062 public void setUp() throws SQLException { 063 super.setUp(); 064 try { 065 Class.forName(DRIVER); 066 } catch (ReflectiveOperationException e) { 067 throw new RuntimeException(e); 068 } 069 setProperties(); 070 Connection connection = DriverManager.getConnection(Framework.getProperty(URL_PROPERTY), 071 Framework.getProperty(USER_PROPERTY), Framework.getProperty(PASSWORD_PROPERTY)); 072 try { 073 doOnAllTables(connection, null, "public", "DROP TABLE \"%s\" CASCADE"); 074 Statement st = connection.createStatement(); 075 executeSql(st, "DROP SEQUENCE IF EXISTS hierarchy_seq"); 076 st.close(); 077 } finally { 078 connection.close(); 079 } 080 } 081 082 @Override 083 public String getDeploymentContrib() { 084 return CONTRIB_XML; 085 } 086 087 @Override 088 public RepositoryDescriptor getRepositoryDescriptor() { 089 RepositoryDescriptor descriptor = new RepositoryDescriptor(); 090 descriptor.setFulltextAnalyzer("french"); 091 descriptor.setPathOptimizationsEnabled(true); 092 descriptor.setAclOptimizationsEnabled(true); 093 descriptor.idType = Framework.getProperty(ID_TYPE_PROPERTY); 094 return descriptor; 095 } 096 097 @Override 098 public boolean supportsClustering() { 099 return true; 100 } 101 102 @Override 103 public boolean supportsSoftDelete() { 104 return true; 105 } 106 107 @Override 108 public boolean supportsSequenceId() { 109 return true; 110 } 111 112 @Override 113 public boolean supportsArrayColumns() { 114 return true; 115 } 116 117}