From 2c041ecb0e46e00742f2eee3ea13289f531ee10d Mon Sep 17 00:00:00 2001 From: Christopher Schnick Date: Thu, 3 Mar 2022 16:44:14 +0100 Subject: [PATCH] Add more data sources and refactor some parts --- api/src/main/java/io/xpipe/api/DataRaw.java | 16 +++ .../main/java/io/xpipe/api/DataSource.java | 75 ++++++++++-- .../main/java/io/xpipe/api/DataStructure.java | 11 ++ api/src/main/java/io/xpipe/api/DataTable.java | 16 +-- .../io/xpipe/api/DataTableAccumulator.java | 28 +++++ api/src/main/java/io/xpipe/api/DataText.java | 18 +++ .../io/xpipe/api/XPipeClientException.java | 19 --- .../io/xpipe/api/XPipeConnectException.java | 19 --- .../xpipe/api/XPipeDataStructureSource.java | 8 -- .../io/xpipe/api/XPipeDataTableBuilder.java | 12 -- .../java/io/xpipe/api/XPipeException.java | 23 ---- .../io/xpipe/api/XPipeServerException.java | 19 --- .../{ => connector}/XPipeApiConnector.java | 4 +- .../java/io/xpipe/api/impl/DataRawImpl.java | 49 ++++++++ .../io/xpipe/api/impl/DataSourceImpl.java | 27 ++++- .../io/xpipe/api/impl/DataStructureImpl.java | 38 ++++++ .../api/impl/DataTableAccumulatorImpl.java | 30 +++++ .../java/io/xpipe/api/impl/DataTableImpl.java | 36 ++---- .../java/io/xpipe/api/impl/DataTextImpl.java | 60 ++++++++++ api/src/main/java/module-info.java | 1 + .../java/io/xpipe/beacon/BeaconConfig.java | 4 +- ...ange.java => QueryDataSourceExchange.java} | 20 ++-- beacon/src/main/java/module-info.java | 2 +- .../xpipe/core/source/DataSourceConfig.java | 1 - .../io/xpipe/core/source/DataSourceInfo.java | 111 ++++++++++++++++++ .../core/source/DataSourceReference.java | 75 ++++++++++-- .../core/source/TextDataSourceDescriptor.java | 16 +++ .../xpipe/core/source/TextReadConnection.java | 8 ++ .../core/source/TextWriteConnection.java | 8 ++ .../core/test/DataSourceReferenceTest.java | 4 +- extension/build.gradle | 2 + .../SupportedApplicationProvider.java | 9 +- .../java/io/xpipe/extension/Translatable.java | 49 ++++++++ .../io/xpipe/extension/comp/CodeSnippet.java | 4 + .../xpipe/extension/comp/CodeSnippetComp.java | 15 ++- .../io/xpipe/extension/event/TrackEvent.java | 23 ++++ .../extension/prefs/PrefsChoiceValue.java | 14 +++ .../prefs/PrefsChoiceValueModule.java | 51 ++++++++ .../xpipe/extension/prefs/PrefsHandler.java | 10 ++ .../xpipe/extension/prefs/PrefsProvider.java | 6 + .../xpipe/extension/prefs/PrefsProviders.java | 21 ++++ extension/src/main/java/module-info.java | 9 ++ 42 files changed, 775 insertions(+), 196 deletions(-) create mode 100644 api/src/main/java/io/xpipe/api/DataRaw.java create mode 100644 api/src/main/java/io/xpipe/api/DataStructure.java create mode 100644 api/src/main/java/io/xpipe/api/DataTableAccumulator.java create mode 100644 api/src/main/java/io/xpipe/api/DataText.java delete mode 100644 api/src/main/java/io/xpipe/api/XPipeClientException.java delete mode 100644 api/src/main/java/io/xpipe/api/XPipeConnectException.java delete mode 100644 api/src/main/java/io/xpipe/api/XPipeDataStructureSource.java delete mode 100644 api/src/main/java/io/xpipe/api/XPipeDataTableBuilder.java delete mode 100644 api/src/main/java/io/xpipe/api/XPipeException.java delete mode 100644 api/src/main/java/io/xpipe/api/XPipeServerException.java rename api/src/main/java/io/xpipe/api/{ => connector}/XPipeApiConnector.java (96%) create mode 100644 api/src/main/java/io/xpipe/api/impl/DataRawImpl.java create mode 100644 api/src/main/java/io/xpipe/api/impl/DataStructureImpl.java create mode 100644 api/src/main/java/io/xpipe/api/impl/DataTableAccumulatorImpl.java create mode 100644 api/src/main/java/io/xpipe/api/impl/DataTextImpl.java rename beacon/src/main/java/io/xpipe/beacon/exchange/{InfoExchange.java => QueryDataSourceExchange.java} (58%) create mode 100644 core/src/main/java/io/xpipe/core/source/TextDataSourceDescriptor.java create mode 100644 core/src/main/java/io/xpipe/core/source/TextReadConnection.java create mode 100644 core/src/main/java/io/xpipe/core/source/TextWriteConnection.java create mode 100644 extension/src/main/java/io/xpipe/extension/Translatable.java create mode 100644 extension/src/main/java/io/xpipe/extension/prefs/PrefsChoiceValue.java create mode 100644 extension/src/main/java/io/xpipe/extension/prefs/PrefsChoiceValueModule.java create mode 100644 extension/src/main/java/io/xpipe/extension/prefs/PrefsHandler.java create mode 100644 extension/src/main/java/io/xpipe/extension/prefs/PrefsProvider.java create mode 100644 extension/src/main/java/io/xpipe/extension/prefs/PrefsProviders.java diff --git a/api/src/main/java/io/xpipe/api/DataRaw.java b/api/src/main/java/io/xpipe/api/DataRaw.java new file mode 100644 index 000000000..fd6768596 --- /dev/null +++ b/api/src/main/java/io/xpipe/api/DataRaw.java @@ -0,0 +1,16 @@ +package io.xpipe.api; + +import io.xpipe.core.source.DataSourceInfo; + +import java.io.InputStream; + +public interface DataRaw extends DataSource { + + DataSourceInfo.Raw getInfo(); + + InputStream open(); + + byte[] readAll(); + + byte[] read(int maxBytes); +} diff --git a/api/src/main/java/io/xpipe/api/DataSource.java b/api/src/main/java/io/xpipe/api/DataSource.java index 7c2271897..d29368769 100644 --- a/api/src/main/java/io/xpipe/api/DataSource.java +++ b/api/src/main/java/io/xpipe/api/DataSource.java @@ -3,6 +3,7 @@ package io.xpipe.api; import io.xpipe.api.impl.DataSourceImpl; import io.xpipe.core.source.DataSourceConfig; import io.xpipe.core.source.DataSourceId; +import io.xpipe.core.source.DataSourceReference; import io.xpipe.core.source.DataSourceType; import java.io.InputStream; @@ -10,14 +11,22 @@ import java.net.URL; import java.util.Map; /** - * Represents a reference to an XPipe data source. + * Represents a reference to a data source that is managed by X-Pipe. * * The actual data is only queried when required and is not cached. * Therefore, the queried data is always up-to-date at the point of calling a method that queries the data. + * + * As soon a data source reference is created, the data source is locked + * within X-Pipe to prevent concurrent modification and the problems that can arise from it. + * By default, the lock is held until the calling program terminates and prevents + * other applications from modifying the data source in any way. + * To unlock the data source earlier, you can make use the {@link #unlock()} method. */ public interface DataSource { /** + * NOT YET IMPLEMENTED! + * * Creates a new supplier data source that will be interpreted as the generated data source. * In case this program should be a data source generator, this method has to be called at * least once to register that it actually generates a data source. @@ -29,28 +38,49 @@ public interface DataSource { * * @return the generator data source */ + @Deprecated static DataSource supplySource() { return null; } /** - * Wrapper for {@link #get(DataSourceId)}. + * Wrapper for {@link #get(DataSourceReference)}. * * @throws IllegalArgumentException if {@code id} is not a valid data source id */ - static DataSource get(String id) { - return get(DataSourceId.fromString(id)); + static DataSource getById(String id) { + return get(DataSourceReference.id(id)); + } + + /** + * Wrapper for {@link #get(DataSourceReference)} using the latest reference. + */ + static DataSource getLatest() { + return get(DataSourceReference.latest()); + } + + /** + * Wrapper for {@link #get(DataSourceReference)} using a name reference. + */ + static DataSource getByName(String name) { + return get(DataSourceReference.name(name)); } /** * Retrieves a reference to the given data source. * - * @param id the data source id - * @return a reference to the data source that can be used to access the underlying data source + * @param ref the data source reference */ - static DataSource get(DataSourceId id) { - return null; - //return DataSourceImpl.get(id); + static DataSource get(DataSourceReference ref) { + return DataSourceImpl.get(ref); + } + + /** + * Releases the lock held by this program for this data source such + * that other applications can modify the data source again. + */ + static void unlock() { + throw new UnsupportedOperationException(); } static DataSource wrap(InputStream in, String type, Map configOptions) { @@ -110,4 +140,31 @@ public interface DataSource { default DataTable asTable() { throw new UnsupportedOperationException("Data source is not a table"); } + + /** + * Attempts to cast this object to a {@link DataStructure}. + * + * @throws UnsupportedOperationException if the data source is not a structure + */ + default DataStructure asStructure() { + throw new UnsupportedOperationException("Data source is not a structure"); + } + + /** + * Attempts to cast this object to a {@link DataText}. + * + * @throws UnsupportedOperationException if the data source is not a text + */ + default DataText asText() { + throw new UnsupportedOperationException("Data source is not a text"); + } + + /** + * Attempts to cast this object to a {@link DataRaw}. + * + * @throws UnsupportedOperationException if the data source is not raw + */ + default DataRaw asRaw() { + throw new UnsupportedOperationException("Data source is not raw"); + } } diff --git a/api/src/main/java/io/xpipe/api/DataStructure.java b/api/src/main/java/io/xpipe/api/DataStructure.java new file mode 100644 index 000000000..c4b8d8dcc --- /dev/null +++ b/api/src/main/java/io/xpipe/api/DataStructure.java @@ -0,0 +1,11 @@ +package io.xpipe.api; + +import io.xpipe.core.data.node.DataStructureNode; +import io.xpipe.core.source.DataSourceInfo; + +public interface DataStructure extends DataSource { + + DataSourceInfo.Structure getInfo(); + + DataStructureNode read(); +} diff --git a/api/src/main/java/io/xpipe/api/DataTable.java b/api/src/main/java/io/xpipe/api/DataTable.java index 33af114a8..7a3e6df21 100644 --- a/api/src/main/java/io/xpipe/api/DataTable.java +++ b/api/src/main/java/io/xpipe/api/DataTable.java @@ -2,28 +2,16 @@ package io.xpipe.api; import io.xpipe.core.data.node.ArrayNode; import io.xpipe.core.data.node.TupleNode; -import io.xpipe.core.data.type.TupleType; +import io.xpipe.core.source.DataSourceInfo; -import java.util.OptionalInt; import java.util.stream.Stream; public interface DataTable extends Iterable, DataSource { - /** - * @see DataSource#supplySource() - */ - static DataTable supplySource() { - return null; - } + DataSourceInfo.Table getInfo(); Stream stream(); - int getRowCount(); - - OptionalInt getRowCountIfPresent(); - - TupleType getDataType(); - ArrayNode readAll(); ArrayNode read(int maxRows); diff --git a/api/src/main/java/io/xpipe/api/DataTableAccumulator.java b/api/src/main/java/io/xpipe/api/DataTableAccumulator.java new file mode 100644 index 000000000..821f50733 --- /dev/null +++ b/api/src/main/java/io/xpipe/api/DataTableAccumulator.java @@ -0,0 +1,28 @@ +package io.xpipe.api; + +import io.xpipe.core.data.node.DataStructureNodeAcceptor; +import io.xpipe.core.data.node.TupleNode; +import io.xpipe.core.source.DataSourceId; + +/** + * An accumulator for table data. + * + * This class can be used to construct new table data sources by + * accumulating the rows using {@link #add(TupleNode)} or {@link #acceptor()} and then calling + * {@link #finish(DataSourceId)} to complete the construction process and create a new data source. + */ +public interface DataTableAccumulator { + + /** + * Finishes the construction process and returns the data source reference. + * + * @param id the data source id to assign + */ + DataTable finish(DataSourceId id); + + void add(TupleNode row); + + DataStructureNodeAcceptor acceptor(); + + int getCurrentRows(); +} diff --git a/api/src/main/java/io/xpipe/api/DataText.java b/api/src/main/java/io/xpipe/api/DataText.java new file mode 100644 index 000000000..386a4b672 --- /dev/null +++ b/api/src/main/java/io/xpipe/api/DataText.java @@ -0,0 +1,18 @@ +package io.xpipe.api; + +import io.xpipe.core.source.DataSourceInfo; + +import java.util.List; + +public interface DataText extends DataSource, Iterable { + + DataSourceInfo.Text getInfo(); + + List readAllLines(); + + List readLines(int maxLines); + + String readAll(); + + String read(int maxCharacters); +} diff --git a/api/src/main/java/io/xpipe/api/XPipeClientException.java b/api/src/main/java/io/xpipe/api/XPipeClientException.java deleted file mode 100644 index ed376dcff..000000000 --- a/api/src/main/java/io/xpipe/api/XPipeClientException.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.xpipe.api; - -public class XPipeClientException extends RuntimeException { - - public XPipeClientException() { - } - - public XPipeClientException(String message) { - super(message); - } - - public XPipeClientException(String message, Throwable cause) { - super(message, cause); - } - - public XPipeClientException(Throwable cause) { - super(cause); - } -} diff --git a/api/src/main/java/io/xpipe/api/XPipeConnectException.java b/api/src/main/java/io/xpipe/api/XPipeConnectException.java deleted file mode 100644 index 90ed51048..000000000 --- a/api/src/main/java/io/xpipe/api/XPipeConnectException.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.xpipe.api; - -public class XPipeConnectException extends RuntimeException { - - public XPipeConnectException() { - } - - public XPipeConnectException(String message) { - super(message); - } - - public XPipeConnectException(String message, Throwable cause) { - super(message, cause); - } - - public XPipeConnectException(Throwable cause) { - super(cause); - } -} diff --git a/api/src/main/java/io/xpipe/api/XPipeDataStructureSource.java b/api/src/main/java/io/xpipe/api/XPipeDataStructureSource.java deleted file mode 100644 index 6ef52c232..000000000 --- a/api/src/main/java/io/xpipe/api/XPipeDataStructureSource.java +++ /dev/null @@ -1,8 +0,0 @@ -package io.xpipe.api; - -import io.xpipe.core.data.node.DataStructureNode; - -public interface XPipeDataStructureSource { - - DataStructureNode read(); -} diff --git a/api/src/main/java/io/xpipe/api/XPipeDataTableBuilder.java b/api/src/main/java/io/xpipe/api/XPipeDataTableBuilder.java deleted file mode 100644 index 8f99cb962..000000000 --- a/api/src/main/java/io/xpipe/api/XPipeDataTableBuilder.java +++ /dev/null @@ -1,12 +0,0 @@ -package io.xpipe.api; - -import io.xpipe.core.source.DataSourceId; - -public abstract class XPipeDataTableBuilder { - - private DataSourceId id; - - public abstract void write(); - - public abstract void commit(); -} diff --git a/api/src/main/java/io/xpipe/api/XPipeException.java b/api/src/main/java/io/xpipe/api/XPipeException.java deleted file mode 100644 index d5b62bebd..000000000 --- a/api/src/main/java/io/xpipe/api/XPipeException.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.xpipe.api; - -public class XPipeException extends RuntimeException { - - public XPipeException() { - } - - public XPipeException(String message) { - super(message); - } - - public XPipeException(String message, Throwable cause) { - super(message, cause); - } - - public XPipeException(Throwable cause) { - super(cause); - } - - public XPipeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } -} diff --git a/api/src/main/java/io/xpipe/api/XPipeServerException.java b/api/src/main/java/io/xpipe/api/XPipeServerException.java deleted file mode 100644 index 137e5bbbf..000000000 --- a/api/src/main/java/io/xpipe/api/XPipeServerException.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.xpipe.api; - -public class XPipeServerException extends RuntimeException { - - public XPipeServerException() { - } - - public XPipeServerException(String message) { - super(message); - } - - public XPipeServerException(String message, Throwable cause) { - super(message, cause); - } - - public XPipeServerException(Throwable cause) { - super(cause); - } -} diff --git a/api/src/main/java/io/xpipe/api/XPipeApiConnector.java b/api/src/main/java/io/xpipe/api/connector/XPipeApiConnector.java similarity index 96% rename from api/src/main/java/io/xpipe/api/XPipeApiConnector.java rename to api/src/main/java/io/xpipe/api/connector/XPipeApiConnector.java index 1bca846a6..9fc3f4569 100644 --- a/api/src/main/java/io/xpipe/api/XPipeApiConnector.java +++ b/api/src/main/java/io/xpipe/api/connector/XPipeApiConnector.java @@ -1,4 +1,4 @@ -package io.xpipe.api; +package io.xpipe.api.connector; import io.xpipe.beacon.*; import io.xpipe.core.util.JacksonHelper; @@ -12,7 +12,7 @@ public abstract class XPipeApiConnector extends BeaconConnector { var socket = constructSocket(); handle(socket); } catch (Throwable ce) { - throw new XPipeException(ce); + throw new RuntimeException(ce); } } diff --git a/api/src/main/java/io/xpipe/api/impl/DataRawImpl.java b/api/src/main/java/io/xpipe/api/impl/DataRawImpl.java new file mode 100644 index 000000000..abef43fe6 --- /dev/null +++ b/api/src/main/java/io/xpipe/api/impl/DataRawImpl.java @@ -0,0 +1,49 @@ +package io.xpipe.api.impl; + +import io.xpipe.api.DataRaw; +import io.xpipe.core.source.DataSourceConfig; +import io.xpipe.core.source.DataSourceId; +import io.xpipe.core.source.DataSourceInfo; +import io.xpipe.core.source.DataSourceType; + +import java.io.InputStream; + +public class DataRawImpl extends DataSourceImpl implements DataRaw { + + private final DataSourceInfo.Raw info; + + public DataRawImpl(DataSourceId sourceId, DataSourceConfig sourceConfig, DataSourceInfo.Raw info) { + super(sourceId, sourceConfig); + this.info = info; + } + + @Override + public DataSourceInfo.Raw getInfo() { + return info; + } + + @Override + public InputStream open() { + return null; + } + + @Override + public byte[] readAll() { + return new byte[0]; + } + + @Override + public byte[] read(int maxBytes) { + return new byte[0]; + } + + @Override + public DataSourceType getType() { + return DataSourceType.RAW; + } + + @Override + public DataRaw asRaw() { + return this; + } +} diff --git a/api/src/main/java/io/xpipe/api/impl/DataSourceImpl.java b/api/src/main/java/io/xpipe/api/impl/DataSourceImpl.java index bcb709172..570681206 100644 --- a/api/src/main/java/io/xpipe/api/impl/DataSourceImpl.java +++ b/api/src/main/java/io/xpipe/api/impl/DataSourceImpl.java @@ -1,12 +1,12 @@ package io.xpipe.api.impl; import io.xpipe.api.DataSource; -import io.xpipe.api.XPipeApiConnector; +import io.xpipe.api.connector.XPipeApiConnector; import io.xpipe.beacon.BeaconClient; import io.xpipe.beacon.ClientException; import io.xpipe.beacon.ConnectorException; import io.xpipe.beacon.ServerException; -import io.xpipe.beacon.exchange.InfoExchange; +import io.xpipe.beacon.exchange.QueryDataSourceExchange; import io.xpipe.beacon.exchange.StoreResourceExchange; import io.xpipe.beacon.exchange.StoreStreamExchange; import io.xpipe.core.source.DataSourceConfig; @@ -24,9 +24,26 @@ public abstract class DataSourceImpl implements DataSource { new XPipeApiConnector() { @Override protected void handle(BeaconClient sc) throws ClientException, ServerException, ConnectorException { - var req = InfoExchange.Request.builder().ref(ds).build(); - InfoExchange.Response res = performSimpleExchange(sc, req); - + var req = QueryDataSourceExchange.Request.builder().ref(ds).build(); + QueryDataSourceExchange.Response res = performSimpleExchange(sc, req); + switch (res.getInfo().getType()) { + case TABLE -> { + var data = res.getInfo().asTable(); + source[0] = new DataTableImpl(res.getId(), res.getConfig().getConfig(), data); + } + case STRUCTURE -> { + var info = res.getInfo().asStructure(); + source[0] = new DataStructureImpl(res.getId(), res.getConfig().getConfig(), info); + } + case TEXT -> { + var info = res.getInfo().asText(); + source[0] = new DataTextImpl(res.getId(), res.getConfig().getConfig(), info); + } + case RAW -> { + var info = res.getInfo().asRaw(); + source[0] = new DataRawImpl(res.getId(), res.getConfig().getConfig(), info); + } + } } }.execute(); return source[0]; diff --git a/api/src/main/java/io/xpipe/api/impl/DataStructureImpl.java b/api/src/main/java/io/xpipe/api/impl/DataStructureImpl.java new file mode 100644 index 000000000..8e2e624ab --- /dev/null +++ b/api/src/main/java/io/xpipe/api/impl/DataStructureImpl.java @@ -0,0 +1,38 @@ +package io.xpipe.api.impl; + +import io.xpipe.api.DataStructure; +import io.xpipe.core.data.node.DataStructureNode; +import io.xpipe.core.source.DataSourceConfig; +import io.xpipe.core.source.DataSourceId; +import io.xpipe.core.source.DataSourceInfo; +import io.xpipe.core.source.DataSourceType; + +public class DataStructureImpl extends DataSourceImpl implements DataStructure { + + private final DataSourceInfo.Structure info; + + public DataStructureImpl(DataSourceId sourceId, DataSourceConfig sourceConfig, DataSourceInfo.Structure info) { + super(sourceId, sourceConfig); + this.info = info; + } + + @Override + public DataSourceType getType() { + return DataSourceType.STRUCTURE; + } + + @Override + public DataStructure asStructure() { + return this; + } + + @Override + public DataSourceInfo.Structure getInfo() { + return info; + } + + @Override + public DataStructureNode read() { + return null; + } +} diff --git a/api/src/main/java/io/xpipe/api/impl/DataTableAccumulatorImpl.java b/api/src/main/java/io/xpipe/api/impl/DataTableAccumulatorImpl.java new file mode 100644 index 000000000..56993373a --- /dev/null +++ b/api/src/main/java/io/xpipe/api/impl/DataTableAccumulatorImpl.java @@ -0,0 +1,30 @@ +package io.xpipe.api.impl; + +import io.xpipe.api.DataTable; +import io.xpipe.api.DataTableAccumulator; +import io.xpipe.core.data.node.DataStructureNodeAcceptor; +import io.xpipe.core.data.node.TupleNode; +import io.xpipe.core.source.DataSourceId; + +public class DataTableAccumulatorImpl implements DataTableAccumulator { + + @Override + public DataTable finish(DataSourceId id) { + return null; + } + + @Override + public void add(TupleNode row) { + + } + + @Override + public DataStructureNodeAcceptor acceptor() { + return null; + } + + @Override + public int getCurrentRows() { + return 0; + } +} diff --git a/api/src/main/java/io/xpipe/api/impl/DataTableImpl.java b/api/src/main/java/io/xpipe/api/impl/DataTableImpl.java index 36ab9ef58..66efcc92f 100644 --- a/api/src/main/java/io/xpipe/api/impl/DataTableImpl.java +++ b/api/src/main/java/io/xpipe/api/impl/DataTableImpl.java @@ -1,7 +1,7 @@ package io.xpipe.api.impl; import io.xpipe.api.DataTable; -import io.xpipe.api.XPipeApiConnector; +import io.xpipe.api.connector.XPipeApiConnector; import io.xpipe.beacon.BeaconClient; import io.xpipe.beacon.ClientException; import io.xpipe.beacon.ConnectorException; @@ -9,7 +9,6 @@ import io.xpipe.beacon.ServerException; import io.xpipe.core.data.node.ArrayNode; import io.xpipe.core.data.node.DataStructureNode; import io.xpipe.core.data.node.TupleNode; -import io.xpipe.core.data.type.TupleType; import io.xpipe.core.data.typed.TypedAbstractReader; import io.xpipe.core.data.typed.TypedDataStreamParser; import io.xpipe.core.data.typed.TypedReusableDataStructureNodeReader; @@ -27,12 +26,10 @@ import java.util.stream.StreamSupport; public class DataTableImpl extends DataSourceImpl implements DataTable { - private final DataSourceId id; private final DataSourceInfo.Table info; - public DataTableImpl(DataSourceId id, DataSourceConfig sourceConfig, DataSourceInfo.Table info) { + DataTableImpl(DataSourceId id, DataSourceConfig sourceConfig, DataSourceInfo.Table info) { super(id, sourceConfig); - this.id = id; this.info = info; } @@ -41,40 +38,21 @@ public class DataTableImpl extends DataSourceImpl implements DataTable { return this; } + @Override + public DataSourceInfo.Table getInfo() { + return info; + } + public Stream stream() { return StreamSupport.stream( Spliterators.spliteratorUnknownSize(iterator(), Spliterator.ORDERED), false); } - @Override - public DataSourceId getId() { - return id; - } - @Override public DataSourceType getType() { return DataSourceType.TABLE; } - @Override - public int getRowCount() { - if (info.getRowCount() == -1) { - throw new UnsupportedOperationException("Row count is unknown"); - } - - return info.getRowCount(); - } - - @Override - public OptionalInt getRowCountIfPresent() { - return info.getRowCount() != -1 ? OptionalInt.of(info.getRowCount()) : OptionalInt.empty(); - } - - @Override - public TupleType getDataType() { - return info.getDataType(); - } - @Override public ArrayNode readAll() { return read(Integer.MAX_VALUE); diff --git a/api/src/main/java/io/xpipe/api/impl/DataTextImpl.java b/api/src/main/java/io/xpipe/api/impl/DataTextImpl.java new file mode 100644 index 000000000..390c00eb2 --- /dev/null +++ b/api/src/main/java/io/xpipe/api/impl/DataTextImpl.java @@ -0,0 +1,60 @@ +package io.xpipe.api.impl; + +import io.xpipe.api.DataText; +import io.xpipe.core.source.DataSourceConfig; +import io.xpipe.core.source.DataSourceId; +import io.xpipe.core.source.DataSourceInfo; +import io.xpipe.core.source.DataSourceType; + +import java.util.Iterator; +import java.util.List; + +public class DataTextImpl extends DataSourceImpl implements DataText { + + private final DataSourceInfo.Text info; + + public DataTextImpl(DataSourceId sourceId, DataSourceConfig sourceConfig, DataSourceInfo.Text info) { + super(sourceId, sourceConfig); + this.info = info; + } + + @Override + public DataSourceType getType() { + return DataSourceType.TEXT; + } + + @Override + public DataText asText() { + return this; + } + + @Override + public DataSourceInfo.Text getInfo() { + return info; + } + + @Override + public List readAllLines() { + return null; + } + + @Override + public List readLines(int maxLines) { + return null; + } + + @Override + public String readAll() { + return null; + } + + @Override + public String read(int maxCharacters) { + return null; + } + + @Override + public Iterator iterator() { + return null; + } +} diff --git a/api/src/main/java/module-info.java b/api/src/main/java/module-info.java index a8fe12e9c..8b4fd89dd 100644 --- a/api/src/main/java/module-info.java +++ b/api/src/main/java/module-info.java @@ -3,4 +3,5 @@ module io.xpipe.api { requires io.xpipe.beacon; exports io.xpipe.api; + exports io.xpipe.api.connector; } \ No newline at end of file diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconConfig.java b/beacon/src/main/java/io/xpipe/beacon/BeaconConfig.java index 5b870b18b..d748918f8 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconConfig.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconConfig.java @@ -16,8 +16,8 @@ public class BeaconConfig { - private static final String BEACON_PORT_PROP = "io.xpipe.beacon.port"; - private static final int DEFAULT_PORT = 21721; + public static final String BEACON_PORT_PROP = "io.xpipe.beacon.port"; + public static final int DEFAULT_PORT = 21721; public static int getUsedPort() { if (System.getProperty(BEACON_PORT_PROP) != null) { diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/InfoExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/QueryDataSourceExchange.java similarity index 58% rename from beacon/src/main/java/io/xpipe/beacon/exchange/InfoExchange.java rename to beacon/src/main/java/io/xpipe/beacon/exchange/QueryDataSourceExchange.java index 94a9ec687..7fd5da0b1 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/InfoExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/QueryDataSourceExchange.java @@ -2,30 +2,28 @@ package io.xpipe.beacon.exchange; import io.xpipe.beacon.message.RequestMessage; import io.xpipe.beacon.message.ResponseMessage; -import io.xpipe.core.source.DataSourceConfigInstance; -import io.xpipe.core.source.DataSourceInfo; -import io.xpipe.core.source.DataSourceReference; +import io.xpipe.core.source.*; import io.xpipe.core.store.DataStore; import lombok.Builder; import lombok.NonNull; import lombok.Value; import lombok.extern.jackson.Jacksonized; -public class InfoExchange implements MessageExchange { +public class QueryDataSourceExchange implements MessageExchange { @Override public String getId() { - return "info"; + return "queryDataSource"; } @Override - public Class getRequestClass() { - return InfoExchange.Request.class; + public Class getRequestClass() { + return QueryDataSourceExchange.Request.class; } @Override - public Class getResponseClass() { - return InfoExchange.Response.class; + public Class getResponseClass() { + return QueryDataSourceExchange.Response.class; } @Jacksonized @@ -40,11 +38,15 @@ public class InfoExchange implements MessageExchange descriptor; + @NonNull DataSourceConfigInstance config; } } diff --git a/beacon/src/main/java/module-info.java b/beacon/src/main/java/module-info.java index b2c306b81..b19af2e1d 100644 --- a/beacon/src/main/java/module-info.java +++ b/beacon/src/main/java/module-info.java @@ -31,7 +31,7 @@ module io.xpipe.beacon { ReadPreparationExchange, ReadExecuteExchange, DialogExchange, - InfoExchange, + QueryDataSourceExchange, PreStoreExchange, EditPreparationExchange, EditExecuteExchange, diff --git a/core/src/main/java/io/xpipe/core/source/DataSourceConfig.java b/core/src/main/java/io/xpipe/core/source/DataSourceConfig.java index f4b26fd45..35e085316 100644 --- a/core/src/main/java/io/xpipe/core/source/DataSourceConfig.java +++ b/core/src/main/java/io/xpipe/core/source/DataSourceConfig.java @@ -13,7 +13,6 @@ import java.util.List; @Builder @Jacksonized public class DataSourceConfig { - String description; @Singular List