use of org.mybatis.generator.api.FullyQualifiedTable in project generator by mybatis.
the class ExampleGenerator method getCompilationUnits.
@Override
public List<CompilationUnit> getCompilationUnits() {
FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
progressCallback.startTask(getString("Progress.6", //$NON-NLS-1$
table.toString()));
CommentGenerator commentGenerator = context.getCommentGenerator();
FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getExampleType());
TopLevelClass topLevelClass = new TopLevelClass(type);
topLevelClass.setVisibility(JavaVisibility.PUBLIC);
commentGenerator.addJavaFileComment(topLevelClass);
// add default constructor
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setConstructor(true);
method.setName(type.getShortName());
//$NON-NLS-1$
method.addBodyLine("oredCriteria = new ArrayList<Criteria>();");
commentGenerator.addGeneralMethodComment(method, introspectedTable);
topLevelClass.addMethod(method);
// add field, getter, setter for orderby clause
Field field = new Field();
field.setVisibility(JavaVisibility.PROTECTED);
field.setType(FullyQualifiedJavaType.getStringInstance());
//$NON-NLS-1$
field.setName("orderByClause");
commentGenerator.addFieldComment(field, introspectedTable);
topLevelClass.addField(field);
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
//$NON-NLS-1$
method.setName("setOrderByClause");
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), //$NON-NLS-1$
"orderByClause"));
//$NON-NLS-1$
method.addBodyLine("this.orderByClause = orderByClause;");
commentGenerator.addGeneralMethodComment(method, introspectedTable);
topLevelClass.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(FullyQualifiedJavaType.getStringInstance());
//$NON-NLS-1$
method.setName("getOrderByClause");
//$NON-NLS-1$
method.addBodyLine("return orderByClause;");
commentGenerator.addGeneralMethodComment(method, introspectedTable);
topLevelClass.addMethod(method);
// add field, getter, setter for distinct
field = new Field();
field.setVisibility(JavaVisibility.PROTECTED);
field.setType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
//$NON-NLS-1$
field.setName("distinct");
commentGenerator.addFieldComment(field, introspectedTable);
topLevelClass.addField(field);
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
//$NON-NLS-1$
method.setName("setDistinct");
method.addParameter(new Parameter(FullyQualifiedJavaType.getBooleanPrimitiveInstance(), //$NON-NLS-1$
"distinct"));
//$NON-NLS-1$
method.addBodyLine("this.distinct = distinct;");
commentGenerator.addGeneralMethodComment(method, introspectedTable);
topLevelClass.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
//$NON-NLS-1$
method.setName("isDistinct");
//$NON-NLS-1$
method.addBodyLine("return distinct;");
commentGenerator.addGeneralMethodComment(method, introspectedTable);
topLevelClass.addMethod(method);
// add field and methods for the list of ored criteria
field = new Field();
field.setVisibility(JavaVisibility.PROTECTED);
FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(//$NON-NLS-1$
"java.util.List<Criteria>");
field.setType(fqjt);
//$NON-NLS-1$
field.setName("oredCriteria");
commentGenerator.addFieldComment(field, introspectedTable);
topLevelClass.addField(field);
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(fqjt);
//$NON-NLS-1$
method.setName("getOredCriteria");
//$NON-NLS-1$
method.addBodyLine("return oredCriteria;");
commentGenerator.addGeneralMethodComment(method, introspectedTable);
topLevelClass.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
//$NON-NLS-1$
method.setName("or");
method.addParameter(new Parameter(FullyQualifiedJavaType.getCriteriaInstance(), //$NON-NLS-1$
"criteria"));
//$NON-NLS-1$
method.addBodyLine("oredCriteria.add(criteria);");
commentGenerator.addGeneralMethodComment(method, introspectedTable);
topLevelClass.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
//$NON-NLS-1$
method.setName("or");
method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
//$NON-NLS-1$
method.addBodyLine("Criteria criteria = createCriteriaInternal();");
//$NON-NLS-1$
method.addBodyLine("oredCriteria.add(criteria);");
//$NON-NLS-1$
method.addBodyLine("return criteria;");
commentGenerator.addGeneralMethodComment(method, introspectedTable);
topLevelClass.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
//$NON-NLS-1$
method.setName("createCriteria");
method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
//$NON-NLS-1$
method.addBodyLine("Criteria criteria = createCriteriaInternal();");
//$NON-NLS-1$
method.addBodyLine("if (oredCriteria.size() == 0) {");
//$NON-NLS-1$
method.addBodyLine("oredCriteria.add(criteria);");
//$NON-NLS-1$
method.addBodyLine("}");
//$NON-NLS-1$
method.addBodyLine("return criteria;");
commentGenerator.addGeneralMethodComment(method, introspectedTable);
topLevelClass.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
//$NON-NLS-1$
method.setName("createCriteriaInternal");
method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
//$NON-NLS-1$
method.addBodyLine("Criteria criteria = new Criteria();");
//$NON-NLS-1$
method.addBodyLine("return criteria;");
commentGenerator.addGeneralMethodComment(method, introspectedTable);
topLevelClass.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
//$NON-NLS-1$
method.setName("clear");
//$NON-NLS-1$
method.addBodyLine("oredCriteria.clear();");
//$NON-NLS-1$
method.addBodyLine("orderByClause = null;");
//$NON-NLS-1$
method.addBodyLine("distinct = false;");
commentGenerator.addGeneralMethodComment(method, introspectedTable);
topLevelClass.addMethod(method);
// now generate the inner class that holds the AND conditions
topLevelClass.addInnerClass(getGeneratedCriteriaInnerClass(topLevelClass));
topLevelClass.addInnerClass(getCriteriaInnerClass());
topLevelClass.addInnerClass(getCriterionInnerClass());
List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
if (context.getPlugins().modelExampleClassGenerated(topLevelClass, introspectedTable)) {
answer.add(topLevelClass);
}
return answer;
}
use of org.mybatis.generator.api.FullyQualifiedTable in project generator by mybatis.
the class PrimaryKeyGenerator method getCompilationUnits.
@Override
public List<CompilationUnit> getCompilationUnits() {
FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
progressCallback.startTask(getString("Progress.7", //$NON-NLS-1$
table.toString()));
Plugin plugins = context.getPlugins();
CommentGenerator commentGenerator = context.getCommentGenerator();
TopLevelClass topLevelClass = new TopLevelClass(introspectedTable.getPrimaryKeyType());
topLevelClass.setVisibility(JavaVisibility.PUBLIC);
commentGenerator.addJavaFileComment(topLevelClass);
String rootClass = getRootClass();
if (rootClass != null) {
topLevelClass.setSuperClass(new FullyQualifiedJavaType(rootClass));
topLevelClass.addImportedType(topLevelClass.getSuperClass());
}
if (introspectedTable.isConstructorBased()) {
addParameterizedConstructor(topLevelClass);
if (!introspectedTable.isImmutable()) {
addDefaultConstructor(topLevelClass);
}
}
commentGenerator.addModelClassComment(topLevelClass, introspectedTable);
for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
if (RootClassInfo.getInstance(rootClass, warnings).containsProperty(introspectedColumn)) {
continue;
}
Field field = getJavaBeansField(introspectedColumn, context, introspectedTable);
if (plugins.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.PRIMARY_KEY)) {
topLevelClass.addField(field);
topLevelClass.addImportedType(field.getType());
}
Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable);
if (plugins.modelGetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.PRIMARY_KEY)) {
topLevelClass.addMethod(method);
}
if (!introspectedTable.isImmutable()) {
method = getJavaBeansSetter(introspectedColumn, context, introspectedTable);
if (plugins.modelSetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.PRIMARY_KEY)) {
topLevelClass.addMethod(method);
}
}
}
List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
if (context.getPlugins().modelPrimaryKeyClassGenerated(topLevelClass, introspectedTable)) {
answer.add(topLevelClass);
}
return answer;
}
use of org.mybatis.generator.api.FullyQualifiedTable in project generator by mybatis.
the class SqlMapGenerator method getSqlMapElement.
protected XmlElement getSqlMapElement() {
FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
progressCallback.startTask(getString("Progress.12", //$NON-NLS-1$
table.toString()));
//$NON-NLS-1$
XmlElement answer = new XmlElement("sqlMap");
answer.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"namespace", introspectedTable.getIbatis2SqlMapNamespace()));
context.getCommentGenerator().addRootComment(answer);
addResultMapWithoutBLOBsElement(answer);
addResultMapWithBLOBsElement(answer);
addExampleWhereClauseElement(answer);
addBaseColumnListElement(answer);
addBlobColumnListElement(answer);
addSelectByExampleWithBLOBsElement(answer);
addSelectByExampleWithoutBLOBsElement(answer);
addSelectByPrimaryKeyElement(answer);
addDeleteByPrimaryKeyElement(answer);
addDeleteByExampleElement(answer);
addInsertElement(answer);
addInsertSelectiveElement(answer);
addCountByExampleElement(answer);
addUpdateByExampleSelectiveElement(answer);
addUpdateByExampleWithBLOBsElement(answer);
addUpdateByExampleWithoutBLOBsElement(answer);
addUpdateByPrimaryKeySelectiveElement(answer);
addUpdateByPrimaryKeyWithBLOBsElement(answer);
addUpdateByPrimaryKeyWithoutBLOBsElement(answer);
return answer;
}
use of org.mybatis.generator.api.FullyQualifiedTable in project generator by mybatis.
the class DAOGenerator method getCompilationUnits.
@Override
public List<CompilationUnit> getCompilationUnits() {
FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
progressCallback.startTask(getString("Progress.14", //$NON-NLS-1$
table.toString()));
TopLevelClass topLevelClass = getTopLevelClassShell();
Interface interfaze = getInterfaceShell();
addCountByExampleMethod(topLevelClass, interfaze);
addDeleteByExampleMethod(topLevelClass, interfaze);
addDeleteByPrimaryKeyMethod(topLevelClass, interfaze);
addInsertMethod(topLevelClass, interfaze);
addInsertSelectiveMethod(topLevelClass, interfaze);
addSelectByExampleWithBLOBsMethod(topLevelClass, interfaze);
addSelectByExampleWithoutBLOBsMethod(topLevelClass, interfaze);
addSelectByPrimaryKeyMethod(topLevelClass, interfaze);
addUpdateByExampleParmsInnerclass(topLevelClass, interfaze);
addUpdateByExampleSelectiveMethod(topLevelClass, interfaze);
addUpdateByExampleWithBLOBsMethod(topLevelClass, interfaze);
addUpdateByExampleWithoutBLOBsMethod(topLevelClass, interfaze);
addUpdateByPrimaryKeySelectiveMethod(topLevelClass, interfaze);
addUpdateByPrimaryKeyWithBLOBsMethod(topLevelClass, interfaze);
addUpdateByPrimaryKeyWithoutBLOBsMethod(topLevelClass, interfaze);
List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
if (context.getPlugins().clientGenerated(interfaze, topLevelClass, introspectedTable)) {
answer.add(topLevelClass);
answer.add(interfaze);
}
return answer;
}
use of org.mybatis.generator.api.FullyQualifiedTable in project generator by mybatis.
the class DatabaseIntrospector method enhanceIntrospectedTable.
/**
* This method calls database metadata to retrieve some extra information about the table
* such as remarks associated with the table and the type.
*
* If there is any error, we just add a warning and continue.
*
* @param introspectedTable
*/
private void enhanceIntrospectedTable(IntrospectedTable introspectedTable) {
try {
FullyQualifiedTable fqt = introspectedTable.getFullyQualifiedTable();
ResultSet rs = databaseMetaData.getTables(fqt.getIntrospectedCatalog(), fqt.getIntrospectedSchema(), fqt.getIntrospectedTableName(), null);
if (rs.next()) {
//$NON-NLS-1$
String remarks = rs.getString("REMARKS");
//$NON-NLS-1$
String tableType = rs.getString("TABLE_TYPE");
introspectedTable.setRemarks(remarks);
introspectedTable.setTableType(tableType);
}
closeResultSet(rs);
} catch (SQLException e) {
//$NON-NLS-1$
warnings.add(getString("Warning.27", e.getMessage()));
}
}
Aggregations