Skip to content

Commit

Permalink
#128: jdk11: major changes in persistence - WIP
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/services/core/persistence/pom.xml
#	src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GFUserDAOImpl.java
#	src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GSInstanceDAOImpl.java
#	src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GSUserDAOImpl.java
#	src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/LayerDetailsDAOImpl.java
#	src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/UserGroupDAOImpl.java
#	src/services/core/persistence/src/test/java/org/geoserver/geofence/core/dao/RuleDAOTest.java
#	src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/RuleReaderServiceImpl.java
#	src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/util/FilterUtils.java
#	src/services/core/webtest/pom.xml
#	src/services/modules/ldap/pom.xml
#	src/services/modules/rest/impl/src/main/java/org/geoserver/geofence/services/rest/utils/MultiPolygonUtils.java
#	src/services/modules/rest/test/pom.xml
#	src/services/pom.xml
  • Loading branch information
etj committed Mar 1, 2024
1 parent 584b20f commit e31a126
Show file tree
Hide file tree
Showing 38 changed files with 864 additions and 355 deletions.
7 changes: 7 additions & 0 deletions src/services/core/model-external/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@
<include name="**/*.java"/>
</fileset>
</replaceregexp>

<replaceregexp byline="true" replace="">
<regexp pattern="(@ElementCollection).*"/>
<fileset dir="${project.build.directory}/generated-sources/original">
<include name="**/*.java"/>
</fileset>
</replaceregexp>

<replaceregexp byline="true" replace="">
<regexp pattern="(@Id|@GeneratedValue|@Enumerated|@Column|@Type|@Temporal|@OneToOne|@ManyToOne|@ManyToMany|@ForeignKey|@UniqueConstraint|@AttributeOverride|@JoinTable).*"/>
Expand Down
5 changes: 5 additions & 0 deletions src/services/core/model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</dependency>
<!-- <dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>-->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
Expand Down Expand Up @@ -49,7 +50,7 @@
@Table(name = "gf_layer_details")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "LayerDetails")
@XmlRootElement(name = "LayerDetails")
public class LayerDetails implements Serializable {
public class LayerDetails implements Identifiable, Serializable {

private static final long serialVersionUID = -4150963895550551513L;

Expand All @@ -72,7 +73,7 @@ public class LayerDetails implements Serializable {
@Column(length=4000)
private String cqlFilterWrite;

@Type(type = "org.hibernatespatial.GeometryUserType")
// @Type(type = "org.hibernate.spatial.JTSGeometryType")
@Column(name = "area")
private MultiPolygon area;

Expand All @@ -90,23 +91,23 @@ public class LayerDetails implements Serializable {
private Rule rule;

/** Styles allowed for this layer */
@org.hibernate.annotations.CollectionOfElements(fetch=FetchType.EAGER)
@ElementCollection(fetch=FetchType.EAGER)
@JoinTable( name = "gf_layer_styles", joinColumns = @JoinColumn(name = "details_id"))
@ForeignKey(name="fk_styles_layer")
@Column(name="styleName")
private Set<String> allowedStyles = new HashSet<String>();
private Set<String> allowedStyles = new HashSet<>();

/** Feature Attributes associated to the Layer
* <P>We'll use the pair <TT>(details_id, name)</TT> as PK for the associated table.
* To do so, we have to perform some trick on the <TT>{@link LayerAttribute#access}</TT> field.
*/
@org.hibernate.annotations.CollectionOfElements(fetch=FetchType.EAGER)
@ElementCollection(fetch=FetchType.EAGER)
@JoinTable( name = "gf_layer_attributes", joinColumns = @JoinColumn(name = "details_id"), uniqueConstraints = @UniqueConstraint(columnNames={"details_id", "name"}))
// override is used to set the pk as {"details_id", "name"}
// @AttributeOverride( name="access", column=@Column(name="access", nullable=false) )
@ForeignKey(name="fk_attribute_layer")
@Fetch(FetchMode.SELECT) // without this, hibernate will duplicate results(!)
private Set<LayerAttribute> attributes = new HashSet<LayerAttribute>();
private Set<LayerAttribute> attributes = new HashSet<>();

@XmlJavaTypeAdapter(MultiPolygonAdapter.class)
public MultiPolygon getArea() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
@Table(name = "gf_rule_limits", uniqueConstraints = @UniqueConstraint(columnNames = "rule_id"))
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "RuleLimits")
@XmlRootElement(name = "RuleLimits")
public class RuleLimits implements Serializable {
public class RuleLimits implements Identifiable, Serializable {

private static final long serialVersionUID = 2829839552804345725L;

Expand All @@ -56,7 +56,7 @@ public class RuleLimits implements Serializable {
@ForeignKey(name = "fk_limits_rule")
private Rule rule;

@Type(type = "org.hibernatespatial.GeometryUserType")
//@Type(type = "org.hibernate.spatial.JTSGeometryType")
@Column(name = "area")
private MultiPolygon allowedArea;

Expand Down
78 changes: 51 additions & 27 deletions src/services/core/persistence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,36 +98,36 @@
<artifactId>spring-jdbc</artifactId>
</dependency>

<!-- =========================================================== -->
<!-- Persistence libs -->
<!-- =========================================================== -->
<!-- =========================================================== -->
<!-- Persistence libs -->
<!-- =========================================================== -->


<!-- HIBERNATE-GENERIC-DAO -->
<dependency>
<!-- HIBERNATE-GENERIC-DAO -->
<!-- <dependency>
<groupId>com.googlecode.genericdao</groupId>
<artifactId>dao</artifactId>
<!-- JPA1 dependency will excluded by exclusions in depenendency management -->
JPA1 dependency will excluded by exclusions in depenendency management
</dependency>
<dependency>
<groupId>com.googlecode.genericdao</groupId>
<artifactId>search-jpa-hibernate</artifactId>
</dependency>
</dependency>-->

<!-- -->
<!-- -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
</dependency>

<dependency>
<!-- <dependency>
<groupId>org.hibernatespatial</groupId>
<artifactId>hibernate-spatial-h2-geodb</artifactId>
<scope>test</scope>
</dependency>
</dependency>-->

<dependency>
<groupId>org.hibernatespatial</groupId>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
</dependency>

Expand All @@ -152,23 +152,30 @@

<!-- =========================================================== -->

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>

<!-- =========================================================== -->
<!-- Hibernate -->
<!-- =========================================================== -->
<!-- =========================================================== -->
<!-- Hibernate -->
<!-- =========================================================== -->

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jcache</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.ehcache/ehcache -->
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.8.1</version>
</dependency>


<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<artifactId>hibernate-core</artifactId>
<exclusions>
<exclusion>
<groupId>asm</groupId>
Expand All @@ -185,14 +192,14 @@
</exclusions>
</dependency>

<!-- CGLIB -->
<!-- CGLIB -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
</dependency>

<!-- HTTP UTILS -->
<!-- <dependency>
<!-- HTTP UTILS -->
<!-- <dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
</dependency> -->
Expand All @@ -205,13 +212,21 @@
<artifactId>aspectjweaver</artifactId>
</dependency>

<!-- JUnit -->
<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.26</version>
<scope>test</scope>
</dependency>


</dependencies>

<build>
Expand Down Expand Up @@ -276,6 +291,15 @@
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<!--<version></version>-->
<configuration>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>

</plugins>

</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

package org.geoserver.geofence.core.dao;

import org.geoserver.geofence.core.dao.search.Search;
import java.util.List;

import com.googlecode.genericdao.search.ISearch;
import org.geoserver.geofence.core.model.Identifiable;

/**
* Public interface to define a restricted set of operation wrt to ones
Expand All @@ -20,12 +20,15 @@

public interface RestrictedGenericDAO<ENTITY> /* extends GenericDAO<ENTITY, Long> */{

public Search createSearch();
public Search createCountSearch();

public List<ENTITY> findAll();
public ENTITY find(Long id);
public void persist(ENTITY... entities);
public ENTITY merge(ENTITY entity);
public boolean remove(ENTITY entity);
public void remove(ENTITY entity);
public boolean removeById(Long id);
public List<ENTITY> search(ISearch search);
public int count(ISearch search);
public List<ENTITY> search(Search search);
public long count(Search search);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@

import java.util.List;

import com.googlecode.genericdao.search.ISearch;
import com.googlecode.genericdao.search.Search;

import static org.geoserver.geofence.core.dao.util.SearchUtil.*;
import static org.geoserver.geofence.core.dao.search.SearchUtil.*;

import org.geoserver.geofence.core.model.enums.InsertPosition;
import org.geoserver.geofence.core.dao.AdminRuleDAO;
import org.geoserver.geofence.core.dao.DuplicateKeyException;
import org.geoserver.geofence.core.dao.search.Search;
import org.geoserver.geofence.core.model.AdminRule;

import org.apache.logging.log4j.LogManager;
Expand All @@ -28,10 +26,17 @@
* @author Emanuele Tajariol (etj at geo-solutions.it)
*/
@Transactional(value = "geofenceTransactionManager")
public class AdminRuleDAOImpl extends PrioritizableDAOImpl<AdminRule> implements AdminRuleDAO {
public class AdminRuleDAOImpl
extends PrioritizableDAOImpl<AdminRule>
implements AdminRuleDAO {

// public class RuleDAOImpl extends PrioritizableDAOImpl<Rule> implements RuleDAO {
private static final Logger LOGGER = LogManager.getLogger(AdminRuleDAOImpl.class);

public AdminRuleDAOImpl() {
super(AdminRule.class);
}

@Override
public void persist(AdminRule... entities) {

Expand Down Expand Up @@ -77,7 +82,7 @@ public void persistInternal(AdminRule entity) {
}

protected Search getDupSearch(AdminRule rule) {
Search search = new Search(AdminRule.class);
Search search = createSearch();
addSearchField(search, "username", rule.getUsername());
addSearchField(search, "rolename", rule.getRolename());
addSearchField(search, "instance", rule.getInstance());
Expand All @@ -94,7 +99,7 @@ public List<AdminRule> findAll() {
}

@Override
public List<AdminRule> search(ISearch search) {
public List<AdminRule> search(Search search) {
return super.search(search);
}

Expand Down Expand Up @@ -123,8 +128,8 @@ public AdminRule merge(AdminRule entity) {
}

@Override
public boolean remove(AdminRule entity) {
return super.remove(entity);
public void remove(AdminRule entity) {
super.remove(entity);
}

@Override
Expand Down
Loading

0 comments on commit e31a126

Please sign in to comment.