This commit is contained in:
FabioISTI 2020-03-27 12:34:53 +01:00
parent 3ac79e94d6
commit b5b7b1abdf
5 changed files with 38 additions and 11 deletions

View File

@ -1,9 +1,10 @@
package org.gcube.application.geoportal.model;
import java.util.ArrayList;
import java.util.Map;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
@ -23,14 +24,15 @@ public class ArchiveDescriptor {
// content
private String archiveLocation;
@OneToMany
@OneToMany(cascade=CascadeType.ALL, mappedBy="archive",fetch=FetchType.EAGER)
private ArrayList<AssociatedContent> attachments;
// meta
private String metadataID;
private Map<String,LayerDescriptor> layers;
@OneToMany(cascade=CascadeType.ALL, mappedBy="archive",fetch=FetchType.EAGER)
private ArrayList<LayerDescriptor> layers;
}

View File

@ -3,6 +3,8 @@ package org.gcube.application.geoportal.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
@Entity
public class AssociatedContent {
@ -20,5 +22,7 @@ public class AssociatedContent {
private String itemID;
private String link;
@ManyToOne
@JoinColumn(name="archive_uuid", nullable=false)
private ArchiveDescriptor archive;
}

View File

@ -1,5 +1,17 @@
package org.gcube.application.geoportal.model;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
@Entity
public class LayerDescriptor {
@Id
private String uuid;
@ManyToOne
@JoinColumn(name="archive_uuid", nullable=false)
private ArchiveDescriptor archive;
}

View File

@ -4,7 +4,7 @@ import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.junit.BeforeClass;
import org.gcube.application.geoportal.model.ArchiveDescriptor;
import org.junit.Test;
public class Archives {
@ -21,7 +21,9 @@ public class Archives {
@Test
public void listExistent() {
// EntityManager em = jpaResourceBean.getEMF().createEntityManager();
EntityManager em = getEMF().createEntityManager();
em.find(ArchiveDescriptor.class, "some");
}
}

View File

@ -1,12 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="archiveDB" transaction-type="RESOURCE_LOCAL">
<class>org.gcube.application.geoportal.model.ArchiveDescriptor</class>
<class>org.gcube.application.geoportal.model.AssociatedContent</class>
<class>org.gcube.application.geoportal.model.LayerDescriptor</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:derby:sample;create=true"/>
<property name="javax.persistence.jdbc.user" value="user"/>
<property name="javax.persistence.jdbc.password" value="xxxx"/>
<property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:unit-testing-geona;create=true"/>
<!-- <property name="javax.persistence.jdbc.user" value="user"/>
<property name="javax.persistence.jdbc.password" value="xxxx"/> -->
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
<property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>
<property name="eclipselink.logging.logger" value="org.eclipse.persistence.logging.DefaultSessionLog"/>
<property name="eclipselink.logging.level" value="INFO"/>
</properties>
</persistence-unit>
</persistence-unit>
</persistence>