mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-04-25 17:07:26 -04:00
Rework many parts and move some components into the core module
This commit is contained in:
@@ -64,7 +64,12 @@ public class SimpleTupleNode extends TupleNode {
|
||||
|
||||
@Override
|
||||
public DataStructureNode forKey(String name) {
|
||||
return nodes.get(names.indexOf(name));
|
||||
var index = names.indexOf(name);
|
||||
if (index == -1) {
|
||||
throw new IllegalArgumentException("Key " + name + " not found");
|
||||
}
|
||||
|
||||
return nodes.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,5 +10,7 @@ public interface DataSourceDescriptor<DS extends DataStore> {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
DataSourceInfo determineInfo(DS store) throws Exception;
|
||||
|
||||
DataSourceType getType();
|
||||
}
|
||||
|
||||
@@ -87,6 +87,6 @@ public class DataSourceId {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return collectionName + SEPARATOR + entryName;
|
||||
return (collectionName != null ? collectionName : "") + SEPARATOR + entryName;
|
||||
}
|
||||
}
|
||||
|
||||
41
core/src/main/java/io/xpipe/core/source/DataSourceInfo.java
Normal file
41
core/src/main/java/io/xpipe/core/source/DataSourceInfo.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package io.xpipe.core.source;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import io.xpipe.core.data.type.TupleType;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Value;
|
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
|
||||
public abstract class DataSourceInfo {
|
||||
|
||||
public abstract DataSourceType getType();
|
||||
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Value
|
||||
@JsonTypeName("table")
|
||||
public static class Table extends DataSourceInfo {
|
||||
TupleType dataType;
|
||||
int rowCount;
|
||||
|
||||
@JsonCreator
|
||||
public Table(TupleType dataType, int rowCount) {
|
||||
this.dataType = dataType;
|
||||
this.rowCount = rowCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSourceType getType() {
|
||||
return DataSourceType.TABLE;
|
||||
}
|
||||
}
|
||||
|
||||
public Table asTable() {
|
||||
if (!getType().equals(DataSourceType.TABLE)) {
|
||||
throw new IllegalStateException("Not a table");
|
||||
}
|
||||
|
||||
return (Table) this;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,11 @@ import java.util.Optional;
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
|
||||
public interface DataStore {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default <DS extends DataStore> DS asNeeded() {
|
||||
return (DS) this;
|
||||
}
|
||||
|
||||
default Optional<String> determineDefaultName() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.xpipe.core.util;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
@@ -12,6 +11,7 @@ import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import io.xpipe.core.data.type.ArrayType;
|
||||
import io.xpipe.core.data.type.TupleType;
|
||||
import io.xpipe.core.data.type.ValueType;
|
||||
import io.xpipe.core.source.DataSourceInfo;
|
||||
import io.xpipe.core.store.LocalFileDataStore;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -26,7 +26,8 @@ public class CoreJacksonModule extends SimpleModule {
|
||||
new NamedType(LocalFileDataStore.class),
|
||||
new NamedType(ValueType.class),
|
||||
new NamedType(TupleType.class),
|
||||
new NamedType(ArrayType.class)
|
||||
new NamedType(ArrayType.class),
|
||||
new NamedType(DataSourceInfo.Table.class)
|
||||
);
|
||||
|
||||
addSerializer(Charset.class, new CharsetSerializer());
|
||||
|
||||
Reference in New Issue
Block a user