├── project ├── build.properties └── plugins.sbt ├── scala-dddbase-core ├── jvm │ └── src │ │ └── test │ │ ├── resources │ │ └── readme.txt │ │ └── scala │ │ └── org │ │ └── sisioh │ │ └── dddbase │ │ └── core │ │ ├── model │ │ ├── EntityCloneableSpec.scala │ │ ├── EntitySpec.scala │ │ └── IdentitySpec.scala │ │ └── lifecycle │ │ └── ValueObjectBuilderSpec.scala └── shared │ └── src │ └── main │ ├── resources │ └── readme.txt │ └── scala │ └── org │ └── sisioh │ └── dddbase │ └── core │ ├── model │ ├── EntitySerializable.scala │ ├── EntityOrdered.scala │ ├── EntityCloneable.scala │ ├── Entity.scala │ └── Identifier.scala │ ├── lifecycle │ ├── EntityIOContext.scala │ ├── sync │ │ ├── SyncEntityIO.scala │ │ ├── SyncEntityIOContext.scala │ │ ├── SyncEntityReadableByIterable.scala │ │ ├── SyncRepository.scala │ │ ├── SyncEntityReadableAsOption.scala │ │ ├── SyncEntityReadableAsChunk.scala │ │ ├── SyncEntityReadableAsPredicate.scala │ │ ├── SyncResultWithEntity.scala │ │ ├── SyncResultWithEntities.scala │ │ ├── SyncEntityReader.scala │ │ └── SyncEntityWriter.scala │ ├── EntityIO.scala │ ├── EntitiesChunk.scala │ ├── RepositoryException.scala │ ├── EntityNotFoundException.scala │ ├── ResultWithEntity.scala │ ├── ResultWithEntities.scala │ ├── Repository.scala │ ├── EntityReadableAsOption.scala │ ├── EntityReadableAsChunk.scala │ ├── async │ │ ├── AsyncEntityReadableAsSeq.scala │ │ ├── AsyncRepository.scala │ │ ├── AsyncEntityReadableAsChunk.scala │ │ ├── AsyncEntityIO.scala │ │ ├── AsyncEntityReadableAsPredicate.scala │ │ ├── AsyncResultWithEntity.scala │ │ ├── AsyncResultWithEntities.scala │ │ ├── AsyncEntityReader.scala │ │ ├── AsyncEntityWriter.scala │ │ └── AsyncEntityIOContext.scala │ ├── EntityReadableAsPredicate.scala │ ├── EntityReader.scala │ ├── ValueObjectBuilder.scala │ └── EntityWriter.scala │ └── BaseException.scala ├── scala-dddbase-spec ├── jvm │ └── src │ │ └── test │ │ ├── resources │ │ └── readme.txt │ │ └── scala │ │ └── org │ │ └── sisioh │ │ └── dddbase │ │ └── spec │ │ ├── SpecificationTest.scala │ │ ├── NotSpecificationTest.scala │ │ ├── OrSpecificationTest.scala │ │ └── AndSpecificationTest.scala └── shared │ └── src │ └── main │ ├── resources │ └── readme.txt │ └── scala │ └── org │ └── sisioh │ └── dddbase │ ├── core │ ├── EntityReadableBySpecification.scala │ ├── SyncEntityReadableBySpecification.scala │ └── AsyncEntityReadableBySpecification.scala │ └── spec │ ├── AndSpecification.scala │ ├── NotSpecification.scala │ ├── OrSpecification.scala │ └── Specification.scala ├── version.sbt ├── .gitignore ├── scala-dddbase-lifecycle-repositories-memory ├── jvm │ └── src │ │ └── test │ │ └── scala │ │ └── org │ │ └── sisioh │ │ └── dddbase │ │ └── lifecycle │ │ └── memory │ │ ├── mutable │ │ ├── async │ │ │ ├── TestAsyncRepository.scala │ │ │ ├── TestEntity.scala │ │ │ ├── TestAsyncRepositoryOnMemory.scala │ │ │ └── GenericAsyncRepositoryOnMemorySpec.scala │ │ └── sync │ │ │ ├── GenericSyncRepositoryOnMemoryAsChunkSpec.scala │ │ │ ├── GenericSyncRepositoryOnMemoryAsPredicateSpec.scala │ │ │ └── GenericSyncRepositoryOnMemorySpec.scala │ │ └── sync │ │ ├── SyncRepositoryOnMemorySupportAsChunk2Spec.scala │ │ ├── SyncRepositoryOnMemorySupportAsChunkSpec.scala │ │ └── SyncRepositoryOnMemorySupportByPredicateSpec.scala └── shared │ └── src │ └── main │ └── scala │ └── org │ └── sisioh │ └── dddbase │ └── lifecycle │ └── memory │ ├── JDKCollectionConvertersCompat.scala │ ├── sync │ ├── AbstractSyncRepositoryOnMemory.scala │ ├── SyncRepositoryOnMemory.scala │ ├── SyncRepositoryOnMemorySupportAsChunk.scala │ ├── SyncRepositoryOnMemorySupportAsOption.scala │ ├── SyncRepositoryOnMemorySupportAsPredicate.scala │ ├── GenericSyncRepositoryOnMemory.scala │ └── SyncRepositoryOnMemorySupport.scala │ ├── mutable │ ├── sync │ │ ├── AbstractSyncRepositoryOnMemory.scala │ │ ├── SyncRepositoryOnMemory.scala │ │ ├── SyncRepositoryOnMemorySupport.scala │ │ └── GenericSyncRepositoryOnMemory.scala │ └── async │ │ ├── AsyncRepositoryOnMemory.scala │ │ ├── AbstractAsyncRepositoryOnMemory.scala │ │ ├── AsyncRepositoryOnMemorySupport.scala │ │ └── GenericAsyncRepositoryOnMemory.scala │ └── async │ ├── AsyncRepositoryOnMemory.scala │ ├── AbstractAsyncRepositoryOnMemory.scala │ ├── AsyncRepositoryOnMemorySupportAsSeq.scala │ ├── AsyncRepositoryOnMemorySupportAsChunk.scala │ ├── AsyncRepositoryOnMemorySupportAsPredicate.scala │ ├── AsyncRepositoryOnMemorySupport.scala │ └── GenericAsyncRepositoryOnMemory.scala ├── .travis.yml ├── scala-dddbase-lifecycle-repositories-forwarding ├── jvm │ └── src │ │ └── test │ │ └── scala │ │ └── org │ │ └── sisioh │ │ └── dddbase │ │ └── lifecycle │ │ └── forwarding │ │ ├── TestSyncMutableRepository.scala │ │ ├── TestSyncRepository.scala │ │ ├── TestAsyncMutableRepository.scala │ │ └── TestAsyncRepository.scala └── shared │ └── src │ └── main │ └── scala │ └── org │ └── sisioh │ └── dddbase │ └── lifecycle │ └── forwarding │ ├── async │ ├── ForwardingAsyncRepository.scala │ ├── wrapped │ │ ├── AsyncWrappedSyncRepository.scala │ │ ├── AsyncWrappedSyncEntityIO.scala │ │ ├── AsyncWrappedSyncEntityReader.scala │ │ ├── AsyncWrappedSyncEntityIOContext.scala │ │ └── AsyncWrappedSyncEntityWriter.scala │ ├── ForwardingAsyncEntityReader.scala │ ├── ForwardingAsyncEntityReadableAsChunk.scala │ ├── ForwardingAsyncEntityReadableAsPredicate.scala │ └── ForwardingAsyncEntityWriter.scala │ └── sync │ ├── wrapped │ ├── SyncWrappedAsyncRepository.scala │ ├── SyncWrappedAsyncEntityIO.scala │ ├── SyncWrappedAsyncEntityReader.scala │ ├── SyncWrappedAsyncEntityIOContext.scala │ └── SyncWrappedAsyncEntityWriter.scala │ ├── ForwardingSyncRepository.scala │ ├── ForwardingSyncEntityReadableAsOption.scala │ ├── ForwardingSyncEntityReader.scala │ ├── ForwardingSyncEntityReadableAsChunk.scala │ ├── ForwardingSyncEntityReadableAsPredicate.scala │ └── ForwardingSyncEntityWriter.scala ├── release.sbt └── README.md /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.3.4 2 | -------------------------------------------------------------------------------- /scala-dddbase-core/jvm/src/test/resources/readme.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scala-dddbase-spec/jvm/src/test/resources/readme.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/resources/readme.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scala-dddbase-spec/shared/src/main/resources/readme.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /version.sbt: -------------------------------------------------------------------------------- 1 | version in ThisBuild := "0.2.13-SNAPSHOT" 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | target/ 3 | .project 4 | .classpath 5 | .idea* 6 | .settings 7 | *.iml 8 | 9 | .credentials -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | //logLevel := Level.Warn 2 | 3 | addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.6") 4 | 5 | addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.0") 6 | 7 | addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.12") 8 | 9 | addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.1") 10 | 11 | addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.31") 12 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/model/EntitySerializable.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.core.model 2 | 3 | /** 4 | * シリアライズに対応したエンティティを実装するためのトレイト。 5 | * 6 | * @tparam ID 識別子の型 7 | * @tparam E エンティティの型 8 | */ 9 | trait EntitySerializable[ID <: Identifier[_ <: java.io.Serializable], E <: Entity[ID]] 10 | extends Serializable { 11 | this: Entity[ID] => 12 | 13 | } 14 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/jvm/src/test/scala/org/sisioh/dddbase/lifecycle/memory/mutable/async/TestAsyncRepository.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.lifecycle.memory.mutable.async 2 | 3 | import java.util.UUID 4 | import org.sisioh.dddbase.core.lifecycle.async.AsyncRepository 5 | import org.sisioh.dddbase.core.model.Identifier 6 | 7 | trait TestAsyncRepository 8 | extends AsyncRepository[Identifier[UUID], TestEntity] { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/jvm/src/test/scala/org/sisioh/dddbase/lifecycle/memory/mutable/async/TestEntity.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.lifecycle.memory.mutable.async 2 | 3 | import java.util.UUID 4 | import org.sisioh.dddbase.core.model.{ Identifier, EntityCloneable, Entity } 5 | 6 | trait TestEntity 7 | extends Entity[Identifier[UUID]] 8 | with EntityCloneable[Identifier[UUID], TestEntity] 9 | with Ordered[TestEntity] { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/model/EntityOrdered.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.core.model 2 | 3 | /** 4 | * 順序に対応したエンティティを実装するためのトレイト。 5 | * 6 | * @tparam ID 識別子の型 7 | * @tparam E エンティティの型 8 | */ 9 | trait EntityOrdered[A, ID <: OrderedIdentifier[A, ID], E <: Entity[ID]] 10 | extends Ordered[E] { 11 | this: Entity[ID] => 12 | 13 | def compare(that: E): Int = { 14 | identifier compare that.identifier 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/jvm/src/test/scala/org/sisioh/dddbase/lifecycle/memory/mutable/async/TestAsyncRepositoryOnMemory.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.lifecycle.memory.mutable.async 2 | 3 | import java.util.UUID 4 | import org.sisioh.dddbase.core.model.Identifier 5 | 6 | class TestAsyncRepositoryOnMemory 7 | extends AbstractAsyncRepositoryOnMemory[Identifier[UUID], TestEntity] 8 | with TestAsyncRepository { 9 | 10 | type This = TestAsyncRepositoryOnMemory 11 | 12 | } 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: scala 2 | 3 | scala: 4 | - "2.13.1" 5 | - "2.12.8" 6 | - "2.11.7" 7 | 8 | jdk: 9 | - openjdk8 10 | 11 | sudo: false 12 | 13 | cache: 14 | directories: 15 | - $HOME/.ivy2/cache 16 | script: 17 | - sbt ++${TRAVIS_SCALA_VERSION} test 18 | - find $HOME/.ivy2/cache -name "ivydata-*.properties" | xargs rm 19 | - find $HOME/.ivy2/cache -name "*SNAPSHOT*" | xargs rm -rf 20 | - if [[ ${JAVA_HOME} == $(jdk_switcher home oraclejdk7) ]]; then rm -rf $HOME/.ivy2/cache ; fi 21 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/model/EntityCloneable.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.core.model 2 | 3 | /** 4 | * クローンに対応したエンティティを実装するためのトレイト。 5 | * 6 | * @tparam ID 識別子の型 7 | * @tparam E エンティティの型 8 | */ 9 | trait EntityCloneable[ID <: Identifier[_], E <: Entity[ID]] 10 | extends Cloneable { 11 | this: Entity[ID] => 12 | 13 | /** 14 | * クローンを生成する。 15 | * 16 | * @return クローンしたインスタンス 17 | */ 18 | override def clone: E = 19 | super.clone.asInstanceOf[E] 20 | 21 | } 22 | -------------------------------------------------------------------------------- /scala-dddbase-core/jvm/src/test/scala/org/sisioh/dddbase/core/model/EntityCloneableSpec.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.core.model 2 | 3 | import java.util.UUID 4 | import org.specs2.mutable._ 5 | 6 | class EntityCloneableSpec extends Specification { 7 | val id = Identifier(UUID.randomUUID) 8 | 9 | "a cloned entity" should { 10 | val entity = new Entity[Identifier[UUID]] with EntityCloneable[Identifier[UUID], Entity[Identifier[UUID]]] { 11 | val identifier = id 12 | } 13 | "equal the entity that before clone it" in { 14 | entity must_== entity.clone 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/shared/src/main/scala/org/sisioh/dddbase/lifecycle/memory/JDKCollectionConvertersCompat.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.lifecycle.memory 2 | 3 | //FIXME cross-build用オブジェクトの置き場が分からない 4 | object JDKCollectionConvertersCompat { 5 | object Scope1 { 6 | object jdk { 7 | type CollectionConverters = Int 8 | } 9 | } 10 | import Scope1._ 11 | 12 | object Scope2 { 13 | import scala.collection.{JavaConverters => CollectionConverters} 14 | object Inner { 15 | import scala._ 16 | import jdk.CollectionConverters 17 | val Converters = CollectionConverters 18 | } 19 | } 20 | 21 | val Converters = Scope2.Inner.Converters 22 | } 23 | -------------------------------------------------------------------------------- /scala-dddbase-spec/shared/src/main/scala/org/sisioh/dddbase/core/EntityReadableBySpecification.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.core 2 | 3 | import org.sisioh.dddbase.core.lifecycle.EntitiesChunk 4 | import org.sisioh.dddbase.core.model._ 5 | import org.sisioh.dddbase.spec.Specification 6 | 7 | import scala.language.higherKinds 8 | 9 | /** 10 | * `Specification` を使った検索を行うためのトレイト。 11 | * 12 | * @tparam ID 識別子の型 13 | * @tparam T エンティティの型 14 | * @tparam M モナドの型 15 | */ 16 | trait EntityReadableBySpecification[ID <: Identifier[_], T <: Entity[ID], M[+A]] { 17 | 18 | /** 19 | * `Specification` に該当したエンティティを取得する。 20 | * 21 | * @param specification `Specification` 22 | * @return モナドにラップされた `EntitiesChunk` 23 | */ 24 | def filterBySpecification(specification: Specification[T], index: Option[Int] = None, maxEntities: Option[Int] = None): M[EntitiesChunk[ID, T]] 25 | 26 | } 27 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/EntityIOContext.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle 17 | 18 | import scala.language.higherKinds 19 | 20 | trait EntityIOContext[M[+_]] 21 | 22 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/sync/SyncEntityIO.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle.sync 17 | 18 | import org.sisioh.dddbase.core.lifecycle.EntityIO 19 | import scala.util.Try 20 | 21 | trait SyncEntityIO extends EntityIO[Try] 22 | 23 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/EntityIO.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle 17 | 18 | import scala.language.higherKinds 19 | 20 | /** 21 | * エンティティをIOするためのトレイト。 22 | */ 23 | trait EntityIO[M[+_]] { 24 | 25 | type Ctx = EntityIOContext[M] 26 | 27 | } 28 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/sync/SyncEntityIOContext.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle.sync 17 | 18 | import org.sisioh.dddbase.core.lifecycle.EntityIOContext 19 | import scala.util.Try 20 | 21 | trait SyncEntityIOContext extends EntityIOContext[Try] 22 | 23 | object SyncEntityIOContext extends SyncEntityIOContext 24 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/BaseException.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 TRICREO, Inc. (http://tricreo.jp/) 3 | * Copyright 2011 Sisioh Project and others. (http://www.sisioh.org/) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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 writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific language 15 | * governing permissions and limitations under the License. 16 | */ 17 | package org.sisioh.dddbase.core 18 | 19 | /** 20 | * 基底例外クラス。 21 | * 22 | * @author j5ik2o 23 | */ 24 | abstract class BaseException(val message: Option[String] = None, val cause: Option[Throwable] = None) 25 | extends Exception(message.orNull, cause.orNull) -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/EntitiesChunk.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle 17 | 18 | import org.sisioh.dddbase.core.model.{ Identifier, Entity } 19 | 20 | /** 21 | * 複数のエンティティをまとめたIO単位。 22 | * 23 | * @param index チャンクインデックス 24 | * @param entities 複数のエンティティ 25 | * @tparam ID 識別子 26 | * @tparam E エンティティ 27 | */ 28 | case class EntitiesChunk[ID <: Identifier[_], E <: Entity[ID]](index: Int, entities: Seq[E]) 29 | 30 | -------------------------------------------------------------------------------- /scala-dddbase-spec/shared/src/main/scala/org/sisioh/dddbase/core/SyncEntityReadableBySpecification.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.core 2 | 3 | import org.sisioh.dddbase.core.lifecycle.EntitiesChunk 4 | import org.sisioh.dddbase.core.lifecycle.sync.SyncEntityReader 5 | import org.sisioh.dddbase.core.model.{ Identifier, Entity } 6 | import org.sisioh.dddbase.spec.Specification 7 | import scala.util.Try 8 | 9 | /** 10 | * 同期I/O`EntityReadableBySpecification` 11 | * 12 | * @tparam ID 識別子の型 13 | * @tparam T エンティティの型 14 | */ 15 | trait SyncEntityReadableBySpecification[ID <: Identifier[_], T <: Entity[ID]] 16 | extends EntityReadableBySpecification[ID, T, Try] { 17 | this: SyncEntityReader[ID, T] => 18 | 19 | /** 20 | * `Specification` に該当したエンティティを取得する。 21 | * 22 | * @param specification `Specification` 23 | * @return Success: 24 | * チャンク 25 | * Failure: 26 | * EntityNotFoundExceptionは、エンティティが見つからなかった場合 27 | * RepositoryExceptionは、リポジトリにアクセスできなかった場合。 28 | */ 29 | def filterBySpecification(specification: Specification[T], 30 | index: Option[Int] = None, 31 | maxEntities: Option[Int] = None): Try[EntitiesChunk[ID, T]] 32 | 33 | } 34 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/shared/src/main/scala/org/sisioh/dddbase/lifecycle/memory/sync/AbstractSyncRepositoryOnMemory.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.memory.sync 17 | 18 | import org.sisioh.dddbase.core.model.{ EntityCloneable, Entity, Identifier } 19 | 20 | abstract class AbstractSyncRepositoryOnMemory[ID <: Identifier[_], E <: Entity[ID] with EntityCloneable[ID, E] with Ordered[E]](entities: Map[ID, E]) 21 | extends SyncRepositoryOnMemorySupport[ID, E] { 22 | 23 | override protected def getEntities: collection.Map[ID, E] = entities 24 | 25 | } 26 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/shared/src/main/scala/org/sisioh/dddbase/lifecycle/memory/mutable/sync/AbstractSyncRepositoryOnMemory.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.memory.mutable.sync 17 | 18 | import org.sisioh.dddbase.core.model.{ EntityCloneable, Entity, Identifier } 19 | 20 | abstract class AbstractSyncRepositoryOnMemory[ID <: Identifier[_], E <: Entity[ID] with EntityCloneable[ID, E] with Ordered[E]](override protected val _entities: collection.mutable.Map[ID, E] = collection.mutable.Map.empty[ID, E]) 21 | extends SyncRepositoryOnMemorySupport[ID, E] 22 | 23 | -------------------------------------------------------------------------------- /scala-dddbase-spec/shared/src/main/scala/org/sisioh/dddbase/core/AsyncEntityReadableBySpecification.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.core 2 | 3 | import org.sisioh.dddbase.core.lifecycle.EntitiesChunk 4 | import org.sisioh.dddbase.core.lifecycle.async.AsyncEntityReader 5 | import org.sisioh.dddbase.core.model.{ Identifier, Entity } 6 | import org.sisioh.dddbase.spec.Specification 7 | import scala.concurrent.Future 8 | 9 | /** 10 | * 非同期版`SyncEntityReadableBySpecification`。 11 | * 12 | * @tparam ID 識別子の型 13 | * @tparam T エンティティの型 14 | */ 15 | trait AsyncEntityReadableBySpecification[ID <: Identifier[_], T <: Entity[ID]] 16 | extends EntityReadableBySpecification[ID, T, Future] { 17 | this: AsyncEntityReader[ID, T] => 18 | 19 | /** 20 | * `Specification` に該当したエンティティを取得する。 21 | * 22 | * @param specification `Specification` 23 | * @param index チャンクのインデックス 24 | * @param maxEntities 1チャンク内の件数 25 | * @return Success: 26 | * チャンク 27 | * Failure: 28 | * EntityNotFoundExceptionは、エンティティが見つからなかった場合 29 | * RepositoryExceptionは、リポジトリにアクセスできなかった場合。 30 | */ 31 | def filterBySpecification(specification: Specification[T], index: Option[Int] = None, maxEntities: Option[Int] = None): Future[EntitiesChunk[ID, T]] 32 | 33 | } 34 | -------------------------------------------------------------------------------- /scala-dddbase-spec/shared/src/main/scala/org/sisioh/dddbase/spec/AndSpecification.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 TRICREO, Inc. (http://tricreo.jp/) 3 | * Copyright 2011 Sisioh Project and others. (http://www.sisioh.org/) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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 writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific language 15 | * governing permissions and limitations under the License. 16 | */ 17 | package org.sisioh.dddbase.spec 18 | 19 | import scala.scalajs.js.annotation.JSExportTopLevel 20 | 21 | /** 22 | * ANDを表す仕様。 23 | * 24 | * @tparam T モデルの型 25 | */ 26 | @JSExportTopLevel("AndSpecification") 27 | class AndSpecification[T](private[spec] val spec1: Specification[T], 28 | private[spec] val spec2: Specification[T]) 29 | extends Specification[T] { 30 | 31 | override def isSatisfiedBy(t: T) = 32 | spec1.isSatisfiedBy(t) && spec2.isSatisfiedBy(t) 33 | } 34 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/RepositoryException.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 TRICREO, Inc. (http://tricreo.jp/) 3 | * Copyright 2011 Sisioh Project and others. (http://www.sisioh.org/) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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 writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific language 15 | * governing permissions and limitations under the License. 16 | */ 17 | package org.sisioh.dddbase.core.lifecycle 18 | 19 | import org.sisioh.dddbase.core.BaseException 20 | 21 | import scala.scalajs.js.annotation.JSExportTopLevel 22 | 23 | /** 24 | * リポジトリにアクセスできなかった場合の例外。 25 | * 26 | * @author j5ik2o 27 | */ 28 | @JSExportTopLevel("RepositoryException") 29 | case class RepositoryException(override val message: Option[String] = None, 30 | override val cause: Option[Throwable] = None) 31 | extends BaseException(message, cause) 32 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/EntityNotFoundException.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 TRICREO, Inc. (http://tricreo.jp/) 3 | * Copyright 2011 Sisioh Project and others. (http://www.sisioh.org/) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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 writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific language 15 | * governing permissions and limitations under the License. 16 | */ 17 | package org.sisioh.dddbase.core.lifecycle 18 | 19 | import org.sisioh.dddbase.core.BaseException 20 | 21 | import scala.scalajs.js.annotation.JSExportTopLevel 22 | 23 | /** 24 | * リポジトリにアクセスできなかった場合の例外。 25 | * 26 | * @author j5ik2o 27 | */ 28 | @JSExportTopLevel("EntityNotFoundException") 29 | case class EntityNotFoundException(override val message: Option[String] = None, 30 | override val cause: Option[Throwable] = None) 31 | extends BaseException(message, cause) 32 | -------------------------------------------------------------------------------- /scala-dddbase-spec/shared/src/main/scala/org/sisioh/dddbase/spec/NotSpecification.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 TRICREO, Inc. (http://tricreo.jp/) 3 | * Copyright 2011 Sisioh Project and others. (http://www.sisioh.org/) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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 writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific language 15 | * governing permissions and limitations under the License. 16 | */ 17 | package org.sisioh.dddbase.spec 18 | 19 | import scala.scalajs.js.annotation.JSExportTopLevel 20 | 21 | /** 22 | * 否定の仕様を表すモデル。 23 | * 24 | *
ある `Specification` の否定をとる `Specification` 実装クラス。 25 | * デコレータではないので注意。
26 | * 27 | * @tparam T `NotSpecification`の型 28 | */ 29 | @JSExportTopLevel("NotSpecification") 30 | class NotSpecification[T](private[spec] val spec1: Specification[T]) 31 | extends Specification[T] { 32 | 33 | override def isSatisfiedBy(t: T) = 34 | !spec1.isSatisfiedBy(t) 35 | 36 | } 37 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/shared/src/main/scala/org/sisioh/dddbase/lifecycle/memory/mutable/async/AsyncRepositoryOnMemory.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 TRICREO, Inc. (http://tricreo.jp/) 3 | * Copyright 2011 Sisioh Project and others. (http://www.sisioh.org/) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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 writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific language 15 | * governing permissions and limitations under the License. 16 | */ 17 | package org.sisioh.dddbase.lifecycle.memory.mutable.async 18 | 19 | import org.sisioh.dddbase.lifecycle.memory.async.{ AsyncRepositoryOnMemory => AROM } 20 | import org.sisioh.dddbase.core.model.{ Identifier, EntityCloneable, Entity } 21 | 22 | /** 23 | * 非同期型オンメモリ可変リポジトリのためのトレイト。 24 | * 25 | * @tparam ID 識別子の型 26 | * @tparam E エンティティの型 27 | */ 28 | trait AsyncRepositoryOnMemory[ID <: Identifier[_], E <: Entity[ID] with EntityCloneable[ID, E] with Ordered[E]] 29 | extends AROM[ID, E] 30 | 31 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/ResultWithEntity.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle 17 | 18 | import org.sisioh.dddbase.core.model.{ Identifier, Entity } 19 | import scala.language.higherKinds 20 | 21 | /** 22 | * `EntityWriter`の新しい状態とエンティティを保持する値オブジェクト。 23 | * 24 | * @tparam EW `EntityWriter`の型 25 | * @tparam ID エンティティの識別子の型 26 | * @tparam E エンティティの型 27 | * @tparam M モナドの型 28 | */ 29 | trait ResultWithEntity[+EW <: EntityWriter[ID, E, M], ID <: Identifier[_], E <: Entity[ID], M[+A]] { 30 | 31 | /** 32 | * 結果 33 | */ 34 | val result: EW 35 | 36 | /** 37 | * エンティティ 38 | */ 39 | val entity: E 40 | 41 | } 42 | 43 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/ResultWithEntities.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle 17 | 18 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 19 | import scala.language.higherKinds 20 | 21 | /** 22 | * `EntityWriter`の新しい状態と複数のエンティティを保持する値オブジェクト。 23 | * 24 | * @tparam EW `EntityWriter`の型 25 | * @tparam ID エンティティの識別子の型 26 | * @tparam E エンティティの型 27 | * @tparam M モナドの型 28 | */ 29 | trait ResultWithEntities[+EW <: EntityWriter[ID, E, M], ID <: Identifier[_], E <: Entity[ID], M[+A]] { 30 | 31 | /** 32 | * 結果 33 | */ 34 | val result: EW 35 | 36 | /** 37 | * エンティティ 38 | */ 39 | val entities: Seq[E] 40 | 41 | } 42 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/shared/src/main/scala/org/sisioh/dddbase/lifecycle/memory/mutable/sync/SyncRepositoryOnMemory.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 TRICREO, Inc. (http://tricreo.jp/) 3 | * Copyright 2011 Sisioh Project and others. (http://www.sisioh.org/) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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 writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific language 15 | * governing permissions and limitations under the License. 16 | */ 17 | package org.sisioh.dddbase.lifecycle.memory.mutable.sync 18 | 19 | import org.sisioh.dddbase.lifecycle.memory.sync.{ SyncRepositoryOnMemory => SROM } 20 | import org.sisioh.dddbase.core.model.{ Identifier, EntityCloneable, Entity } 21 | 22 | /** 23 | * オンメモリで動作する可変リポジトリの実装。 24 | * 25 | * @tparam ID エンティティの識別子の型 26 | * @tparam E エンティティの型 27 | */ 28 | trait SyncRepositoryOnMemory[ID <: Identifier[_], E <: Entity[ID] with EntityCloneable[ID, E] with Ordered[E]] 29 | extends SROM[ID, E] { 30 | 31 | } 32 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/shared/src/main/scala/org/sisioh/dddbase/lifecycle/memory/async/AsyncRepositoryOnMemory.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.memory.async 17 | 18 | import org.sisioh.dddbase.core.lifecycle.async._ 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | 21 | /** 22 | * Represents async repository that have entities on memories. 23 | * 24 | * @tparam ID id type 25 | * @tparam E entity type 26 | */ 27 | trait AsyncRepositoryOnMemory[ID <: Identifier[_], E <: Entity[ID]] 28 | extends AsyncRepository[ID, E] { 29 | 30 | protected def getEntities: collection.Map[ID, E] 31 | 32 | def entities: Map[ID, E] = getEntities.toMap 33 | 34 | } 35 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/Repository.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle 17 | 18 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 19 | import scala.language.higherKinds 20 | 21 | /** 22 | * 基本的なリポジトリのトレイト。 23 | * リポジトリとして、基本的に必要な機能を定義するトレイト。 24 | * 25 | * リポジトリの状態を変更するメソッドの戻り値としては、 26 | * Immutableなリポジトリは新しいリポジトリインスタンスを返し、 27 | * Mutableなリポジトリは同一インスタンスを返すこと、を推奨する。 28 | * 29 | * @tparam ID エンティティの識別子の型 30 | * @tparam E エンティティの型 31 | * @tparam M モナドの型 32 | */ 33 | trait Repository[ID <: Identifier[_], E <: Entity[ID], M[+A]] 34 | extends EntityReader[ID, E, M] with EntityWriter[ID, E, M] { 35 | 36 | type This <: Repository[ID, E, M] 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /scala-dddbase-spec/shared/src/main/scala/org/sisioh/dddbase/spec/OrSpecification.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 TRICREO, Inc. (http://tricreo.jp/) 3 | * Copyright 2011 Sisioh Project and others. (http://www.sisioh.org/) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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 writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific language 15 | * governing permissions and limitations under the License. 16 | */ 17 | package org.sisioh.dddbase.spec 18 | 19 | import scala.scalajs.js.annotation.JSExportTopLevel 20 | 21 | /** 22 | * 論理和の仕様を表すモデル。 23 | * 24 | *2つの `Specification` の論理和をとる `Specification` 実装クラス。
25 | * 26 | * @tparam T `OrSpecification`の型 27 | */ 28 | 29 | @JSExportTopLevel("OrSpecification") 30 | class OrSpecification[T](private[spec] val spec1: Specification[T], 31 | private[spec] val spec2: Specification[T]) 32 | extends Specification[T] { 33 | 34 | override def isSatisfiedBy(t: T) = 35 | spec1.isSatisfiedBy(t) || spec2.isSatisfiedBy(t) 36 | 37 | } 38 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/shared/src/main/scala/org/sisioh/dddbase/lifecycle/memory/mutable/async/AbstractAsyncRepositoryOnMemory.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.memory.mutable.async 17 | 18 | import org.sisioh.dddbase.core.model.{EntityCloneable, Entity, Identifier} 19 | import java.util.concurrent.ConcurrentHashMap 20 | import org.sisioh.dddbase.lifecycle.memory.JDKCollectionConvertersCompat.Converters._ 21 | 22 | abstract class AbstractAsyncRepositoryOnMemory[ID <: Identifier[_], E <: Entity[ 23 | ID 24 | ] with EntityCloneable[ID, E] with Ordered[E]]( 25 | protected val _entities: collection.concurrent.Map[ID, E] = 26 | new ConcurrentHashMap[ID, E]().asScala 27 | ) extends AsyncRepositoryOnMemorySupport[ID, E] 28 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/shared/src/main/scala/org/sisioh/dddbase/lifecycle/memory/sync/SyncRepositoryOnMemory.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.memory.sync 17 | 18 | import org.sisioh.dddbase.core.lifecycle.sync.{ SyncEntityReadableByIterable, SyncRepository } 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | 21 | /** 22 | * オンメモリリポジトリを表すトレイト。 23 | * 24 | * @tparam ID エンティティの識別子の型 25 | * @tparam E エンティティの型 26 | */ 27 | trait SyncRepositoryOnMemory[ID <: Identifier[_], E <: Entity[ID]] 28 | extends SyncRepository[ID, E] with SyncEntityReadableByIterable[ID, E] { 29 | 30 | protected def getEntities: collection.Map[ID, E] 31 | 32 | def entities: Map[ID, E] = getEntities.toMap 33 | 34 | } 35 | 36 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/jvm/src/test/scala/org/sisioh/dddbase/lifecycle/forwarding/TestSyncMutableRepository.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.lifecycle.forwarding 2 | 3 | import org.sisioh.dddbase.core.lifecycle.EntityNotFoundException 4 | import org.sisioh.dddbase.core.lifecycle.sync.{ SyncResultWithEntity, SyncRepository } 5 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 6 | import scala.util.Try 7 | 8 | case class TestSyncMutableRepository[ID <: Identifier[_], E <: Entity[ID]]() extends SyncRepository[ID, E] { 9 | override type This = TestSyncMutableRepository[ID, E] 10 | 11 | val entities = collection.mutable.Map.empty[ID, E] 12 | 13 | override def existBy(identifier: ID)(implicit ctx: Ctx): Try[Boolean] = Try { 14 | entities.contains(identifier) 15 | } 16 | 17 | override def resolveBy(identifier: ID)(implicit ctx: Ctx): Try[E] = Try { 18 | entities.get(identifier).getOrElse(throw EntityNotFoundException()) 19 | } 20 | 21 | override def store(entity: E)(implicit ctx: Ctx): Try[Result] = Try { 22 | entities.put(entity.identifier, entity) 23 | SyncResultWithEntity[This, ID, E](this.asInstanceOf[This], entity) 24 | } 25 | 26 | override def deleteBy(identifier: ID)(implicit ctx: Ctx): Try[Result] = Try { 27 | val entity = entities.remove(identifier).getOrElse(throw EntityNotFoundException()) 28 | SyncResultWithEntity[This, ID, E](this.asInstanceOf[This], entity) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/jvm/src/test/scala/org/sisioh/dddbase/lifecycle/forwarding/TestSyncRepository.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.lifecycle.forwarding 2 | 3 | import org.sisioh.dddbase.core.lifecycle.sync.{ SyncResultWithEntity, SyncRepository } 4 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 5 | import scala.util.Try 6 | import org.sisioh.dddbase.core.lifecycle.EntityNotFoundException 7 | 8 | case class TestSyncRepository[ID <: Identifier[_], E <: Entity[ID]](entities: Map[ID, E] = Map.empty[ID, E]) extends SyncRepository[ID, E] { 9 | 10 | override type This = TestSyncRepository[ID, E] 11 | 12 | override def existBy(identifier: ID)(implicit ctx: Ctx): Try[Boolean] = Try { 13 | entities.contains(identifier) 14 | } 15 | 16 | override def resolveBy(identifier: ID)(implicit ctx: Ctx): Try[E] = Try { 17 | entities.get(identifier).getOrElse(throw EntityNotFoundException()) 18 | } 19 | 20 | override def store(entity: E)(implicit ctx: Ctx): Try[Result] = Try { 21 | SyncResultWithEntity[This, ID, E](TestSyncRepository(entities + (entity.identifier -> entity)).asInstanceOf[This], entity) 22 | } 23 | 24 | override def deleteBy(identifier: ID)(implicit ctx: Ctx): Try[Result] = Try { 25 | val entity = entities.get(identifier).getOrElse(throw EntityNotFoundException()) 26 | SyncResultWithEntity[This, ID, E](TestSyncRepository(entities - identifier).asInstanceOf[This], entity) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/sync/SyncEntityReadableByIterable.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle.sync 17 | 18 | import org.sisioh.dddbase.core.lifecycle.EntityIOContext 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | import scala.util.{ Success, Try } 21 | 22 | /** 23 | * `SyncEntityReader`に 24 | * `scala.collection.Iterable`を実装するためのトレイト。 25 | * 26 | * @tparam ID 識別子の型 27 | * @tparam E エンティティの型 28 | */ 29 | trait SyncEntityReadableByIterable[ID <: Identifier[_], E <: Entity[ID]] extends Iterable[E] { 30 | this: SyncEntityReader[ID, E] => 31 | 32 | def existBy(identifier: ID)(implicit ctx: EntityIOContext[Try]): Try[Boolean] = 33 | Success(exists(_.identifier == identifier)) 34 | 35 | } 36 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/EntityReadableAsOption.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle 17 | 18 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 19 | import scala.language.higherKinds 20 | 21 | /** 22 | * エンティティを`Option`でラップして返すための`EntityReader`。 23 | * 24 | * @tparam ID 識別子の型 25 | * @tparam E エンティティの型 26 | */ 27 | trait EntityReadableAsOption[ID <: Identifier[_], E <: Entity[ID], M[+A]] { 28 | this: EntityReader[ID, E, M] => 29 | 30 | /** 31 | * 識別子に該当するエンティティを解決する。 32 | * 33 | * @see `EntityReader` `resolve` 34 | * 35 | * @param identifier 識別子 36 | * @return Mと`Option`でラップされたエンティティ。エンティティがない場合はNoneとなる。 37 | */ 38 | def resolveAsOptionBy(identifier: ID)(implicit ctx: Ctx): Option[E] 39 | 40 | } 41 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/EntityReadableAsChunk.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle 17 | 18 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 19 | import scala.language.higherKinds 20 | 21 | /** 22 | * `EntitiesChunk`による検索を行うためのトレイト。 23 | * 24 | * @tparam ID 識別子の型 25 | * @tparam E エンティティの型 26 | * @tparam M モナド 27 | */ 28 | trait EntityReadableAsChunk[ID <: Identifier[_], E <: Entity[ID], M[+A]] { 29 | this: EntityReader[ID, E, M] => 30 | 31 | /** 32 | * エンティティをチャンク単位で検索する。 33 | * 34 | * @param index 検索するチャンクのインデックス 35 | * @param maxEntities 1チャンクの件数 36 | * @return Mにラップされた`EntitiesChunk` 37 | */ 38 | def resolveAsChunk(index: Int, maxEntities: Int)(implicit ctx: Ctx): M[EntitiesChunk[ID, E]] 39 | 40 | } 41 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/async/AsyncEntityReadableAsSeq.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle.async 17 | 18 | import org.sisioh.dddbase.core.lifecycle.EntityIOContext 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | import scala.concurrent.Future 21 | 22 | /** 23 | * 非同期ですべてのエンティティを取得するためのトレイト。 24 | * 25 | * @tparam ID 識別子の型 26 | * @tparam E エンティティの型 27 | */ 28 | trait AsyncEntityReadableAsSeq[ID <: Identifier[_], E <: Entity[ID]] { 29 | this: AsyncEntityReader[ID, E] => 30 | 31 | /** 32 | * @return Success: 33 | * エンティティの列 34 | * Failure: 35 | * RepositoryExceptionは、リポジトリにアクセスできなかった場合。 36 | */ 37 | def resolveAll(implicit ctx: EntityIOContext[Future]): Future[Seq[E]] 38 | 39 | } 40 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/shared/src/main/scala/org/sisioh/dddbase/lifecycle/memory/async/AbstractAsyncRepositoryOnMemory.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.memory.async 17 | 18 | import org.sisioh.dddbase.core.model.{ EntityCloneable, Entity, Identifier } 19 | import scala.collection 20 | 21 | /** 22 | * Represents abstract class for `AsyncRepositoryOnMemory`. 23 | * 24 | * @param entities entities 25 | * @tparam ID id type 26 | * @tparam E entity type 27 | */ 28 | abstract class AbstractAsyncRepositoryOnMemory[ID <: Identifier[_], E <: Entity[ID] with EntityCloneable[ID, E] with Ordered[E]](entities: Map[ID, E] = Map.empty[ID, E]) 29 | extends AsyncRepositoryOnMemorySupport[ID, E] { 30 | 31 | override protected def getEntities: collection.Map[ID, E] = entities 32 | 33 | } 34 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/async/AsyncRepository.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 TRICREO, Inc. (http://tricreo.jp/) 3 | * Copyright 2011 Sisioh Project and others. (http://www.sisioh.org/) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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 writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific language 15 | * governing permissions and limitations under the License. 16 | */ 17 | package org.sisioh.dddbase.core.lifecycle.async 18 | 19 | import org.sisioh.dddbase.core.lifecycle.Repository 20 | import org.sisioh.dddbase.core.model.{ Identifier, Entity } 21 | import scala.concurrent._ 22 | 23 | /** 24 | * 非同期版`org.sisioh.dddbase.core.lifecycle.Repository`。 25 | * 26 | * @see `org.sisioh.dddbase.core.lifecycle.Repository` 27 | * 28 | * @tparam ID 識別子の型 29 | * @tparam E エンティティの型 30 | */ 31 | trait AsyncRepository[ID <: Identifier[_], E <: Entity[ID]] 32 | extends Repository[ID, E, Future] 33 | with AsyncEntityReader[ID, E] 34 | with AsyncEntityWriter[ID, E] { 35 | 36 | type This <: AsyncRepository[ID, E] 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/sync/SyncRepository.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle.sync 17 | 18 | import org.sisioh.dddbase.core.lifecycle.Repository 19 | import org.sisioh.dddbase.core.model.{ Identifier, Entity } 20 | import scala.util._ 21 | 22 | /** 23 | * 基本的なリポジトリのトレイト。 24 | * リポジトリとして、基本的に必要な機能を定義するトレイト。 25 | * 26 | * リポジトリの状態を変更するメソッドの戻り値としては、 27 | * Immutableなリポジトリは新しいリポジトリインスタンスを返し、 28 | * Mutableなリポジトリは同一インスタンスを返すこと、を推奨する。 29 | * 30 | * @tparam E エンティティの型 31 | * @tparam ID エンティティの識別子の型 32 | */ 33 | trait SyncRepository[ID <: Identifier[_], E <: Entity[ID]] 34 | extends Repository[ID, E, Try] 35 | with SyncEntityReader[ID, E] 36 | with SyncEntityWriter[ID, E] { 37 | 38 | type This <: SyncRepository[ID, E] 39 | 40 | } 41 | 42 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/model/Entity.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 TRICREO, Inc. (http://tricreo.jp/) 3 | * Copyright 2011 Sisioh Project and others. (http://www.sisioh.org/) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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 writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific language 15 | * governing permissions and limitations under the License. 16 | */ 17 | package org.sisioh.dddbase.core.model 18 | 19 | /** 20 | * エンティティを表すトレイト。 21 | * 22 | * @tparam ID 識別子の型 23 | */ 24 | trait Entity[ID <: Identifier[_]] { 25 | 26 | /** エンティティの識別子。 */ 27 | val identifier: ID 28 | 29 | /** 30 | * ハッシュコードを返す。 31 | * 32 | * @return ハッシュコード 33 | */ 34 | override final def hashCode: Int = 31 * identifier.## 35 | 36 | /** 37 | * 指定されたオブジェクトと等価であるかを判定する。 38 | * 39 | * @param that オブジェクト 40 | * @return 等価である場合はtrue 41 | */ 42 | override final def equals(that: Any): Boolean = that match { 43 | case that: Entity[_] => identifier == that.identifier 44 | case _ => false 45 | } 46 | 47 | } 48 | 49 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/shared/src/main/scala/org/sisioh/dddbase/lifecycle/forwarding/async/ForwardingAsyncRepository.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.forwarding.async 17 | 18 | import org.sisioh.dddbase.core.lifecycle.async.AsyncRepository 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | 21 | /** 22 | * `AsyncRepository`のデコレータ。 23 | * 24 | * @tparam ID 識別子の型 25 | * @tparam E エンティティの型 26 | */ 27 | trait ForwardingAsyncRepository[ID <: Identifier[_], E <: Entity[ID]] 28 | extends ForwardingAsyncEntityReader[ID, E] 29 | with ForwardingAsyncEntityWriter[ID, E] 30 | with AsyncRepository[ID, E] { 31 | 32 | type Delegate <: AsyncRepository[ID, E] 33 | 34 | /** 35 | * デリゲート。 36 | */ 37 | protected val delegate: Delegate 38 | 39 | } 40 | 41 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/shared/src/main/scala/org/sisioh/dddbase/lifecycle/forwarding/async/wrapped/AsyncWrappedSyncRepository.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.forwarding.async.wrapped 17 | 18 | import org.sisioh.dddbase.core.lifecycle.async.AsyncRepository 19 | import org.sisioh.dddbase.core.lifecycle.sync.SyncRepository 20 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 21 | 22 | /** 23 | * `SyncRepository`を`AsyncRepository`としてラップするためのデコレータ。 24 | * 25 | * @tparam ID 識別子の型 26 | * @tparam E エンティティの型 27 | */ 28 | trait AsyncWrappedSyncRepository[ID <: Identifier[_], E <: Entity[ID]] 29 | extends AsyncWrappedSyncEntityReader[ID, E] 30 | with AsyncWrappedSyncEntityWriter[ID, E] 31 | with AsyncRepository[ID, E] { 32 | 33 | type Delegate <: SyncRepository[ID, E] 34 | 35 | } 36 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/shared/src/main/scala/org/sisioh/dddbase/lifecycle/forwarding/sync/wrapped/SyncWrappedAsyncRepository.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | * 16 | */ 17 | package org.sisioh.dddbase.lifecycle.forwarding.sync.wrapped 18 | 19 | import org.sisioh.dddbase.core.lifecycle.async.AsyncRepository 20 | import org.sisioh.dddbase.core.lifecycle.sync.SyncRepository 21 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 22 | 23 | /** 24 | * `AsyncRepository`を`SyncRepository`としてラップするためのデコレータ。 25 | * 26 | * @tparam ID 識別子の型 27 | * @tparam E エンティティの型 28 | */ 29 | trait SyncWrappedAsyncRepository[ID <: Identifier[_], E <: Entity[ID]] 30 | extends SyncWrappedAsyncEntityReader[ID, E] 31 | with SyncWrappedAsyncEntityWriter[ID, E] 32 | with SyncRepository[ID, E] { 33 | 34 | type Delegate <: AsyncRepository[ID, E] 35 | 36 | } 37 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/shared/src/main/scala/org/sisioh/dddbase/lifecycle/forwarding/sync/ForwardingSyncRepository.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.forwarding.sync 17 | 18 | import org.sisioh.dddbase.core.lifecycle.sync.SyncRepository 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | 21 | /** 22 | * `SyncRepository`のデコレータ。 23 | * 24 | * @tparam ID 識別子の型 25 | * @tparam E エンティティの型 26 | */ 27 | trait ForwardingSyncRepository[ID <: Identifier[_], E <: Entity[ID]] 28 | extends ForwardingSyncEntityReader[ID, E] 29 | with ForwardingSyncEntityWriter[ID, E] 30 | with SyncRepository[ID, E] { 31 | 32 | type This <: ForwardingSyncRepository[ID, E] 33 | 34 | type Delegate <: SyncRepository[ID, E] 35 | 36 | /** 37 | * デリゲート。 38 | */ 39 | protected val delegate: Delegate 40 | 41 | } 42 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/jvm/src/test/scala/org/sisioh/dddbase/lifecycle/forwarding/TestAsyncMutableRepository.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.lifecycle.forwarding 2 | 3 | import org.sisioh.dddbase.core.lifecycle.EntityNotFoundException 4 | import org.sisioh.dddbase.core.lifecycle.async.{ AsyncResultWithEntity, AsyncRepository } 5 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 6 | import scala.concurrent.ExecutionContext.Implicits.global 7 | import scala.concurrent.Future 8 | 9 | case class TestAsyncMutableRepository[ID <: Identifier[_], E <: Entity[ID]]() extends AsyncRepository[ID, E] { 10 | 11 | override type This = TestAsyncMutableRepository[ID, E] 12 | 13 | val entities = collection.mutable.Map.empty[ID, E] 14 | 15 | override def existBy(identifier: ID)(implicit ctx: Ctx): Future[Boolean] = Future { 16 | entities.contains(identifier) 17 | } 18 | 19 | override def resolveBy(identifier: ID)(implicit ctx: Ctx): Future[E] = Future { 20 | entities.get(identifier).getOrElse(throw EntityNotFoundException()) 21 | } 22 | 23 | override def store(entity: E)(implicit ctx: Ctx): Future[Result] = Future { 24 | entities.put(entity.identifier, entity) 25 | AsyncResultWithEntity[This, ID, E](this.asInstanceOf[This], entity) 26 | } 27 | 28 | override def deleteBy(identifier: ID)(implicit ctx: Ctx): Future[Result] = Future { 29 | val entity = entities.remove(identifier).getOrElse(throw EntityNotFoundException()) 30 | AsyncResultWithEntity[This, ID, E](this.asInstanceOf[This], entity) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/jvm/src/test/scala/org/sisioh/dddbase/lifecycle/forwarding/TestAsyncRepository.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.lifecycle.forwarding 2 | 3 | import org.sisioh.dddbase.core.lifecycle.EntityNotFoundException 4 | import org.sisioh.dddbase.core.lifecycle.async.{ AsyncResultWithEntity, AsyncRepository } 5 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 6 | import scala.concurrent.ExecutionContext.Implicits.global 7 | import scala.concurrent.Future 8 | 9 | case class TestAsyncRepository[ID <: Identifier[_], E <: Entity[ID]](entities: Map[ID, E] = Map.empty[ID, E]) extends AsyncRepository[ID, E] { 10 | 11 | override type This = TestAsyncRepository[ID, E] 12 | 13 | override def existBy(identifier: ID)(implicit ctx: Ctx): Future[Boolean] = Future { 14 | entities.contains(identifier) 15 | } 16 | 17 | override def resolveBy(identifier: ID)(implicit ctx: Ctx): Future[E] = Future { 18 | entities.get(identifier).getOrElse(throw EntityNotFoundException()) 19 | } 20 | 21 | override def store(entity: E)(implicit ctx: Ctx): Future[Result] = Future { 22 | AsyncResultWithEntity[This, ID, E](TestAsyncRepository(entities + (entity.identifier -> entity)).asInstanceOf[This], entity) 23 | } 24 | 25 | override def deleteBy(identifier: ID)(implicit ctx: Ctx): Future[Result] = Future { 26 | val entity = entities.get(identifier).getOrElse(throw EntityNotFoundException()) 27 | AsyncResultWithEntity[This, ID, E](TestAsyncRepository(entities - identifier).asInstanceOf[This], entity) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/sync/SyncEntityReadableAsOption.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle.sync 17 | 18 | import org.sisioh.dddbase.core.lifecycle.{ EntityIOContext, EntityReadableAsOption } 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | import scala.util.Try 21 | 22 | /** 23 | * 同期的に読み込むための`EntityReadableAsOption`。 24 | * 25 | * @tparam ID 識別子の型 26 | * @tparam E エンティティの型 27 | */ 28 | trait SyncEntityReadableAsOption[ID <: Identifier[_], E <: Entity[ID]] 29 | extends EntityReadableAsOption[ID, E, Try] { 30 | this: SyncEntityReader[ID, E] => 31 | 32 | /** 33 | * @return Success: Some: エンティティが存在する場合、None: エンティティが存在しない場合 34 | * Failure: RepositoryExceptionは、リポジトリにアクセスできなかった場合 35 | */ 36 | def resolveAsOptionBy(identifier: ID)(implicit ctx: EntityIOContext[Try]): Option[E] 37 | 38 | } 39 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/EntityReadableAsPredicate.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle 17 | 18 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 19 | import scala.language.higherKinds 20 | 21 | /** 22 | * 述語関数に該当したエンティティを検索することができるトレイト。 23 | * 24 | * @tparam ID 識別子の型 25 | * @tparam E エンティティの型 26 | */ 27 | trait EntityReadableAsPredicate[ID <: Identifier[_], E <: Entity[ID], M[+A]] { 28 | this: EntityReader[ID, E, M] => 29 | 30 | /** 31 | * 述語関数に該当したエンティティを取得する。 32 | * 33 | * @param predicate 述語関数 34 | * @param index チャンクのインデックス 35 | * @param maxEntities 1チャンク内の件数 36 | * @return モナドにラップした`org.sisioh.dddbase.core.lifecycle.EntitiesChunk` 37 | */ 38 | def filterBy(predicate: E => Boolean, index: Option[Int] = None, maxEntities: Option[Int] = None)(implicit ctx: Ctx): M[EntitiesChunk[ID, E]] 39 | 40 | } 41 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/sync/SyncEntityReadableAsChunk.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle.sync 17 | 18 | import org.sisioh.dddbase.core.lifecycle.{ EntityIOContext, EntityReadableAsChunk, EntitiesChunk } 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | import scala.util.Try 21 | 22 | /** 23 | * 同期的に読み込むための`EntityReadableAsChunk`。 24 | * 25 | * @tparam ID 識別子の型 26 | * @tparam E エンティティの型 27 | */ 28 | trait SyncEntityReadableAsChunk[ID <: Identifier[_], E <: Entity[ID]] 29 | extends EntityReadableAsChunk[ID, E, Try] { 30 | this: SyncEntityReader[ID, E] => 31 | 32 | /** 33 | * @return Success: `EntitiesChunk` 34 | * Failure: RepositoryExceptionはリポジトリにアクセスできなかった場合 35 | */ 36 | def resolveAsChunk(index: Int, maxEntities: Int)(implicit ctx: EntityIOContext[Try]): Try[EntitiesChunk[ID, E]] 37 | 38 | } 39 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/shared/src/main/scala/org/sisioh/dddbase/lifecycle/forwarding/sync/ForwardingSyncEntityReadableAsOption.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.forwarding.sync 17 | 18 | import org.sisioh.dddbase.core.lifecycle.sync.{ SyncEntityReadableAsOption, SyncEntityReader } 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | 21 | /** 22 | * `SyncEntityReadableAsOption`のデコレータ。 23 | * 24 | * @tparam ID 識別子の型 25 | * @tparam E エンティティの型 26 | */ 27 | trait ForwardingSyncEntityReadableAsOption[ID <: Identifier[_], E <: Entity[ID]] 28 | extends SyncEntityReadableAsOption[ID, E] { 29 | this: SyncEntityReader[ID, E] => 30 | 31 | type Delegate <: SyncEntityReadableAsOption[ID, E] 32 | 33 | /** 34 | * デリゲート。 35 | */ 36 | protected val delegate: Delegate 37 | 38 | def resolveAsOptionBy(identifier: ID)(implicit ctx: Ctx): Option[E] = delegate.resolveAsOptionBy(identifier) 39 | 40 | } 41 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/shared/src/main/scala/org/sisioh/dddbase/lifecycle/forwarding/sync/ForwardingSyncEntityReader.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.forwarding.sync 17 | 18 | import org.sisioh.dddbase.core.lifecycle.sync.SyncEntityReader 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | import scala.util.Try 21 | 22 | /** 23 | * `SyncEntityReader`のデコレータ実装 24 | * 25 | * @tparam ID 識別子の型 26 | * @tparam E エンティティの型 27 | */ 28 | trait ForwardingSyncEntityReader[ID <: Identifier[_], E <: Entity[ID]] 29 | extends SyncEntityReader[ID, E] { 30 | 31 | type Delegate <: SyncEntityReader[ID, E] 32 | 33 | /** 34 | * デリゲート。 35 | */ 36 | protected val delegate: Delegate 37 | 38 | def resolveBy(identifier: ID)(implicit ctx: Ctx): Try[E] = 39 | delegate.resolveBy(identifier) 40 | 41 | def existBy(identifier: ID)(implicit ctx: Ctx): Try[Boolean] = 42 | delegate.existBy(identifier) 43 | 44 | } 45 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/shared/src/main/scala/org/sisioh/dddbase/lifecycle/memory/async/AsyncRepositoryOnMemorySupportAsSeq.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.memory.async 17 | 18 | import org.sisioh.dddbase.core.lifecycle.EntityIOContext 19 | import org.sisioh.dddbase.core.lifecycle.async._ 20 | import org.sisioh.dddbase.core.model._ 21 | import scala.concurrent._ 22 | 23 | /** 24 | * `AsyncRepositoryOnMemorySupport`に全件取得のための機能を追加するトレイト。 25 | * 26 | * @tparam ID 識別子の型 27 | * @tparam E エンティティの型 28 | */ 29 | trait AsyncRepositoryOnMemorySupportAsSeq[ID <: Identifier[_], E <: Entity[ID] with EntityCloneable[ID, E]] 30 | extends AsyncEntityReadableAsSeq[ID, E] { 31 | this: AsyncRepositoryOnMemory[ID, E] => 32 | 33 | def resolveAll(implicit ctx: EntityIOContext[Future]): Future[Seq[E]] = { 34 | implicit val executor = getExecutionContext(ctx) 35 | Future { 36 | getEntities.values.toSeq 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/async/AsyncEntityReadableAsChunk.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle.async 17 | 18 | import org.sisioh.dddbase.core.lifecycle.{ EntityIOContext, EntityReadableAsChunk, EntitiesChunk } 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | import scala.concurrent.Future 21 | 22 | /** 23 | * 非同期版`org.sisioh.dddbase.core.lifecycle.EntityReadableAsChunk`。 24 | * 25 | * @tparam ID 識別子の型 26 | * @tparam E エンティティの型 27 | */ 28 | trait AsyncEntityReadableAsChunk[ID <: Identifier[_], E <: Entity[ID]] 29 | extends EntityReadableAsChunk[ID, E, Future] { 30 | this: AsyncEntityReader[ID, E] => 31 | 32 | /** 33 | * @return Success: 34 | * チャンク 35 | * Failure: 36 | * RepositoryExceptionは、リポジトリにアクセスできなかった場合。 37 | */ 38 | def resolveAsChunk(index: Int, maxEntities: Int)(implicit ctx: EntityIOContext[Future]): Future[EntitiesChunk[ID, E]] 39 | 40 | } 41 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/shared/src/main/scala/org/sisioh/dddbase/lifecycle/forwarding/async/ForwardingAsyncEntityReader.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.forwarding.async 17 | 18 | import org.sisioh.dddbase.core.lifecycle.async.AsyncEntityReader 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | 21 | import scala.concurrent.Future 22 | 23 | /** 24 | * `AsyncEntityReader`のデコレータ。 25 | * 26 | * @tparam ID 識別子の型 27 | * @tparam E エンティティの型 28 | */ 29 | trait ForwardingAsyncEntityReader[ID <: Identifier[_], E <: Entity[ID]] 30 | extends AsyncEntityReader[ID, E] { 31 | 32 | type Delegate <: AsyncEntityReader[ID, E] 33 | 34 | /** 35 | * デリゲート。 36 | */ 37 | protected val delegate: Delegate 38 | 39 | def resolveBy(identifier: ID)(implicit ctx: Ctx): Future[E] = 40 | delegate.resolveBy(identifier) 41 | 42 | def existBy(identifier: ID)(implicit ctx: Ctx): Future[Boolean] = 43 | delegate.existBy(identifier) 44 | 45 | } 46 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/async/AsyncEntityIO.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle.async 17 | 18 | import org.sisioh.dddbase.core.lifecycle.EntityIO 19 | import scala.concurrent.{ ExecutionContext, Future } 20 | 21 | /** 22 | * `org.sisioh.dddbase.core.lifecycle.EntityIO`の非同期版。 23 | */ 24 | trait AsyncEntityIO extends EntityIO[Future] { 25 | 26 | /** 27 | * `org.sisioh.dddbase.core.lifecycle.EntityIOContext`から 28 | * `scala.concurrent.ExecutionContext`を取得する。 29 | * 30 | * @param ctx `org.sisioh.dddbase.core.lifecycle.EntityIOContext` 31 | * @return `scala.concurrent.ExecutionContext` 32 | */ 33 | protected def getExecutionContext(ctx: Ctx): ExecutionContext = { 34 | ctx match { 35 | case actx: AsyncEntityIOContext => actx.executor 36 | case _ => throw new IllegalArgumentException(s"$ctx is type miss match. please set to AsyncEntityIOContext.") 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/shared/src/main/scala/org/sisioh/dddbase/lifecycle/forwarding/async/wrapped/AsyncWrappedSyncEntityIO.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.forwarding.async.wrapped 17 | 18 | import org.sisioh.dddbase.core.lifecycle.async.AsyncEntityIO 19 | import org.sisioh.dddbase.core.lifecycle.EntityIOContext 20 | /** 21 | * ラッパー用の`AsyncEntityIO`の実装。 22 | */ 23 | trait AsyncWrappedSyncEntityIO extends AsyncEntityIO { 24 | 25 | /** 26 | * `EntityIOContext`を 27 | * `AsyncWrappedSyncEntityIOContext`に変換する。 28 | * 29 | * @param ctx `EntityIOContext` 30 | * @return `AsyncWrappedSyncEntityIOContext` 31 | */ 32 | protected def getAsyncWrappedEntityIOContext(ctx: Ctx): AsyncWrappedSyncEntityIOContext = 33 | ctx match { 34 | case result: AsyncWrappedSyncEntityIOContext => result 35 | case _ => throw new IllegalArgumentException(s"$ctx is type miss match. please set to AsyncWrappedSyncEntityIOContext.") 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/shared/src/main/scala/org/sisioh/dddbase/lifecycle/memory/sync/SyncRepositoryOnMemorySupportAsChunk.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.memory.sync 17 | 18 | import org.sisioh.dddbase.core.lifecycle.EntitiesChunk 19 | import org.sisioh.dddbase.core.lifecycle.sync._ 20 | import org.sisioh.dddbase.core.model._ 21 | import scala.util._ 22 | 23 | /** 24 | * `SyncRepositoryOnMemorySupport`に`EntitiesChunk`ための機能を追加するトレイト。 25 | * 26 | * @tparam ID エンティティの識別子の型 27 | * @tparam E エンティティの型 28 | */ 29 | trait SyncRepositoryOnMemorySupportAsChunk[ID <: Identifier[_], E <: Entity[ID] with EntityCloneable[ID, E] with Ordered[E]] 30 | extends SyncEntityReadableAsChunk[ID, E] { 31 | this: SyncRepositoryOnMemory[ID, E] => 32 | 33 | def resolveAsChunk(index: Int, maxEntities: Int)(implicit ctx: Ctx): Try[EntitiesChunk[ID, E]] = { 34 | val subEntities = toList.slice(index * maxEntities, index * maxEntities + maxEntities) 35 | Success(EntitiesChunk(index, subEntities)) 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/shared/src/main/scala/org/sisioh/dddbase/lifecycle/forwarding/sync/wrapped/SyncWrappedAsyncEntityIO.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.forwarding.sync.wrapped 17 | 18 | import org.sisioh.dddbase.core.lifecycle.EntityIOContext 19 | import org.sisioh.dddbase.core.lifecycle.async.AsyncEntityIOContext 20 | import org.sisioh.dddbase.core.lifecycle.sync.SyncEntityIO 21 | 22 | /** 23 | * 24 | */ 25 | trait SyncWrappedAsyncEntityIO extends SyncEntityIO { 26 | 27 | /** 28 | * `EntityIOContext`から 29 | * `AsyncEntityIOContext`を取得する。 30 | * 31 | * 32 | * @param ctx `EntityIOContext` 33 | * @return `AsyncEntityIOContext` 34 | */ 35 | protected def getAsyncEntityIOContext(ctx: Ctx): AsyncEntityIOContext = 36 | ctx match { 37 | case SyncWrappedAsyncEntityIOContext(async) => async 38 | case _ => throw new IllegalArgumentException(s"$ctx is type miss match. please set to SyncWrappedAsyncEntityIOContext.") 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/sync/SyncEntityReadableAsPredicate.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 TRICREO, Inc. (http://tricreo.jp/) 3 | * Copyright 2011 Sisioh Project and others. (http://www.sisioh.org/) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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 writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific language 15 | * governing permissions and limitations under the License. 16 | */ 17 | package org.sisioh.dddbase.core.lifecycle.sync 18 | 19 | import org.sisioh.dddbase.core.lifecycle.{ EntitiesChunk, EntityIOContext, EntityReadableAsPredicate, RepositoryException } 20 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 21 | 22 | import scala.util.Try 23 | 24 | /** 25 | * 同期的に読み込むための`EntityReadableAsPredicate`。 26 | * 27 | * @tparam ID 識別子の型 28 | * @tparam E エンティティの型 29 | */ 30 | trait SyncEntityReadableAsPredicate[ID <: Identifier[_], E <: Entity[ID]] 31 | extends EntityReadableAsPredicate[ID, E, Try] { 32 | this: SyncEntityReader[ID, E] => 33 | 34 | /** 35 | * @return Success: `EntitiesChunk` 36 | * Faliure: `RepositoryException` 37 | */ 38 | def filterBy(predicate: E => Boolean, 39 | index: Option[Int] = None, maxEntities: Option[Int] = None)(implicit ctx: EntityIOContext[Try]): Try[EntitiesChunk[ID, E]] 40 | 41 | } 42 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/shared/src/main/scala/org/sisioh/dddbase/lifecycle/memory/sync/SyncRepositoryOnMemorySupportAsOption.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.memory.sync 17 | 18 | import org.sisioh.dddbase.core.lifecycle.EntityNotFoundException 19 | import org.sisioh.dddbase.core.lifecycle.sync._ 20 | import org.sisioh.dddbase.core.model._ 21 | import scala.Some 22 | import scala.util._ 23 | 24 | /** 25 | * `SyncRepositoryOnMemorySupport`にOption型のサポートを追加するトレイト。 26 | * 27 | * @tparam ID エンティティの識別子の型 28 | * @tparam E エンティティの型 29 | */ 30 | trait SyncRepositoryOnMemorySupportAsOption[ID <: Identifier[_], E <: Entity[ID] with EntityCloneable[ID, E] with Ordered[E]] 31 | extends SyncEntityReadableAsOption[ID, E] { 32 | this: SyncRepositoryOnMemory[ID, E] => 33 | 34 | override def resolveAsOptionBy(identifier: ID)(implicit ctx: Ctx) = synchronized { 35 | resolveBy(identifier).map(Some(_)).recoverWith { 36 | case ex: EntityNotFoundException => 37 | Success(None) 38 | }.getOrElse(None) 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /scala-dddbase-spec/jvm/src/test/scala/org/sisioh/dddbase/spec/SpecificationTest.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 TRICREO, Inc. (http://tricreo.jp/) 3 | * Copyright 2011 Sisioh Project and others. (http://www.sisioh.org/) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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 writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific language 15 | * governing permissions and limitations under the License. 16 | */ 17 | package org.sisioh.dddbase.spec 18 | 19 | import org.junit.Test 20 | import org.scalatestplus.junit.AssertionsForJUnit 21 | 22 | /** 23 | * `org.sisioh.dddbase.spec.Specification`のテストクラス。 24 | */ 25 | class SpecificationTest extends AssertionsForJUnit { 26 | 27 | /** 28 | * `org.sisioh.dddbase.spec.Specification# a n d ( S p e c i f i c a t i o n )` 29 | * `org.sisioh.dddbase.spec.Specification# o r ( S p e c i f i c a t i o n )` 30 | * `org.sisioh.dddbase.spec.Specification# n o t`のテスト。 31 | * 32 | * @throws Exception 例外が発生した場合 33 | */ 34 | @Test 35 | def test01_and_or_not(): Unit = { 36 | val spec = new Specification[Unit] { 37 | def isSatisfiedBy(t: Unit): Boolean = false 38 | } 39 | assert(spec.and(spec).isInstanceOf[AndSpecification[_]]) 40 | assert(spec.or(spec).isInstanceOf[OrSpecification[_]]) 41 | assert(spec.not.isInstanceOf[NotSpecification[_]]) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/shared/src/main/scala/org/sisioh/dddbase/lifecycle/forwarding/sync/ForwardingSyncEntityReadableAsChunk.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.forwarding.sync 17 | 18 | import org.sisioh.dddbase.core.lifecycle.EntitiesChunk 19 | import org.sisioh.dddbase.core.lifecycle.sync.{ SyncEntityReadableAsChunk, SyncEntityReader } 20 | import org.sisioh.dddbase.core.model.{ Identifier, Entity } 21 | import scala.util.Try 22 | 23 | /** 24 | * `SyncEntityReadableAsChunk`のデコレータ。 25 | * 26 | * @tparam ID 識別子の型 27 | * @tparam E エンティティの型 28 | */ 29 | trait ForwardingSyncEntityReadableAsChunk[ID <: Identifier[_], E <: Entity[ID]] 30 | extends SyncEntityReadableAsChunk[ID, E] { 31 | this: SyncEntityReader[ID, E] => 32 | 33 | type Delegate <: SyncEntityReadableAsChunk[ID, E] 34 | 35 | /** 36 | * デリゲート。 37 | */ 38 | protected val delegate: Delegate 39 | 40 | def resolveAsChunk(index: Int, maxEntities: Int)(implicit ctx: Ctx): Try[EntitiesChunk[ID, E]] = 41 | delegate.resolveAsChunk(index, maxEntities) 42 | 43 | } 44 | 45 | -------------------------------------------------------------------------------- /scala-dddbase-core/jvm/src/test/scala/org/sisioh/dddbase/core/lifecycle/ValueObjectBuilderSpec.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.core.lifecycle 2 | 3 | import org.specs2.mutable._ 4 | 5 | class ValueObjectBuilderSpec extends Specification { 6 | 7 | case class PersonName(firstName: String, lastName: String) 8 | 9 | class PersonNameBuilder extends ValueObjectBuilder[PersonName, PersonNameBuilder] { 10 | private var firstName: String = _ 11 | private var lastName: String = _ 12 | 13 | def withFirstName(firstName: String) = { 14 | addConfigurator(_.firstName = firstName) 15 | getThis 16 | } 17 | 18 | def withLastName(lastName: String) = { 19 | addConfigurator(_.lastName = lastName) 20 | getThis 21 | } 22 | 23 | protected def newInstance = PersonNameBuilder() 24 | 25 | protected def getThis = this 26 | 27 | protected def createValueObject = PersonName(firstName, lastName) 28 | 29 | protected def apply(vo: PersonName, builder: PersonNameBuilder) = { 30 | builder.withFirstName(vo.firstName) 31 | builder.withLastName(vo.lastName) 32 | } 33 | } 34 | 35 | object PersonNameBuilder { 36 | 37 | def apply() = new PersonNameBuilder() 38 | } 39 | 40 | "PersonNameBuilder" should { 41 | "build PersonName" in { 42 | val personName1 = PersonNameBuilder().withFirstName("Junichi").withLastName("Kato").build 43 | val PersonName(firstName, lastName) = personName1 // 抽出子を使ってそれぞれのプロパティに分解 44 | firstName must_== "Junichi" 45 | lastName must_== "Kato" 46 | val personName2 = PersonNameBuilder().withLastName(lastName.toUpperCase).build(personName1) 47 | personName2.firstName must_== "Junichi" 48 | personName2.lastName must_== "KATO" 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/shared/src/main/scala/org/sisioh/dddbase/lifecycle/forwarding/async/ForwardingAsyncEntityReadableAsChunk.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.forwarding.async 17 | 18 | import org.sisioh.dddbase.core.lifecycle.EntitiesChunk 19 | import org.sisioh.dddbase.core.lifecycle.async.{ AsyncEntityReadableAsChunk, AsyncEntityReader } 20 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 21 | import scala.concurrent.Future 22 | 23 | /** 24 | * `AsyncEntityReadableAsChunk`のデコレータ。 25 | * 26 | * @tparam ID 識別子の型 27 | * @tparam E エンティティの型 28 | */ 29 | trait ForwardingAsyncEntityReadableAsChunk[ID <: Identifier[_], E <: Entity[ID]] 30 | extends AsyncEntityReadableAsChunk[ID, E] { 31 | this: AsyncEntityReader[ID, E] => 32 | 33 | type Delegate <: AsyncEntityReadableAsChunk[ID, E] 34 | 35 | /** 36 | * デリゲート。 37 | */ 38 | protected val delegate: Delegate 39 | 40 | def resolveAsChunk(index: Int, maxEntities: Int)(implicit ctx: Ctx): Future[EntitiesChunk[ID, E]] = 41 | delegate.resolveAsChunk(index, maxEntities) 42 | 43 | } 44 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/async/AsyncEntityReadableAsPredicate.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle.async 17 | 18 | import org.sisioh.dddbase.core.lifecycle.{ EntityIOContext, EntityReadableAsPredicate, EntitiesChunk } 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | import scala.concurrent.Future 21 | 22 | /** 23 | * 非同期版`org.sisioh.dddbase.core.lifecycle.EntityReadableAsPredicate`。 24 | * 25 | * @tparam ID 識別子の型 26 | * @tparam E エンティティの型 27 | */ 28 | trait AsyncEntityReadableAsPredicate[ID <: Identifier[_], E <: Entity[ID]] 29 | extends EntityReadableAsPredicate[ID, E, Future] { 30 | this: AsyncEntityReader[ID, E] => 31 | 32 | /** 33 | * @return Success: 34 | * チャンク 35 | * Failure: 36 | * EntityNotFoundExceptionは、エンティティが見つからなかった場合 37 | * RepositoryExceptionは、リポジトリにアクセスできなかった場合。 38 | */ 39 | def filterBy(predicate: E => Boolean, index: Option[Int] = None, maxEntities: Option[Int] = None)(implicit ctx: EntityIOContext[Future]): Future[EntitiesChunk[ID, E]] 40 | 41 | } 42 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/sync/SyncResultWithEntity.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle.sync 17 | 18 | import org.sisioh.dddbase.core.lifecycle.ResultWithEntity 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | import scala.util.Try 21 | 22 | trait SyncResultWithEntity[+R <: SyncEntityWriter[ID, T], ID <: Identifier[_], T <: Entity[ID]] 23 | extends ResultWithEntity[R, ID, T, Try] 24 | 25 | object SyncResultWithEntity { 26 | 27 | def apply[R <: SyncEntityWriter[ID, T], ID <: Identifier[_], T <: Entity[ID]](result: R, entity: T): SyncResultWithEntity[R, ID, T] = 28 | SyncResultWithEntityImpl(result, entity) 29 | 30 | def unapply[R <: SyncEntityWriter[ID, T], ID <: Identifier[_], T <: Entity[ID]](resultWithEntity: SyncResultWithEntity[R, ID, T]): Option[(R, T)] = Some(resultWithEntity.result, resultWithEntity.entity) 31 | 32 | } 33 | 34 | private[sync] case class SyncResultWithEntityImpl[+R <: SyncEntityWriter[ID, T], ID <: Identifier[_], T <: Entity[ID]](result: R, entity: T) 35 | extends SyncResultWithEntity[R, ID, T] 36 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/sync/SyncResultWithEntities.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle.sync 17 | 18 | import org.sisioh.dddbase.core.lifecycle.ResultWithEntities 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | import scala.util.Try 21 | 22 | trait SyncResultWithEntities[+R <: SyncEntityWriter[ID, T], ID <: Identifier[_], T <: Entity[ID]] 23 | extends ResultWithEntities[R, ID, T, Try] 24 | 25 | object SyncResultWithEntities { 26 | 27 | def apply[R <: SyncEntityWriter[ID, T], ID <: Identifier[_], T <: Entity[ID]](result: R, entities: Seq[T]): SyncResultWithEntities[R, ID, T] = 28 | SyncResultWithEntitiesImpl(result, entities) 29 | 30 | def unapply[R <: SyncEntityWriter[ID, T], ID <: Identifier[_], T <: Entity[ID]](target: SyncResultWithEntities[R, ID, T]): Option[(R, Seq[T])] = Some(target.result, target.entities) 31 | 32 | } 33 | 34 | private[sync] case class SyncResultWithEntitiesImpl[+R <: SyncEntityWriter[ID, T], ID <: Identifier[_], T <: Entity[ID]](result: R, entities: Seq[T]) 35 | extends SyncResultWithEntities[R, ID, T] 36 | 37 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/async/AsyncResultWithEntity.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle.async 17 | 18 | import org.sisioh.dddbase.core.lifecycle.ResultWithEntity 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | import scala.concurrent.Future 21 | 22 | trait AsyncResultWithEntity[+R <: AsyncEntityWriter[ID, E], ID <: Identifier[_], E <: Entity[ID]] 23 | extends ResultWithEntity[R, ID, E, Future] 24 | 25 | object AsyncResultWithEntity { 26 | 27 | def apply[R <: AsyncEntityWriter[ID, T], ID <: Identifier[_], T <: Entity[ID]](result: R, entity: T): AsyncResultWithEntity[R, ID, T] = AsyncResultWithEntityImpl(result, entity) 28 | 29 | def unapply[R <: AsyncEntityWriter[ID, T], ID <: Identifier[_], T <: Entity[ID]](resultWithEntity: AsyncResultWithEntity[R, ID, T]): Option[(R, T)] = 30 | Some(resultWithEntity.result, resultWithEntity.entity) 31 | 32 | } 33 | 34 | private[async] case class AsyncResultWithEntityImpl[+R <: AsyncEntityWriter[ID, T], ID <: Identifier[_], T <: Entity[ID]](result: R, entity: T) extends AsyncResultWithEntity[R, ID, T] 35 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/async/AsyncResultWithEntities.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle.async 17 | 18 | import org.sisioh.dddbase.core.lifecycle.ResultWithEntities 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | import scala.concurrent.Future 21 | 22 | trait AsyncResultWithEntities[+R <: AsyncEntityWriter[ID, T], ID <: Identifier[_], T <: Entity[ID]] 23 | extends ResultWithEntities[R, ID, T, Future] 24 | 25 | object AsyncResultWithEntities { 26 | 27 | def apply[R <: AsyncEntityWriter[ID, T], ID <: Identifier[_], T <: Entity[ID]](result: R, entities: Seq[T]): AsyncResultWithEntities[R, ID, T] = 28 | AsyncResultWithEntitiesImpl(result, entities) 29 | 30 | def unapply[R <: AsyncEntityWriter[ID, T], ID <: Identifier[_], T <: Entity[ID]](target: AsyncResultWithEntities[R, ID, T]): Option[(R, Seq[T])] = Some(target.result, target.entities) 31 | 32 | } 33 | 34 | case class AsyncResultWithEntitiesImpl[+R <: AsyncEntityWriter[ID, T], ID <: Identifier[_], T <: Entity[ID]](result: R, entities: Seq[T]) 35 | extends AsyncResultWithEntities[R, ID, T] 36 | 37 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/sync/SyncEntityReader.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle.sync 17 | 18 | import org.sisioh.dddbase.core.lifecycle.EntityReader 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | import scala.util.{ Failure, Success, Try } 21 | 22 | /** 23 | * 同期的に読み込むための`EntityReader` 24 | * 25 | * @tparam ID 識別子の型 26 | * @tparam E エンティティの型 27 | */ 28 | trait SyncEntityReader[ID <: Identifier[_], E <: Entity[ID]] 29 | extends EntityReader[ID, E, Try] { 30 | 31 | protected def mapValues[A, R](values: Try[A])(f: (A) => R)(implicit ctx: Ctx): Try[R] = { 32 | values.map(f) 33 | } 34 | 35 | protected def traverse[A, R](values: Seq[A], forceSuccess: Boolean)(f: (A) => Try[R])(implicit ctx: Ctx): Try[Seq[R]] = { 36 | values.map(f).foldLeft(Try(Seq.empty[R])) { 37 | (resultsTry, resultTry) => 38 | (for { entities <- resultsTry; entity <- resultTry } yield entities :+ entity).recoverWith { 39 | case e => if (forceSuccess) Success(resultsTry.getOrElse(Seq.empty[R])) else Failure(e) 40 | } 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/shared/src/main/scala/org/sisioh/dddbase/lifecycle/memory/async/AsyncRepositoryOnMemorySupportAsChunk.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.memory.async 17 | 18 | import org.sisioh.dddbase.core.lifecycle.async._ 19 | import org.sisioh.dddbase.core.lifecycle.{ EntityIOContext, EntitiesChunk } 20 | import org.sisioh.dddbase.core.model._ 21 | import scala.concurrent._ 22 | 23 | /** 24 | * `AsyncRepositoryOnMemorySupport`に`EntitiesChunk`のための機能を追加するトレイト。 25 | * 26 | * @tparam ID 識別子の型 27 | * @tparam E エンティティの型 28 | */ 29 | trait AsyncRepositoryOnMemorySupportAsChunk[ID <: Identifier[_], E <: Entity[ID] with EntityCloneable[ID, E]] 30 | extends AsyncEntityReadableAsChunk[ID, E] { 31 | this: AsyncRepositoryOnMemory[ID, E] => 32 | 33 | def resolveAsChunk(index: Int, maxEntities: Int)(implicit ctx: EntityIOContext[Future]): Future[EntitiesChunk[ID, E]] = { 34 | implicit val executor = getExecutionContext(ctx) 35 | Future { 36 | val subEntities = getEntities.values.toList.slice(index * maxEntities, index * maxEntities + maxEntities) 37 | EntitiesChunk(index, subEntities) 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/shared/src/main/scala/org/sisioh/dddbase/lifecycle/forwarding/sync/ForwardingSyncEntityReadableAsPredicate.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.forwarding.sync 17 | 18 | import org.sisioh.dddbase.core.lifecycle.sync.{ SyncEntityReadableAsPredicate, SyncEntityReader } 19 | import org.sisioh.dddbase.core.lifecycle.{ EntityIOContext, EntitiesChunk } 20 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 21 | import scala.util.Try 22 | 23 | /** 24 | * `SyncEntityReadableAsPredicate`のデコレータ。 25 | * 26 | * @tparam ID 識別子の型 27 | * @tparam E エンティティの型 28 | */ 29 | trait ForwardingSyncEntityReadableAsPredicate[ID <: Identifier[_], E <: Entity[ID]] 30 | extends SyncEntityReadableAsPredicate[ID, E] { 31 | this: SyncEntityReader[ID, E] => 32 | 33 | type Delegate <: SyncEntityReadableAsPredicate[ID, E] 34 | 35 | /** 36 | * デリゲート。 37 | */ 38 | protected val delegate: Delegate 39 | 40 | def filterBy(predicate: (E) => Boolean, 41 | index: Option[Int], maxEntities: Option[Int])(implicit ctx: Ctx): Try[EntitiesChunk[ID, E]] = 42 | delegate.filterBy(predicate, index, maxEntities) 43 | 44 | } 45 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/shared/src/main/scala/org/sisioh/dddbase/lifecycle/forwarding/async/ForwardingAsyncEntityReadableAsPredicate.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.forwarding.async 17 | 18 | import org.sisioh.dddbase.core.lifecycle.EntitiesChunk 19 | import org.sisioh.dddbase.core.lifecycle.async.{ AsyncEntityReadableAsPredicate, AsyncEntityReader } 20 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 21 | import scala.concurrent.Future 22 | 23 | /** 24 | * `AsyncEntityReadableAsPredicate`のデコレータ。 25 | * 26 | * @tparam ID 識別子の型 27 | * @tparam E エンティティの型 28 | */ 29 | trait ForwardingAsyncEntityReadableAsPredicate[ID <: Identifier[_], E <: Entity[ID]] 30 | extends AsyncEntityReadableAsPredicate[ID, E] { 31 | this: AsyncEntityReader[ID, E] => 32 | 33 | type Delegate <: AsyncEntityReadableAsPredicate[ID, E] 34 | 35 | /** 36 | * デリゲート。 37 | */ 38 | protected val delegate: Delegate 39 | 40 | def filterBy(predicate: (E) => Boolean, 41 | index: Option[Int], maxEntities: Option[Int])(implicit ctx: Ctx): Future[EntitiesChunk[ID, E]] = 42 | delegate.filterBy(predicate, index, maxEntities) 43 | 44 | } 45 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/jvm/src/test/scala/org/sisioh/dddbase/lifecycle/memory/mutable/sync/GenericSyncRepositoryOnMemoryAsChunkSpec.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.lifecycle.memory.mutable.sync 2 | 3 | import org.sisioh.dddbase.core.lifecycle.sync.SyncEntityIOContext 4 | import org.sisioh.dddbase.core.model.{Identifier, EntityCloneable, Entity} 5 | import org.sisioh.dddbase.lifecycle.memory.sync.SyncRepositoryOnMemorySupportAsChunk 6 | import org.specs2.mutable._ 7 | 8 | class GenericSyncRepositoryOnMemoryAsChunkSpec extends Specification { 9 | 10 | sequential 11 | 12 | class EntityImpl(val identifier: Identifier[Int]) 13 | extends Entity[Identifier[Int]] 14 | with EntityCloneable[Identifier[Int], EntityImpl] 15 | with Ordered[EntityImpl] { 16 | def compare(that: EntityImpl): Int = { 17 | identifier.value.compareTo(that.identifier.value) 18 | } 19 | } 20 | 21 | class TestSyncRepository 22 | extends AbstractSyncRepositoryOnMemory[Identifier[Int], EntityImpl] 23 | with SyncRepositoryOnMemorySupportAsChunk[Identifier[Int], EntityImpl] { 24 | 25 | type This = TestSyncRepository 26 | 27 | } 28 | 29 | implicit val ctx = SyncEntityIOContext 30 | 31 | "The repository" should { 32 | "have stored entities" in { 33 | 34 | val repository = new TestSyncRepository() 35 | 36 | for (i <- 1 to 10) { 37 | val entity = new EntityImpl(Identifier[Int](i)) 38 | repository.store(entity).get.result 39 | } 40 | 41 | val chunk = repository.resolveAsChunk(1, 5).get 42 | 43 | chunk.index must_== 1 44 | chunk.entities.size must_== 5 45 | chunk.entities(0).identifier.value must_== 6 46 | chunk.entities(1).identifier.value must_== 7 47 | chunk.entities(2).identifier.value must_== 8 48 | chunk.entities(3).identifier.value must_== 9 49 | chunk.entities(4).identifier.value must_== 10 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /release.sbt: -------------------------------------------------------------------------------- 1 | import sbtrelease._ 2 | import ReleaseTransformations._ 3 | 4 | val sonatypeURL = "https://oss.sonatype.org/service/local/repositories/" 5 | 6 | val updateReadme = { state: State => 7 | val extracted = Project.extract(state) 8 | val scalaV = extracted get scalaBinaryVersion 9 | val v = extracted get version 10 | val org = extracted get organization 11 | val n = extracted get name 12 | val snapshotOrRelease = 13 | if (extracted get isSnapshot) "snapshots" else "releases" 14 | val readme = "README.md" 15 | val readmeFile = file(readme) 16 | val newReadme = Predef 17 | .augmentString(IO.read(readmeFile)) 18 | .lines 19 | .map { line => 20 | val matchReleaseOrSnapshot = line.contains("SNAPSHOT") == v.contains( 21 | "SNAPSHOT" 22 | ) 23 | if (line.startsWith("libraryDependencies") && matchReleaseOrSnapshot) { 24 | s"""libraryDependencies += "${org}" %% "${n}" % "$v"""" 25 | } else line 26 | } 27 | .mkString("", "\n", "\n") 28 | IO.write(readmeFile, newReadme) 29 | val git = new Git(extracted get baseDirectory) 30 | git.add(readme) ! state.log 31 | //FIXME 署名を入れるかどうか確認 32 | git.commit("update " + readme, sign = false, signOff = false) ! state.log 33 | // "git diff HEAD^" ! state.log 34 | state 35 | } 36 | 37 | commands += Command.command("updateReadme")(updateReadme) 38 | 39 | val updateReadmeProcess: ReleaseStep = updateReadme 40 | 41 | releaseCrossBuild := true 42 | 43 | releasePublishArtifactsAction := PgpKeys.publishSigned.value 44 | 45 | releaseProcess := Seq[ReleaseStep]( 46 | checkSnapshotDependencies, 47 | inquireVersions, 48 | runClean, 49 | runTest, 50 | setReleaseVersion, 51 | commitReleaseVersion, 52 | updateReadmeProcess, 53 | tagRelease, 54 | releaseStepCommandAndRemaining("+publishSigned"), 55 | setNextVersion, 56 | commitNextVersion, 57 | updateReadmeProcess, 58 | ReleaseStep(action = Command.process("sonatypeReleaseAll", _)), 59 | pushChanges 60 | ) 61 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/sync/SyncEntityWriter.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 TRICREO, Inc. (http://tricreo.jp/) 3 | * Copyright 2011 Sisioh Project and others. (http://www.sisioh.org/) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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 writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific language 15 | * governing permissions and limitations under the License. 16 | */ 17 | package org.sisioh.dddbase.core.lifecycle.sync 18 | 19 | import org.sisioh.dddbase.core.lifecycle.EntityWriter 20 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 21 | import scala.util.Try 22 | 23 | /** 24 | * `Identifier`を用いて 25 | * `Entity` 26 | * を書き込むための責務を表すインターフェイス。 27 | * 28 | * @tparam ID 識別子の型 29 | * @tparam E エンティティの型 30 | */ 31 | trait SyncEntityWriter[ID <: Identifier[_], E <: Entity[ID]] 32 | extends EntityWriter[ID, E, Try] { 33 | 34 | type This <: SyncEntityWriter[ID, E] 35 | type Result = SyncResultWithEntity[This, ID, E] 36 | type Results = SyncResultWithEntities[This, ID, E] 37 | 38 | protected def traverseWithThis[A](values: Seq[A])(processor: (This, A) => Try[Result])(implicit ctx: Ctx): Try[Results] = Try { 39 | val result = values.foldLeft[(This, Seq[E])]((this.asInstanceOf[This], Seq.empty[E])) { 40 | (resultWithEntities, task) => 41 | val resultWithEntity = processor(resultWithEntities._1, task).get 42 | (resultWithEntity.result.asInstanceOf[This], resultWithEntities._2 :+ resultWithEntity.entity) 43 | } 44 | SyncResultWithEntities(result._1, result._2) 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/shared/src/main/scala/org/sisioh/dddbase/lifecycle/memory/sync/SyncRepositoryOnMemorySupportAsPredicate.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.memory.sync 17 | 18 | import org.sisioh.dddbase.core.lifecycle.EntitiesChunk 19 | import org.sisioh.dddbase.core.lifecycle.sync._ 20 | import org.sisioh.dddbase.core.model._ 21 | import scala.util._ 22 | 23 | /** 24 | * `SyncRepositoryOnMemorySupport`に`SyncEntityReadableAsPredicate`のための機能を追加するトレイト。 25 | * 26 | * @tparam ID エンティティの識別子の型 27 | * @tparam E エンティティの型 28 | */ 29 | trait SyncRepositoryOnMemorySupportAsPredicate[ID <: Identifier[_], E <: Entity[ID] with EntityCloneable[ID, E] with Ordered[E]] 30 | extends SyncEntityReadableAsPredicate[ID, E] { 31 | this: SyncRepositoryOnMemory[ID, E] => 32 | 33 | def filterBy(predicate: (E) => Boolean, 34 | indexOpt: Option[Int] = None, 35 | maxEntitiesOpt: Option[Int] = None)(implicit ctx: Ctx): Try[EntitiesChunk[ID, E]] = { 36 | val filteredSubEntities = toList.filter(predicate) 37 | val index = indexOpt.getOrElse(0) 38 | val maxEntities = maxEntitiesOpt.getOrElse(filteredSubEntities.size) 39 | val subEntities = filteredSubEntities.slice(index * maxEntities, index * maxEntities + maxEntities) 40 | Success(EntitiesChunk(index, subEntities)) 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /scala-dddbase-spec/jvm/src/test/scala/org/sisioh/dddbase/spec/NotSpecificationTest.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 TRICREO, Inc. (http://tricreo.jp/) 3 | * Copyright 2011 Sisioh Project and others. (http://www.sisioh.org/) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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 writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific language 15 | * governing permissions and limitations under the License. 16 | */ 17 | package org.sisioh.dddbase.spec 18 | 19 | import org.junit.Test 20 | import org.mockito.ArgumentMatchers._ 21 | import org.mockito.Mockito._ 22 | import org.scalatestplus.junit.AssertionsForJUnit 23 | import org.scalatestplus.mockito.MockitoSugar 24 | 25 | class NotSpecificationTest extends AssertionsForJUnit with MockitoSugar { 26 | 27 | /** 28 | * NOT `false` が `true` となること。 29 | * 30 | * @throws Exception 例外が発生した場合 31 | */ 32 | @Test 33 | def test01_false_To_true(): Unit = { 34 | val mock1 = mock[Specification[Unit]] 35 | 36 | when(mock1.isSatisfiedBy(any(classOf[Unit]))).thenReturn(false) 37 | 38 | val not = new NotSpecification[Unit](mock1) 39 | assert(not.isSatisfiedBy(())) 40 | 41 | verify(mock1).isSatisfiedBy(()) 42 | } 43 | 44 | /** 45 | * NOT `true` が `false` となること。 46 | * 47 | * @throws Exception 例外が発生した場合 48 | */ 49 | @Test 50 | def test01_true_To_false(): Unit = { 51 | val mock1 = mock[Specification[Unit]] 52 | 53 | when(mock1.isSatisfiedBy(any(classOf[Unit]))).thenReturn(true) 54 | 55 | val not = new NotSpecification[Unit](mock1) 56 | assert(!not.isSatisfiedBy(())) 57 | 58 | verify(mock1).isSatisfiedBy(()) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/jvm/src/test/scala/org/sisioh/dddbase/lifecycle/memory/mutable/sync/GenericSyncRepositoryOnMemoryAsPredicateSpec.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.lifecycle.memory.mutable.sync 2 | 3 | import org.sisioh.dddbase.core.lifecycle.sync.SyncEntityIOContext 4 | import org.sisioh.dddbase.core.model.{Identifier, EntityCloneable, Entity} 5 | import org.sisioh.dddbase.lifecycle.memory.sync.SyncRepositoryOnMemorySupportAsPredicate 6 | import org.specs2.mutable._ 7 | 8 | class GenericSyncRepositoryOnMemoryAsPredicateSpec extends Specification { 9 | 10 | sequential 11 | 12 | class EntityImpl(val identifier: Identifier[Int]) 13 | extends Entity[Identifier[Int]] 14 | with EntityCloneable[Identifier[Int], EntityImpl] 15 | with Ordered[EntityImpl] { 16 | def compare(that: EntityImpl): Int = { 17 | identifier.value.compareTo(that.identifier.value) 18 | } 19 | } 20 | 21 | class TestSyncRepository 22 | extends AbstractSyncRepositoryOnMemory[Identifier[Int], EntityImpl] 23 | with SyncRepositoryOnMemorySupportAsPredicate[Identifier[Int], EntityImpl] { 24 | 25 | type This = TestSyncRepository 26 | 27 | } 28 | 29 | implicit val ctx = SyncEntityIOContext 30 | 31 | "The repository" should { 32 | "have stored entities" in { 33 | 34 | val repository = new TestSyncRepository() 35 | 36 | for (i <- 1 to 10) { 37 | val entity = new EntityImpl(Identifier[Int](i)) 38 | repository.store(entity).get.result 39 | } 40 | 41 | val chunk = repository 42 | .filterBy({ e => 43 | e.identifier.value % 2 == 0 44 | }, Some(0), Some(5)) 45 | .get 46 | 47 | chunk.index must_== 0 48 | chunk.entities.size must_== 5 49 | chunk.entities(0).identifier.value must_== 2 50 | chunk.entities(1).identifier.value must_== 4 51 | chunk.entities(2).identifier.value must_== 6 52 | chunk.entities(3).identifier.value must_== 8 53 | chunk.entities(4).identifier.value must_== 10 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/async/AsyncEntityReader.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle.async 17 | 18 | import org.sisioh.dddbase.core.lifecycle.EntityReader 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | import scala.concurrent.Future 21 | 22 | /** 23 | * 非同期版`org.sisioh.dddbase.core.lifecycle.EntityReader`。 24 | * 25 | * @see `org.sisioh.dddbase.core.lifecycle.EntityReader` 26 | * 27 | * @tparam ID 識別子の型 28 | * @tparam E エンティティの型 29 | */ 30 | trait AsyncEntityReader[ID <: Identifier[_], E <: Entity[ID]] 31 | extends AsyncEntityIO with EntityReader[ID, E, Future] { 32 | 33 | protected def mapValues[A, R](values: Future[A])(f: (A) => R)(implicit ctx: Ctx): Future[R] = { 34 | implicit val executor = getExecutionContext(ctx) 35 | values.map(f) 36 | } 37 | 38 | protected def traverse[A, R](values: Seq[A], forceSuccess: Boolean)(f: (A) => Future[R])(implicit ctx: Ctx): Future[Seq[R]] = { 39 | implicit val executor = getExecutionContext(ctx) 40 | values.map(f).foldLeft(Future.successful(Seq.empty[R])) { 41 | (resultsFuture, resultFuture) => 42 | (for { results <- resultsFuture; result <- resultFuture } yield results :+ result).recoverWith { 43 | case e => if (forceSuccess) resultsFuture else Future.failed(e) 44 | } 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/shared/src/main/scala/org/sisioh/dddbase/lifecycle/forwarding/sync/wrapped/SyncWrappedAsyncEntityReader.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.forwarding.sync.wrapped 17 | 18 | import org.sisioh.dddbase.core.lifecycle.async.AsyncEntityReader 19 | import org.sisioh.dddbase.core.lifecycle.sync.SyncEntityReader 20 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 21 | import scala.concurrent.Await 22 | import scala.concurrent.duration.Duration 23 | import scala.util.Try 24 | 25 | /** 26 | * `AsyncEntityReader`を`SyncEntityReader`としてラップするためのデコレータ。 27 | * 28 | * @tparam ID 識別子の型 29 | * @tparam E エンティティの型 30 | */ 31 | trait SyncWrappedAsyncEntityReader[ID <: Identifier[_], E <: Entity[ID]] 32 | extends SyncEntityReader[ID, E] with SyncWrappedAsyncEntityIO { 33 | 34 | type Delegate <: AsyncEntityReader[ID, E] 35 | 36 | protected val delegate: Delegate 37 | 38 | protected val timeout: Duration 39 | 40 | def resolveBy(identifier: ID)(implicit ctx: Ctx): Try[E] = Try { 41 | implicit val asyncEntityIOContext = getAsyncEntityIOContext(ctx) 42 | Await.result(delegate.resolveBy(identifier), timeout) 43 | } 44 | 45 | def existBy(identifier: ID)(implicit ctx: Ctx): Try[Boolean] = Try { 46 | implicit val asyncEntityIOContext = getAsyncEntityIOContext(ctx) 47 | Await.result(delegate.existBy(identifier), timeout) 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/jvm/src/test/scala/org/sisioh/dddbase/lifecycle/memory/sync/SyncRepositoryOnMemorySupportAsChunk2Spec.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.lifecycle.memory.sync 2 | 3 | import org.sisioh.dddbase.core.lifecycle.sync.SyncEntityIOContext 4 | import org.sisioh.dddbase.core.model._ 5 | import org.specs2.mutable.Specification 6 | 7 | class SyncRepositoryOnMemorySupportAsChunk2Spec extends Specification { 8 | 9 | case class IntIdentifier(value: Int) 10 | extends AbstractOrderedIdentifier[Int, IntIdentifier] 11 | 12 | class EntityImpl(val identifier: IntIdentifier) 13 | extends Entity[IntIdentifier] 14 | with EntityCloneable[IntIdentifier, EntityImpl] 15 | with EntityOrdered[Int, IntIdentifier, EntityImpl] 16 | 17 | class TestSyncRepository(entities: Map[IntIdentifier, EntityImpl] = Map.empty) 18 | extends AbstractSyncRepositoryOnMemory[IntIdentifier, EntityImpl]( 19 | entities 20 | ) 21 | with SyncRepositoryOnMemorySupportAsChunk[IntIdentifier, EntityImpl] { 22 | type This = TestSyncRepository 23 | 24 | override protected def createInstance( 25 | entities: Map[IntIdentifier, EntityImpl] 26 | ): This = 27 | new TestSyncRepository(entities) 28 | } 29 | 30 | implicit val ctx = SyncEntityIOContext 31 | 32 | "The repository" should { 33 | "have stored entities" in { 34 | 35 | var repository = new TestSyncRepository() 36 | 37 | for (i <- 1 to 10) { 38 | val entity = new EntityImpl(IntIdentifier(i)) 39 | repository = repository.store(entity).get.result 40 | } 41 | 42 | val chunk = repository.resolveAsChunk(0, 5).get 43 | 44 | chunk.index must_== 0 45 | chunk.entities.size must_== 5 46 | chunk.entities(0) must_== new EntityImpl(IntIdentifier(1)) 47 | chunk.entities(1) must_== new EntityImpl(IntIdentifier(2)) 48 | chunk.entities(2) must_== new EntityImpl(IntIdentifier(3)) 49 | chunk.entities(3) must_== new EntityImpl(IntIdentifier(4)) 50 | chunk.entities(4) must_== new EntityImpl(IntIdentifier(5)) 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/shared/src/main/scala/org/sisioh/dddbase/lifecycle/memory/async/AsyncRepositoryOnMemorySupportAsPredicate.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.memory.async 17 | 18 | import org.sisioh.dddbase.core.lifecycle.async._ 19 | import org.sisioh.dddbase.core.lifecycle.{ EntityIOContext, EntitiesChunk } 20 | import org.sisioh.dddbase.core.model._ 21 | import scala.concurrent._ 22 | 23 | /** 24 | * `AsyncRepositoryOnMemorySupport`に`AsyncEntityReadableAsPredicate`のための機能を追加するトレイト。 25 | * 26 | * @tparam ID 識別子の型 27 | * @tparam E エンティティの型 28 | */ 29 | trait AsyncRepositoryOnMemorySupportAsPredicate[ID <: Identifier[_], E <: Entity[ID] with EntityCloneable[ID, E]] 30 | extends AsyncEntityReadableAsPredicate[ID, E] { 31 | this: AsyncRepositoryOnMemory[ID, E] => 32 | 33 | def filterBy(predicate: (E) => Boolean, indexOpt: Option[Int], maxEntitiesOpt: Option[Int])(implicit ctx: EntityIOContext[Future]): Future[EntitiesChunk[ID, E]] = { 34 | implicit val executor = getExecutionContext(ctx) 35 | Future { 36 | val filteredSubEntities = getEntities.values.toList.filter(predicate) 37 | val index = indexOpt.getOrElse(0) 38 | val maxEntities = maxEntitiesOpt.getOrElse(filteredSubEntities.size) 39 | val subEntities = filteredSubEntities.slice(index * maxEntities, index * maxEntities + maxEntities) 40 | EntitiesChunk(index, subEntities) 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/async/AsyncEntityWriter.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle.async 17 | 18 | import org.sisioh.dddbase.core.lifecycle.EntityWriter 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | import scala.concurrent._ 21 | 22 | /** 23 | * 非同期版`org.sisioh.dddbase.core.lifecycle.EntityWriter`。 24 | * 25 | * @see `org.sisioh.dddbase.core.lifecycle.EntityWriter` 26 | * 27 | * @tparam ID 識別子の型 28 | * @tparam E エンティティの型 29 | */ 30 | trait AsyncEntityWriter[ID <: Identifier[_], E <: Entity[ID]] 31 | extends AsyncEntityIO with EntityWriter[ID, E, Future] { 32 | 33 | type This <: AsyncEntityWriter[ID, E] 34 | type Result = AsyncResultWithEntity[This, ID, E] 35 | type Results = AsyncResultWithEntities[This, ID, E] 36 | 37 | protected final def traverseWithThis[A](values: Seq[A])(processor: (This, A) => Future[Result])(implicit ctx: Ctx): Future[Results] = { 38 | implicit val executor = getExecutionContext(ctx) 39 | values.foldLeft(Future.successful(AsyncResultWithEntities[This, ID, E](this.asInstanceOf[This], Seq.empty[E]))) { 40 | case (future, value) => 41 | for { 42 | AsyncResultWithEntities(repo, entities) <- future 43 | AsyncResultWithEntity(r, e) <- processor(repo, value) 44 | } yield { 45 | AsyncResultWithEntities(r, entities :+ e) 46 | } 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/async/AsyncEntityIOContext.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle.async 17 | 18 | import org.sisioh.dddbase.core.lifecycle.EntityIOContext 19 | import scala.concurrent.{Future, ExecutionContext} 20 | 21 | /** 22 | * `org.sisioh.dddbase.core.lifecycle.EntityIOContext`の非同期版。 23 | */ 24 | trait AsyncEntityIOContext extends EntityIOContext[Future] { 25 | 26 | /** 27 | * `scala.concurrent.ExecutionContext` 28 | */ 29 | val executor: ExecutionContext 30 | 31 | } 32 | 33 | /** 34 | * コンパニオンオブジェクト。 35 | */ 36 | object AsyncEntityIOContext { 37 | 38 | /** 39 | * ファクトリメソッド。 40 | * 41 | * @param executor `scala.concurrent.ExecutionContext` 42 | * @return `org.sisioh.dddbase.core.lifecycle.async.AsyncEntityIOContext` 43 | */ 44 | def apply()(implicit executor: ExecutionContext): AsyncEntityIOContext = 45 | new AsyncEntityIOContextImpl() 46 | 47 | /** 48 | * エクストラクタメソッド。 49 | * 50 | * @param asyncEntityIOContext `org.sisioh.dddbase.core.lifecycle.async.AsyncEntityIOContext` 51 | * @return 構成要素 52 | */ 53 | def unapply( 54 | asyncEntityIOContext: AsyncEntityIOContext 55 | ): Option[(ExecutionContext)] = 56 | Some(asyncEntityIOContext.executor) 57 | 58 | } 59 | 60 | private[async] case class AsyncEntityIOContextImpl()( 61 | implicit val executor: ExecutionContext 62 | ) extends AsyncEntityIOContext 63 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/jvm/src/test/scala/org/sisioh/dddbase/lifecycle/memory/sync/SyncRepositoryOnMemorySupportAsChunkSpec.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.lifecycle.memory.sync 2 | 3 | import org.sisioh.dddbase.core.lifecycle.sync.SyncEntityIOContext 4 | import org.sisioh.dddbase.core.model._ 5 | import org.specs2.mutable.Specification 6 | 7 | class SyncRepositoryOnMemorySupportAsChunkSpec extends Specification { 8 | 9 | class EntityImpl(val identifier: Identifier[Int]) 10 | extends Entity[Identifier[Int]] 11 | with EntityCloneable[Identifier[Int], EntityImpl] 12 | with Ordered[EntityImpl] { 13 | 14 | def compare( 15 | that: SyncRepositoryOnMemorySupportAsChunkSpec.this.type#EntityImpl 16 | ): Int = { 17 | this.identifier.value.compareTo(that.identifier.value) 18 | } 19 | 20 | } 21 | 22 | class TestSyncRepository( 23 | entities: Map[Identifier[Int], EntityImpl] = Map.empty 24 | ) extends AbstractSyncRepositoryOnMemory[Identifier[Int], EntityImpl]( 25 | entities 26 | ) 27 | with SyncRepositoryOnMemorySupportAsChunk[Identifier[Int], EntityImpl] { 28 | type This = TestSyncRepository 29 | 30 | override protected def createInstance( 31 | entities: Map[Identifier[Int], EntityImpl] 32 | ): TestSyncRepository#This = 33 | new TestSyncRepository(entities) 34 | } 35 | 36 | implicit val ctx = SyncEntityIOContext 37 | 38 | "The repository" should { 39 | "have stored entities" in { 40 | 41 | var repository = new TestSyncRepository() 42 | 43 | for (i <- 1 to 10) { 44 | val entity = new EntityImpl(Identifier[Int](i)) 45 | repository = repository.store(entity).get.result 46 | } 47 | 48 | val chunk = repository.resolveAsChunk(1, 5).get 49 | 50 | chunk.index must_== 1 51 | chunk.entities.size must_== 5 52 | chunk.entities(0).identifier.value must_== 6 53 | chunk.entities(1).identifier.value must_== 7 54 | chunk.entities(2).identifier.value must_== 8 55 | chunk.entities(3).identifier.value must_== 9 56 | chunk.entities(4).identifier.value must_== 10 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Domain Driven-Design support library for Scala 2 | 3 | [](https://gitter.im/sisioh/scala-dddbase?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | 5 | If you use this library, you can develop applications based on Domain Driven Design advocated by Eric Evans. 6 | 7 | [](https://travis-ci.org/sisioh/scala-dddbase) 8 | [](https://maven-badges.herokuapp.com/maven-central/org.sisioh/scala-dddbase) 9 | [](http://javadoc-badge.appspot.com/org.sisioh/scala-dddbase_2.11) 10 | [](https://www.versioneye.com/java/org.sisioh:scala-dddbase_2.11/references) 11 | 12 | 13 | ## Installation 14 | 15 | Add the following to your sbt build (Scala 2.10.x, and Scala 2.11.x): 16 | 17 | ### Release Version 18 | 19 | for scala 20 | 21 | ```scala 22 | resolvers += "Sonatype OSS Release Repository" at "https://oss.sonatype.org/content/repositories/releases/" 23 | 24 | libraryDependencies += "org.sisioh" %% "scala-dddbase" % "0.2.12" 25 | ``` 26 | 27 | for scala.js 28 | 29 | ```scala 30 | resolvers += "Sonatype OSS Release Repository" at "https://oss.sonatype.org/content/repositories/releases/" 31 | 32 | libraryDependencies += "org.sisioh" %% "scala-dddbase" % "0.2.12" 33 | ``` 34 | 35 | ### Snapshot Version 36 | 37 | for scala 38 | 39 | ```scala 40 | resolvers += "Sonatype OSS Snapshot Repository" at "https://oss.sonatype.org/content/repositories/snapshots/" 41 | 42 | libraryDependencies += "org.sisioh" %% "scala-dddbase" % "0.2.13-SNAPSHOT" 43 | ``` 44 | 45 | for scala.js 46 | 47 | ```scala 48 | resolvers += "Sonatype OSS Snapshot Repository" at "https://oss.sonatype.org/content/repositories/snapshots/" 49 | 50 | libraryDependencies += "org.sisioh" %% "scala-dddbase" % "0.2.13-SNAPSHOT" 51 | ``` 52 | 53 | 54 | ## Short url 55 | 56 | http://git.io/scala-dddbase 57 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/jvm/src/test/scala/org/sisioh/dddbase/lifecycle/memory/sync/SyncRepositoryOnMemorySupportByPredicateSpec.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.lifecycle.memory.sync 2 | 3 | import org.sisioh.dddbase.core.lifecycle.sync.SyncEntityIOContext 4 | import org.sisioh.dddbase.core.model._ 5 | import org.specs2.mutable.Specification 6 | 7 | class SyncRepositoryOnMemorySupportByPredicateSpec extends Specification { 8 | 9 | class EntityImpl(val identifier: Identifier[Int]) 10 | extends Entity[Identifier[Int]] 11 | with EntityCloneable[Identifier[Int], EntityImpl] 12 | with Ordered[EntityImpl] { 13 | 14 | def compare(that: EntityImpl): Int = { 15 | this.identifier.value.compareTo(that.identifier.value) 16 | } 17 | 18 | } 19 | 20 | class TestSyncRepository( 21 | entities: Map[Identifier[Int], EntityImpl] = Map.empty 22 | ) extends AbstractSyncRepositoryOnMemory[Identifier[Int], EntityImpl]( 23 | entities 24 | ) 25 | with SyncRepositoryOnMemorySupportAsPredicate[Identifier[Int], EntityImpl] { 26 | type This = TestSyncRepository 27 | 28 | override protected def createInstance( 29 | entities: Map[Identifier[Int], EntityImpl] 30 | ): TestSyncRepository#This = 31 | new TestSyncRepository(entities) 32 | } 33 | 34 | implicit val ctx = SyncEntityIOContext 35 | 36 | "The repository" should { 37 | "have stored entities" in { 38 | 39 | var repository = new TestSyncRepository 40 | 41 | for (i <- 1 to 10) { 42 | val entity = new EntityImpl(Identifier[Int](i)) 43 | repository = repository.store(entity).get.result 44 | } 45 | 46 | val chunk = repository 47 | .filterBy({ e => 48 | e.identifier.value % 2 == 0 49 | }, Some(0), Some(5)) 50 | .get 51 | 52 | chunk.index must_== 0 53 | chunk.entities.size must_== 5 54 | chunk.entities(0).identifier.value must_== 2 55 | chunk.entities(1).identifier.value must_== 4 56 | chunk.entities(2).identifier.value must_== 6 57 | chunk.entities(3).identifier.value must_== 8 58 | chunk.entities(4).identifier.value must_== 10 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/shared/src/main/scala/org/sisioh/dddbase/lifecycle/forwarding/async/wrapped/AsyncWrappedSyncEntityReader.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.forwarding.async.wrapped 17 | 18 | import org.sisioh.dddbase.core.lifecycle.async.AsyncEntityReader 19 | import org.sisioh.dddbase.core.lifecycle.sync.SyncEntityReader 20 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 21 | import scala.concurrent._ 22 | import scala.util.Try 23 | 24 | /** 25 | * `SyncEntityReader`を`AsyncEntityReader`としてラップするためのデコレータ。 26 | * 27 | * @tparam ID 識別子の型 28 | * @tparam E エンティティの型 29 | */ 30 | trait AsyncWrappedSyncEntityReader[ID <: Identifier[_], E <: Entity[ID]] 31 | extends AsyncEntityReader[ID, E] with AsyncWrappedSyncEntityIO { 32 | 33 | type Delegate <: SyncEntityReader[ID, E] 34 | 35 | protected val delegate: Delegate 36 | 37 | def resolveBy(identifier: ID)(implicit ctx: Ctx): Future[E] = { 38 | val asyncCtx = getAsyncWrappedEntityIOContext(ctx) 39 | implicit val executor = asyncCtx.executor 40 | Future { 41 | implicit val syncCtx = asyncCtx.syncEntityIOContext 42 | delegate.resolveBy(identifier).get 43 | } 44 | } 45 | 46 | def existBy(identifier: ID)(implicit ctx: Ctx): Future[Boolean] = { 47 | val asyncCtx = getAsyncWrappedEntityIOContext(ctx) 48 | implicit val executor = asyncCtx.executor 49 | Future { 50 | implicit val syncCtx = asyncCtx.syncEntityIOContext 51 | delegate.existBy(identifier).get 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/shared/src/main/scala/org/sisioh/dddbase/lifecycle/forwarding/sync/ForwardingSyncEntityWriter.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.forwarding.sync 17 | 18 | import org.sisioh.dddbase.core.lifecycle.sync.{ SyncEntityWriter, SyncResultWithEntity } 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | import scala.util.Try 21 | 22 | /** 23 | * `SyncEntityWriter`のデリゲート。 24 | * 25 | * @tparam ID 識別子の型 26 | * @tparam E エンティティの型 27 | */ 28 | trait ForwardingSyncEntityWriter[ID <: Identifier[_], E <: Entity[ID]] 29 | extends SyncEntityWriter[ID, E] { 30 | 31 | type This <: ForwardingSyncEntityWriter[ID, E] 32 | 33 | type Delegate <: SyncEntityWriter[ID, E] 34 | 35 | /** 36 | * デリゲート。 37 | */ 38 | protected val delegate: Delegate 39 | 40 | /** 41 | * 新しいインスタンスを作成する。 42 | * 43 | * @param state 新しい状態のデリゲートとエンティティ 44 | * @return 新しいインスタンスとエンティティ 45 | */ 46 | protected def createInstance(state: Try[(Delegate#This, Option[E])]): Try[(This, Option[E])] 47 | 48 | def store(entity: E)(implicit ctx: Ctx): Try[Result] = { 49 | createInstance( 50 | delegate.store(entity).map { 51 | e => 52 | (e.result.asInstanceOf[Delegate#This], Some(e.entity)) 53 | } 54 | ).map(e => SyncResultWithEntity(e._1, e._2.get)) 55 | } 56 | 57 | def deleteBy(identifier: ID)(implicit ctx: Ctx): Try[Result] = { 58 | createInstance( 59 | delegate.deleteBy(identifier).map { 60 | e => 61 | (e.result.asInstanceOf[Delegate#This], Some(e.entity)) 62 | } 63 | ).map(e => SyncResultWithEntity(e._1, e._2.get)) 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/shared/src/main/scala/org/sisioh/dddbase/lifecycle/forwarding/async/wrapped/AsyncWrappedSyncEntityIOContext.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.forwarding.async.wrapped 17 | 18 | import org.sisioh.dddbase.core.lifecycle.async.AsyncEntityIOContext 19 | import org.sisioh.dddbase.core.lifecycle.sync.SyncEntityIOContext 20 | import scala.concurrent.ExecutionContext 21 | 22 | /** 23 | * `AsyncEntityIOContext`のラッパー版。 24 | */ 25 | trait AsyncWrappedSyncEntityIOContext extends AsyncEntityIOContext { 26 | 27 | /** 28 | * `SyncEntityIOContext` 29 | */ 30 | val syncEntityIOContext: SyncEntityIOContext 31 | 32 | } 33 | 34 | /** 35 | * コンパニオンオブジェクト。 36 | */ 37 | object AsyncWrappedSyncEntityIOContext { 38 | 39 | /** 40 | * ファクトリメソッド。 41 | * 42 | * @param syncEntityIOContext `SyncEntityIOContext` 43 | * @param executor `ExecutionContext` 44 | * @return `AsyncWrappedSyncEntityIOContext` 45 | */ 46 | def apply(syncEntityIOContext: SyncEntityIOContext = SyncEntityIOContext)(implicit executor: ExecutionContext): AsyncWrappedSyncEntityIOContext = 47 | new AsyncWrappedSyncEntityIOContextImpl(syncEntityIOContext) 48 | 49 | /** 50 | * エクストラクタメソッド。 51 | * 52 | * @param asyncWrappedEntityIOContext `AsyncWrappedSyncEntityIOContext` 53 | * @return 構成要素 54 | */ 55 | def unapply(asyncWrappedEntityIOContext: AsyncWrappedSyncEntityIOContext): Option[(SyncEntityIOContext)] = 56 | Some(asyncWrappedEntityIOContext.syncEntityIOContext) 57 | 58 | } 59 | 60 | private[wrapped] case class AsyncWrappedSyncEntityIOContextImpl(syncEntityIOContext: SyncEntityIOContext = SyncEntityIOContext)(implicit val executor: ExecutionContext) 61 | extends AsyncWrappedSyncEntityIOContext 62 | 63 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/shared/src/main/scala/org/sisioh/dddbase/lifecycle/forwarding/sync/wrapped/SyncWrappedAsyncEntityIOContext.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.forwarding.sync.wrapped 17 | 18 | import org.sisioh.dddbase.core.lifecycle.async.AsyncEntityIOContext 19 | import org.sisioh.dddbase.core.lifecycle.sync.SyncEntityIOContext 20 | 21 | /** 22 | * `org.sisioh.dddbase.core.lifecycle.async.AsyncEntityIOContext`を 23 | * `org.sisioh.dddbase.core.lifecycle.sync.SyncEntityIOContext`として 24 | * ラップするトレイト。 25 | */ 26 | trait SyncWrappedAsyncEntityIOContext extends SyncEntityIOContext { 27 | 28 | /** 29 | * `org.sisioh.dddbase.core.lifecycle.async.AsyncEntityIOContext` 30 | */ 31 | val asyncEntityIOContext: AsyncEntityIOContext 32 | 33 | } 34 | 35 | /** 36 | * コンパニオンオブジェクト。 37 | */ 38 | object SyncWrappedAsyncEntityIOContext { 39 | 40 | /** 41 | * ファクトリメソッド。 42 | * 43 | * @param asyncEntityIOContext `org.sisioh.dddbase.core.lifecycle.async.AsyncEntityIOContext` 44 | * @return `org.sisioh.dddbase.lifecycle.forwarding.sync.wrapped.SyncWrappedAsyncEntityIOContext` 45 | */ 46 | def apply(asyncEntityIOContext: AsyncEntityIOContext): SyncWrappedAsyncEntityIOContext = 47 | new SyncWrappedEntityIOContextImpl(asyncEntityIOContext) 48 | 49 | /** 50 | * エクストラクタメソッド。 51 | * 52 | * @param syncWrappedEntityIOContext `org.sisioh.dddbase.lifecycle.forwarding.sync.wrapped.SyncWrappedAsyncEntityIOContext` 53 | * @return 構成要素 54 | */ 55 | def unapply(syncWrappedEntityIOContext: SyncWrappedAsyncEntityIOContext): Option[(AsyncEntityIOContext)] = 56 | Some(syncWrappedEntityIOContext.asyncEntityIOContext) 57 | 58 | } 59 | 60 | private[wrapped] case class SyncWrappedEntityIOContextImpl(asyncEntityIOContext: AsyncEntityIOContext) 61 | extends SyncWrappedAsyncEntityIOContext 62 | 63 | -------------------------------------------------------------------------------- /scala-dddbase-spec/shared/src/main/scala/org/sisioh/dddbase/spec/Specification.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 TRICREO, Inc. (http://tricreo.jp/) 3 | * Copyright 2011 Sisioh Project and others. (http://www.sisioh.org/) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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 writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific language 15 | * governing permissions and limitations under the License. 16 | */ 17 | package org.sisioh.dddbase.spec 18 | 19 | /** 20 | * 仕様を表すモデル。 21 | * 22 | *DDD本の中で説明している Specification パターンに則ったオブジェクトを表すインターフェイス。 23 | * Specificationの実装は、 AbstractSpecification を基底クラスとして実装するとよい。 24 | * その場合、 `#isSatisfiedBy(Object)` を実装する必要しかない。
25 | * 26 | * @tparam T { @link Specification}の型 27 | * @author j5ik2o 28 | */ 29 | trait Specification[T] { 30 | 31 | /** 32 | * Check if {@code t} is satisfied by the specification. 33 | * 34 | * @param t Object to test. 35 | * @return { @code true} if { @code t} satisfies the specification. 36 | * @throws `IllegalArgumentException` 引数に{ @code null}を与えた場合 37 | */ 38 | def isSatisfiedBy(t: T): Boolean 39 | 40 | /** 41 | * Create a new specification that is the NOT operation of {@code this} specification. 42 | * 43 | * @return A new specification. 44 | */ 45 | def not: Specification[T] = new NotSpecification[T](this) 46 | 47 | /** 48 | * Create a new specification that is the AND operation of {@code this} specification and another specification. 49 | * 50 | * @param specification Specification to AND. 51 | * @return A new specification. 52 | * @throws `IllegalArgumentException` 引数に{ @code null}を与えた場合 53 | */ 54 | def and(specification: Specification[T]): Specification[T] = new AndSpecification(this, specification) 55 | 56 | /** 57 | * Create a new specification that is the OR operation of {@code this} specification and another specification. 58 | * 59 | * @param specification Specification to OR. 60 | * @return A new specification. 61 | * @throws `IllegalArgumentException` 引数に{ @code null}を与えた場合 62 | */ 63 | def or(specification: Specification[T]): Specification[T] = new OrSpecification(this, specification) 64 | 65 | } 66 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/shared/src/main/scala/org/sisioh/dddbase/lifecycle/forwarding/async/ForwardingAsyncEntityWriter.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.forwarding.async 17 | 18 | import org.sisioh.dddbase.core.lifecycle.async.{ AsyncResultWithEntity, AsyncEntityWriter } 19 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 20 | import scala.concurrent.Future 21 | 22 | /** 23 | * `AsyncEntityWriter`のデコレータ。 24 | * 25 | * @tparam ID 識別子の型 26 | * @tparam E エンティティの型 27 | */ 28 | trait ForwardingAsyncEntityWriter[ID <: Identifier[_], E <: Entity[ID]] 29 | extends AsyncEntityWriter[ID, E] { 30 | 31 | type Delegate <: AsyncEntityWriter[ID, E] 32 | 33 | /** 34 | * デリゲート。 35 | */ 36 | protected val delegate: Delegate 37 | 38 | /** 39 | * 新しいインスタンスを作成する。 40 | * 41 | * @param state 新しい状態のデリゲートとエンティティ 42 | * @return 新しいインスタンスとエンティティ 43 | */ 44 | protected def createInstance(state: Future[(Delegate#This, Option[E])]): Future[(This, Option[E])] 45 | 46 | def store(entity: E)(implicit ctx: Ctx): Future[Result] = { 47 | implicit val executor = getExecutionContext(ctx) 48 | val state = delegate.store(entity).map { 49 | result => 50 | (result.result.asInstanceOf[Delegate#This], Some(result.entity)) 51 | } 52 | val instance = createInstance(state) 53 | instance.map { 54 | e => 55 | AsyncResultWithEntity(e._1, e._2.get) 56 | } 57 | } 58 | 59 | def deleteBy(identifier: ID)(implicit ctx: Ctx): Future[Result] = { 60 | implicit val executor = getExecutionContext(ctx) 61 | val state = delegate.deleteBy(identifier).map { 62 | result => 63 | (result.result.asInstanceOf[Delegate#This], Some(result.entity)) 64 | } 65 | val instance = createInstance(state) 66 | instance.map { 67 | e => 68 | AsyncResultWithEntity(e._1, e._2.get) 69 | } 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/shared/src/main/scala/org/sisioh/dddbase/lifecycle/memory/mutable/async/AsyncRepositoryOnMemorySupport.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.memory.mutable.async 17 | 18 | import org.sisioh.dddbase.core.lifecycle.EntityNotFoundException 19 | import org.sisioh.dddbase.core.lifecycle.async.AsyncResultWithEntity 20 | import org.sisioh.dddbase.core.model.{ EntityCloneable, Entity, Identifier } 21 | import scala.collection.Map 22 | import scala.concurrent._ 23 | 24 | trait AsyncRepositoryOnMemorySupport[ID <: Identifier[_], E <: Entity[ID] with EntityCloneable[ID, E] with Ordered[E]] 25 | extends AsyncRepositoryOnMemory[ID, E] { 26 | 27 | protected val _entities: collection.concurrent.Map[ID, E] 28 | 29 | override protected def getEntities: Map[ID, E] = _entities 30 | 31 | override def existBy(identifier: ID)(implicit ctx: Ctx): Future[Boolean] = 32 | Future.successful(entities.contains(identifier)) 33 | 34 | override def resolveBy(identifier: ID)(implicit ctx: Ctx): Future[E] = { 35 | implicit val executor = getExecutionContext(ctx) 36 | Future { 37 | _entities.getOrElse(identifier, throw EntityNotFoundException(Some(s"identifier = $identifier"))) 38 | } 39 | } 40 | 41 | override def store(entity: E)(implicit ctx: Ctx): Future[Result] = { 42 | implicit val executor = getExecutionContext(ctx) 43 | Future { 44 | _entities.put(entity.identifier, entity) 45 | AsyncResultWithEntity[This, ID, E](this.asInstanceOf[This], entity) 46 | } 47 | } 48 | 49 | override def deleteBy(identifier: ID)(implicit ctx: Ctx): Future[Result] = { 50 | implicit val executor = getExecutionContext(ctx) 51 | Future { 52 | val entity = _entities.remove(identifier).getOrElse(throw EntityNotFoundException(Some(s"identifier = $identifier"))) 53 | AsyncResultWithEntity[This, ID, E](this.asInstanceOf[This], entity) 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/EntityReader.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.core.lifecycle 17 | 18 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 19 | import scala.language.higherKinds 20 | import scala.language.implicitConversions 21 | import scala.language.reflectiveCalls 22 | 23 | /** 24 | * `Identifier` を用いて `Entity` を読み込むための責務を表すトレイト。 25 | * 26 | * @tparam ID 識別子の型 27 | * @tparam E エンティティの型 28 | * @tparam M モナド 29 | */ 30 | trait EntityReader[ID <: Identifier[_], E <: Entity[ID], M[+_]] 31 | extends EntityIO[M] { 32 | self => 33 | 34 | protected def traverseWithoutFailures[A, R](values: Seq[A])(f: (A) => M[R])(implicit ctx: Ctx): M[Seq[R]] = 35 | traverse[A, R](values, forceSuccess = true)(f) 36 | 37 | protected def traverse[A, R](values: Seq[A], forceSuccess: Boolean = false)(f: (A) => M[R])(implicit ctx: Ctx): M[Seq[R]] 38 | 39 | protected def mapValues[A, R](values: M[A])(f: (A) => R)(implicit ctx: Ctx): M[R] 40 | 41 | private implicit def MapExtension[A](values: M[A]) = new { 42 | 43 | def mapValues[R](f: (A) => R)(implicit ctx: Ctx): M[R] = self.mapValues(values)(f) 44 | 45 | } 46 | 47 | def resolveBy(identifier: ID)(implicit ctx: Ctx): M[E] 48 | 49 | def resolveByMulti(identifiers: ID*)(implicit ctx: Ctx): M[Seq[E]] = 50 | traverseWithoutFailures(identifiers)(resolveBy) 51 | 52 | def apply(identifier: ID)(implicit ctx: Ctx): M[E] = resolveBy(identifier) 53 | 54 | def existBy(identifier: ID)(implicit ctx: Ctx): M[Boolean] 55 | 56 | def existByMulti(identifiers: ID*)(implicit ctx: Ctx): M[Boolean] = 57 | traverseWithoutFailures(identifiers)(existBy).mapValues(_.forall(_ == true)) 58 | 59 | def exist(entity: E)(implicit ctx: Ctx): M[Boolean] = 60 | existBy(entity.identifier) 61 | 62 | def existMulti(entities: E*)(implicit ctx: Ctx): M[Boolean] = 63 | existByMulti(entities.map(_.identifier): _*) 64 | 65 | } 66 | 67 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/shared/src/main/scala/org/sisioh/dddbase/lifecycle/memory/mutable/sync/SyncRepositoryOnMemorySupport.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.memory.mutable.sync 17 | 18 | import org.sisioh.dddbase.core.lifecycle.EntityNotFoundException 19 | import org.sisioh.dddbase.core.lifecycle.sync.SyncResultWithEntity 20 | import org.sisioh.dddbase.core.model.{ EntityCloneable, Entity, Identifier } 21 | import scala.collection.Map 22 | import scala.util.{ Success, Failure, Try } 23 | 24 | trait SyncRepositoryOnMemorySupport[ID <: Identifier[_], E <: Entity[ID] with EntityCloneable[ID, E] with Ordered[E]] 25 | extends SyncRepositoryOnMemory[ID, E] { 26 | 27 | protected val _entities: collection.mutable.Map[ID, E] 28 | 29 | override protected def getEntities: Map[ID, E] = _entities 30 | 31 | override def equals(obj: Any) = obj match { 32 | case that: SyncRepositoryOnMemorySupport[_, _] => 33 | this.entities == that.entities 34 | case _ => false 35 | } 36 | 37 | override def hashCode = 31 * entities.## 38 | 39 | override def resolveBy(identifier: ID)(implicit ctx: Ctx) = synchronized { 40 | existBy(identifier).flatMap { 41 | _ => 42 | Try { 43 | entities(identifier).clone 44 | }.recoverWith { 45 | case ex: NoSuchElementException => 46 | Failure(new EntityNotFoundException(Some(s"identifier = $identifier"))) 47 | } 48 | } 49 | } 50 | 51 | override def store(entity: E)(implicit ctx: Ctx): Try[Result] = synchronized { 52 | _entities += (entity.identifier -> entity) 53 | Success(SyncResultWithEntity(this.asInstanceOf[This], entity)) 54 | } 55 | 56 | override def deleteBy(identifier: ID)(implicit ctx: Ctx): Try[Result] = synchronized { 57 | resolveBy(identifier).flatMap { 58 | entity => 59 | _entities -= identifier 60 | Success(SyncResultWithEntity(this.asInstanceOf[This], entity)) 61 | } 62 | } 63 | 64 | def iterator = 65 | entities.map(_._2.clone).toSeq.sorted.iterator 66 | 67 | } 68 | 69 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-memory/shared/src/main/scala/org/sisioh/dddbase/lifecycle/memory/sync/GenericSyncRepositoryOnMemory.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 TRICREO, Inc. (http://tricreo.jp/) 3 | * Copyright 2011 Sisioh Project and others. (http://www.sisioh.org/) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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 writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific language 15 | * governing permissions and limitations under the License. 16 | */ 17 | package org.sisioh.dddbase.lifecycle.memory.sync 18 | 19 | import org.sisioh.dddbase.core.lifecycle.sync.SyncEntityIOContext 20 | import org.sisioh.dddbase.core.model.{Entity, EntityCloneable, Identifier} 21 | 22 | import scala.scalajs.js.annotation.JSExportTopLevel 23 | 24 | //FIXME @JSExportTopLevelのnameを変更する 25 | /** 26 | * 汎用的な非同期型オンメモリ不変リポジトリ。 27 | * 28 | * @tparam ID 識別子の型 29 | * @tparam E エンティティの型 30 | */ 31 | @JSExportTopLevel("SyncGenericSyncRepositoryOnMemoryClass") 32 | class GenericSyncRepositoryOnMemory[ID <: Identifier[_], E <: Entity[ID] with EntityCloneable[ 33 | ID, 34 | E 35 | ] with Ordered[E]](entities: Map[ID, E] = Map.empty[ID, E]) 36 | extends AbstractSyncRepositoryOnMemory[ID, E](entities) { 37 | 38 | type This = GenericSyncRepositoryOnMemory[ID, E] 39 | 40 | override protected def createInstance( 41 | entities: Map[ID, E] 42 | ): GenericSyncRepositoryOnMemory[ID, E]#This = 43 | new GenericSyncRepositoryOnMemory(entities) 44 | } 45 | 46 | /** 47 | * コンパニオンオブジェクト。 48 | */ 49 | @JSExportTopLevel("SyncGenericSyncRepositoryOnMemoryObject") 50 | object GenericSyncRepositoryOnMemory { 51 | 52 | object Implicits { 53 | 54 | implicit val defaultEntityIOContext = SyncEntityIOContext 55 | 56 | } 57 | 58 | /** 59 | * ファクトリメソッド。 60 | * 61 | * @tparam ID 識別子の型 62 | * @tparam E エンティティの型 63 | * @return `GenericSyncRepositoryOnMemory` 64 | */ 65 | def apply[ID <: Identifier[_], E <: Entity[ID] with EntityCloneable[ID, E] with Ordered[ 66 | E 67 | ]](entities: Map[ID, E] = Map.empty[ID, E]) = 68 | new GenericSyncRepositoryOnMemory[ID, E](entities) 69 | 70 | def unapply[ID <: Identifier[_], E <: Entity[ID] with EntityCloneable[ID, E] with Ordered[ 71 | E 72 | ]](repository: GenericSyncRepositoryOnMemory[ID, E]): Option[(Map[ID, E])] = 73 | Some(repository.entities) 74 | 75 | } 76 | -------------------------------------------------------------------------------- /scala-dddbase-core/jvm/src/test/scala/org/sisioh/dddbase/core/model/EntitySpec.scala: -------------------------------------------------------------------------------- 1 | package org.sisioh.dddbase.core.model 2 | 3 | import java.io._ 4 | import java.util.UUID 5 | import org.specs2.mutable._ 6 | 7 | case class TestSerializableId(value: UUID) extends Identifier[UUID] 8 | 9 | // with IdentitySerializable[UUID] 10 | 11 | class TestSerializableEntity(val identifier: TestSerializableId, val name: String) 12 | extends Entity[TestSerializableId] with EntitySerializable[TestSerializableId, TestSerializableEntity] 13 | 14 | class EntitySpec extends Specification { 15 | 16 | class TestEntity(val identifier: Identifier[UUID]) extends Entity[Identifier[UUID]] 17 | 18 | val identifier = Identifier(UUID.randomUUID) 19 | 20 | "Entity's Identity" should { 21 | val entity = new TestEntity(identifier) 22 | "equal the identifier of the paramter for the constructor" in { 23 | entity.identifier must_== identifier 24 | } 25 | } 26 | 27 | "Entity's equals method return value" should { 28 | "is true when each entities have a same identifier" in { 29 | new TestEntity(identifier) must_== new TestEntity(identifier) 30 | } 31 | "is false when each entities have a different identifier" in { 32 | new TestEntity(identifier) must_!= new TestEntity(Identifier(UUID.randomUUID)) 33 | } 34 | } 35 | 36 | "Entity's hashCode method return value" should { 37 | "is same when each entities have a same identifier" in { 38 | new TestEntity(identifier).hashCode must_== new TestEntity(identifier).hashCode 39 | } 40 | "is different when each entities have a different identifier" in { 41 | new TestEntity(identifier).hashCode must_!= new TestEntity(Identifier(UUID.randomUUID)).hashCode 42 | } 43 | } 44 | 45 | "not EntitySerializable entity" should { 46 | "fail to seriarize entity not extends EntitySerializable" in { 47 | val oos = new ObjectOutputStream(new ByteArrayOutputStream) 48 | val entity = new TestEntity(identifier) 49 | oos.writeObject(entity) must throwA[NotSerializableException] 50 | } 51 | } 52 | 53 | "EntitySerializable" should { 54 | "deserialize seriarized entity if entity is serilizable" in { 55 | val os = new ByteArrayOutputStream() 56 | val oos = new ObjectOutputStream(os) 57 | val name = "custom" 58 | val id = TestSerializableId(UUID.randomUUID) 59 | val entity = new TestSerializableEntity(id, name) 60 | oos.writeObject(entity) 61 | val ois = new ObjectInputStream(new ByteArrayInputStream(os.toByteArray)) 62 | val deserializedEntity: TestSerializableEntity = ois.readObject.asInstanceOf[TestSerializableEntity] 63 | entity must_== deserializedEntity 64 | entity.name must_== deserializedEntity.name 65 | } 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /scala-dddbase-lifecycle-repositories-forwarding/shared/src/main/scala/org/sisioh/dddbase/lifecycle/forwarding/sync/wrapped/SyncWrappedAsyncEntityWriter.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Sisioh Project and others. (http://www.sisioh.org/) 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, 13 | * either express or implied. See the License for the specific language 14 | * governing permissions and limitations under the License. 15 | */ 16 | package org.sisioh.dddbase.lifecycle.forwarding.sync.wrapped 17 | 18 | import org.sisioh.dddbase.core.lifecycle.async.AsyncEntityWriter 19 | import org.sisioh.dddbase.core.lifecycle.sync.{ SyncEntityWriter, SyncResultWithEntity } 20 | import org.sisioh.dddbase.core.model.{ Entity, Identifier } 21 | 22 | import scala.concurrent.Await 23 | import scala.concurrent.duration.Duration 24 | import scala.util.Try 25 | 26 | /** 27 | * `AsyncEntityWriter`を`SyncEntityWriter`としてラップするためのデコレータ。 28 | * 29 | * @tparam ID 識別子の型 30 | * @tparam E エンティティの型 31 | */ 32 | trait SyncWrappedAsyncEntityWriter[ID <: Identifier[_], E <: Entity[ID]] 33 | extends SyncEntityWriter[ID, E] with SyncWrappedAsyncEntityIO { 34 | 35 | type Delegate <: AsyncEntityWriter[ID, E] 36 | 37 | /** 38 | * デリゲート。 39 | */ 40 | protected val delegate: Delegate 41 | 42 | protected val timeout: Duration 43 | 44 | protected def createInstance(state: (Delegate#This, Option[E])): (This, Option[E]) 45 | 46 | def store(entity: E)(implicit ctx: Ctx): Try[Result] = Try { 47 | implicit val asyncEntityIOContext = getAsyncEntityIOContext(ctx) 48 | val resultWithEntity = Await.result(delegate.store(entity), timeout) 49 | val _entity = Some(resultWithEntity.entity.asInstanceOf[E]) 50 | val result = createInstance((resultWithEntity.result.asInstanceOf[Delegate#This], _entity)) 51 | SyncResultWithEntity[This, ID, E](result._1.asInstanceOf[This], result._2.get) 52 | } 53 | 54 | def deleteBy(identifier: ID)(implicit ctx: Ctx): Try[Result] = Try { 55 | implicit val asyncEntityIOContext = getAsyncEntityIOContext(ctx) 56 | val resultWithEntity = Await.result(delegate.deleteBy(identifier), timeout) 57 | val _entity = Some(resultWithEntity.entity.asInstanceOf[E]) 58 | val result = createInstance((resultWithEntity.result.asInstanceOf[Delegate#This], _entity)) 59 | SyncResultWithEntity[This, ID, E](result._1.asInstanceOf[This], result._2.get) 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /scala-dddbase-core/shared/src/main/scala/org/sisioh/dddbase/core/lifecycle/ValueObjectBuilder.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 TRICREO, Inc. (http://tricreo.jp/) 3 | * Copyright 2011 Sisioh Project and others. (http://www.sisioh.org/) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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 writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 14 | * either express or implied. See the License for the specific language 15 | * governing permissions and limitations under the License. 16 | */ 17 | package org.sisioh.dddbase.core.lifecycle 18 | 19 | import collection.mutable.ListBuffer 20 | 21 | /** 22 | * 値オブジェクトのインスタンスを生成するビルダーのトレイト。 23 | * 24 | * @tparam T ビルド対象のインスタンスの型 25 | * @tparam S このビルダークラスの型 26 | * @author j5ik2o 27 | */ 28 | trait ValueObjectBuilder[T, S <: ValueObjectBuilder[T, S]] { 29 | type Configure = (S) => Unit 30 | 31 | /** 32 | * ビルダの設定に基づいて値オブジェクトの新しいインスタンスを生成する。 33 | * 34 | * @return 値オブジェクトの新しいインスタンス 35 | */ 36 | def build: T = { 37 | configurators.foreach(_(getThis)) 38 | createValueObject 39 | } 40 | 41 | /** 42 | * このビルダークラスのインスタンスを返す。 43 | * 44 | * @return このビルダークラスのインスタンス。 45 | */ 46 | protected def getThis: S 47 | 48 | /** 49 | * ビルダの設定に基づき、引数の値オブジェクトの内容を変更した新しいインスタンスを生成する。 50 | * 51 | * @param vo 状態を引用する値オブジェクト 52 | * @return voの内容に対して、このビルダの設定を上書きした値オブジェクトの新しいインスタンス 53 | */ 54 | def build(vo: T): T = { 55 | val builder = newInstance 56 | apply(vo, builder) 57 | configurators.foreach(builder.addConfigurator) 58 | builder.build 59 | } 60 | 61 | /** 62 | * ビルダを設定する関数を追加する。 63 | * 64 | * @param configure `Configure` 65 | */ 66 | protected def addConfigurator(configure: Configure): Unit = { 67 | configurators += configure 68 | } 69 | 70 | /** 71 | * このビルダークラスの新しいインスタンスを返す。 72 | * 73 | * @return このビルダークラスの新しいインスタンス。 74 | */ 75 | protected def newInstance: S 76 | 77 | /** 78 | * 引数のビルダに対して、引数の値オブジェクトの内容を適用する。 79 | * 80 | * @param vo 状態を引用する値オブジェクト 81 | * @param builder ビルダ 82 | */ 83 | protected def apply(vo: T, builder: S): Unit 84 | 85 | /** 86 | * ビルダの設定に基づいて値オブジェクトの新しいインスタンスを生成する。 87 | * 88 | *`build` 内でこのビルダに追加された `Configure` を全て実行した後に、このメソッドが呼ばれる。
89 | * その為、このビルダに対する変更を行うロジックはこのメソッド内に記述せず、目的となる値オブジェクトを生成し
90 | * 返すロジックを記述することが望まれる。