Skip to content
Commits on Source (8)
repo: 1d7c4b96183115894767b40ed485045665f2c75c
node: 56dbbd7f5f785c5e343c60ab6a6e11b85d252615
branch: OrthancPostgreSQL-2.0
node: 8994bbdbc6d09f0824f789bb02e3d5b1b44e60e2
branch: OrthancPostgreSQL-2.1
latesttag: null
latesttagdistance: 88
latesttagdistance: 166
changessincelatesttag: 178
......@@ -6,8 +6,15 @@ Authors
-------
* Sebastien Jodogne <s.jodogne@gmail.com>
Department of Medical Physics
Overall design and lead developer.
* Department of Medical Physics
University Hospital of Liege
4000 Liege
Belgium
Overall design and lead developer.
* Osimis S.A. <info@osimis.io>
Rue des Chasseurs Ardennais 3
4031 Liege
Belgium
# Orthanc - A Lightweight, RESTful DICOM Store
# Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
# Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
# Department, University Hospital of Liege, Belgium
# Copyright (C) 2017-2018 Osimis S.A., Belgium
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License
......@@ -20,44 +21,51 @@ cmake_minimum_required(VERSION 2.8)
project(OrthancPostgreSQL)
set(ORTHANC_POSTGRESQL_VERSION "2.0")
set(ORTHANC_POSTGRESQL_VERSION "2.1")
if (ORTHANC_POSTGRESQL_VERSION STREQUAL "mainline")
set(ORTHANC_FRAMEWORK_VERSION "mainline")
set(ORTHANC_FRAMEWORK_DEFAULT_SOURCE "hg")
else()
set(ORTHANC_FRAMEWORK_VERSION "1.3.2")
set(ORTHANC_FRAMEWORK_DEFAULT_SOURCE "web")
endif()
# Parameters of the build
set(STATIC_BUILD OFF CACHE BOOL "Static build of the third-party libraries (necessary for Windows)")
set(ALLOW_DOWNLOADS OFF CACHE BOOL "Allow CMake to download packages")
set(BUILD_UNIT_TESTS ON CACHE BOOL "Build UnitTests")
set(ORTHANC_FRAMEWORK_SOURCE "${ORTHANC_FRAMEWORK_DEFAULT_SOURCE}" CACHE STRING "Source of the Orthanc source code (can be \"hg\", \"archive\", \"web\" or \"path\")")
set(ORTHANC_FRAMEWORK_ARCHIVE "" CACHE STRING "Path to the Orthanc archive, if ORTHANC_FRAMEWORK_SOURCE is \"archive\"")
set(ORTHANC_FRAMEWORK_ROOT "" CACHE STRING "Path to the Orthanc source directory, if ORTHANC_FRAMEWORK_SOURCE is \"path\"")
# Advanced parameters to fine-tune linking against system libraries
set(USE_SYSTEM_JSONCPP ON CACHE BOOL "Use the system version of JsonCpp")
set(USE_SYSTEM_BOOST ON CACHE BOOL "Use the system version of Boost")
set(USE_SYSTEM_GOOGLE_TEST ON CACHE BOOL "Use the system version of Google Test")
set(USE_SYSTEM_LIBPQ ON CACHE BOOL "Use the system version of the PostgreSQL client library")
set(USE_SYSTEM_ORTHANC_SDK ON CACHE BOOL "Use the system version of the Orthanc plugin SDK")
# Distribution-specific settings
set(USE_GTEST_DEBIAN_SOURCE_PACKAGE OFF CACHE BOOL "Use the sources of Google Test shipped with libgtest-dev (Debian only)")
mark_as_advanced(USE_GTEST_DEBIAN_SOURCE_PACKAGE)
set(ORTHANC_ROOT ${CMAKE_SOURCE_DIR}/Orthanc)
include(CheckIncludeFiles)
include(CheckIncludeFileCXX)
include(CheckLibraryExists)
include(FindPythonInterp)
include(${ORTHANC_ROOT}/Resources/CMake/Compiler.cmake)
include(${ORTHANC_ROOT}/Resources/CMake/AutoGeneratedCode.cmake)
include(${ORTHANC_ROOT}/Resources/CMake/DownloadPackage.cmake)
include(${ORTHANC_ROOT}/Resources/CMake/BoostConfiguration.cmake)
include(${ORTHANC_ROOT}/Resources/CMake/JsonCppConfiguration.cmake)
include(${CMAKE_SOURCE_DIR}/Resources/CMake/PostgreSQLConfiguration.cmake)
if (BUILD_UNIT_TESTS)
include(${ORTHANC_ROOT}/Resources/CMake/GoogleTestConfiguration.cmake)
endif()
# Download and setup the Orthanc framework
include(${CMAKE_SOURCE_DIR}/Resources/Orthanc/DownloadOrthancFramework.cmake)
set(ORTHANC_FRAMEWORK_PLUGIN ON)
include(${ORTHANC_ROOT}/Resources/CMake/OrthancFrameworkParameters.cmake)
set(ENABLE_LOCALE OFF) # Disable support for locales (notably in Boost)
set(ENABLE_GOOGLE_TEST ON)
include(${ORTHANC_ROOT}/Resources/CMake/OrthancFrameworkConfiguration.cmake)
include_directories(${ORTHANC_ROOT})
# The CMake script in "Graveyard" was used up to release 2.0. The new
# script makes auto-configuration of the variables.
include(${CMAKE_SOURCE_DIR}/Resources/CMake/PostgreSQLConfiguration.cmake)
#include(${CMAKE_SOURCE_DIR}/Resources/Graveyard/PostgreSQLConfiguration.cmake)
if (STATIC_BUILD OR NOT USE_SYSTEM_ORTHANC_SDK)
include_directories(${ORTHANC_ROOT}/Sdk-0.9.5)
include_directories(${CMAKE_SOURCE_DIR}/Resources/Orthanc/Sdk-0.9.5)
else ()
CHECK_INCLUDE_FILE_CXX(orthanc/OrthancCppDatabasePlugin.h HAVE_ORTHANC_H)
if (NOT HAVE_ORTHANC_H)
......@@ -66,7 +74,6 @@ else ()
endif()
if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
link_libraries(secur32)
......@@ -119,10 +126,10 @@ set(CORE_SOURCES
${CMAKE_SOURCE_DIR}/Core/PostgreSQLTransaction.cpp
${CMAKE_SOURCE_DIR}/Core/Configuration.cpp
${CMAKE_SOURCE_DIR}/Core/GlobalProperties.cpp
${AUTOGENERATED_DIR}/EmbeddedResources.cpp
${ORTHANC_CORE_SOURCES}
${LIBPQ_SOURCES}
${BOOST_SOURCES}
${JSONCPP_SOURCES}
)
add_library(OrthancPostgreSQLStorage
......@@ -136,7 +143,6 @@ add_library(OrthancPostgreSQLStorage
add_library(OrthancPostgreSQLIndex
SHARED
${CORE_SOURCES}
${AUTOGENERATED_SOURCES}
${CMAKE_SOURCE_DIR}/IndexPlugin/PostgreSQLWrapper.cpp
${CMAKE_SOURCE_DIR}/IndexPlugin/Plugin.cpp
${INDEX_RESOURCES}
......@@ -166,12 +172,13 @@ install(
if (BUILD_UNIT_TESTS)
add_executable(UnitTests
${CORE_SOURCES}
${GTEST_SOURCES}
${AUTOGENERATED_SOURCES}
${CMAKE_SOURCE_DIR}/IndexPlugin/PostgreSQLWrapper.cpp
${CMAKE_SOURCE_DIR}/StoragePlugin/PostgreSQLStorageArea.cpp
${CMAKE_SOURCE_DIR}/UnitTestsSources/UnitTestsMain.cpp
${CMAKE_SOURCE_DIR}/UnitTestsSources/PostgreSQLTests.cpp
${CMAKE_SOURCE_DIR}/UnitTestsSources/PostgreSQLWrapperTests.cpp
${GOOGLE_TEST_SOURCES}
)
target_link_libraries(UnitTests ${GOOGLE_TEST_LIBRARIES})
endif()
/**
* Orthanc - A Lightweight, RESTful DICOM Store
* Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
* Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
* Department, University Hospital of Liege, Belgium
* Copyright (C) 2017-2018 Osimis S.A., Belgium
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
......
/**
* Orthanc - A Lightweight, RESTful DICOM Store
* Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
* Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
* Department, University Hospital of Liege, Belgium
* Copyright (C) 2017-2018 Osimis S.A., Belgium
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
......
/**
* Orthanc - A Lightweight, RESTful DICOM Store
* Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
* Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
* Department, University Hospital of Liege, Belgium
* Copyright (C) 2017-2018 Osimis S.A., Belgium
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
......
/**
* Orthanc - A Lightweight, RESTful DICOM Store
* Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
* Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
* Department, University Hospital of Liege, Belgium
* Copyright (C) 2017-2018 Osimis S.A., Belgium
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
......
/**
* Orthanc - A Lightweight, RESTful DICOM Store
* Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
* Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
* Department, University Hospital of Liege, Belgium
* Copyright (C) 2017-2018 Osimis S.A., Belgium
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
......@@ -45,26 +46,15 @@ namespace OrthancPlugins
}
PostgreSQLConnection::PostgreSQLConnection()
{
pg_ = NULL;
host_ = "localhost";
port_ = 5432;
username_ = "postgres";
password_ = "postgres";
database_ = "";
uri_.clear();
}
PostgreSQLConnection::PostgreSQLConnection(const PostgreSQLConnection& other) :
host_(other.host_),
port_(other.port_),
username_(other.username_),
password_(other.password_),
database_(other.database_),
PostgreSQLConnection::PostgreSQLConnection() :
host_("localhost"),
port_(5432),
username_("postgres"),
password_("postgres"),
pg_(NULL)
{
database_.clear();
uri_.clear();
}
......@@ -79,8 +69,32 @@ namespace OrthancPlugins
{
if (uri_.empty())
{
return ("postgresql://" + username_ + ":" + password_ + "@" +
host_ + ":" + boost::lexical_cast<std::string>(port_) + "/" + database_);
std::string actualUri = "postgresql://";
if (!username_.empty())
{
actualUri += username_;
if (!password_.empty())
{
actualUri += ":" + password_;
}
actualUri += "@" + host_;
}
else
{
actualUri += host_;
}
if (port_ > 0)
{
actualUri += ":" + boost::lexical_cast<std::string>(port_);
}
actualUri += "/" + database_;
return actualUri;
}
else
{
......
/**
* Orthanc - A Lightweight, RESTful DICOM Store
* Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
* Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
* Department, University Hospital of Liege, Belgium
* Copyright (C) 2017-2018 Osimis S.A., Belgium
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
......@@ -20,18 +21,6 @@
#pragma once
#if defined(_WIN32)
#include <winsock2.h>
# if defined(_MSC_VER)
// http://msdn.microsoft.com/en-us/library/a3140177.aspx
# define htobe32(x) _byteswap_ulong(x)
# define htobe64(x) _byteswap_uint64(x)
# else // MinGW
# define htobe32(x) __builtin_bswap32(x)
# define htobe64(x) __builtin_bswap64(x)
# endif
#endif
#include <string>
#include <boost/noncopyable.hpp>
#include <stdint.h>
......@@ -57,8 +46,6 @@ namespace OrthancPlugins
public:
PostgreSQLConnection();
PostgreSQLConnection(const PostgreSQLConnection& other);
~PostgreSQLConnection()
{
Close();
......
/**
* Orthanc - A Lightweight, RESTful DICOM Store
* Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
* Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
* Department, University Hospital of Liege, Belgium
* Copyright (C) 2017-2018 Osimis S.A., Belgium
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
......@@ -33,7 +34,7 @@ namespace OrthancPlugins
{
}
PostgreSQLException(const std::string& message) :
explicit PostgreSQLException(const std::string& message) :
std::runtime_error("Error in PostgreSQL: " + message)
{
}
......
/**
* Orthanc - A Lightweight, RESTful DICOM Store
* Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
* Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
* Department, University Hospital of Liege, Belgium
* Copyright (C) 2017-2018 Osimis S.A., Belgium
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
......@@ -150,14 +151,14 @@ namespace OrthancPlugins
for (size_t position = 0; position < size_; )
{
size_t remaining = size_ - position;
size_t nbytes = lo_read(pg_, fd_, target + position, remaining);
int nbytes = lo_read(pg_, fd_, target + position, remaining);
if (nbytes < 0)
{
throw PostgreSQLException("Unable to read the large object in the database");
}
position += nbytes;
position += static_cast<size_t>(nbytes);
}
}
};
......
/**
* Orthanc - A Lightweight, RESTful DICOM Store
* Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
* Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
* Department, University Hospital of Liege, Belgium
* Copyright (C) 2017-2018 Osimis S.A., Belgium
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
......
/**
* Orthanc - A Lightweight, RESTful DICOM Store
* Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
* Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
* Department, University Hospital of Liege, Belgium
* Copyright (C) 2017-2018 Osimis S.A., Belgium
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
......@@ -30,13 +31,7 @@
#include <c.h>
#include <catalog/pg_type.h>
#if defined(__FreeBSD__)
# include <arpa/inet.h> // ntohl()
#elif defined(__APPLE__)
# include <libkern/OSByteOrder.h>
# define htobe32(x) OSSwapHostToBigInt32(x)
# define htobe64(x) OSSwapHostToBigInt64(x)
#endif
#include <Core/Endianness.h>
namespace OrthancPlugins
......
/**
* Orthanc - A Lightweight, RESTful DICOM Store
* Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
* Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
* Department, University Hospital of Liege, Belgium
* Copyright (C) 2017-2018 Osimis S.A., Belgium
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
......@@ -38,7 +39,7 @@ namespace OrthancPlugins
void CheckColumn(unsigned int column, /*Oid*/ unsigned int expectedType) const;
public:
PostgreSQLResult(PostgreSQLStatement& statement);
explicit PostgreSQLResult(PostgreSQLStatement& statement);
~PostgreSQLResult()
{
......
/**
* Orthanc - A Lightweight, RESTful DICOM Store
* Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
* Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
* Department, University Hospital of Liege, Belgium
* Copyright (C) 2017-2018 Osimis S.A., Belgium
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
......@@ -30,11 +31,7 @@
#include <c.h>
#include <catalog/pg_type.h>
#if defined(__APPLE__)
# include <libkern/OSByteOrder.h>
# define htobe32(x) OSSwapHostToBigInt32(x)
# define htobe64(x) OSSwapHostToBigInt64(x)
#endif
#include <Core/Endianness.h>
namespace OrthancPlugins
......
/**
* Orthanc - A Lightweight, RESTful DICOM Store
* Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
* Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
* Department, University Hospital of Liege, Belgium
* Copyright (C) 2017-2018 Osimis S.A., Belgium
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
......
/**
* Orthanc - A Lightweight, RESTful DICOM Store
* Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
* Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
* Department, University Hospital of Liege, Belgium
* Copyright (C) 2017-2018 Osimis S.A., Belgium
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
......@@ -51,6 +52,7 @@ namespace OrthancPlugins
}
connection_.Execute("BEGIN");
connection_.Execute("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE");
isOpen_ = true;
}
......
/**
* Orthanc - A Lightweight, RESTful DICOM Store
* Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
* Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
* Department, University Hospital of Liege, Belgium
* Copyright (C) 2017-2018 Osimis S.A., Belgium
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
......
/**
* Orthanc - A Lightweight, RESTful DICOM Store
* Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
* Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
* Department, University Hospital of Liege, Belgium
* Copyright (C) 2017-2018 Osimis S.A., Belgium
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
......@@ -29,11 +30,21 @@ static OrthancPluginContext* context_ = NULL;
static OrthancPlugins::PostgreSQLWrapper* backend_ = NULL;
static bool DisplayPerformanceWarning()
{
(void) DisplayPerformanceWarning; // Disable warning about unused function
OrthancPluginLogWarning(context_, "Performance warning in PostgreSQL index: "
"Non-release build, runtime debug assertions are turned on");
return true;
}
extern "C"
{
ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
{
context_ = context;
assert(DisplayPerformanceWarning());
/* Check the version of the Orthanc core */
if (OrthancPluginCheckVersion(context_) == 0)
......
/**
* Orthanc - A Lightweight, RESTful DICOM Store
* Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
* Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
* Department, University Hospital of Liege, Belgium
* Copyright (C) 2017-2018 Osimis S.A., Belgium
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
......@@ -126,7 +127,7 @@ namespace OrthancPlugins
{
char info[1024];
sprintf(info, "This database plugin is incompatible with your version of Orthanc "
"expecting the DB schema version %d, but this plugin is compatible with versions 5 or 6",
"expecting the DB schema version %u, but this plugin is compatible with versions 5 or 6",
expectedVersion);
OrthancPluginLogError(context_, info);
throw PostgreSQLException(info);
......