body method
Defines the actual body code. path
is passed relative to lib
, baseName
is the filename, and className
is the filename converted to Pascal case.
実際の本体コードを定義します。path
にlib
からの相対パス、baseName
にファイル名が渡され、className
にファイル名をパスカルケースに変換した値が渡されます。
Implementation
@override
String body(String path, String baseName, String className) {
return """
/// Model adapter for use with DocumentModel and CollectionModel.
///
/// It can be given by [MasamuneApp] or various [ModelQuery], or specified by [CollectionModelPath] or [DocumentModelPath].
@immutable
class ${className}ModelAdapter extends ModelAdapter {
/// Model adapter for use with DocumentModel and CollectionModel.
///
/// It can be given by [MasamuneApp] or various [ModelQuery], or specified by [CollectionModelPath] or [DocumentModelPath].
const ${className}ModelAdapter();
@override
Future<DynamicMap> loadDocument(ModelAdapterDocumentQuery query) {
// TODO: implement loadDocument
throw UnimplementedError();
}
@override
Future<Map<String, DynamicMap>> loadCollection(
ModelAdapterCollectionQuery query,
) {
// TODO: implement loadCollection
throw UnimplementedError();
}
@override
Future<T?> loadAggregation<T>(
ModelAdapterCollectionQuery query,
ModelAggregateQuery aggregateQuery,
) {
// TODO: implement loadAggregation
throw UnimplementedError();
}
@override
Future<void> saveDocument(
ModelAdapterDocumentQuery query,
DynamicMap value,
) {
// TODO: implement saveDocument
throw UnimplementedError();
}
@override
Future<void> deleteDocument(ModelAdapterDocumentQuery query) {
// TODO: implement deleteDocument
throw UnimplementedError();
}
@override
void disposeDocument(ModelAdapterDocumentQuery query) {
// TODO: implement disposeDocument
}
@override
void disposeCollection(ModelAdapterCollectionQuery query) {
// TODO: implement disposeCollection
}
@override
Future<void> clearAll() {
// TODO: implement clearAll
throw UnimplementedError();
}
@override
// TODO: implement availableListen
bool get availableListen => false;
@override
Future<List<StreamSubscription>> listenDocument(
ModelAdapterDocumentQuery query,
) {
// TODO: implement listenDocument
throw UnsupportedError("This function is not supported.");
}
@override
Future<List<StreamSubscription>> listenCollection(
ModelAdapterCollectionQuery query,
) {
// TODO: implement listenCollection
throw UnsupportedError("This function is not supported.");
}
@override
FutureOr<void> runTransaction(
FutureOr<void> Function(ModelTransactionRef ref) transaction,
) async {
// TODO: implement runTransaction
final ref = ${className}ModelTransactionRef._();
await transaction.call(ref);
for (final tmp in ref._transactionList) {
await tmp.call();
}
}
@override
FutureOr<DynamicMap> loadOnTransaction(
ModelTransactionRef ref,
ModelAdapterDocumentQuery query,
) {
// TODO: implement loadOnTransaction
throw UnsupportedError("This function is not supported.");
}
@override
void saveOnTransaction(
ModelTransactionRef ref,
ModelAdapterDocumentQuery query,
DynamicMap value,
) {
if (ref is! ${className}ModelTransactionRef) {
throw Exception("[ref] is not [${className}ModelTransactionRef].");
}
// TODO: implement saveOnTransaction
throw UnsupportedError("This function is not supported.");
}
@override
void deleteOnTransaction(
ModelTransactionRef ref,
ModelAdapterDocumentQuery query,
) {
if (ref is! ${className}ModelTransactionRef) {
throw Exception("[ref] is not [${className}ModelTransactionRef].");
}
// TODO: implement deleteOnTransaction
throw UnsupportedError("This function is not supported.");
}
@override
FutureOr<void> runBatch(
FutureOr<void> Function(ModelBatchRef ref) batch,
int splitLength,
) async {
// TODO: implement runBatch
final ref = ${className}ModelBatchRef._();
await wait(
ref._batchList.map((tmp) => tmp.call()),
);
}
@override
void saveOnBatch(
ModelBatchRef ref,
ModelAdapterDocumentQuery query,
DynamicMap value,
) {
if (ref is! ${className}ModelBatchRef) {
throw Exception("[ref] is not [${className}ModelBatchRef].");
}
// TODO: implement saveOnBatch
throw UnsupportedError("This function is not supported.");
}
@override
void deleteOnBatch(
ModelBatchRef ref,
ModelAdapterDocumentQuery query,
) {
if (ref is! ${className}ModelBatchRef) {
throw Exception("[ref] is not [${className}ModelBatchRef].");
}
// TODO: implement deleteOnBatch
throw UnsupportedError("This function is not supported.");
}
@override
Future<void> clearCache() {
// TODO: implement clearCache
throw UnsupportedError("This function is not supported.");
}
}
/// [ModelTransactionRef] for [${className}ModelAdapter].
@immutable
class ${className}ModelTransactionRef extends ModelTransactionRef {
${className}ModelTransactionRef._();
final List<FutureOr<void> Function()> _transactionList = [];
}
/// [ModelBatchRef] for [${className}ModelAdapter].
@immutable
class ${className}ModelBatchRef extends ModelBatchRef {
${className}ModelBatchRef._();
final List<FutureOr<void> Function()> _batchList = [];
}
""";
}