Skip to content

Commit

Permalink
First step in chaning lib-psql into new cursor model.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Lowey-Weber authored and Alexander Lowey-Weber committed Nov 17, 2023
1 parent d95b488 commit 7466ec3
Show file tree
Hide file tree
Showing 88 changed files with 4,415 additions and 2,088 deletions.
267 changes: 83 additions & 184 deletions docs/diagrams/architecture.drawio

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package com.here.naksha.lib.core.exceptions;

import com.here.naksha.lib.core.models.storage.Result;
import com.here.naksha.lib.core.models.storage.ResultCursor;
import org.jetbrains.annotations.NotNull;

/**
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import com.here.naksha.lib.core.util.json.JsonSerializable;

/**
* An base interface to be implemented by all types that are serializable and have a property "type" that holds the type of the object.
* A base interface to be implemented by all types that are serializable and have a property "type" that holds the type of the object.
*/
@JsonTypeInfo(use = Id.NAME, property = "type")
@JsonSubTypes({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public static MultiPolygonCoordinates createMultiPolygonCoordinates(MultiPolygon
}

@SuppressWarnings("unchecked")
public static <X extends XyzGeometry> X fromGeometry(Geometry jtsGeometry) {
public static <X extends XyzGeometry> @Nullable X fromGeometry(@Nullable Geometry jtsGeometry) {
if (jtsGeometry == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
*/
package com.here.naksha.lib.core.models.naksha;

import static com.here.naksha.lib.core.exceptions.UncheckedException.unchecked;
import static com.here.naksha.lib.core.models.PluginCache.getEventHandlerConstructor;

import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.here.naksha.lib.core.IEventHandler;
import com.here.naksha.lib.core.INaksha;
import com.here.naksha.lib.core.NakshaVersion;
import com.here.naksha.lib.core.lambdas.Fe3;
import com.here.naksha.lib.core.models.PluginCache;
import org.jetbrains.annotations.ApiStatus.AvailableSince;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -93,15 +97,37 @@ public void setExtensionId(@Nullable String extensionId) {
this.extensionId = extensionId;
}

/**
* Do not use anymore, please call {@link PluginCache#getEventHandlerConstructor(String, Class, Class)} and create the instance yourself.
*/
@Deprecated
@AvailableSince(NakshaVersion.v2_0_7)
@Override
public @NotNull IEventHandler newInstance(@NotNull INaksha naksha) {
return PluginCache.newInstance(getClassName(), IEventHandler.class, this, naksha);
final Fe3<IEventHandler, INaksha, EventHandler, Space> constructor =
getEventHandlerConstructor(getClassName(), EventHandler.class, Space.class);
try {
return constructor.call(naksha, this, null);
} catch (Exception e) {
throw unchecked(e);
}
}

/**
* Do not use anymore, please call {@link PluginCache#getEventHandlerConstructor(String, Class, Class)} and create the instance yourself.
*/
@Deprecated
@AvailableSince(NakshaVersion.v2_0_7)
public @NotNull IEventHandler newInstance(@NotNull INaksha naksha, @NotNull EventTarget<?> eventTarget) {
return PluginCache.newInstance(getClassName(), IEventHandler.class, this, naksha, eventTarget);
//noinspection unchecked
final Fe3<IEventHandler, INaksha, EventHandler, EventTarget<?>> constructor =
(Fe3<IEventHandler, INaksha, EventHandler, EventTarget<?>>)
getEventHandlerConstructor(getClassName(), EventHandler.class, eventTarget.getClass());
try {
return constructor.call(naksha, this, eventTarget);
} catch (Exception e) {
throw unchecked(e);
}
}

@AvailableSince(NakshaVersion.v2_0_7)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
*/
package com.here.naksha.lib.core.models.naksha;

import static com.here.naksha.lib.core.exceptions.UncheckedException.unchecked;
import static com.here.naksha.lib.core.models.PluginCache.getStorageConstructor;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.here.naksha.lib.core.INaksha;
import com.here.naksha.lib.core.NakshaVersion;
import com.here.naksha.lib.core.lambdas.Fe1;
import com.here.naksha.lib.core.models.PluginCache;
import com.here.naksha.lib.core.storage.IStorage;
import org.jetbrains.annotations.ApiStatus.AvailableSince;
Expand Down Expand Up @@ -71,15 +75,18 @@ public Storage(@JsonProperty(CLASS_NAME) @NotNull String className, @JsonPropert
private long number;

/**
* Initialize the storage engine, invoked from the Naksha-Hub when creating a new instance of the storage. This should ensure that the
* storage is accessible and in a good state. If the method fails, it is invoked again after a couple of minutes. This method is invoked
* at least ones for every service start and therefore must be concurrency safe, because it may be called in parallel by multiple
* Naksha-Hub instances.
* Do not use anymore, please call {@link PluginCache#getStorageConstructor(String, Class)} and create the instance yourself.
*/
@Deprecated
@Override
public @NotNull IStorage newInstance(@NotNull INaksha naksha) {
// TODO: Keep storage engines in memory and only instantiate the same storage ones!
return PluginCache.newInstance(className, IStorage.class, this, naksha);
Fe1<IStorage, Storage> constructor =
getStorageConstructor("com.here.naksha.lib.psql.PsqlStorage", Storage.class);
try {
return constructor.call(null);
} catch (Exception e) {
throw unchecked(e);
}
}

@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class XyzCollection extends NakshaFeature {
public static final String PARTITION_COUNT = "partitionCount";

/**
* Create a new empty collection with default properties.
* Create a new empty default collection with default properties.
*
* @param id The identifier of the collection.
*/
Expand All @@ -84,7 +84,7 @@ public XyzCollection(@JsonProperty(ID) @NotNull String id) {
* @param partition If the collection should be partitioned for better performance to improve bulk operations.
* @param pointsOnly If only points will be stored in the collection, which allows to use different indexing, and to reduce the storage
* space consumed.
* @param unlogged If the collection should be unlogged, this makes it not crash-safe, but much faster.
* @param unlogged If the collection should be unlogged, this makes it not crash-safe, but much faster.
*/
@AvailableSince(NakshaVersion.v2_0_7)
public XyzCollection(@NotNull String id, boolean partition, boolean pointsOnly, boolean unlogged) {
Expand Down Expand Up @@ -157,10 +157,22 @@ public boolean pointsOnly() {
* @return {@code true} if this collection is unlogged (optimized for performance); {@code false} otherwise, which means that it may come
* to data loss, if the database crashes while writing to it.
*/
public boolean unlogged() {
public boolean isUnlogged() {
return unlogged;
}

/**
* Changes the unlogged state.
*
* @param unlogged {@code true} if this collection should become unlogged (optimized for performance, but not crash safe).
* @return The previous log-state.
*/
public boolean setUnlogged(boolean unlogged) {
final boolean old = this.unlogged;
this.unlogged = unlogged;
return old;
}

/**
* If the partition should be unlogged, so not crash safe (improves the performance).
*/
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
package com.here.naksha.lib.core.models.storage;

import com.here.naksha.lib.core.NakshaVersion;
import com.here.naksha.lib.core.util.json.JsonEnum;
import org.jetbrains.annotations.ApiStatus.AvailableSince;

/**
* The operation that was actually executed.
*/
@SuppressWarnings("unused")
@AvailableSince(NakshaVersion.v2_0_7)
public class EExecutedOp extends JsonEnum {
public class EExecutedOp extends EStorageOp {

/**
* A read operation was executed.
*/
Expand All @@ -38,7 +38,7 @@ public class EExecutedOp extends JsonEnum {
* A write operation was performed, but the existing state was retained.
*/
@AvailableSince(NakshaVersion.v2_0_7)
public static final EExecutedOp RETAIN = def(EExecutedOp.class, "RETAIN");
public static final EExecutedOp RETAINED = def(EExecutedOp.class, "RETAINED");

/**
* A new feature was created.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2017-2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* License-Filename: LICENSE
*/
package com.here.naksha.lib.core.models.storage;

import com.here.naksha.lib.core.util.json.JsonEnum;

/**
* All operations supported by storages.
*/
public class EStorageOp extends JsonEnum {

/**
* A constant for {@code null}.
*/
public static final EStorageOp NULL = def(EStorageOp.class, null);

@Override
protected void init() {
register(EStorageOp.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@
package com.here.naksha.lib.core.models.storage;

import com.here.naksha.lib.core.NakshaVersion;
import com.here.naksha.lib.core.util.json.JsonEnum;
import org.jetbrains.annotations.ApiStatus.AvailableSince;
import org.jetbrains.annotations.NotNull;

/**
* The write operation to perform.
* The write operations that can be performed.
*/
@SuppressWarnings("unused")
@AvailableSince(NakshaVersion.v2_0_7)
public class EWriteOp extends JsonEnum {
public class EWriteOp extends EStorageOp {

/**
* Create a new feature or collection. Fails if the feature or collection exist.
Expand Down
Loading

0 comments on commit 7466ec3

Please sign in to comment.