# Class BaseKey.Builder&lt;B&gt; (3.1.0)

3.1.0 (latest) 2.40.0 2.37.0 2.36.0 2.34.0 2.33.3 2.32.3 2.31.4 2.30.0 2.29.1 2.28.2 2.27.1 2.26.4 2.25.2 2.24.3 2.23.0 2.22.0 2.21.3 2.20.2 2.19.2 2.18.5 2.17.6

    public abstract static class BaseKey.Builder<B>

Base class for key builders.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> BaseKey.Builder\<B\>

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

| ## Type Parameter ||
|---|---|
| **Name** | **Description** |
| `B` |   |

## Methods

### addAncestor(PathElement ancestor)

    public B addAncestor(PathElement ancestor)

Adds an ancestor for this key.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `ancestor` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.PathElement` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `B` |   |

### addAncestors(PathElement ancestor, PathElement\[\] other)

    public B addAncestors(PathElement ancestor, PathElement[] other)

Adds the provided ancestors to the key.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `ancestor` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.PathElement` |
| `other` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.PathElement[]` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `B` |   |

### addAncestors(Iterable\<PathElement\> ancestors)

    public B addAncestors(Iterable<PathElement> ancestors)

Adds the provided ancestors to the key.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `ancestors` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html<https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.PathElement>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `B` |   |

### build()

    protected abstract BaseKey build()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.BaseKey` |   |

### setDatabaseId(String databaseId)

    public B setDatabaseId(String databaseId)

Sets the database id of the key.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `databaseId` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `B` |   |

### setKind(String kind)

    public B setKind(String kind)

Sets the kind of the key.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `kind` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `B` |   |

### setNamespace(String namespace)

    public B setNamespace(String namespace)

Sets the namespace of the key.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `namespace` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `B` |   |

### setProjectId(String projectId)

    public B setProjectId(String projectId)

Sets the project ID of the key.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `projectId` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `B` |   |