| 1 | /** |
| 2 | * Copyright (C) 2006 NetMind Consulting Bt. |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 3 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | */ |
| 18 | |
| 19 | package hu.netmind.beankeeper.db.impl; |
| 20 | |
| 21 | import java.sql.Types; |
| 22 | import java.util.List; |
| 23 | import hu.netmind.beankeeper.db.*; |
| 24 | |
| 25 | /** |
| 26 | * Postgres database implementation. |
| 27 | * @author Brautigam Robert |
| 28 | * @version CVS Revision: $Revision$ |
| 29 | */ |
| 30 | public class PostgresDatabaseImpl extends GenericDatabase implements Database |
| 31 | { |
| 32 | /** |
| 33 | * Get the limit component of statement, if it can be expressed in |
| 34 | * the current database with simple statement part. |
| 35 | * @param limits The limits to apply. |
| 36 | */ |
| 37 | protected String getLimitStatement(String statement, Limits limits, List types) |
| 38 | { |
| 39 | StringBuffer result = new StringBuffer(statement); |
| 40 | if ( limits.getLimit() > 0 ) |
| 41 | result.append(" limit "+limits.getLimit()); |
| 42 | if ( limits.getOffset() > 0 ) |
| 43 | result.append(" offset "+limits.getOffset()); |
| 44 | return result.toString(); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Get the sql type for a class. |
| 49 | */ |
| 50 | protected int getSQLType(Class type) |
| 51 | { |
| 52 | if ( byte[].class.equals(type) ) |
| 53 | return Types.LONGVARBINARY; |
| 54 | return super.getSQLType(type); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Get the class for an sql type. Override for blob type. |
| 59 | */ |
| 60 | protected String getSQLTypeName(int sqltype) |
| 61 | { |
| 62 | switch ( sqltype ) |
| 63 | { |
| 64 | case Types.BLOB: |
| 65 | case Types.BINARY: |
| 66 | case Types.VARBINARY: |
| 67 | case Types.LONGVARBINARY: |
| 68 | return "bytea"; |
| 69 | default: |
| 70 | return super.getSQLTypeName(sqltype); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | } |
| 75 | |
| 76 | |
| 77 | |