本文整理汇总了Java中de.greenrobot.daogenerator.Entity.addToMany方法的典型用法代码示例。如果您正苦于以下问题:Java Entity.addToMany方法的具体用法?Java Entity.addToMany怎么用?Java Entity.addToMany使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类de.greenrobot.daogenerator.Entity
的用法示例。
在下文中一共展示了Entity.addToMany方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addCustomerOrder
import de.greenrobot.daogenerator.Entity; //导入方法依赖的package包/类
/**
* @author:keivn
* @param schema
*/
private static void addCustomerOrder(Schema schema) {
Entity customer = schema.addEntity("Customer");
customer.addIdProperty();
customer.addStringProperty("name").notNull();
Entity order = schema.addEntity("Order");
order.setTableName("ORDERS"); // "ORDER" is a reserved keyword
order.addIdProperty();
Property orderDate = order.addDateProperty("date").getProperty();
Property customerId = order.addLongProperty("customerId").notNull().getProperty();
order.addToOne(customer, customerId);
ToMany customerToOrders = customer.addToMany(order, customerId);
customerToOrders.setName("orders");
customerToOrders.orderAsc(orderDate);
}
示例2: main
import de.greenrobot.daogenerator.Entity; //导入方法依赖的package包/类
public static void main(String[] args) {
Schema schema = new Schema(1, "com.raizlabs.android.databasecomparison.greendao.gen");
Entity simpleAddressItem = getAddressItemEntity(schema, "SimpleAddressItem");
Entity addressItem = getAddressItemEntity(schema, "AddressItem");
Entity contactItem = getContactItemEntity(schema);
Entity addressBook = getAddressBookEntity(schema);
addressItem.addToOne(addressBook, addressItem.getProperties().get(0));
contactItem.addToOne(addressBook, contactItem.getProperties().get(0));
addressBook.addToMany(addressItem, addressItem.getProperties().get(0));
addressBook.addToMany(contactItem, contactItem.getProperties().get(0));
try {
new DaoGenerator().generateAll(schema,
"../app/src/main/java");
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: addAddress
import de.greenrobot.daogenerator.Entity; //导入方法依赖的package包/类
private Entity addAddress(Entity user) {
Entity address = this.getSchema().addEntity("Address");
address.addIdProperty();
address.addIntProperty("number").notNull();
address.addStringProperty("street").notNull();
address.addStringProperty("zipCode").notNull();
address.addStringProperty("city").notNull();
address.addStringProperty("country").notNull();
Property userProperty = address.addLongProperty("userId").getProperty();
address.addToOne(user, userProperty, "user");
user.addToMany(address, userProperty, "addresses");
return address;
}
示例4: addCustomerOrder
import de.greenrobot.daogenerator.Entity; //导入方法依赖的package包/类
private static void addCustomerOrder(Schema schema) {
Entity customer = schema.addEntity("Customer");
customer.addIdProperty();
customer.addStringProperty("name").notNull();
Entity order = schema.addEntity("Order");
order.setTableName("ORDERS"); // "ORDER" is a reserved keyword
order.addIdProperty();
Property orderDate = order.addDateProperty("date").getProperty();
Property customerId = order.addLongProperty("customerId").notNull().getProperty();
order.addToOne(customer, customerId);
ToMany customerToOrders = customer.addToMany(order, customerId);
customerToOrders.setName("orders");
customerToOrders.orderAsc(orderDate);
}
示例5: main
import de.greenrobot.daogenerator.Entity; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Schema schema = new Schema(3, "br.com.ricardolonga.mercadinho");
Entity categoria = schema.addEntity("Categoria");
categoria.addIdProperty().autoincrement();
categoria.addStringProperty("nome").notNull();
categoria.implementsSerializable();
Entity item = schema.addEntity("Item");
item.addIdProperty().autoincrement();
item.addStringProperty("nome").notNull();
item.addIntProperty("quantidade");
item.addDoubleProperty("valorUnitario");
item.addDoubleProperty("valorTotal");
item.implementsSerializable();
Property idCategoria = item.addLongProperty("idCategoria").notNull().getProperty();
item.addToOne(categoria, idCategoria);
categoria.addToMany(item, idCategoria, "itens");
new DaoGenerator().generateAll(schema, "../mercadinho/src-gen");
}
示例6: main
import de.greenrobot.daogenerator.Entity; //导入方法依赖的package包/类
public static void main(String[] args) {
Schema schema = new Schema(DB_VERSION, PACKAGE);
Entity user = schema.addEntity(USER_ENTITY);
Property userPk = addCommonColumns(user);
Entity message = schema.addEntity(MESSAGE_ENTITY);
message.addIdProperty().autoincrement();
message.addStringProperty(CONTENT);
message.addLongProperty(CLIENT_ID);
message.addIntProperty(CREATED_AT);
message.addDoubleProperty(SORTED_BY);
message.addLongProperty(COMMAND_ID).index();
message.addLongProperty(SENDER_ID).notNull();
message.addLongProperty(CHANNEL_ID).notNull();
// One-to-many relationship
message.addToMany(user, userPk, READERS);
try {
new DaoGenerator().generateAll(schema, "../ORM-Benchmark/src/");
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: setBidirectionalToMany
import de.greenrobot.daogenerator.Entity; //导入方法依赖的package包/类
/**
* Adds a toMany relationship to oneEntity, and a toOne relationship to manyEntity.
* The property names will be the names specified, and the Ids will be the names of the
* respective entities with the suffix of "DaoId"
*
*
* @param oneEntity entity that only will be linking to manyEntities
* @param manyEntity entity that will be linking to oneEntity
* @param toOnePropertyName to specify the property name, otherwise null works
* @param toManyPropertyName to specify the property name, otherwise null works
*
*/
private static void setBidirectionalToMany(Entity oneEntity, Entity manyEntity,
String toOnePropertyName,
String toManyPropertyName){
Property manyIdProp;
if (toOnePropertyName == null) {
manyIdProp = manyEntity.addLongProperty(oneEntity.getClassName() + "DaoId").getProperty();
}else{
manyIdProp = manyEntity.addLongProperty(toOnePropertyName + "DaoId").getProperty();
}
ToOne toOne = manyEntity.addToOne(oneEntity, manyIdProp);
ToMany toMany = oneEntity.addToMany(manyEntity, manyIdProp);
if(toOnePropertyName == null){
toOnePropertyName = oneEntity.getClassName();
toOnePropertyName = toOnePropertyName.substring(0, 1).toLowerCase() +
toOnePropertyName.substring(1);
}
if(toManyPropertyName == null){
toManyPropertyName = oneEntity.getClassName();
toManyPropertyName = toManyPropertyName.substring(0, 1).toLowerCase() +
toManyPropertyName.substring(1) + "s";
}
toOne.setName(toOnePropertyName);
toMany.setName(toManyPropertyName);
}
示例8: setManyToMany
import de.greenrobot.daogenerator.Entity; //导入方法依赖的package包/类
private static void setManyToMany(Entity linkEntity, Entity entityOne, Entity entityTwo){
Property entityOneProp;
Property entityTwoProp;
String entityOneName = entityOne.getClassName();
String entityTwoName = entityTwo.getClassName();
// Distinguish entity links if they are to the same entity type
if(entityOne.getClassName().equals(entityTwo.getClassName())) {
entityTwoName = "linkOwner" + entityTwoName;
}
entityOneProp = linkEntity.addLongProperty(entityOneName + "DaoId").getProperty();
entityTwoProp = linkEntity.addLongProperty(entityTwoName + "DaoId").getProperty();
linkEntity.addToOne(entityOne, entityOneProp).setName(entityOneName);
linkEntity.addToOne(entityTwo, entityTwoProp).setName(entityTwoName);
String linkEntityName = linkEntity.getClassName();
linkEntityName = linkEntityName.substring(0, 1).toLowerCase() +
linkEntityName.substring(1) + "s";
ToMany linkFromEntityOne = entityOne.addToMany(linkEntity, entityOneProp);
linkFromEntityOne.setName(linkEntityName);
// If the entities are not the same they each need a property
if(!entityOne.getClassName().equals(entityTwo.getClassName())) {
ToMany linkFromEntityTwo = entityTwo.addToMany(linkEntity, entityTwoProp);
linkFromEntityTwo.setName(linkEntityName);
}
}
示例9: createV2Schema
import de.greenrobot.daogenerator.Entity; //导入方法依赖的package包/类
private static void createV2Schema(Schema v2) {
//Define entities
final Entity companyEntity = v2.addEntity("Company");
companyEntity.addIdProperty().autoincrement();
companyEntity.addStringProperty("companyCode").notNull().unique().index();
companyEntity.addStringProperty("name").notNull();
companyEntity.addStringProperty("address");
companyEntity.addDateProperty("incorporationDate");
final Entity functionEntity = v2.addEntity("Function");
functionEntity.addIdProperty().autoincrement();
functionEntity.addStringProperty("functionCode").notNull().unique();
functionEntity.addStringProperty("name").notNull();
final Entity employeeEntity = v2.addEntity("Employee");
employeeEntity.addIdProperty().autoincrement();
employeeEntity.addStringProperty("employeeId").notNull().unique();
employeeEntity.addStringProperty("designation").notNull().index();
employeeEntity.addStringProperty("name").notNull();
employeeEntity.addIntProperty("age");
employeeEntity.addStringProperty("sex").index();
employeeEntity.addDateProperty("dateOfBirth");
employeeEntity.addDateProperty("dateOfJoining").notNull();
final Entity orderEntity = v2.addEntity("Order");
orderEntity.addIdProperty().autoincrement();
orderEntity.addStringProperty("orderId").notNull().unique().index();
orderEntity.addDateProperty("orderDate").notNull();
//Define relationships
final Property functionCompanyId = functionEntity.addLongProperty("companyId").notNull().getProperty();
functionEntity.addToOne(companyEntity, functionCompanyId);
companyEntity.addToMany(functionEntity, functionCompanyId);
final Property employeeFunctionId = employeeEntity.addLongProperty("functionId").notNull().getProperty();
employeeEntity.addToOne(functionEntity, employeeFunctionId);
functionEntity.addToMany(employeeEntity, employeeFunctionId);
}
示例10: createV1Schema
import de.greenrobot.daogenerator.Entity; //导入方法依赖的package包/类
private static void createV1Schema(Schema v1) {
//Define entities
final Entity companyEntity = v1.addEntity("Company");
companyEntity.addIdProperty().autoincrement();
companyEntity.addStringProperty("companyCode").notNull().unique().index();
companyEntity.addStringProperty("name").notNull();
companyEntity.addStringProperty("address");
final Entity functionEntity = v1.addEntity("Function");
functionEntity.addIdProperty().autoincrement();
functionEntity.addStringProperty("functionCode").notNull().unique();
functionEntity.addStringProperty("name").notNull();
final Entity employeeEntity = v1.addEntity("Employee");
employeeEntity.addIdProperty().autoincrement();
employeeEntity.addStringProperty("employeeId").notNull().unique();
employeeEntity.addStringProperty("designation").notNull().index();
employeeEntity.addStringProperty("name").notNull();
employeeEntity.addIntProperty("age");
employeeEntity.addStringProperty("sex").index();
employeeEntity.addDateProperty("dateOfBirth");
//Define relationships
final Property functionCompanyId = functionEntity.addLongProperty("companyId").notNull().getProperty();
functionEntity.addToOne(companyEntity, functionCompanyId);
companyEntity.addToMany(functionEntity, functionCompanyId);
final Property employeeFunctionId = employeeEntity.addLongProperty("functionId").notNull().getProperty();
employeeEntity.addToOne(functionEntity, employeeFunctionId);
functionEntity.addToMany(employeeEntity, employeeFunctionId);
}
示例11: addEntities
import de.greenrobot.daogenerator.Entity; //导入方法依赖的package包/类
private static void addEntities(Schema schema) {
Entity repository = schema.addEntity("Repository");
repository.addIdProperty().index();
repository.addStringProperty("url").notNull().unique().index();
repository.addStringProperty("alias");
repository.addBooleanProperty("hidden").index();
repository.addIntProperty("order");
repository.addDateProperty("lastUpdateDate");
Entity category = schema.addEntity("Category");
category.addIdProperty().index();
category.addStringProperty("name");
category.addBooleanProperty("hidden").index();
category.addDateProperty("lastUpdateDate").index();
Property repositoryId = category.addLongProperty("repositoryId").index().getProperty();
category.addToOne(repository, repositoryId);
ToMany repositoryToCategories = repository.addToMany(category, repositoryId);
repositoryToCategories.setName("categories");
Entity entry = schema.addEntity("Entry");
entry.addIdProperty().index();
entry.addStringProperty("emoticon").notNull();
entry.addStringProperty("description");
entry.addBooleanProperty("star").index();
Property lastUsed = entry.addDateProperty("lastUsed").indexDesc(null, false).getProperty();
entry.addDateProperty("lastUpdateDate").index();
Property categoryId = entry.addLongProperty("categoryId").index().getProperty();
entry.addToOne(category, categoryId);
ToMany categoryToEntries = category.addToMany(entry, categoryId);
categoryToEntries.setName("entries");
categoryToEntries.orderDesc(lastUsed);
}
示例12: createParentChildRelationship
import de.greenrobot.daogenerator.Entity; //导入方法依赖的package包/类
public static void createParentChildRelationship(Entity parent, String childAttributeName, Entity child,
String parentAttributeName) throws NullPointerException{
Property parentOfChildProperty = child.addLongProperty(parentAttributeName).notNull().getProperty();
child.addToOne(parent, parentOfChildProperty);
parent.addToMany(child, parentOfChildProperty, childAttributeName);
}
示例13: createToMany
import de.greenrobot.daogenerator.Entity; //导入方法依赖的package包/类
protected void createToMany() {
Entity toManyTargetEntity = schema.addEntity("ToManyTargetEntity");
Property toManyIdProperty = toManyTargetEntity.addLongProperty("toManyId").getProperty();
Property toManyIdDescProperty = toManyTargetEntity.addLongProperty("toManyIdDesc").getProperty();
Property targetIdProperty = toManyTargetEntity.addIdProperty().getProperty();
Property targetJoinProperty = toManyTargetEntity.addStringProperty("targetJoinProperty").getProperty();
Entity toManyEntity = schema.addEntity("ToManyEntity");
Property sourceIdProperty = toManyEntity.addIdProperty().getProperty();
Property sourceJoinProperty = toManyEntity.addStringProperty("sourceJoinProperty").getProperty();
ToMany toMany = toManyEntity.addToMany(toManyTargetEntity, toManyIdProperty);
toMany.orderAsc(targetIdProperty);
ToMany toManyDesc = toManyEntity.addToMany(toManyTargetEntity, toManyIdDescProperty);
toManyDesc.setName("toManyDescList");
toManyDesc.orderDesc(targetIdProperty);
ToMany toManyByJoinProperty = toManyEntity
.addToMany(sourceJoinProperty, toManyTargetEntity, targetJoinProperty);
toManyByJoinProperty.setName("toManyByJoinProperty");
toManyByJoinProperty.orderAsc(targetIdProperty);
Property[] sourceProperties = { sourceIdProperty, sourceJoinProperty };
Property[] targetProperties = { toManyIdProperty, targetJoinProperty };
ToMany toManyJoinTwo = toManyEntity.addToMany(sourceProperties, toManyTargetEntity, targetProperties);
toManyJoinTwo.setName("toManyJoinTwo");
toManyJoinTwo.orderDesc(targetJoinProperty);
toManyJoinTwo.orderDesc(targetIdProperty);
}
示例14: createSchema2
import de.greenrobot.daogenerator.Entity; //导入方法依赖的package包/类
private void createSchema2() {
schema2 = new Schema(1, "de.greenrobot.daotest2");
schema2.setDefaultJavaPackageTest("de.greenrobot.daotest2.entity");
schema2.setDefaultJavaPackageDao("de.greenrobot.daotest2.dao");
schema2.enableKeepSectionsByDefault();
Entity keepEntity = schema2.addEntity("KeepEntity");
keepEntity.addIdProperty();
Entity toManyTarget2 = schema2.addEntity("ToManyTarget2");
toManyTarget2.addIdProperty();
Property toManyTarget2FkId = toManyTarget2.addLongProperty("fkId").getProperty();
toManyTarget2.setSkipGenerationTest(true);
Entity toOneTarget2 = schema2.addEntity("ToOneTarget2");
toOneTarget2.addIdProperty();
toOneTarget2.setJavaPackage("de.greenrobot.daotest2.to1_specialentity");
toOneTarget2.setJavaPackageDao("de.greenrobot.daotest2.to1_specialdao");
toOneTarget2.setJavaPackageTest("de.greenrobot.daotest2.to1_specialtest");
toOneTarget2.setSkipGenerationTest(true);
Entity relationSource2 = schema2.addEntity("RelationSource2");
relationSource2.addIdProperty();
relationSource2.addToMany(toManyTarget2, toManyTarget2FkId);
Property toOneId = relationSource2.addLongProperty("toOneId").getProperty();
relationSource2.addToOne(toOneTarget2, toOneId);
relationSource2.setJavaPackage("de.greenrobot.daotest2.specialentity");
relationSource2.setJavaPackageDao("de.greenrobot.daotest2.specialdao");
relationSource2.setJavaPackageTest("de.greenrobot.daotest2.specialtest");
relationSource2.setSkipGenerationTest(true);
}
示例15: main
import de.greenrobot.daogenerator.Entity; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
Schema schema = new Schema(DATABASE_VERSION, "de.fhdw.ergoholics.brainphaser.model");
// Create entities
Entity userEntity = createUserEntity(schema);
Entity categoryEntity = createCategoryEntity(schema);
Entity challengeEntity = createChallengeEntity(schema);
Entity answerEntity = createAnswerEntity(schema);
Entity completedEntity = createCompletedEntity(schema);
Entity settingsEntity = createSettingsEntity(schema);
Entity statisticsEntity = createStatisticsEntity(schema);
// category HAS MANY challenge
Property categoryId = challengeEntity.addLongProperty("categoryId").notNull().getProperty();
ToMany categoryToChallenge = categoryEntity.addToMany(challengeEntity, categoryId);
categoryToChallenge.setName("challenges");
// challenge HAS MANY answer
Property challengeIdAnswer = answerEntity.addLongProperty("challengeId").notNull().getProperty();
ToMany challengeToAnswer = challengeEntity.addToMany(answerEntity, challengeIdAnswer);
challengeToAnswer.setName("answers");
// user HAS MANY completion
Property userIdCompleted = completedEntity.addLongProperty("userId").notNull().getProperty();
ToMany userToCompleted = userEntity.addToMany(completedEntity, userIdCompleted);
userToCompleted.setName("completions");
// completion TO ONE challenge
Property challengeIdCompleted = completedEntity.addLongProperty("challengeId").notNull().getProperty();
ToOne completedToChallenge = completedEntity.addToOne(challengeEntity, challengeIdCompleted);
completedToChallenge.setName("challenge");
// user HAS MANY statistics
Property userIdStatistics = statisticsEntity.addLongProperty("userId").notNull().getProperty();
ToMany userToStatistics = userEntity.addToMany(statisticsEntity, userIdStatistics);
userToStatistics.setName("statistics");
// statistics TO ONE challenge
Property challengeIdStatistics = statisticsEntity.addLongProperty("challengeId").notNull().getProperty();
ToOne completedToStatistics = statisticsEntity.addToOne(challengeEntity, challengeIdStatistics);
completedToStatistics.setName("statistic");
// user HAS ONE settings
Property userIdSettings = userEntity.addLongProperty("settingsId").notNull().getProperty();
ToOne userToSettings = userEntity.addToOne(settingsEntity, userIdSettings);
userToSettings.setName("settings");
new DaoGenerator().generateAll(schema, "../app/src/main/java/");
}