Skip to content

Commit

Permalink
Merge branch 'releases/release-0.7.0' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
valesu committed Oct 18, 2017
2 parents 3057758 + 6635a50 commit df5530c
Show file tree
Hide file tree
Showing 21 changed files with 751 additions and 64 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>ee.eesti.riha</groupId>
<artifactId>rest</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>

<packaging>war</packaging>

Expand Down
4 changes: 4 additions & 0 deletions sql/create_fk.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ alter table riha.comment add CONSTRAINT fk_comment_comment FOREIGN KEY (comment_
REFERENCES riha.comment (comment_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;

ALTER TABLE riha.file_resource ADD CONSTRAINT fk_file_resource_large_object FOREIGN KEY (large_object_id)
REFERENCES riha.large_object (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;

CREATE TRIGGER tr_infosystem_update AFTER UPDATE ON main_resource FOR EACH ROW EXECUTE PROCEDURE infosystem_trg();
51 changes: 50 additions & 1 deletion sql/create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ START 436069
CACHE 1;
GRANT SELECT, USAGE ON SEQUENCE riha.main_resource_seq TO riha;

CREATE SEQUENCE riha.large_object_seq
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
GRANT SELECT, USAGE ON SEQUENCE riha.large_object_seq TO riha;

-- Table: riha.kind

-- DROP TABLE riha.kind;
Expand Down Expand Up @@ -356,9 +364,50 @@ COMMENT ON COLUMN riha.comment.type IS 'Hinnangu tüüp';
COMMENT ON COLUMN riha.comment.title IS 'Hinnangu pealkiri';
COMMENT ON COLUMN riha.comment.sub_type IS 'Hinnangu alamtüüp';


GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE riha.comment TO riha;

-- Table: riha.large_object

-- DROP TABLE riha.large_object;

CREATE TABLE riha.large_object
(
id integer NOT NULL,
creation_date timestamp without time zone,
data oid,
hash character varying(255),
length bigint,
CONSTRAINT large_object_pkey PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
);

GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE riha.large_object TO riha;

-- Table: riha.file_resource

-- DROP TABLE riha.file_resource;

CREATE TABLE riha.file_resource
(
uuid uuid NOT NULL,
content_type character varying(255),
creation_date timestamp without time zone,
name character varying(255),
large_object_id integer NOT NULL,
CONSTRAINT file_resource_pkey PRIMARY KEY (uuid),
CONSTRAINT fk_file_resource_large_object FOREIGN KEY (large_object_id)
REFERENCES riha.large_object (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
WITH (
OIDS = FALSE
);

GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE riha.file_resource TO riha;

-- Index: riha.ixfk_comment_comment

-- DROP INDEX riha.ixfk_comment_comment;
Expand Down
7 changes: 4 additions & 3 deletions sql/create_views.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CREATE VIEW riha.main_resource_view AS
SELECT DISTINCT ON (json_content ->> 'uuid') *
FROM riha.main_resource
CREATE OR REPLACE VIEW riha.main_resource_view AS
SELECT DISTINCT ON (json_content ->> 'uuid') *,
((main_resource.json_content #>> '{meta,creation_timestamp}'::text[]))::timestamp AS j_creation_timestamp
FROM riha.main_resource as main_resource
ORDER BY json_content ->> 'uuid',
creation_date DESC,
main_resource_id DESC;
1 change: 1 addition & 0 deletions sql/drop_fk.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ alter table riha.data_object drop constraint fk_data_object_main_resource;
alter table riha.document drop CONSTRAINT fk_data_object;
alter TABLE riha.document DROP CONSTRAINT fk_main_resource;
alter table riha.comment drop CONSTRAINT fk_comment_comment;
alter table riha.file_resource drop CONSTRAINT fk_file_resource_large_object;
DROP TRIGGER IF EXISTS tr_infosystem_update ON main_resource;
8 changes: 8 additions & 0 deletions sql/drop_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ DROP TABLE riha.main_resource;

DROP TABLE riha.kind;

-- Table: riha.file_resource

DROP TABLE riha.file_resource;

-- Table: riha.large_object

DROP TABLE riha.large_object;

-- Sequence: riha.comment_seq

DROP SEQUENCE riha.comment_seq;
Expand Down
48 changes: 48 additions & 0 deletions sql/update/update_20171009_create_large_object_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
CREATE SEQUENCE riha.large_object_seq
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
GRANT SELECT, USAGE ON SEQUENCE riha.large_object_seq TO riha;

-- Table: riha.large_object

-- DROP TABLE riha.large_object;

CREATE TABLE riha.large_object
(
id integer NOT NULL,
creation_date timestamp without time zone,
data oid,
hash character varying(255),
CONSTRAINT large_object_pkey PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
);

GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE riha.large_object TO riha;

-- Table: riha.file_resource

-- DROP TABLE riha.file_resource;

CREATE TABLE riha.file_resource
(
uuid uuid NOT NULL,
content_type character varying(255),
creation_date timestamp without time zone,
name character varying(255),
large_object_id integer NOT NULL,
CONSTRAINT file_resource_pkey PRIMARY KEY (uuid),
CONSTRAINT fk_file_resource_large_object FOREIGN KEY (large_object_id)
REFERENCES riha.large_object (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
WITH (
OIDS = FALSE
);

GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE riha.file_resource TO riha;
2 changes: 2 additions & 0 deletions sql/update/update_20171012_add_large_object_length_column.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE riha.large_object
ADD COLUMN length BIGINT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE OR REPLACE VIEW riha.main_resource_view AS
SELECT DISTINCT ON (json_content ->> 'uuid') *,
((main_resource.json_content #>> '{meta,creation_timestamp}'::text[]))::timestamp AS j_creation_timestamp
FROM riha.main_resource as main_resource
ORDER BY json_content ->> 'uuid',
creation_date DESC,
main_resource_id DESC;
39 changes: 39 additions & 0 deletions src/main/java/ee/eesti/riha/rest/dao/FileResourceDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ee.eesti.riha.rest.dao;

import ee.eesti.riha.rest.model.FileResource;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.transaction.Transactional;
import java.util.Date;
import java.util.UUID;

@Component
@Transactional
public class FileResourceDAO {

@Autowired
private SessionFactory sessionFactory;

/**
* Creates single {@link FileResource} entity.
*
* @param entity persisted entity
* @return UUID of persisted {@link FileResource}
*/
public UUID create(FileResource entity) {
entity.setCreationDate(new Date());
return (UUID) sessionFactory.getCurrentSession().save(entity);
}

/**
* Retrieves single {@link FileResource} entity by its UUID.
*
* @param uuid entity UUID
* @return loaded entity or null if not found
*/
public FileResource get(UUID uuid) {
return (FileResource) sessionFactory.getCurrentSession().get(FileResource.class, uuid);
}
}
Loading

0 comments on commit df5530c

Please sign in to comment.