Coverage Summary for Class: SQLStatement (com.acciente.oacc.sql.internal.persister)

Class Class, % Method, % Line, %
SQLStatement 100% (1/ 1) 94.4% (17/ 18) 93.9% (31/ 33)


1 /* 2  * Copyright 2009-2018, Acciente LLC 3  * 4  * Acciente LLC licenses this file to you under the 5  * Apache License, Version 2.0 (the "License"); you 6  * may not use this file except in compliance with the 7  * License. You may obtain a copy of the License at 8  * 9  * http://www.apache.org/licenses/LICENSE-2.0 10  * 11  * Unless required by applicable law or agreed to in 12  * writing, software distributed under the License is 13  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES 14  * OR CONDITIONS OF ANY KIND, either express or implied. 15  * See the License for the specific language governing 16  * permissions and limitations under the License. 17  */ 18 package com.acciente.oacc.sql.internal.persister; 19  20 import com.acciente.oacc.Resource; 21 import com.acciente.oacc.sql.internal.persister.id.DomainId; 22 import com.acciente.oacc.sql.internal.persister.id.Id; 23 import com.acciente.oacc.sql.internal.persister.id.ResourceClassId; 24 import com.acciente.oacc.sql.internal.persister.id.ResourceId; 25 import com.acciente.oacc.sql.internal.persister.id.ResourcePermissionId; 26  27 import java.sql.PreparedStatement; 28 import java.sql.SQLException; 29  30 public class SQLStatement { 31  private final PreparedStatement statement; 32  33  SQLStatement(PreparedStatement statement) { 34  this.statement = statement; 35  } 36  37  public void setResourceId(int parameterIndex, Id<ResourceId> resourceId) throws SQLException { 38  statement.setLong(parameterIndex, resourceId.getValue()); 39  } 40  41  public void setResourceId(int parameterIndex, Resource resource) throws SQLException { 42  statement.setLong(parameterIndex, resource.getId()); 43  } 44  45  public void setResourceClassId(int parameterIndex, Id<ResourceClassId> id) throws SQLException { 46  statement.setLong(parameterIndex, id.getValue()); 47  } 48  49  public void setResourceDomainId(int parameterIndex, Id<DomainId> id) throws SQLException { 50  statement.setLong(parameterIndex, id.getValue()); 51  } 52  53  public void setResourceCreateSystemPermissionId(int parameterIndex, long resourceCreateSystemPermissionId) throws SQLException { 54  statement.setLong(parameterIndex, resourceCreateSystemPermissionId); 55  } 56  57  public void setResourceSystemPermissionId(int parameterIndex, long resourceSystemPermissionId) throws SQLException { 58  statement.setLong(parameterIndex, resourceSystemPermissionId); 59  } 60  61  public void setResourcePermissionId(int parameterIndex, 62  Id<ResourcePermissionId> resourcePermissionId) throws SQLException { 63  statement.setLong(parameterIndex, resourcePermissionId.getValue()); 64  } 65  66  public void setDomainCreateSystemPermissionId(int parameterIndex, long domainCreateSystemPermissionId) throws SQLException { 67  statement.setLong(parameterIndex, domainCreateSystemPermissionId); 68  } 69  70  public void setDomainSystemPermissionId(int parameterIndex, long domainSystemPermissionId) throws SQLException { 71  statement.setLong(parameterIndex, domainSystemPermissionId); 72  } 73  74  public void setBoolean(int parameterIndex, boolean value) throws SQLException { 75  statement.setInt(parameterIndex, bool2int(value)); 76  } 77  78  public void setString(int parameterIndex, String value) throws SQLException { 79  statement.setString(parameterIndex, value); 80  } 81  82  public void setNull(int parameterIndex, int sqlType) throws SQLException { 83  statement.setNull(parameterIndex, sqlType); 84  } 85  86  SQLResult executeQuery() throws SQLException { 87  return new SQLResult(statement.executeQuery()); 88  } 89  90  int executeUpdate() throws SQLException { 91  return statement.executeUpdate(); 92  } 93  94  public SQLResult getGeneratedKeys() throws SQLException { 95  return new SQLResult(statement.getGeneratedKeys()); 96  } 97  98  void close() throws SQLException { 99  statement.close(); 100  } 101  102  // helpers 103  104  private static int bool2int(boolean value) { 105  return value ? 1 : 0; 106  } 107 }