Java Reference
In-Depth Information
of users on a large server, and complicated sets of nested data, you may need
to look into the SQL techniques. There's an official tutorial online.
1
But it's a
much more advanced and potentially confusing topic, even for professionals.
On the other hand, if your data needs are relatively flat and simple, and you're
only dealing with hundreds of users, then Canary has a nice option for you:
DataAccess
objects and the
Database
front end.
When dealing with databases, the words we use to describe things are a little
different from the words we use in code. In code, you might have a class or
a record, made up of variables, or fields. Databases have these same things,
but we call fields
columns.
A bunch of columns are grouped together in a
table.
And since searching for records is a big part of databases, we have a new
word for the thing we might search for the most: a table's
primary key
field.
A primary key means there's only one record in that table with that value.
For instance,
player_name
might be a good primary key, because every user has
a unique name, so it's an easy way to find an individual player.
DataAccess
objects
In the Canary API, you can create a
DataAccess
object that defines what you
want to store in a database. For example, suppose you want to store the
location of a player. You'd want to be able to save and look up that record by
the player's name, and maybe save the x-, y-, and z-coordinates.
To do that, you'd start with a separate class, derived from
DataAccess
, that just
has the data you want to load and save:
public class
AllPlayerLocations
extends
DataAccess {
public String
player_name;
public double
x;
public double
y;
public double
z;
}
That's the data itself, but Canary needs a few more things before you can use
this with a database.
First off, it needs to know what to call this field in the database, and what
type of data it represents. For each of x, y, and z, we'll name the database
field the same thing as the variable. Each of these is a Java
double
. You'd
specify these details using the
@Column
annotation, like this: