Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*  d6 Lightweight O/R mapper for java with ease of use 
   *  Copyright (c) 2006- Tom Misawa,
   *  Permission is hereby granted, free of charge, to any person obtaining a
   *  copy of this software and associated documentation files (the "Software"),
   *  to deal in the Software without restriction, including without limitation
   *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
   *  and/or sell copies of the Software, and to permit persons to whom the
  *  Software is furnished to do so, subject to the following conditions:
  *  The above copyright notice and this permission notice shall be included in
  *  all copies or substantial portions of the Software.
 package org.riversun.d6.core;
 import java.util.Map;
To generate the Map which key is columnName and value is model class's field info from D6 Model class

Tom Misawa (
     private final Class<?> mModelClazz;
     private final Map<StringD6ModelClassFieldInfomFieldMap;
     public ModelClazzColumnNameAndFieldMapper(Class<?> modelClazz) {
          = modelClazz;
          = new LinkedHashMap<StringD6ModelClassFieldInfo>();
     public void rebuild(Map<StringD6ModelClassFieldInfomap) {
     public Map<StringD6ModelClassFieldInfobuild() {
         return ;

To populate FieldMap(key is columnName,value is fieldInfo) holding the column and fields

refFieldMap reference of non-null field map
     private void build(Map<StringD6ModelClassFieldInforefFieldMap) {
         final Field[] fields = .getFields();
         for (int i = 0; i < fields.lengthi++) {
             final Field field = fields[i];
             final DBColumn annoColumn = field.getAnnotation(DBColumn.class);
             if (annoColumn == null) {
                 // there is no column annotation.
             final String columnName = annoColumn.columnName();
             final String columnType = annoColumn.columnType();
             if (columnName == null || columnType == null) {
             final D6ModelClassFieldInfo fieldInfo = new D6ModelClassFieldInfo();
             fieldInfo.field = field;
             fieldInfo.columnName = columnName;
             fieldInfo.columnType = columnType;
             fieldInfo.value = null;
             fieldInfo.isAutoIncrement = annoColumn.isAutoIncrement();
             fieldInfo.isNullable = annoColumn.isNullable();
             fieldInfo.isPrimaryKey = annoColumn.isPrimaryKey();
             fieldInfo.isUnique = annoColumn.isUnique();
New to GrepCode? Check out our FAQ X