public PropertyBuilder(Schema schema, Entity entity, PropertyType propertyType, String propertyName) { property = new Property(schema, entity, propertyType, propertyName); }
public String getDatabaseValueExpression() { return getDatabaseValueExpression(propertyName); }
/** Constructs fkColumns. Depends on 2nd pass of target key properties. */ void init3ndPass() { Property targetPkProperty = targetEntity.getPkProperty(); if (fkProperties.length != 1 || targetPkProperty == null) { throw new RuntimeException("Currently only single FK columns are supported: " + this); } Property property = fkProperties[0]; PropertyType propertyType = property.getPropertyType(); if (propertyType == null) { propertyType = targetPkProperty.getPropertyType(); property.setPropertyType(propertyType); // Property is not a regular property with primitive getters/setters, so let it catch up property.init2ndPass(); property.init3ndPass(); } else if (propertyType != targetPkProperty.getPropertyType()) { System.err.println("Warning to-one property type does not match target key type: " + this); } resolvedKeyJavaType[0] = schema.mapToJavaTypeNullable(propertyType); resolvedKeyUseEquals[0] = checkUseEquals(propertyType); }
property.setOrdinal(i); property.init2ndPass(); if (property.isPrimaryKey()) { propertiesPk.add(property); } else { if (propertiesSize == 1) { final Property property = index.getProperties().get(0); property.setIndex(index); } else if (propertiesSize > 1) { multiIndexes.add(index); pkType = schema.mapToJavaTypeNullable(pkProperty.getPropertyType()); } else { pkType = "Void";
String customType = property.getCustomType(); if (customType != null) { String pack = DaoUtil.getPackageFromFullyQualified(customType); String converter = property.getConverter(); if (converter != null) { String pack = DaoUtil.getPackageFromFullyQualified(converter);
public String getCommaSeparatedString(String tablePrefixOrNull) { StringBuilder builder = new StringBuilder(); int size = properties.size(); for (int i = 0; i < size; i++) { Property property = properties.get(i); String order = propertiesOrder.get(i); if (property != null) { if(tablePrefixOrNull != null) { builder.append(tablePrefixOrNull).append('.'); } builder.append('\'').append(property.getDbName()).append('\'').append(' '); } if (order != null) { builder.append(order); } if (i < size - 1) { builder.append(','); } } return builder.toString(); }
public String getOrderSpec() { final List<Property> properties = getProperties(); final List<String> propertiesOrder = getPropertiesOrder(); final StringBuilder builder = new StringBuilder(); final int size = properties.size(); for (int i = 0; i < size; i++) { final Property property = properties.get(i); final String order = propertiesOrder.get(i); builder.append(property.getPropertyName()); if (order != null) { builder.append(' ').append(order); } if (i < size - 1) { builder.append(", "); } } return builder.toString(); } }
void init2ndPass() { super.init2ndPass(); if (sourceProperties == null) { List<Property> pks = sourceEntity.getPropertiesPk(); if (pks.isEmpty()) { throw new RuntimeException("Source entity has no primary key, but we need it for " + this); } sourceProperties = new Property[pks.size()]; sourceProperties = pks.toArray(sourceProperties); } int count = sourceProperties.length; if (count != targetProperties.length) { throw new RuntimeException("Source properties do not match target properties: " + this); } for (int i = 0; i < count; i++) { Property sourceProperty = sourceProperties[i]; Property targetProperty = targetProperties[i]; PropertyType sourceType = sourceProperty.getPropertyType(); PropertyType targetType = targetProperty.getPropertyType(); if (sourceType == null || targetType == null) { throw new RuntimeException("Property type uninitialized"); } if (sourceType != targetType) { System.err.println("Warning to-one property type does not match target key type: " + this); } } }
void init3rdPass() { for (Property property : properties) { property.init3ndPass(); } init3rdPassRelations(); init3rdPassAdditionalImports(); }
@Test public void testMinimalSchema() throws Exception { Schema schema = new Schema(1, "org.greenrobot.testdao"); Entity addressEntity = schema.addEntity("Addresse"); Property idProperty = addressEntity.addIdProperty().getProperty(); addressEntity.addIntProperty("count").index(); addressEntity.addIntProperty("dummy").notNull(); assertEquals(1, schema.getEntities().size()); assertEquals(3, addressEntity.getProperties().size()); File outputDir = new File("build/test-out"); outputDir.mkdirs(); File daoFile = new File(outputDir, "org/greenrobot/testdao/" + addressEntity.getClassName() + "Dao.java"); daoFile.delete(); assertFalse(daoFile.exists()); new DaoGenerator().generateAll(schema, outputDir.getPath()); assertEquals("PRIMARY KEY", idProperty.getConstraints()); assertTrue(daoFile.toString(), daoFile.exists()); }
protected void init2ndPassIndexNamesWithDefaults() { for (int i = 0; i < indexes.size(); i++) { Index index = indexes.get(i); if (index.getName() == null) { String indexName = "IDX_" + getDbName(); List<Property> properties = index.getProperties(); for (int j = 0; j < properties.size(); j++) { Property property = properties.get(j); indexName += "_" + property.getDbName(); if ("DESC".equalsIgnoreCase(index.getPropertiesOrder().get(j))) { indexName += "_DESC"; } } // TODO can this get too long? how to shorten reliably without depending on the order (i) index.setDefaultName(indexName); } } }
public String getDatabaseValueExpressionNotNull() { return getDatabaseValueExpression("entity.get" + DaoUtil.capFirst(propertyName) + "()"); }