-
Notifications
You must be signed in to change notification settings - Fork 16
Documentation and generated source
xcesco edited this page Apr 26, 2018
·
1 revision
One of the key features of Kripton is the capability to well documented generate code. Especially when you work with ORM components, you need to know what the library does for you. Ok, you can always check the generated source code. But it much better to read Javadoc documentation of generated code, isn't it?
Just for example: if you create a DAO's interface like this:
@BindDao(City.class)
public interface CityDao {
@BindSqlInsert
public void insert(City bean);
@BindSqlSelect
public List<City> listCities();
}
Kripton will generate the following DAO implementation, with Javadoc included:
/**
* <p>
* DAO implementation for entity <code>City</code>, based on interface <code>CityDao</code>
* </p>
*
* @see City
* @see CityDao
* @see CityTable
*/
public class CityDaoImpl extends Dao implements CityDao {
private static SQLiteStatement insertPreparedStatement0;
private static final String LIST_CITIES_SQL1 = "SELECT id, name FROM city";
public CityDaoImpl(BindAppDaoFactory daoFactory) {
super(daoFactory.context());
}
/**
* <p>SQL insert:</p>
* <pre>INSERT INTO city (name) VALUES (${bean.name})</pre>
*
* <p><code>bean.id</code> is automatically updated because it is the primary key</p>
*
* <p><strong>Inserted columns:</strong></p>
* <dl>
* <dt>name</dt><dd>is mapped to <strong>${bean.name}</strong></dd>
* </dl>
*
* @param bean
* is mapped to parameter <strong>bean</strong>
*
*/
@Override
public void insert(City bean) {
if (insertPreparedStatement0==null) {
// generate static SQL for statement
String _sql="INSERT INTO city (name) VALUES (?)";
insertPreparedStatement0 = KriptonDatabaseWrapper.compile(_context, _sql);
}
KriptonContentValues _contentValues=contentValuesForUpdate(insertPreparedStatement0);
_contentValues.put("name", bean.name);
// log section BEGIN
if (_context.isLogEnabled()) {
// log for insert -- BEGIN
StringBuffer _columnNameBuffer=new StringBuffer();
StringBuffer _columnValueBuffer=new StringBuffer();
String _columnSeparator="";
for (String columnName:_contentValues.keys()) {
_columnNameBuffer.append(_columnSeparator+columnName);
_columnValueBuffer.append(_columnSeparator+":"+columnName);
_columnSeparator=", ";
}
Logger.info("INSERT INTO city (%s) VALUES (%s)", _columnNameBuffer.toString(), _columnValueBuffer.toString());
// log for content values -- BEGIN
Triple<String, Object, KriptonContentValues.ParamType> _contentValue;
for (int i = 0; i < _contentValues.size(); i++) {
_contentValue = _contentValues.get(i);
if (_contentValue.value1==null) {
Logger.info("==> :%s = <null>", _contentValue.value0);
} else {
Logger.info("==> :%s = '%s' (%s)", _contentValue.value0, StringUtils.checkSize(_contentValue.value1), _contentValue.value1.getClass().getCanonicalName());
}
}
// log for content values -- END
// log for insert -- END
// log for where parameters -- BEGIN
int _whereParamCounter=0;
for (String _whereParamItem: _contentValues.whereArgs()) {
Logger.info("==> param%s: '%s'",(_whereParamCounter++), StringUtils.checkSize(_whereParamItem));
}
// log for where parameters -- END
}
// log section END
// insert operation
long result = KriptonDatabaseWrapper.insert(insertPreparedStatement0, _contentValues);
bean.id=result;
}
/**
* <h2>Select SQL:</h2>
*
* <pre>SELECT id, name FROM city</pre>
*
* <h2>Projected columns:</h2>
* <dl>
* <dt>id</dt><dd>is associated to bean's property <strong>id</strong></dd>
* <dt>name</dt><dd>is associated to bean's property <strong>name</strong></dd>
* </dl>
*
* @return collection of bean or empty collection.
*/
@Override
public List<City> listCities() {
KriptonContentValues _contentValues=contentValues();
// query SQL is statically defined
String _sql=LIST_CITIES_SQL1;
// add where arguments
String[] _sqlArgs=_contentValues.whereArgsAsArray();
// log section BEGIN
if (_context.isLogEnabled()) {
// manage log
Logger.info(_sql);
// log for where parameters -- BEGIN
int _whereParamCounter=0;
for (String _whereParamItem: _contentValues.whereArgs()) {
Logger.info("==> param%s: '%s'",(_whereParamCounter++), StringUtils.checkSize(_whereParamItem));
}
// log for where parameters -- END
}
// log section END
try (Cursor _cursor = database().rawQuery(_sql, _sqlArgs)) {
// log section BEGIN
if (_context.isLogEnabled()) {
Logger.info("Rows found: %s",_cursor.getCount());
}
// log section END
ArrayList<City> resultList=new ArrayList<City>(_cursor.getCount());
City resultBean=null;
if (_cursor.moveToFirst()) {
int index0=_cursor.getColumnIndex("id");
int index1=_cursor.getColumnIndex("name");
do
{
resultBean=new City();
resultBean.id=_cursor.getLong(index0);
if (!_cursor.isNull(index1)) { resultBean.name=_cursor.getString(index1); }
resultList.add(resultBean);
} while (_cursor.moveToNext());
}
return resultList;
}
}
public static void clearCompiledStatements() {
if (insertPreparedStatement0!=null) {
insertPreparedStatement0.close();
insertPreparedStatement0=null;
}
}
}
As you can see, for each method, source code and documentation are generated!!
- Introduction
- Goals & Features
- Kotlin
- Immutable or Mutable Pojo
- Annotation Processor Args
- Credits
- Articles
- Benchmarks
- Setup
- Tutorial
- Usage
- Dependencies and inspirations
- Stackoverflow
- Documentation
- SQL logging
- Data source options
- Indices
- SQL Type adapter
- Global SQL Type adapter
- Constraints
- Live data: welcome Architectural components!!
- Paged Live data
- Dynamic parts
- Transactional and batch operations
- Async Transactional and batch operations
- Global transaction
- Support for immutable POJO
- Generate Content provider
- Generate Database schema generation
- Database migration
- BindSqlColumn
- BindContentProvider
- BindContentProviderEntry
- BindContentProviderPath
- BindDao
- BindDaoMany2Many
- BindDataSource
- BindDataSourceOptions
- BindDataSourceUpdateTask
- BindIndex
- BindSqlRelation
- BindSqlAdapter
- BindSqlChildSelect
- BindSqlDelete
- BindSqlDynamicOrderBy
- BindSqlDynamicWhere
- BindSqlDynamicWhereParams
- BindSqlInsert
- BindSqlPageSize
- BindSqlParam
- BindSqlSelect
- BindSqlUpdate
- BindSqlType
- BindSqlTransaction