1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.room.vo 18 19 import androidx.room.OnConflictStrategy 20 import androidx.room.ext.typeName 21 import com.squareup.javapoet.ArrayTypeName 22 import com.squareup.javapoet.ParameterizedTypeName 23 import com.squareup.javapoet.TypeName 24 import javax.lang.model.element.ExecutableElement 25 import javax.lang.model.type.TypeMirror 26 27 data class InsertionMethod(val element: ExecutableElement, val name: String, 28 @OnConflictStrategy val onConflict: Int, 29 val entities: Map<String, Entity>, val returnType: TypeMirror, 30 val insertionType: Type?, 31 val parameters: List<ShortcutQueryParameter>) { insertMethodTypeFornull32 fun insertMethodTypeFor(param: ShortcutQueryParameter): Type { 33 return if (insertionType == Type.INSERT_VOID || insertionType == null) { 34 Type.INSERT_VOID 35 } else if (!param.isMultiple) { 36 Type.INSERT_SINGLE_ID 37 } else { 38 insertionType 39 } 40 } 41 42 enum class Type( 43 // methodName matches EntityInsertionAdapter methods 44 val methodName: String, val returnTypeName: TypeName) { 45 INSERT_VOID("insert", TypeName.VOID), // return void 46 INSERT_SINGLE_ID("insertAndReturnId", TypeName.LONG), // return long 47 INSERT_ID_ARRAY("insertAndReturnIdsArray", 48 ArrayTypeName.of(TypeName.LONG)), // return long[] 49 INSERT_ID_ARRAY_BOX("insertAndReturnIdsArrayBox", 50 ArrayTypeName.of(TypeName.LONG.box())), // return Long[] 51 INSERT_ID_LIST("insertAndReturnIdsList", // return List<Long> 52 ParameterizedTypeName.get(List::class.typeName(), TypeName.LONG.box())) 53 } 54 } 55