-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rather than composing string for postgres, we pass composite key from businnes layer
- Loading branch information
Showing
34 changed files
with
310 additions
and
357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...rage-common/src/main/java/org/kie/kogito/index/storage/ModelProcessDefinitionStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
package org.kie.kogito.index.storage; | ||
|
||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.stream.Collectors; | ||
|
||
import org.kie.kogito.index.model.ProcessDefinition; | ||
import org.kie.kogito.index.model.ProcessDefinitionKey; | ||
import org.kie.kogito.persistence.api.Storage; | ||
|
||
public class ModelProcessDefinitionStorage extends ModelStorageFetcher<ProcessDefinitionKey, ProcessDefinition> implements Storage<ProcessDefinitionKey, ProcessDefinition> { | ||
|
||
private static final String VERSION_SEPARATOR = "$v:"; | ||
|
||
static ProcessDefinitionKey fromString(String key) { | ||
int indexOf = key.indexOf(VERSION_SEPARATOR); | ||
return indexOf == -1 || indexOf + VERSION_SEPARATOR.length() == key.length() ? new ProcessDefinitionKey(key, null) | ||
: new ProcessDefinitionKey(key.substring(0, indexOf), key.substring(indexOf + VERSION_SEPARATOR.length())); | ||
|
||
} | ||
|
||
static String toString(ProcessDefinitionKey key) { | ||
String id = key.getId(); | ||
String version = key.getVersion(); | ||
return version == null ? id : id + VERSION_SEPARATOR + version; | ||
} | ||
|
||
public ModelProcessDefinitionStorage(Storage<String, ProcessDefinition> storage) { | ||
super(storage, ModelProcessDefinitionStorage::toString, ModelProcessDefinitionStorage::fromString); | ||
} | ||
|
||
@Override | ||
public ProcessDefinition put(ProcessDefinitionKey key, ProcessDefinition value) { | ||
return storage.put(toString(key), value); | ||
} | ||
|
||
@Override | ||
public ProcessDefinition remove(ProcessDefinitionKey key) { | ||
return storage.remove(toString(key)); | ||
} | ||
|
||
@Override | ||
public boolean containsKey(ProcessDefinitionKey key) { | ||
return storage.containsKey(toString(key)); | ||
} | ||
|
||
@Override | ||
public Map<ProcessDefinitionKey, ProcessDefinition> entries() { | ||
return storage.entries().entrySet().stream().collect(Collectors.toMap(e -> fromString(e.getKey()), Entry::getValue)); | ||
} | ||
|
||
@Override | ||
public String getRootType() { | ||
return ProcessDefinition.class.getName(); | ||
} | ||
} |
Oops, something went wrong.