Skip to content

Commit

Permalink
Implemented configurable names of the generated classes (issue #50).
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed Aug 29, 2012
1 parent 505fde6 commit fd1f752
Show file tree
Hide file tree
Showing 13 changed files with 451 additions and 290 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/tightdb/example/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void main(String[] args) {
* generating. And Refresh (F5) tightdb-example to see generated classes.
*/

@Table
@Table(row = "Employee")
class employee {
String firstName;
String lastName;
Expand All @@ -45,7 +45,7 @@ class employee {
phone phones;
}

@Table
@Table(row = "Phone")
class phone {
String type;
String number;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/tightdb/example/SmallExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void main(String[] args) {
}


@Table
@Table(row = "Employee")
class employee {
String firstName;
String lastName;
Expand All @@ -34,7 +34,7 @@ class employee {
phone phones;
}

@Table
@Table(row = "Phone")
class phone {
String type;
String number;
Expand Down
304 changes: 152 additions & 152 deletions src/main/java/com/tightdb/example/TutorialExample.java
Original file line number Diff line number Diff line change
@@ -1,152 +1,152 @@
//
// This example is used in the short introduction "Tightdb Java Interface"
// The @@ comments below are used for automatic extraction to the documentation
//

package com.tightdb.example;

import java.io.IOException;

import com.tightdb.Group;
import com.tightdb.example.generated.People;
import com.tightdb.example.generated.PeopleQuery;
import com.tightdb.example.generated.PeopleTable;
import com.tightdb.lib.Table;

// @@Example: create_table @@
public class TutorialExample {

@Table
class people {
String name;
int age;
boolean hired;
}

public static void main(String[] args) {
PeopleTable people = new PeopleTable();
// ...
// @@EndExample@@

/****************************** BASIC OPERATIONS *************************/

// @@Example: insert_rows @@
people.add("John", 20, true);
people.add("Mary", 21, false);
people.add("Lars", 32, true);
people.add("Phil", 43, false);
people.add("Anni", 53, true);
// @@EndExample@@

// @@Example: insert_at_index @@
people.insert(2, "Frank", 34, true);
// @@EndExample@@

/****************************** GETTERS AND SETTERS **********************/

// @@Example: accessing_rows @@
// 2 ways to get the value
String name = people.at(2).getName(); // name => "Mary"
// or
String name2 = people.at(2).name.get();

// 2 ways to set the value
people.at(2).name.set("NewName");
// or
people.at(2).setName("NewName");
// @@EndExample@@

System.out.println("at(2).getName -> " + name + " or " + name2);
System.out.println("at(2).setName('NewName') -> " + people.at(2).getName());

// @@Example: number_of_rows @@
if (!people.isEmpty()) {
long s = people.size(); // s => 6
}
// @@EndExample@@

System.out.println("Size = " + people.size() + "\n");

/****************************** ITERATION OF ALL RECORDS *****************/

// lazy iteration over the table

// @@Example: iteration @@
for (People person : people) {
System.out.println(person.getName() + " is " + person.getAge() + " years old.");
}
// @@EndExample@@

/****************************** SIMPLE QUERY *****************************/

// @@Example: simple_seach @@
People p = people.name.equal("John").findFirst();
// @@EndExample@@

System.out.println("\nFind 'John': " + p + "\n");

/****************************** COMPLEX QUERY ****************************/

// @@Example: advanced_search @@
// Define the query
PeopleQuery query = people.name.contains("a")
.group()
.hired.equal(false)
.or()
.name.endsWith("y")
.endGroup()
.age.between(20, 30);
// Count matches
System.out.println(query.count() + " person match query.");

// Perform query and use the result
for (People person : query.findAll()) {
// ... do something with matching 'person'
}
// @@EndExample

/****************************** DATA REMOVAL *****************************/
// @@Example: deleting_row @@
people.remove(2);
// @@EndExample@@

System.out.println("\nRemoved row 2. Down to " + people.size() + " rows.\n");

/****************************** SERIALIZE ********************************/

// @@Example: serialisation @@
// Create Table in Group
Group group = new Group();
PeopleTable people1 = new PeopleTable(group);

people1.add("John", 20, true);
people1.add("Mary", 21, false);

// Write to disk
try {
group.writeToFile("people.tightdb");
} catch (IOException e) {
e.printStackTrace();
}

// Load a group from disk (and print contents)
Group fromDisk = new Group("people.tightdb");
PeopleTable people2 = new PeopleTable(fromDisk);

for (People person : people2) {
System.out.println(person.getName() + " is " + person.getAge() + " years old");
}

// Write same group to memory buffer
byte[] buffer = group.writeToMem();

// Load a group from memory (and print contents)
Group fromMem = new Group(buffer);
PeopleTable people3 = new PeopleTable(fromMem);

for (People person : people3) {
System.out.println(person.getName() + " is " + person.getAge() + " years old");
}
// @@EndExample@@
}
}
//
// This example is used in the short introduction "Tightdb Java Interface"
// The @@ comments below are used for automatic extraction to the documentation
//

package com.tightdb.example;

import java.io.IOException;

import com.tightdb.Group;
import com.tightdb.example.generated.PeopleQuery;
import com.tightdb.example.generated.PeopleRow;
import com.tightdb.example.generated.PeopleTable;
import com.tightdb.lib.Table;

// @@Example: create_table @@
public class TutorialExample {

@Table
class people {
String name;
int age;
boolean hired;
}

public static void main(String[] args) {
PeopleTable people = new PeopleTable();
// ...
// @@EndExample@@

/****************************** BASIC OPERATIONS *************************/

// @@Example: insert_rows @@
people.add("John", 20, true);
people.add("Mary", 21, false);
people.add("Lars", 32, true);
people.add("Phil", 43, false);
people.add("Anni", 53, true);
// @@EndExample@@

// @@Example: insert_at_index @@
people.insert(2, "Frank", 34, true);
// @@EndExample@@

/****************************** GETTERS AND SETTERS **********************/

// @@Example: accessing_rows @@
// 2 ways to get the value
String name = people.at(2).getName(); // name => "Mary"
// or
String name2 = people.at(2).name.get();

// 2 ways to set the value
people.at(2).name.set("NewName");
// or
people.at(2).setName("NewName");
// @@EndExample@@

System.out.println("at(2).getName -> " + name + " or " + name2);
System.out.println("at(2).setName('NewName') -> " + people.at(2).getName());

// @@Example: number_of_rows @@
if (!people.isEmpty()) {
long s = people.size(); // s => 6
}
// @@EndExample@@

System.out.println("Size = " + people.size() + "\n");

/****************************** ITERATION OF ALL RECORDS *****************/

// lazy iteration over the table

// @@Example: iteration @@
for (PeopleRow person : people) {
System.out.println(person.getName() + " is " + person.getAge() + " years old.");
}
// @@EndExample@@

/****************************** SIMPLE QUERY *****************************/

// @@Example: simple_seach @@
PeopleRow p = people.name.equal("John").findFirst();
// @@EndExample@@

System.out.println("\nFind 'John': " + p + "\n");

/****************************** COMPLEX QUERY ****************************/

// @@Example: advanced_search @@
// Define the query
PeopleQuery query = people.name.contains("a")
.group()
.hired.equal(false)
.or()
.name.endsWith("y")
.endGroup()
.age.between(20, 30);
// Count matches
System.out.println(query.count() + " person match query.");

// Perform query and use the result
for (PeopleRow person : query.findAll()) {
// ... do something with matching 'person'
}
// @@EndExample

/****************************** DATA REMOVAL *****************************/
// @@Example: deleting_row @@
people.remove(2);
// @@EndExample@@

System.out.println("\nRemoved row 2. Down to " + people.size() + " rows.\n");

/****************************** SERIALIZE ********************************/

// @@Example: serialisation @@
// Create Table in Group
Group group = new Group();
PeopleTable people1 = new PeopleTable(group);

people1.add("John", 20, true);
people1.add("Mary", 21, false);

// Write to disk
try {
group.writeToFile("people.tightdb");
} catch (IOException e) {
e.printStackTrace();
}

// Load a group from disk (and print contents)
Group fromDisk = new Group("people.tightdb");
PeopleTable people2 = new PeopleTable(fromDisk);

for (PeopleRow person : people2) {
System.out.println(person.getName() + " is " + person.getAge() + " years old");
}

// Write same group to memory buffer
byte[] buffer = group.writeToMem();

// Load a group from memory (and print contents)
Group fromMem = new Group(buffer);
PeopleTable people3 = new PeopleTable(fromMem);

for (PeopleRow person : people3) {
System.out.println(person.getName() + " is " + person.getAge() + " years old");
}
// @@EndExample@@
}
}
Loading

0 comments on commit fd1f752

Please sign in to comment.