Was this page helpful?
ScyllaDB Java Driver is available under the Apache v2 License. ScyllaDB Java Driver is a fork of DataStax Java Driver. See Copyright here.
Caution
You're viewing documentation for a previous version of Scylla Java Driver. Switch to the latest stable version.
Scala is an alternative language for the JVM. It doesn’t support annotation processing natively, so using it with the mapper is a bit more complicated, but it can be done.
We have a full example at DataStax-Examples/object-mapper-jvm/scala.
You can use Scala case classes for your entities. Notice the peculiar syntax for field annotations:
@Entity
case class UserVideo(@(PartitionKey@field) userid: UUID,
@(ClusteringColumn@field)(0) addedDate: Instant,
@(ClusteringColumn@field)(1) videoid: UUID,
name: String,
previewImageLocation: String)
Case classes are immutable and use the fluent getter style, but you
don’t need to declare that explicitly with @PropertyStrategy: the mapper detects when it’s
processing a case class, and will assume mutable = false, getterStyle = FLUENT
by default.
The DAOs and main mapper can be defined as Scala traits, that are direct translations of their Java equivalents:
@Dao
trait UserDao {
@Select
def get(userid: UUID): User
}
Since Scala does not support annotation processing, the mapper processor cannot operate on Scala sources directly. But it can process the compiled class files output by the Scala compiler. So the compilation happens in 3 phases:
Compile the Scala sources with the regular sbt task.
Execute a custom task that runs the annotation processor (javac -proc:only ...
) on the compiled
class files.
Execute another custom task that compiles the Java sources generated by the mapper.
See the example’s build.sbt for the full details.
Because of that process, the sources fed to the processor cannot reference any generated code. So the application code needs to be placed in a separate subproject, in order to have access to the mapper builder.
Was this page helpful?
ScyllaDB Java Driver is available under the Apache v2 License. ScyllaDB Java Driver is a fork of DataStax Java Driver. See Copyright here.
On this page