Rework many parts and move some components into the core module

This commit is contained in:
Christopher Schnick
2022-01-08 04:30:16 +01:00
parent e5a84a83db
commit b192fd5b09
29 changed files with 644 additions and 67 deletions

View File

@@ -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

View File

@@ -10,5 +10,7 @@ public interface DataSourceDescriptor<DS extends DataStore> {
return Optional.empty();
}
DataSourceInfo determineInfo(DS store) throws Exception;
DataSourceType getType();
}

View File

@@ -87,6 +87,6 @@ public class DataSourceId {
@Override
public String toString() {
return collectionName + SEPARATOR + entryName;
return (collectionName != null ? collectionName : "") + SEPARATOR + entryName;
}
}

View 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;
}
}

View File

@@ -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();
}

View File

@@ -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());