Skip to content

Commit

Permalink
feat(jans-orm): update Couchbase ORM to use SDK 3.x #1851 (#1852)
Browse files Browse the repository at this point in the history
* chore: fix license type

* feat: add more spaner ORM samples and tests

* fix: fix NPE when table is not exists

* fix: fix empty string check if object is null

* feat: security provider utils

* feat: improve cert loading based on activated security provider

* feat: add more SQL samples and tests

* feat: allow to check is SQL attribute type is JSON

* fix: fix SQL last result set close on pagination

* feat: update Couchbase ORM to use SDK 3.x

* feat: update Couchbase sample code

* chore: remove unused libraries

* chore: re-add missing libs

* chore: use latest CB SDK
  • Loading branch information
yurem authored Jul 22, 2022
1 parent 47ba8b9 commit d9d5157
Show file tree
Hide file tree
Showing 152 changed files with 2,560 additions and 1,210 deletions.
4 changes: 2 additions & 2 deletions jans-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@
<dependency>
<groupId>com.couchbase.client</groupId>
<artifactId>java-client</artifactId>
<version>2.7.22</version>
<version>3.3.2</version>
</dependency>

<!-- SQL JDBC Drivers -->
Expand Down Expand Up @@ -744,7 +744,7 @@
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>4.2</version>
<version>4.3</version>
</dependency>

<!-- Cloud Spanner -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import io.jans.model.SimpleCustomProperty;
import io.jans.model.custom.script.type.BaseExternalType;
import io.jans.orm.exception.extension.PersistenceExtension;
import io.jans.orm.extension.PersistenceExtension;

/**
* Base interface for persistence script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.jans.model.custom.script.conf.CustomScriptConfiguration;
import io.jans.model.custom.script.type.persistence.PersistenceType;
import io.jans.orm.PersistenceEntryManager;
import io.jans.orm.exception.extension.PersistenceExtension;
import io.jans.orm.extension.PersistenceExtension;
import io.jans.service.custom.script.ExternalScriptService;

/**
Expand Down
1 change: 1 addition & 0 deletions jans-orm/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Eclipse project files
.dbeaver
.settings
.project
.classpath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
import jakarta.persistence.criteria.CriteriaUpdate;
import jakarta.persistence.metamodel.Metamodel;
import io.jans.orm.event.DeleteNotifier;
import io.jans.orm.exception.extension.PersistenceExtension;
import io.jans.orm.extension.PersistenceExtension;
import io.jans.orm.model.AttributeData;
import io.jans.orm.model.AttributeType;
import io.jans.orm.model.BatchOperation;
import io.jans.orm.model.PagedResult;
import io.jans.orm.model.SearchScope;
Expand Down Expand Up @@ -94,6 +95,7 @@ <T> PagedResult<T> findPagedEntries(String primaryKey, Class<T> entryClass, Filt

@Deprecated
void remove(String dn);
<T> void removeByDn(String dn, String[] objectClasses);
<T> void remove(String primaryKey, Class<T> entryClass);

<T> int remove(String primaryKey, Class<T> entryClass, Filter filter, int count);
Expand All @@ -102,6 +104,7 @@ <T> PagedResult<T> findPagedEntries(String primaryKey, Class<T> entryClass, Filt
void removeRecursively(String primaryKey);

<T> void removeRecursively(String primaryKey, Class<T> entryClass);
<T> void removeRecursivelyFromDn(String primaryKey, String[] objectClasses);

boolean hasBranchesSupport(String primaryKey);
boolean hasExpirationSupport(String primaryKey);
Expand All @@ -126,7 +129,7 @@ <T> Map<T, List<T>> groupListByProperties(Class<T> entryClass, List<T> entries,
@Deprecated
List<AttributeData> exportEntry(String dn);

List<AttributeData> exportEntry(String dn, String objectClass);
<T> List<AttributeData> exportEntry(String dn, String objectClass);

<T> void importEntry(String dn, Class<T> entryClass, List<AttributeData> data);

Expand All @@ -135,6 +138,8 @@ <T> Map<T, List<T>> groupListByProperties(Class<T> entryClass, List<T> entries,

void setPersistenceExtension(PersistenceExtension persistenceExtension);

<T> AttributeType getAttributeType(String primaryKey, Class<T> entryClass, String propertyName);

boolean destroy();

default void clear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright (c) 2020, Janssen Project
*/

package io.jans.orm.exception.extension;
package io.jans.orm.extension;

/**
* Base interface for persistence script
Expand Down
66 changes: 47 additions & 19 deletions jans-orm/core/src/main/java/io/jans/orm/impl/BaseEntryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,52 @@

package io.jans.orm.impl;

import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.databind.ObjectMapper;

import io.jans.orm.PersistenceEntryManager;
import io.jans.orm.annotation.*;
import io.jans.orm.annotation.AttributeEnum;
import io.jans.orm.annotation.AttributeName;
import io.jans.orm.annotation.AttributesList;
import io.jans.orm.annotation.CustomObjectClass;
import io.jans.orm.annotation.DN;
import io.jans.orm.annotation.DataEntry;
import io.jans.orm.annotation.Expiration;
import io.jans.orm.annotation.JsonObject;
import io.jans.orm.annotation.LanguageTag;
import io.jans.orm.annotation.ObjectClass;
import io.jans.orm.annotation.SchemaEntry;
import io.jans.orm.exception.EntryPersistenceException;
import io.jans.orm.exception.InvalidArgumentException;
import io.jans.orm.exception.MappingException;
import io.jans.orm.exception.extension.PersistenceExtension;
import io.jans.orm.extension.PersistenceExtension;
import io.jans.orm.model.AttributeData;
import io.jans.orm.model.AttributeDataModification;
import io.jans.orm.model.AttributeDataModification.AttributeModificationType;
import io.jans.orm.model.AttributeType;
import io.jans.orm.model.SearchScope;
import io.jans.orm.model.base.LocalizedString;
import io.jans.orm.model.AttributeDataModification.AttributeModificationType;
import io.jans.orm.operation.PersistenceOperationService;
import io.jans.orm.reflect.property.Getter;
import io.jans.orm.reflect.property.PropertyAnnotation;
Expand All @@ -26,24 +60,13 @@
import io.jans.orm.search.filter.Filter;
import io.jans.orm.util.ArrayHelper;
import io.jans.orm.util.StringHelper;
import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;

/**
* Abstract Entry Manager
*
* @author Yuriy Movchan
* @version April 25, 2022
* @author Yuriy Movchan Date: 10.07.2010
*/
public abstract class BaseEntryManager implements PersistenceEntryManager {
public abstract class BaseEntryManager<O extends PersistenceOperationService> implements PersistenceEntryManager {

private static final Logger LOG = LoggerFactory.getLogger(BaseEntryManager.class);

Expand Down Expand Up @@ -80,7 +103,7 @@ public abstract class BaseEntryManager implements PersistenceEntryManager {

protected static final int DEFAULT_PAGINATION_SIZE = 100;

protected PersistenceOperationService operationService = null;
protected O operationService = null;
protected PersistenceExtension persistenceExtension = null;

@Override
Expand Down Expand Up @@ -447,7 +470,7 @@ protected boolean isEmptyAttributeValues(AttributeData attributeData) {

protected abstract void merge(String dn, String[] objectClasses, List<AttributeDataModification> attributeDataModifications, Integer expiration);

protected abstract <T> void removeByDn(String dn, String[] objectClasses);
public abstract <T> void removeByDn(String dn, String[] objectClasses);

@Deprecated
public void remove(String primaryKey) {
Expand All @@ -467,7 +490,7 @@ public <T> void remove(String primaryKey, Class<T> entryClass) {
removeByDn(primaryKey, objectClasses);
}

protected abstract <T> void removeRecursivelyFromDn(String primaryKey, String[] objectClasses);
public abstract <T> void removeRecursivelyFromDn(String primaryKey, String[] objectClasses);

@Deprecated
public void removeRecursively(String primaryKey) {
Expand Down Expand Up @@ -2226,6 +2249,11 @@ public void setPersistenceExtension(PersistenceExtension persistenceExtension) {
}
}

@Override
public <T> AttributeType getAttributeType(String primaryKey, Class<T> entryClass, String propertyName) {
throw new UnsupportedOperationException("Method not implemented.");
}

protected static final class PropertyComparator<T> implements Comparator<T>, Serializable {

private static final long serialVersionUID = 574848841116711467L;
Expand Down
46 changes: 46 additions & 0 deletions jans-orm/core/src/main/java/io/jans/orm/model/AttributeType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Janssen Project software is available under the Apache License (2004). See http://www.apache.org/licenses/ for full text.
*
* Copyright (c) 2020, Janssen Project
*/

package io.jans.orm.model;

/**
* DB Attribute Type
*
* @author Yuriy Movchan Date: 07/04/2022
*/
public class AttributeType {
private final String name;
private final String type;
private final Boolean multiValued;

public AttributeType(String name, String type) {
this(name, type, null);
}

public AttributeType(String name, String type, Boolean multiValued) {
this.name = name;
this.type = type;
this.multiValued = multiValued;
}

public Boolean getMultiValued() {
return multiValued;
}

public String getName() {
return name;
}

public String getType() {
return type;
}

@Override
public String toString() {
return "AttributeType [name=" + name + ", type=" + type + ", multiValued=" + multiValued + "]";
}

}
12 changes: 12 additions & 0 deletions jans-orm/core/src/main/java/io/jans/orm/model/Sort.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ public SortOrder getSortOrder() {
return sortOrder;
}

public static Sort desc(String name) {
return new Sort(name, SortOrder.DESCENDING);
}

public static Sort asc(String name) {
return new Sort(name, SortOrder.ASCENDING);
}

public static Sort def(String name) {
return new Sort(name, SortOrder.DEFAULT);
}

@Override
public int hashCode() {
final int prime = 31;
Expand Down
17 changes: 13 additions & 4 deletions jans-orm/core/src/main/java/io/jans/orm/model/SortOrder.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@
import io.jans.orm.annotation.AttributeEnum;

/**
* @author Val Pecaoco
* Sort order
*
* @author Yuriy Movchan Date: 04/22/2021
*/
public enum SortOrder implements AttributeEnum {

ASCENDING("ascending"),
DESCENDING("descending");
ASCENDING("ascending", "asc"),
DESCENDING("descending", "desc"),
DEFAULT("default", "def");

private String value;
private String shortValue;

private static Map<String, SortOrder> MAP_BY_VALUES = new HashMap<String, SortOrder>();

Expand All @@ -29,15 +33,20 @@ public enum SortOrder implements AttributeEnum {
}
}

SortOrder(String value) {
SortOrder(String value, String shortValue) {
this.value = value;
this.shortValue = shortValue;
}

@Override
public String getValue() {
return value;
}

public String getShortValue() {
return shortValue;
}

public static SortOrder getByValue(String value) {
return MAP_BY_VALUES.get(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
package io.jans.orm.operation;

import io.jans.orm.exception.AuthenticationException;
import io.jans.orm.exception.extension.PersistenceExtension;
import io.jans.orm.exception.operation.ConnectionException;
import io.jans.orm.exception.operation.EntryConvertationException;
import io.jans.orm.exception.operation.SearchException;
import io.jans.orm.extension.PersistenceExtension;

/**
* Base interface for Operation Service
Expand Down
Loading

0 comments on commit d9d5157

Please sign in to comment.