Return-Path: X-Original-To: apmail-empire-db-commits-archive@www.apache.org Delivered-To: apmail-empire-db-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 59D58980D for ; Mon, 4 Jun 2012 09:46:26 +0000 (UTC) Received: (qmail 15077 invoked by uid 500); 4 Jun 2012 09:46:26 -0000 Delivered-To: apmail-empire-db-commits-archive@empire-db.apache.org Received: (qmail 14850 invoked by uid 500); 4 Jun 2012 09:46:25 -0000 Mailing-List: contact commits-help@empire-db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: empire-db-dev@empire-db.apache.org Delivered-To: mailing list commits@empire-db.apache.org Received: (qmail 14670 invoked by uid 99); 4 Jun 2012 09:46:25 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Jun 2012 09:46:25 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Jun 2012 09:46:23 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id DF9422388860 for ; Mon, 4 Jun 2012 09:46:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1345894 - in /empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/postgresql: ./ DBDatabaseDriverPostgreSQLTest.java Date: Mon, 04 Jun 2012 09:46:01 -0000 To: commits@empire-db.apache.org From: francisdb@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120604094601.DF9422388860@eris.apache.org> Author: francisdb Date: Mon Jun 4 09:46:01 2012 New Revision: 1345894 URL: http://svn.apache.org/viewvc?rev=1345894&view=rev Log: EMPIREDB-146 blob data type is not working with postgresql under v2.3 Added: empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/postgresql/ empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQLTest.java Added: empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQLTest.java URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQLTest.java?rev=1345894&view=auto ============================================================================== --- empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQLTest.java (added) +++ empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQLTest.java Mon Jun 4 09:46:01 2012 @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.empire.db.postgresql; + +import java.sql.Connection; + +import org.apache.empire.DBResource; +import org.apache.empire.DBResource.DB; +import org.apache.empire.db.CompanyDB; +import org.apache.empire.db.DBCommand; +import org.apache.empire.db.DBDatabaseDriver; +import org.apache.empire.db.DBSQLScript; +import org.apache.empire.db.exceptions.QueryFailedException; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +@Ignore +public class DBDatabaseDriverPostgreSQLTest +{ + + @Rule + public DBResource dbResource = new DBResource(DB.POSTGRESQL); + + @Test + public void testBlob() + { + Connection conn = dbResource.getConnection(); + + DBDatabaseDriver driver = dbResource.newDriver(); + CompanyDB db = new CompanyDB(); + + // Encoding issue occur when prepared statement is disabled + //db.setPreparedStatementsEnabled(true); + + db.open(driver, dbResource.getConnection()); + + if(!databaseExists(conn, db)){ + DBSQLScript script = new DBSQLScript(); + db.getCreateDDLScript(db.getDriver(), script); + System.out.println(script.toString()); + script.run(db.getDriver(), dbResource.getConnection(), false); + } + } + + /** + * Checks whether the database exists or not by executing + * select count(*) from DEPARTMENTS + * If the Departments table does not exist the querySingleInt() function return -1 for failure. + * Please note that in this case an error will appear in the log which can be ignored. + */ + private static boolean databaseExists(Connection conn, CompanyDB db) + { + // Check whether DB exists + DBCommand cmd = db.createCommand(); + cmd.select(db.DEPARTMENT.count()); + // Check using "select count(*) from DEPARTMENTS" + + try{ + return (db.querySingleInt(cmd.getSelect(), -1, conn) >= 0); + }catch(QueryFailedException ex){ + System.out.println("Checking whether table DEPARTMENTS exists (SQLException will be logged if not - please ignore) ..."); + System.out.println(ex.getMessage()); + } + return false; + } +}