Skip to content
This repository has been archived by the owner on Aug 8, 2020. It is now read-only.

HowTo: Schema

michaelwittig edited this page Oct 26, 2014 · 10 revisions

HowTo: Schema

A simple approach is to create a Java class, extend ATable to get some basic functionality and make the class a singleton. So what? You like to read code, here it comes:

public final class MyTable extends ATable {
	/** Instance. */
	private static final MyTable INSTANCE = new MyTable();

	/**
	 * @return Instance
	 */
	public static MyTable get() {
		return INSTANCE;
	}

	/** Prevent the instanciation of this class from outside. */
	private MyTable() {
		super("mytable");
	}
}

Okay. A table without columns doesn't make a lot of sense, so we need to add columns:

Add a column

Let's assume we want to have four columns. We must provide the type and name for every column!

What types are available:

  • SymbolColumn
  • FloatColumn
  • RealColumn
  • IntegerColumn
  • LongColumn
  • TimeColumn
  • TimestampColumn

The types are named equal to the types in q!

So. let us add the columns to our table:

public final class MyTable extends ATable {

	[...]Stuff from above[...]

	/** Time. */
	public final TimeColumn time = new TimeColumn("time");

	/** Sym. */
	public final SymbolColumn sym = new SymbolColumn("sym");

	/** Price. */
	public final FloatColumn price = new FloatColumn("price");

	/** Size. */
	public final IntegerColumn size = new IntegerColumn("size");

	/** */
	private MyTable() {
		super("mytable");
		this.addColumn(this.time);
		this.addColumn(this.sym);
		this.addColumn(this.price);
		this.addColumn(this.size);
	}
}

Great! Now we have defined our table. Next step is to access the table schema, so we will have a look:

Acces the table / a column

It is good practice to get the table and then operate on the table and get the columns.

Table table = MyTable.get(); // get the table
System.out.println(table.sym.getName()); // get the sym column

Code

[MyTable example] (https://github.com/michaelwittig/java-q/blob/master/src/test/java/info/michaelwittig/javaq/demo/tabledefinition/MyTable.java)

Clone this wiki locally