本文整理汇总了Java中com.j256.ormlite.dao.Dao.create方法的典型用法代码示例。如果您正苦于以下问题:Java Dao.create方法的具体用法?Java Dao.create怎么用?Java Dao.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.j256.ormlite.dao.Dao
的用法示例。
在下文中一共展示了Dao.create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: persist
import com.j256.ormlite.dao.Dao; //导入方法依赖的package包/类
@Override
public void persist(Object entity) {
Dao dao = getDao(entity.getClass());
try {
dao.create(entity);
} catch (SQLException e) {
throw new EntityExistsException(e);
}
}
示例2: initializeBranchTable
import com.j256.ormlite.dao.Dao; //导入方法依赖的package包/类
/**
* Creates the Branch table and generates default values
*
* @param dao ORMLite branch data access object
*/
private void initializeBranchTable(Dao<Branch, Integer> dao) {
try {
TableUtils.createTable(OrmLiteConnectionSingleton.getInstance(), Branch.class);
dao.create(new Branch(1, "London", 51.507351, -0.127758));
dao.create(new Branch(2, "Paris", 48.856614, 2.352222));
dao.create(new Branch(3, "Madrid", 40.416775, -3.703790));
dao.create(new Branch(4, "Berlin", 52.520007, 13.404954));
} catch (SQLException e) {
System.out.println("Error initializing branch table");
e.printStackTrace();
}
}
示例3: testSimpleWrite
import com.j256.ormlite.dao.Dao; //导入方法依赖的package包/类
@Override
public void testSimpleWrite() {
setUp();
Benchmark benchmark = new Benchmark() {
private int i;
@Override
public void setUp() {
i = 0;
}
@Override
public void tearDown() {
// Do nothing
}
@Override
public void run() {
try {
Dao<Employee, Long> dao = Employee.getDao();
Employee employee = new Employee();
employee.setName(dataGenerator.getEmployeeName(i));
employee.setHired(dataGenerator.getHiredBool(i));
employee.setAge(dataGenerator.getEmployeeAge(i));
dao.create(employee);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Override
protected void cleanupRun() {
deleteObjects();
}
};
measurements.put(TEST_SIMPLE_WRITE, benchmark.execute(warmupIterations, testIterations));
tearDown();
}