001package io.ebean.querybean.generator; 002 003import java.util.Set; 004 005/** 006 * Property type definition. 007 */ 008public class PropertyType { 009 010 static final String NEWLINE = SimpleQueryBeanWriter.NEWLINE; 011 012 /** 013 * The property type className or primitive short name. 014 */ 015 final String propertyType; 016 017 /** 018 * Construct with a className of primitive name for the type. 019 */ 020 PropertyType(String propertyType) { 021 this.propertyType = propertyType; 022 } 023 024 @Override 025 public String toString() { 026 return propertyType; 027 } 028 029 /** 030 * Return true if this is an association type. 031 */ 032 public boolean isAssociation() { 033 // overridden by PropertyTypeAssoc 034 return false; 035 } 036 037 /** 038 * Return the type definition for this property. 039 * 040 * @param shortName The short name of the property type 041 * @param assoc flag set to true if the property is on an association bean 042 */ 043 public String getTypeDefn(String shortName, boolean assoc) { 044 if (assoc) { 045 // PLong<R> 046 return propertyType + "<R>"; 047 048 } else { 049 // PLong<QCustomer> 050 return propertyType + "<Q" + shortName + ">"; 051 } 052 } 053 054 /** 055 * Add any required imports for this property to the allImports set. 056 */ 057 public void addImports(Set<String> allImports) { 058 059 allImports.add("io.ebean.typequery." + propertyType); 060 } 061 062// /** 063// * Write the constructor source code. 064// * 065// * @param writer The writer java source code is written to 066// * @param name the property name 067// * @param assoc if true the property is on an a associated bean (not at root level) 068// */ 069// public void writeConstructor(Writer writer, String name, boolean assoc) throws IOException { 070// 071// //PLong<>("id", this); 072// //PLong<>("id", root, path); 073// 074// writer.append(propertyType).append("<>(\"").append(name).append("\""); 075// if (assoc) { 076// writer.append(", root, path);").append(NEWLINE); 077// 078// } else { 079// writer.append(", this);").append(NEWLINE); 080// } 081// } 082}