Skip to content

Commit 4894b9a

Browse files
committed
fixes warnings
1 parent 1019566 commit 4894b9a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+247
-238
lines changed

activerecord/src/main/scala/ActiveRecord.scala

+9-6
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ trait ActiveRecordBase[T] extends CRUDable with ActiveModel with ActiveRecord.As
3737
override def save(): Boolean = save(false)
3838

3939
def save(throws: Boolean = false, validate: Boolean = true): Boolean = {
40-
val result = if (validate) super.save else super.saveWithoutValidation
41-
result || (throws && (throw ActiveRecordException.saveFailed(errors)))
40+
val result = if (validate) super.save() else super.saveWithoutValidation()
41+
if (!result && throws) throw ActiveRecordException.saveFailed(errors)
42+
result
4243
}
4344

4445
def create: this.type = create(true)
@@ -57,17 +58,17 @@ trait ActiveRecordBase[T] extends CRUDable with ActiveModel with ActiveRecord.As
5758
this
5859
}
5960

60-
protected def doCreate: Boolean = {
61+
protected def doCreate(): Boolean = {
6162
recordCompanion.create(this)
6263
true
6364
}
6465

65-
protected def doUpdate: Boolean = {
66+
protected def doUpdate(): Boolean = {
6667
recordCompanion.update(this)
6768
true
6869
}
6970

70-
protected def doDelete: Boolean = {
71+
protected def doDelete(): Boolean = {
7172
val result = if (isDeleted) false else recordCompanion.delete(id)
7273
if (result) _isDeleted = true
7374
result
@@ -156,13 +157,15 @@ trait ActiveRecordBaseCompanion[K, T <: ActiveRecordBase[K]]
156157
*/
157158
protected[activerecord] def create(model: T): Unit = inTransaction {
158159
table.insert(model)
160+
()
159161
}
160162

161163
/**
162164
* update record from model.
163165
*/
164166
protected[activerecord] def update(model: T): Unit = inTransaction {
165167
table.update(model)
168+
()
166169
}
167170

168171
/**
@@ -193,7 +196,7 @@ trait ActiveRecordBaseCompanion[K, T <: ActiveRecordBase[K]]
193196
def forceInsertAll(models: T*): Unit = forceInsertAll(models.toIterable)
194197

195198
def insertWithValidation(models: Iterable[T]): Iterable[T] = {
196-
val (valid, invalid) = models.partition(_.validate)
199+
val (valid, invalid) = models.partition(_.validate())
197200
forceInsertAll(valid)
198201
invalid
199202
}

activerecord/src/main/scala/ActiveRecordConfig.scala

-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package com.github.aselab.activerecord
22

3-
import org.squeryl.Session
43
import org.squeryl.internals.DatabaseAdapter
54
import org.squeryl.adapters._
65
import java.sql.Connection
76
import java.util.TimeZone
87
import com.zaxxer.hikari._
98
import com.typesafe.config._
109
import org.slf4j.{Logger, LoggerFactory}
11-
import scala.util.control.Exception.catching
1210
import scala.jdk.CollectionConverters._
1311
import org.joda.time.format._
1412
import org.joda.time.DateTimeZone

activerecord/src/main/scala/ActiveRecordTables.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import scala.language.existentials
1515
* Base class of database schema.
1616
*/
1717
trait ActiveRecordTables extends Schema {
18-
import ReflectionUtil.{defaultLoader, classToARCompanion, getGenericTypes, toReflectable}
18+
import ReflectionUtil.{classToARCompanion, getGenericTypes, toReflectable}
1919

2020
lazy val tableMap = {
2121
val c = classOf[ActiveRecord.HasAndBelongsToManyAssociation[_, _]]
@@ -79,7 +79,7 @@ trait ActiveRecordTables extends Schema {
7979
def foreignKeyFromClass(c: Class[_]): String =
8080
c.getSimpleName.camelize + "Id"
8181

82-
protected def execute(sql: String, logging: Boolean = true): Unit = inTransaction {
82+
protected def execute(sql: String, logging: Boolean = true): Boolean = inTransaction {
8383
if (logging) config.logger.debug(sql)
8484
val connection = Session.currentSession.connection
8585
val s = connection.createStatement
@@ -131,7 +131,7 @@ trait ActiveRecordTables extends Schema {
131131
if (config.autoDrop) drop
132132
config.cleanup
133133
sessionStack.foreach { case (s1, s2) => s1.foreach(_.cleanup); s2.cleanup }
134-
sessionStack.clear
134+
sessionStack.clear()
135135
_initialized = false
136136
}
137137

@@ -181,7 +181,7 @@ trait ActiveRecordTables extends Schema {
181181
}
182182

183183
def endTransaction: Unit = try {
184-
val (oldSession, newSession) = sessionStack.pop
184+
val (oldSession, newSession) = sessionStack.pop()
185185
newSession.unbindFromCurrentThread
186186
newSession.close
187187
oldSession.foreach(_.bindToCurrentThread)
@@ -191,7 +191,7 @@ trait ActiveRecordTables extends Schema {
191191

192192
/** Rollback to startTransaction point */
193193
def rollback: Unit = try {
194-
val (oldSession, newSession) = sessionStack.pop
194+
val (oldSession, newSession) = sessionStack.pop()
195195
newSession.connection.rollback
196196
newSession.unbindFromCurrentThread
197197
newSession.close
@@ -211,7 +211,7 @@ trait ActiveRecordTables extends Schema {
211211
out.toString
212212
}
213213

214-
def table[T <: AR]()(implicit m: Manifest[T]): Table[T] = {
214+
def table[T <: AR](implicit m: Manifest[T]): Table[T] = {
215215
val typeT = m.runtimeClass.asInstanceOf[Class[T]]
216216
val columnName = baseARType(typeT)
217217
.map(c => tableNameFromClass(c.name.toString))

activerecord/src/main/scala/Timestamps.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ trait Timestamps extends CRUDable {
88
var updatedAt: DateTime = null
99

1010
abstract override protected def doCreate() = {
11-
val now = DateTime.now
11+
val now = DateTime.now()
1212
createdAt = now
1313
updatedAt = now
1414
super.doCreate()
1515
}
1616

1717
abstract override protected def doUpdate() = {
18-
updatedAt = DateTime.now
18+
updatedAt = DateTime.now()
1919
super.doUpdate()
2020
}
2121
}
@@ -25,14 +25,14 @@ trait Datestamps extends CRUDable {
2525
var updatedOn: LocalDate = null
2626

2727
abstract override protected def doCreate() = {
28-
val today = LocalDate.now
28+
val today = LocalDate.now()
2929
createdOn = today
3030
updatedOn = today
3131
super.doCreate()
3232
}
3333

3434
abstract override protected def doUpdate() = {
35-
updatedOn = LocalDate.now
35+
updatedOn = LocalDate.now()
3636
super.doUpdate()
3737
}
3838
}

activerecord/src/main/scala/experimental/versions.scala

+6-7
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ trait Versionable extends ActiveRecord with Serializable {
66
import reflections.ReflectionUtil._
77

88
@dsl.Ignore private lazy val _className = getClass.getName
9+
@dsl.Ignore protected var changed = collection.mutable.Map[String, (Any, Any)]()
910

10-
abstract override def doUpdate: Boolean = Version.inTransaction {
11+
abstract override def doUpdate(): Boolean = Version.inTransaction {
1112
changed.foreach { case (name, value) =>
12-
Version(_className, this.id, name, value._1.toString, value._2.toString).save
13+
Version(_className, this.id, name, value._1.toString, value._2.toString).save()
1314
}
14-
changed.clear
15-
super.doUpdate
15+
changed.clear()
16+
super.doUpdate()
1617
}
1718

18-
@dsl.Ignore private var changed = collection.mutable.Map[String, (Any, Any)]()
19-
2019
private def setId(id: Long) = {
2120
val f = classOf[ActiveRecord].getDeclaredField("id")
2221
f.setAccessible(true)
@@ -54,5 +53,5 @@ case class Version(
5453
object Version extends ActiveRecordCompanion[Version]
5554

5655
trait VersionTable extends org.squeryl.Schema {
57-
val _versionTable = table[Version]
56+
val _versionTable = table[Version]()
5857
}

activerecord/src/main/scala/inner/Associations.scala

+12-12
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ trait Associations {
6565

6666
def delete(): Option[T] = companion.inTransaction {
6767
val result = toOption
68-
result.foreach(_.delete)
68+
result.foreach(_.delete())
6969
relation.cache = Nil
7070
result
7171
}
@@ -78,7 +78,7 @@ trait Associations {
7878

7979
def deleteAll(): List[T] = companion.inTransaction {
8080
val result = relation.toList
81-
result.foreach(_.delete)
81+
result.foreach(_.delete())
8282
relation.cache = Nil
8383
result
8484
}
@@ -138,12 +138,12 @@ trait Associations {
138138
val field = fieldInfo(foreignKey)
139139

140140
val r = source.where(conditionFactory(conditions)).where(
141-
m => field.toInExpression(m.getValue(foreignKey), ids)).toQuery.toList
141+
m => field.toInExpression(m.getValue[Any](foreignKey), ids)).toQuery.toList
142142
r.groupBy(_.getOption[Any](foreignKey).orNull)
143143
}
144144

145145
def associate(m: T): T = companion.inTransaction {
146-
if (hasConstraint) delete else remove
146+
if (hasConstraint) delete() else remove()
147147
if (m.isNewRecord) m.save(throws = true)
148148
assignConditions(m).update
149149
relation.cache = List(m)
@@ -199,7 +199,7 @@ trait Associations {
199199

200200
def associate(m: T): I = companion.inTransaction {
201201
if (m.isNewRecord) throw ActiveRecordException.recordMustBeSaved
202-
if (hasConstraint) delete else remove
202+
if (hasConstraint) delete() else remove()
203203
assignConditions(m).update
204204
relation.cache = List(m)
205205
val inter = through.build
@@ -227,8 +227,8 @@ trait Associations {
227227
}
228228

229229
override def delete(): Option[T] = companion.inTransaction {
230-
val result = super.delete
231-
if (hasConstraint) through.delete else remove
230+
val result = super.delete()
231+
if (hasConstraint) through.delete() else remove()
232232
result
233233
}
234234
}
@@ -250,7 +250,7 @@ trait Associations {
250250
val field = fieldInfo(foreignKey)
251251

252252
val r = source.where(conditionFactory(conditions)).where(
253-
m => field.toInExpression(m.getValue(foreignKey), ids)).toQuery.toList
253+
m => field.toInExpression(m.getValue[Any](foreignKey), ids)).toQuery.toList
254254
r.groupBy(_.getOption[Any](foreignKey).orNull)
255255
}
256256

@@ -272,7 +272,7 @@ trait Associations {
272272
def ++=(list: Iterable[T]): List[T] = this << list
273273

274274
def :=(list: Iterable[T]): List[T] = companion.inTransaction {
275-
if (hasConstraint) deleteAll else removeAll
275+
if (hasConstraint) deleteAll() else removeAll()
276276
relation.cache = list.toList.map(associate)
277277
}
278278

@@ -355,7 +355,7 @@ trait Associations {
355355
def ++=(list: Iterable[T]): List[I] = this << list
356356

357357
def :=(list: Iterable[T]): List[I] = companion.inTransaction {
358-
if (hasConstraint) deleteAll else removeAll
358+
if (hasConstraint) deleteAll() else removeAll()
359359
relation.cache = list.toList
360360
relation.cache.map(associate)
361361
}
@@ -393,8 +393,8 @@ trait Associations {
393393
}
394394

395395
override def deleteAll(): List[T] = companion.inTransaction {
396-
val result = super.deleteAll
397-
if (hasConstraint) through.deleteAll else removeAll
396+
val result = super.deleteAll()
397+
if (hasConstraint) through.deleteAll() else removeAll()
398398
relation.cache = Nil
399399
result
400400
}

activerecord/src/main/scala/inner/Implicits.scala

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import ActiveRecord._
77
import reflections._
88
import scala.reflect.ClassTag
99
import scala.language.reflectiveCalls
10+
import scala.language.implicitConversions
1011

1112
// scalastyle:off
1213

activerecord/src/main/scala/inner/Optimistic.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ trait Optimistic extends CRUDable { self: AR =>
1010
private def occVersion = occVersionNumber
1111

1212
/** update with lock */
13-
abstract override protected def doUpdate = try {
14-
val result = super.doUpdate
13+
abstract override protected def doUpdate() = try {
14+
val result = super.doUpdate()
1515
if (result) {
1616
this.setValue("occVersionNumber", occVersion + 1)
1717
}
@@ -21,9 +21,9 @@ trait Optimistic extends CRUDable { self: AR =>
2121
}
2222

2323
/** destroy with lock */
24-
abstract override protected def doDelete = self.recordInDatabase match {
24+
abstract override protected def doDelete() = self.recordInDatabase match {
2525
case Some(m) if m.occVersion != occVersion =>
2626
throw ActiveRecordException.staleDelete(self.getClass.getName)
27-
case _ => super.doDelete
27+
case _ => super.doDelete()
2828
}
2929
}

activerecord/src/main/scala/inner/ProductModel.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trait ProductModelCompanion[T <: ProductModel] {
2020
/**
2121
* Create a new model object.
2222
*/
23-
def newInstance: T = classInfo.factory.apply
23+
def newInstance: T = classInfo.factory.apply()
2424

2525
/** ProductModel class information */
2626
lazy val classInfo: ClassInfo[T] = ClassInfo(targetClass)

activerecord/src/main/scala/inner/Relations.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import reflections._
99
import ReflectionUtil._
1010
import scala.language.reflectiveCalls
1111
import scala.language.experimental.macros
12+
import scala.language.implicitConversions
1213
import scala.reflect.ClassTag
1314

1415
trait Relations {
@@ -244,8 +245,8 @@ trait Relations {
244245
def findByOrCreate(m: T, fields: String*): S = macro MethodMacros.findByOrCreate[T, S]
245246

246247
def unsafeFindByOrCreate(m: T, field: String, fields: String*)(implicit ev: T =:= S): S = {
247-
unsafeFindBy((field, m.getValue(field)),
248-
fields.map(f => (f, m.getValue(f))).toSeq:_*).getOrElse(m.create)
248+
unsafeFindBy((field, m.getValue[Any](field)),
249+
fields.map(f => (f, m.getValue[Any](f))).toSeq:_*).getOrElse(m.create)
249250
}
250251

251252
/**
@@ -315,7 +316,7 @@ trait Relations {
315316

316317
def deleteAll()(implicit ev: S =:= T): List[T] = companion.inTransaction {
317318
val records = toQuery.toList
318-
records.foreach(_.delete)
319+
records.foreach(_.delete())
319320
records.asInstanceOf[List[T]]
320321
}
321322

activerecord/src/main/scala/io/FormSupport.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ trait FormSerializer extends IO { self: ProductModel =>
121121
errors.toSeq ++ nestErrors
122122
}
123123

124-
override def validate(): Boolean = super.validate && formErrors.isEmpty
124+
override def validate(): Boolean = super.validate() && formErrors.isEmpty
125125
}
126126

127127
trait FormSupport[T <: ActiveModel] { self: ProductModelCompanion[T] =>

activerecord/src/main/scala/io/JsonSupport.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import com.github.aselab.activerecord._
44
import inner._
55
import reflections._
66
import scala.reflect.ClassTag
7+
import scala.language.implicitConversions
78

8-
import java.sql.Timestamp
9-
import java.text.SimpleDateFormat
10-
import java.util.UUID
119
import org.json4s._
1210
import org.json4s.native.JsonMethods
1311
import org.json4s.native.Serialization

activerecord/src/main/scala/io/converters.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ package com.github.aselab.activerecord.io
22

33
import com.github.aselab.activerecord._
44
import reflections._
5-
import java.util.{Date, UUID, TimeZone}
5+
import java.util.{Date, UUID}
66
import java.sql.Timestamp
77
import com.github.nscala_time.time.Imports._
8-
import org.joda.time.format.ISODateTimeFormat
98

109
trait Converter[A, B] {
1110
def serialize(v: Any): B

0 commit comments

Comments
 (0)