Skip to content

2.0 beta #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve annotation system not to have to provide types and names
  • Loading branch information
clun committed Nov 29, 2024
commit c9bf29a7a1f4ba7d48b9039a36c33e4eb7cbb6be
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public T timeout(Duration duration) {
*/
@SuppressWarnings("unchecked")
public T embeddingAuthProvider(EmbeddingHeadersProvider embeddingAuthProvider) {
Assert.notNull(embeddingAuthProvider, "embeddingAuthProvider");
getDataAPIClientOptions().embeddingAuthProvider(embeddingAuthProvider);
return (T) this;
}
Expand All @@ -173,7 +174,9 @@ public T embeddingAuthProvider(EmbeddingHeadersProvider embeddingAuthProvider) {
*/
@SuppressWarnings("unchecked")
public T databaseAdditionalHeaders(Map<String, String> params) {
getDataAPIClientOptions().databaseAdditionalHeaders(params);
if (params!=null && !params.isEmpty()) {
getDataAPIClientOptions().databaseAdditionalHeaders(params);
}
return (T) this;
}

Expand All @@ -187,7 +190,9 @@ public T databaseAdditionalHeaders(Map<String, String> params) {
*/
@SuppressWarnings("unchecked")
public T adminAdditionalHeaders(Map<String, String> params) {
getDataAPIClientOptions().adminAdditionalHeaders(params);
if (params!=null && !params.isEmpty()) {
getDataAPIClientOptions().adminAdditionalHeaders(params);
}
return (T) this;
}

Expand Down Expand Up @@ -215,9 +220,7 @@ public T httpClientOptions(HttpClientOptions options) {
*/
@SuppressWarnings("unchecked")
public T timeoutOptions(TimeoutOptions timeoutOptions) {
if (getDataAPIClientOptions() == null) {
this.dataAPIClientOptions = new DataAPIClientOptions();
}
Assert.notNull(timeoutOptions, "timeoutOptions");
getDataAPIClientOptions().timeoutOptions(timeoutOptions);
return (T) this;
}
Expand All @@ -233,9 +236,9 @@ public T timeoutOptions(TimeoutOptions timeoutOptions) {
*/
@SuppressWarnings("unchecked")
public T registerObserver(String name, CommandObserver observer) {
if (observer != null) {
getDataAPIClientOptions().addObserver(name, observer);
}
Assert.hasLength(name, "name");
Assert.notNull(observer, "observer");
getDataAPIClientOptions().addObserver(name, observer);
return (T) this;
}

Expand All @@ -253,24 +256,6 @@ public T unregisterObserver(String name) {
return (T) this;
}

/**
* Return the HTTP Request Timeout based on the command type
*
* @return value of token
*/
public long getTimeout(CommandType commandType) {
return getTimeout(getDataAPIClientOptions().getTimeoutOptions(), commandType);
}

/**
* Return the HTTP Request Timeout based on the command type
*
* @return value of token
*/
public long getRequestTimeout(CommandType commandType) {
return getRequestTimeout(getDataAPIClientOptions().getTimeoutOptions(), commandType);
}

/**
* Request timeout based on the command type.
*
Expand Down Expand Up @@ -320,9 +305,6 @@ public long getRequestTimeout(TimeoutOptions timeoutOptions, CommandType type) {
* service key
*/
public T timeout(long timeoutMillis, CommandType commandType) {
if (getDataAPIClientOptions() == null) {
dataAPIClientOptions = new DataAPIClientOptions();
}
if (getDataAPIClientOptions().getTimeoutOptions() == null) {
getDataAPIClientOptions().timeoutOptions(new TimeoutOptions());
}
Expand All @@ -348,6 +330,9 @@ public T timeout(long timeoutMillis, CommandType commandType) {
*/
@JsonIgnore
public DataAPIClientOptions getDataAPIClientOptions() {
if (this.dataAPIClientOptions == null) {
this.dataAPIClientOptions = new DataAPIClientOptions();
}
return dataAPIClientOptions;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@
/**
* Options to set up the client for DataApiClient.
*/
@Setter
@Slf4j
@NoArgsConstructor
@Setter
@Accessors(fluent = true, chain = true)
public class DataAPIClientOptions implements Cloneable {

Expand Down Expand Up @@ -374,6 +373,13 @@ public String toString() {
return new DatabaseSerializer().marshall(this);
}

/**
* A default Client Options
*/
public DataAPIClientOptions() {
// defaulting values
}

public DataAPIClientOptions(DataAPIClientOptions options) {
Assert.notNull(options, "Options");
this.apiVersion = options.apiVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
* #L%
*/

import com.datastax.astra.internal.utils.Assert;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.time.Duration;

/**
* This class is used to define the timeout options for the client.
*/
Expand Down Expand Up @@ -84,6 +87,48 @@ public TimeoutOptions clone() {
}
}

public TimeoutOptions connectTimeout(Duration timeout) {
Assert.notNull(timeout, "Timeout");
this.connectTimeoutMillis = timeout.toMillis();
return this;
}

public TimeoutOptions requestTimeout(Duration timeout) {
Assert.notNull(timeout, "Timeout");
this.requestTimeoutMillis = timeout.toMillis();
return this;
}

public TimeoutOptions generalMethodTimeout(Duration timeout) {
Assert.notNull(timeout, "Timeout");
this.generalMethodTimeoutMillis = timeout.toMillis();
return this;
}

public TimeoutOptions databaseAdminTimeout(Duration timeout) {
Assert.notNull(timeout, "Timeout");
this.databaseAdminTimeoutMillis = timeout.toMillis();
return this;
}

public TimeoutOptions keyspaceAdminTimeout(Duration timeout) {
Assert.notNull(timeout, "Timeout");
this.keyspaceAdminTimeoutMillis = timeout.toMillis();
return this;
}

public TimeoutOptions collectionAdminTimeout(Duration timeout) {
Assert.notNull(timeout, "Timeout");
this.collectionAdminTimeoutMillis = timeout.toMillis();
return this;
}

public TimeoutOptions tableAdminTimeout(Duration timeout) {
Assert.notNull(timeout, "Timeout");
this.tableAdminTimeoutMillis = timeout.toMillis();
return this;
}

/**
* Gets connectTimeoutMillis
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ public <T> Table<T> createTable(String tableName,
* @param rowClass the class representing the row type; must not be null
* @return the created table object
*/
private <T> String getTableName(Class<T> rowClass) {
public <T> String getTableName(Class<T> rowClass) {
notNull(rowClass, "rowClass");
EntityTable ann = rowClass.getAnnotation(EntityTable.class);
if (ann == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import static com.datastax.astra.client.core.commands.CommandType.COLLECTION_ADMIN;

public class CreateCollectionOptions extends BaseOptions<ListCollectionOptions> {
public class CreateCollectionOptions extends BaseOptions<CreateCollectionOptions> {

public CreateCollectionOptions() {
super(null, COLLECTION_ADMIN, null);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.datastax.astra.client.tables.columns;

import com.datastax.astra.client.core.vector.DataAPIVector;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.InetAddress;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

/**
* Maps Java types to Cassandra column types.
*/
public class ColumnTypeMapper {

private static final Map<Class<?>, ColumnTypes> typeMapping = new HashMap<>();

static {
typeMapping.put(Integer.class, ColumnTypes.INT);
typeMapping.put(int.class, ColumnTypes.INT);
typeMapping.put(Long.class, ColumnTypes.BIGINT);
typeMapping.put(long.class, ColumnTypes.BIGINT);

typeMapping.put(Double.class, ColumnTypes.DOUBLE);
typeMapping.put(double.class, ColumnTypes.DOUBLE);

typeMapping.put(Float.class, ColumnTypes.FLOAT);
typeMapping.put(float.class, ColumnTypes.FLOAT);
typeMapping.put(Boolean.class, ColumnTypes.BOOLEAN);
typeMapping.put(boolean.class, ColumnTypes.BOOLEAN);
typeMapping.put(Byte.class, ColumnTypes.TINYINT);
typeMapping.put(byte.class, ColumnTypes.TINYINT);
typeMapping.put(Short.class, ColumnTypes.SMALLINT);
typeMapping.put(short.class, ColumnTypes.SMALLINT);

// Commonly used Java types
typeMapping.put(String.class, ColumnTypes.TEXT);
typeMapping.put(UUID.class, ColumnTypes.UUID);
typeMapping.put(BigDecimal.class, ColumnTypes.DECIMAL);
typeMapping.put(BigInteger.class, ColumnTypes.VARINT);
typeMapping.put(InetAddress.class, ColumnTypes.INET);

// Date and time types
typeMapping.put(Instant.class, ColumnTypes.TIMESTAMP);
typeMapping.put(LocalDate.class, ColumnTypes.DATE);
typeMapping.put(LocalTime.class, ColumnTypes.TIME);

// Collection types
typeMapping.put(List.class, ColumnTypes.LIST);
typeMapping.put(Set.class, ColumnTypes.SET);
typeMapping.put(Map.class, ColumnTypes.MAP);
typeMapping.put(DataAPIVector.class, ColumnTypes.VECTOR);

// Unsupported or undefined
typeMapping.put(Object.class, ColumnTypes.UNSUPPORTED);
}

public static ColumnTypes getColumnType(Class<?> clazz) {
return typeMapping.getOrDefault(clazz, ColumnTypes.UNSUPPORTED);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/**
* Column Name, if not provided the field name will be used
*/
String value();
String name();

/**
* Column Type, if not provided the field type will be used
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy