Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
799 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
24 changes: 24 additions & 0 deletions
24
types/src/main/java/com/datastax/oss/driver/api/types/CustomType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (C) 2017-2017 DataStax Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.datastax.oss.driver.api.types; | ||
|
||
public interface CustomType { | ||
/** | ||
* The fully qualified name of the subtype of {@code org.apache.cassandra.db.marshal.AbstractType} | ||
* that represents this type server-side. | ||
*/ | ||
String getClassName(); | ||
} |
23 changes: 23 additions & 0 deletions
23
types/src/main/java/com/datastax/oss/driver/api/types/DataType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (C) 2017-2017 DataStax Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.datastax.oss.driver.api.types; | ||
|
||
/** | ||
* The type of a CQL column or function argument. | ||
* | ||
* @see DataTypes | ||
*/ | ||
public interface DataType {} |
73 changes: 73 additions & 0 deletions
73
types/src/main/java/com/datastax/oss/driver/api/types/DataTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (C) 2017-2017 DataStax Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.datastax.oss.driver.api.types; | ||
|
||
import com.datastax.oss.driver.internal.types.DefaultCustomType; | ||
import com.datastax.oss.driver.internal.types.DefaultListType; | ||
import com.datastax.oss.driver.internal.types.DefaultMapType; | ||
import com.datastax.oss.driver.internal.types.DefaultSetType; | ||
import com.datastax.oss.driver.internal.types.DefaultTupleType; | ||
import com.datastax.oss.driver.internal.types.PrimitiveType; | ||
import com.datastax.oss.protocol.internal.ProtocolConstants; | ||
import com.google.common.collect.ImmutableList; | ||
import java.util.Arrays; | ||
|
||
/** Utility class to get or build {@link DataType} instances. */ | ||
public class DataTypes { | ||
|
||
public static final DataType ASCII = new PrimitiveType(ProtocolConstants.DataType.ASCII); | ||
public static final DataType BIGINT = new PrimitiveType(ProtocolConstants.DataType.BIGINT); | ||
public static final DataType BLOB = new PrimitiveType(ProtocolConstants.DataType.BLOB); | ||
public static final DataType BOOLEAN = new PrimitiveType(ProtocolConstants.DataType.BOOLEAN); | ||
public static final DataType COUNTER = new PrimitiveType(ProtocolConstants.DataType.COUNTER); | ||
public static final DataType DECIMAL = new PrimitiveType(ProtocolConstants.DataType.DECIMAL); | ||
public static final DataType DOUBLE = new PrimitiveType(ProtocolConstants.DataType.DOUBLE); | ||
public static final DataType FLOAT = new PrimitiveType(ProtocolConstants.DataType.FLOAT); | ||
public static final DataType INT = new PrimitiveType(ProtocolConstants.DataType.INT); | ||
public static final DataType TIMESTAMP = new PrimitiveType(ProtocolConstants.DataType.TIMESTAMP); | ||
public static final DataType UUID = new PrimitiveType(ProtocolConstants.DataType.UUID); | ||
public static final DataType VARINT = new PrimitiveType(ProtocolConstants.DataType.VARINT); | ||
public static final DataType TIMEUUID = new PrimitiveType(ProtocolConstants.DataType.TIMEUUID); | ||
public static final DataType INET = new PrimitiveType(ProtocolConstants.DataType.INET); | ||
public static final DataType DATE = new PrimitiveType(ProtocolConstants.DataType.DATE); | ||
public static final DataType TEXT = new PrimitiveType(ProtocolConstants.DataType.VARCHAR); | ||
public static final DataType TIME = new PrimitiveType(ProtocolConstants.DataType.TIME); | ||
public static final DataType SMALLINT = new PrimitiveType(ProtocolConstants.DataType.SMALLINT); | ||
public static final DataType TINYINT = new PrimitiveType(ProtocolConstants.DataType.TINYINT); | ||
public static final DataType DURATION = new PrimitiveType(ProtocolConstants.DataType.DURATION); | ||
|
||
public static CustomType custom(String className) { | ||
return new DefaultCustomType(className); | ||
} | ||
|
||
public static ListType listOf(DataType elementType) { | ||
// frozen == true is only used in column definitions, it's unlikely that end users will need to | ||
// create such instances. | ||
return new DefaultListType(elementType, false); | ||
} | ||
|
||
public static SetType setOf(DataType elementType) { | ||
return new DefaultSetType(elementType, false); | ||
} | ||
|
||
public static MapType mapOf(DataType keyType, DataType valueType) { | ||
return new DefaultMapType(keyType, valueType, false); | ||
} | ||
|
||
public static TupleType tupleOf(DataType... componentTypes) { | ||
return new DefaultTupleType(ImmutableList.copyOf(Arrays.asList(componentTypes))); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
types/src/main/java/com/datastax/oss/driver/api/types/ListType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (C) 2017-2017 DataStax Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.datastax.oss.driver.api.types; | ||
|
||
import com.datastax.oss.driver.api.types.DataType; | ||
|
||
public interface ListType { | ||
public DataType getElementType(); | ||
|
||
public boolean isFrozen(); | ||
} |
26 changes: 26 additions & 0 deletions
26
types/src/main/java/com/datastax/oss/driver/api/types/MapType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (C) 2017-2017 DataStax Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.datastax.oss.driver.api.types; | ||
|
||
import com.datastax.oss.driver.api.types.DataType; | ||
|
||
public interface MapType { | ||
public DataType getKeyType(); | ||
|
||
public DataType getValueType(); | ||
|
||
public boolean isFrozen(); | ||
} |
24 changes: 24 additions & 0 deletions
24
types/src/main/java/com/datastax/oss/driver/api/types/SetType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (C) 2017-2017 DataStax Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.datastax.oss.driver.api.types; | ||
|
||
import com.datastax.oss.driver.api.types.DataType; | ||
|
||
public interface SetType { | ||
public DataType getElementType(); | ||
|
||
public boolean isFrozen(); | ||
} |
22 changes: 22 additions & 0 deletions
22
types/src/main/java/com/datastax/oss/driver/api/types/TupleType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (C) 2017-2017 DataStax Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.datastax.oss.driver.api.types; | ||
|
||
import java.util.List; | ||
|
||
public interface TupleType { | ||
List<DataType> getComponentTypes(); | ||
} |
27 changes: 27 additions & 0 deletions
27
types/src/main/java/com/datastax/oss/driver/api/types/UserDefinedType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (C) 2017-2017 DataStax Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.datastax.oss.driver.api.types; | ||
|
||
import com.datastax.oss.driver.api.core.CqlIdentifier; | ||
import java.util.Map; | ||
|
||
public interface UserDefinedType { | ||
CqlIdentifier getKeyspace(); | ||
|
||
CqlIdentifier getName(); | ||
|
||
Map<CqlIdentifier, DataType> getFieldTypes(); | ||
} |
File renamed without changes.
55 changes: 55 additions & 0 deletions
55
types/src/main/java/com/datastax/oss/driver/internal/types/DefaultCustomType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (C) 2017-2017 DataStax Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.datastax.oss.driver.internal.types; | ||
|
||
import com.datastax.oss.driver.api.types.CustomType; | ||
import com.google.common.base.Preconditions; | ||
|
||
public class DefaultCustomType implements CustomType { | ||
private final String className; | ||
|
||
public DefaultCustomType(String className) { | ||
Preconditions.checkNotNull(className); | ||
this.className = className; | ||
} | ||
|
||
@Override | ||
public String getClassName() { | ||
return className; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} else if (other instanceof CustomType) { | ||
CustomType that = (CustomType) other; | ||
return this.className.equals(that.getClassName()); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return className.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Custom(" + className + ")"; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
types/src/main/java/com/datastax/oss/driver/internal/types/DefaultListType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (C) 2017-2017 DataStax Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.datastax.oss.driver.internal.types; | ||
|
||
import com.datastax.oss.driver.api.types.DataType; | ||
import com.datastax.oss.driver.api.types.ListType; | ||
import com.google.common.base.Preconditions; | ||
|
||
public class DefaultListType implements ListType { | ||
private final DataType elementType; | ||
private final boolean frozen; | ||
|
||
public DefaultListType(DataType elementType, boolean frozen) { | ||
Preconditions.checkNotNull(elementType); | ||
this.elementType = elementType; | ||
this.frozen = frozen; | ||
} | ||
|
||
@Override | ||
public DataType getElementType() { | ||
return elementType; | ||
} | ||
|
||
@Override | ||
public boolean isFrozen() { | ||
return frozen; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} else if (other instanceof ListType) { | ||
ListType that = (ListType) other; | ||
// frozen is not taken into account | ||
return this.elementType.equals(that.getElementType()); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return this.elementType.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "List(" + elementType + ", " + (frozen ? "" : "not ") + "frozen)"; | ||
} | ||
} |
Oops, something went wrong.