提交 5cdfa58c authored 作者: Thomas Mueller's avatar Thomas Mueller

Cleanup:

- Source code formatting (Eclipse will find this)
- Missing Javadoc class comment
- The test didn't compare myString (Eclipse will find this)
- Missing space around '=' (Checkstyle will find this)
上级 164f02af
......@@ -92,7 +92,8 @@ public class ModelsTest extends TestBase {
private void testModelGeneration() {
DbInspector inspector = new DbInspector(db);
List<String> models = inspector.generateModel(null, "SupportedTypes",
List<String> models = inspector.generateModel(null,
"SupportedTypes",
"org.h2.test.jaqu", true, true);
assertEquals(1, models.size());
// a poor test, but a start
......
......@@ -20,26 +20,27 @@ import org.h2.jaqu.Table.JQTable;
@JQIndex(standard = "name, cat")
public class ProductAnnotationOnly {
@JQColumn(autoIncrement = true)
public Integer autoIncrement;
public String unmappedField;
@JQColumn(name = "id")
Integer productId;
@JQColumn(name = "cat", maxLength = 15, trimString = true)
String category;
@JQColumn(name = "name")
private String productName;
@JQColumn(name = "cat", maxLength = 15, trimString=true)
String category;
@SuppressWarnings("unused")
@JQColumn
private Double unitPrice;
@JQColumn
private Integer unitsInStock;
@JQColumn(autoIncrement=true)
public Integer autoIncrement;
public String unmappedField;
public ProductAnnotationOnly() {
// public constructor
}
......@@ -71,7 +72,6 @@ public class ProductAnnotationOnly {
create(8, "Northwoods Cranberry Sauce", "Condiments", 40.0, 6, unmappedField),
create(9, "Mishi Kobe Niku", "Meat/Poultry", 97.0, 29, unmappedField),
create(10, "Ikura", "Seafood", 31.0, 31, unmappedField), };
return Arrays.asList(list);
}
......
......@@ -8,7 +8,6 @@ import org.h2.jaqu.Table.JQTable;
* This class inherits all its fields from a parent class which has annotated
* columns. The JQTable annotation of the parent class is ignored and only
* the JQTable annotation of this class matters.
* <p>
* However, this table inherits JQColumns from its super class.
*/
@JQTable(inheritColumns = true, annotationsOnly = false)
......@@ -40,7 +39,7 @@ public class ProductInheritedAnnotation extends ProductMixedAnnotation {
create(8, "Northwoods Cranberry Sauce", "Condiments", 40.0, 6, mappedField),
create(9, "Mishi Kobe Niku", "Meat/Poultry", 97.0, 29, mappedField),
create(10, "Ikura", "Seafood", 31.0, 31, mappedField), };
return Arrays.asList(list);
}
}
......@@ -17,21 +17,21 @@ import org.h2.jaqu.Table.JQTable;
*/
// ## Java 1.5 begin ##
@JQTable(annotationsOnly = false)
@JQIndex(standard="name,cat")
@JQIndex(standard = "name, cat")
public class ProductMixedAnnotation {
@JQColumn(name = "id", primaryKey=true)
private Integer productId;
@JQColumn(name = "name")
private String productName;
public Double unitPrice;
public Integer unitsInStock;
public String mappedField;
@JQColumn(name = "cat", maxLength = 255)
String category;
public Double unitPrice;
public Integer unitsInStock;
public String mappedField;
@JQColumn(name = "id", primaryKey = true)
private Integer productId;
@JQColumn(name = "name")
private String productName;
public ProductMixedAnnotation() {
// public constructor
......@@ -64,7 +64,6 @@ public class ProductMixedAnnotation {
create(8, "Northwoods Cranberry Sauce", "Condiments", 40.0, 6, mappedField),
create(9, "Mishi Kobe Niku", "Meat/Poultry", 97.0, 29, mappedField),
create(10, "Ikura", "Seafood", 31.0, 31, mappedField), };
return Arrays.asList(list);
}
......@@ -79,5 +78,6 @@ public class ProductMixedAnnotation {
public String name() {
return productName;
}
}
// ## Java 1.5 end ##
......@@ -391,20 +391,22 @@ public class SamplesTest extends TestBase {
Set<Integer> ids = new HashSet<Integer>();
Product p = new Product();
for (int i = 0; i < 5; i++) {
List<Product> products = db.from(p).limit(2).offset(2*i).select();
List<Product> products = db.from(p).limit(2).offset(2 * i).select();
assertTrue(products.size() == 2);
for (Product prod:products)
for (Product prod : products) {
assertTrue("Failed to add product id. Duplicate?", ids.add(prod.productId));
}
}
}
private void testKeyRetrieval() {
List<SupportedTypes> list = SupportedTypes.createList();
List<Long> keys = db.insertAllAndGetKeys(list);
Set<Long> uniqueKeys = new HashSet<Long>();
for (Long l:keys)
for (Long l : keys) {
assertTrue("Failed to add key. Duplicate?", uniqueKeys.add(l));
}
}
//## Java 1.5 end ##
/**
......
......@@ -7,10 +7,15 @@ import org.h2.jaqu.Table.JQColumn;
import org.h2.jaqu.Table.JQTable;
import org.h2.util.New;
@JQTable(strictTypeMapping=true, version=1)
/**
* A data class that contains a column for each data type.
*/
@JQTable(strictTypeMapping = true, version = 1)
public class SupportedTypes {
@JQColumn(primaryKey=true, autoIncrement=true)
static final SupportedTypes SAMPLE = new SupportedTypes();
@JQColumn(primaryKey = true, autoIncrement = true)
public Integer id;
@JQColumn
......@@ -52,20 +57,17 @@ public class SupportedTypes {
@JQColumn
private java.sql.Timestamp mySqlTimestamp;
static SupportedTypes SAMPLE = new SupportedTypes();
static List<SupportedTypes> createList() {
List<SupportedTypes> list = New.arrayList();
for (int i = 0; i < 10; i++)
for (int i = 0; i < 10; i++) {
list.add(randomValue());
}
return list;
}
static SupportedTypes randomValue() {
Random rand = new Random();
SupportedTypes s = new SupportedTypes();
s.myBool = new Boolean(rand.nextBoolean());
s.myByte = new Byte((byte) rand.nextInt(Byte.MAX_VALUE));
s.myShort = new Short((short) rand.nextInt(Short.MAX_VALUE));
......@@ -96,6 +98,7 @@ public class SupportedTypes {
same &= mySqlTimestamp.getTime() == s.mySqlTimestamp.getTime();
same &= mySqlDate.toString().equals(s.mySqlDate.toString());
same &= mySqlTime.toString().equals(s.mySqlTime.toString());
same &= myString.equals(s.myString);
return same;
}
......@@ -103,10 +106,11 @@ public class SupportedTypes {
* Class to demonstrate TableUpdater
*
*/
@JQTable(name="SupportedTypes", version=2, inheritColumns=true, strictTypeMapping=true)
@JQTable(name = "SupportedTypes", version = 2, inheritColumns = true, strictTypeMapping = true)
public static class SupportedTypes2 extends SupportedTypes {
public SupportedTypes2() {
// nothing to do
}
}
}
......@@ -6,11 +6,11 @@
*/
package org.h2.test.jaqu;
import static java.sql.Date.valueOf;
import org.h2.jaqu.Db;
import org.h2.jaqu.util.StatementLogger;
import org.h2.test.TestBase;
import static java.sql.Date.valueOf;
/**
* Tests the Db.update() function.
*
......@@ -31,8 +31,6 @@ public class UpdateTest extends TestBase {
}
public void test() throws Exception {
// EventLogger.activateConsoleLogger();
db = Db.open("jdbc:h2:mem:", "sa", "sa");
db.insertAll(Product.getList());
db.insertAll(Customer.getList());
......@@ -45,7 +43,6 @@ public class UpdateTest extends TestBase {
testSetColumns();
db.close();
// EventLogger.deactivateConsoleLogger();
}
private void testSimpleUpdate() {
......@@ -120,7 +117,7 @@ public class UpdateTest extends TestBase {
Product p = new Product();
Product original = db.from(p).where(p.productId).is(1).selectFirst();
// SetColumn on String and Double
// update string and double columns
db.from(p)
.set(p.productName).to("updated")
.increment(p.unitPrice).by(3.14)
......@@ -129,20 +126,20 @@ public class UpdateTest extends TestBase {
.is(1).
update();
// Confirm fields were properly updated
// confirm the data was properly updated
Product revised = db.from(p).where(p.productId).is(1).selectFirst();
assertEquals("updated", revised.productName);
assertEquals(original.unitPrice + 3.14, revised.unitPrice);
assertEquals(original.unitsInStock + 2, revised.unitsInStock.intValue());
// Restore fields
// restore the data
db.from(p)
.set(p.productName).to(original.productName)
.set(p.unitPrice).to(original.unitPrice)
.increment(p.unitsInStock).by(-2)
.where(p.productId).is(1).update();
// Confirm fields were properly restored
// confirm the data was properly restored
Product restored = db.from(p).where(p.productId).is(1).selectFirst();
assertEquals(original.productName, restored.productName);
assertEquals(original.unitPrice, restored.unitPrice);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论