├── .gitignore
├── README.md
├── beans
├── pom.xml
└── src
│ ├── main
│ └── kotlin
│ │ └── org
│ │ └── kotlinprimavera
│ │ └── beans
│ │ ├── annotation
│ │ └── namespace.kt
│ │ ├── factory
│ │ ├── annotation
│ │ │ └── namespace.kt
│ │ ├── namespace.kt
│ │ └── support
│ │ │ └── namespace.kt
│ │ └── namespace.kt
│ └── test
│ └── kotlin
│ └── org
│ └── kotlinprimavera
│ └── beans
│ ├── BeanUtilsTest.kt
│ └── factory
│ └── BeanFactoryTest.kt
├── context
├── pom.xml
└── src
│ └── main
│ └── kotlin
│ └── org
│ └── kotlinprimavera
│ └── ui
│ └── namespace.kt
├── core
├── pom.xml
└── src
│ ├── main
│ └── kotlin
│ │ └── org
│ │ └── kotlinprimavera
│ │ ├── core
│ │ ├── env
│ │ │ └── namespace.kt
│ │ └── style
│ │ │ ├── ToStringCreatorAppendTokens.kt
│ │ │ └── namespace.kt
│ │ └── util
│ │ └── namespace.kt
│ └── test
│ └── kotlin
│ └── org
│ └── kotlinprimavera
│ ├── core
│ └── env
│ │ └── PropertyResolverTests.kt
│ └── util
│ └── SysPropertyTest.kt
├── jdbc
├── pom.xml
└── src
│ ├── main
│ └── kotlin
│ │ └── org
│ │ └── kotlinprimavera
│ │ └── jdbc
│ │ └── core
│ │ ├── AbstractBlobArgumentSetter.kt
│ │ ├── ArgumentSetter.kt
│ │ ├── ArgumentSetter2.kt
│ │ ├── ArgumentWithLengthSetter.kt
│ │ ├── BlobArgumentSetter.kt
│ │ ├── ClobArgumentSetter.kt
│ │ ├── CombinedArgumentSetter.kt
│ │ ├── DefaultArgumentSetter.kt
│ │ ├── GetFieldsToken.kt
│ │ ├── NClobArgumentSetter.kt
│ │ ├── ObjectArgumentSetter.kt
│ │ ├── PreparedStatementArgumentsSetter.kt
│ │ ├── ResultSetGetFieldTokens.kt
│ │ ├── config
│ │ ├── EmbeddedDatabaseTag.kt
│ │ ├── ExecutionValue.kt
│ │ ├── ScriptTag.kt
│ │ └── namespace.kt
│ │ ├── namedparam
│ │ └── namespace.kt
│ │ └── namespace.kt
│ └── test
│ ├── kotlin
│ └── org
│ │ └── kotlinprimavera
│ │ └── jdbc
│ │ ├── TestBean.kt
│ │ ├── config
│ │ └── DataTestConfig.kt
│ │ └── core
│ │ ├── JdbcOperationsTest.kt
│ │ ├── JdbcTestBase.kt
│ │ ├── PerformanceTest.kt
│ │ └── namedparam
│ │ └── NamedParameterJdbcOperationsTest.kt
│ └── resources
│ ├── logback.xml
│ ├── org
│ └── kotlinprimavera
│ │ └── jdbc
│ │ ├── core
│ │ ├── JdbcOperationsTest-context.xml
│ │ ├── PerformanceTest-context.xml
│ │ └── namedparam
│ │ │ └── NamedParameterJdbcOperationsTest-context.xml
│ │ └── kp-jdbc-test-base.xml
│ ├── schema-hsql.sql
│ ├── test-data.sql
│ └── test-performance.sql
├── pom.xml
├── security
├── pom.xml
└── src
│ └── main
│ └── kotlin
│ └── org
│ └── kotlinprimavera
│ └── security
│ └── config
│ └── annnotation
│ └── web
│ └── builders
│ └── namespace.kt
├── tx
├── pom.xml
└── src
│ └── test
│ ├── kotlin
│ └── org
│ │ └── kotlinprimavera
│ │ └── transaction
│ │ └── support
│ │ └── TransactionOperationsTest.kt
│ └── resources
│ ├── logback.xml
│ ├── org
│ └── kotlinprimavera
│ │ └── transaction
│ │ └── support
│ │ └── TransactionOperationsTest-context.xml
│ ├── schema-hsql.sql
│ └── test-data.sql
└── webmvc
├── pom.xml
└── src
└── main
└── kotlin
└── org
└── kotlinprimavera
└── web
└── servlet
└── namespace.kt
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/*
2 | *.iml
3 | */target/*
4 | target/*
5 | *.kte
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Documentation
2 |
3 | Read the [Wiki](https://github.com/MarioAriasC/KotlinPrimavera/wiki)
--------------------------------------------------------------------------------
/beans/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 | 4.0.0
22 |
23 | org.kotlinprimavera
24 | parent
25 | 0.5
26 |
27 | beans
28 | KotlinPrimavera Beans Module
29 | jar
30 | 0.5
31 |
32 | src/main/kotlin
33 | src/test/kotlin
34 |
35 |
36 | kotlin-maven-plugin
37 | org.jetbrains.kotlin
38 | ${kotlin.version}
39 |
40 |
41 | compile
42 | compile
43 |
44 | compile
45 |
46 |
47 |
48 |
49 | test-compile
50 | test-compile
51 |
52 | test-compile
53 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/beans/src/main/kotlin/org/kotlinprimavera/beans/annotation/namespace.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.beans.annotation
18 |
19 | import org.springframework.beans.annotation.AnnotationBeanUtils
20 | import org.springframework.util.StringValueResolver
21 |
22 | /**
23 | * Created by IntelliJ IDEA.
24 | * @author Mario Arias
25 | * Date: 13/06/15
26 | * Time: 2:23 PM
27 | */
28 |
29 | fun Annotation.copyPropertiesToBean(bean: Any, vararg excludedProperties: String) {
30 | return AnnotationBeanUtils.copyPropertiesToBean(this, bean, *excludedProperties)
31 | }
32 |
33 |
34 | fun Annotation.copyPropertiesToBean(bean: Any, valueResolver: StringValueResolver, vararg excludedProperties: String) {
35 | return AnnotationBeanUtils.copyPropertiesToBean(this, bean, valueResolver, *excludedProperties)
36 | }
--------------------------------------------------------------------------------
/beans/src/main/kotlin/org/kotlinprimavera/beans/factory/annotation/namespace.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.beans.factory.annotation
18 |
19 | import org.springframework.beans.factory.BeanFactory
20 | import org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils
21 |
22 | /**
23 | * Created by IntelliJ IDEA.
24 | * @author Mario Arias
25 | * Date: 13/06/15
26 | * Time: 2:41 PM
27 | */
28 |
29 |
30 | fun BeanFactory.qualifiedBeanOfType(beanType: Class, qualifier: String): T {
31 | return BeanFactoryAnnotationUtils.qualifiedBeanOfType(this, beanType, qualifier)
32 | }
33 |
--------------------------------------------------------------------------------
/beans/src/main/kotlin/org/kotlinprimavera/beans/factory/namespace.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.beans.factory
18 |
19 | import org.springframework.beans.BeansException
20 | import org.springframework.beans.factory.BeanFactory
21 | import org.springframework.beans.factory.BeanFactoryUtils
22 | import org.springframework.beans.factory.ListableBeanFactory
23 |
24 | /**
25 | * Util function extension to add array like access to [org.springframework.beans.factory.BeanFactory]
26 | */
27 | operator fun BeanFactory.get(name: String): Any {
28 | return getBean(name)
29 | }
30 |
31 | /**
32 | * Util function extension to add array like access to [org.springframework.beans.factory.BeanFactory]
33 | */
34 | operator fun BeanFactory.get(requiredType: Class): T {
35 | return getBean(requiredType)
36 | }
37 |
38 | /**
39 | * Util function extension to add array like access to [org.springframework.beans.factory.BeanFactory]
40 | */
41 | operator fun BeanFactory.get(name: String, requiredType: Class): T {
42 | return getBean(name, requiredType)
43 | }
44 |
45 | /**
46 | * Util function extension to add array like access to [org.springframework.beans.factory.BeanFactory]
47 | */
48 | operator fun BeanFactory.get(name: String, vararg args: Any): Any {
49 | return getBean(name, *args)
50 | }
51 |
52 | fun String.isFactoryDereference(): Boolean {
53 | return BeanFactoryUtils.isFactoryDereference(this)
54 | }
55 |
56 |
57 | fun String.transformedBeanName(): String {
58 | return BeanFactoryUtils.transformedBeanName(this)
59 | }
60 |
61 |
62 | fun String.isGeneratedBeanName(): Boolean {
63 | return BeanFactoryUtils.isGeneratedBeanName(this)
64 | }
65 |
66 |
67 | fun String.originalBeanName(): String {
68 | return BeanFactoryUtils.originalBeanName(this)
69 | }
70 |
71 |
72 | fun ListableBeanFactory.countBeansIncludingAncestors(): Int {
73 | return BeanFactoryUtils.countBeansIncludingAncestors(this)
74 | }
75 |
76 |
77 | fun ListableBeanFactory.beanNamesIncludingAncestors(): Array {
78 | return BeanFactoryUtils.beanNamesIncludingAncestors(this)
79 | }
80 |
81 |
82 | fun ListableBeanFactory.beanNamesForTypeIncludingAncestors(type: Class<*>, includeNonSingletons: Boolean, allowEagerInt: Boolean): Array {
83 | return BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this, type, includeNonSingletons, allowEagerInt)
84 | }
85 |
86 |
87 | fun ListableBeanFactory.beanNamesForTypeIncludingAncestors(type: Class<*>): Array {
88 | return BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this, type)
89 | }
90 |
91 |
92 | @Throws(BeansException::class) fun ListableBeanFactory.beansOfTypeIncludingAncestors(type: Class, includeNonSingletons: Boolean, allowEagerInt: Boolean): Map {
93 | return BeanFactoryUtils.beansOfTypeIncludingAncestors(this, type, includeNonSingletons, allowEagerInt)
94 | }
95 |
96 |
97 | @Throws(BeansException::class) fun ListableBeanFactory.beansOfTypeIncludingAncestors(type: Class): Map {
98 | return BeanFactoryUtils.beansOfTypeIncludingAncestors(this, type)
99 | }
100 |
101 |
102 | @Throws(BeansException::class) fun ListableBeanFactory.beanOfTypeIncludingAncestors(type: Class, includeNonSingletons: Boolean, allowEagerInt: Boolean): T {
103 | return BeanFactoryUtils.beanOfTypeIncludingAncestors(this, type, includeNonSingletons, allowEagerInt)
104 | }
105 |
106 |
107 | @Throws(BeansException::class) fun ListableBeanFactory.beanOfTypeIncludingAncestors(type: Class): T {
108 | return BeanFactoryUtils.beanOfTypeIncludingAncestors(this, type)
109 | }
110 |
111 |
112 | @Throws(BeansException::class) fun ListableBeanFactory.beanOfType(type: Class, includeNonSingletons: Boolean, allowEagerInt: Boolean): T {
113 | return BeanFactoryUtils.beanOfType(this, type, includeNonSingletons, allowEagerInt)
114 | }
115 |
116 |
117 | @Throws(BeansException::class) fun ListableBeanFactory.beanOfType(type: Class): T {
118 | return BeanFactoryUtils.beanOfType(this, type)
119 | }
120 |
--------------------------------------------------------------------------------
/beans/src/main/kotlin/org/kotlinprimavera/beans/factory/support/namespace.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.beans.factory.support
18 |
19 | import org.springframework.beans.factory.BeanDefinitionStoreException
20 | import org.springframework.beans.factory.config.BeanDefinition
21 | import org.springframework.beans.factory.config.BeanDefinitionHolder
22 | import org.springframework.beans.factory.support.AbstractBeanDefinition
23 | import org.springframework.beans.factory.support.BeanDefinitionReaderUtils
24 | import org.springframework.beans.factory.support.BeanDefinitionRegistry
25 |
26 | /**
27 | * Created by IntelliJ IDEA.
28 | * @author Mario Arias
29 | * Date: 13/06/15
30 | * Time: 2:29 PM
31 | */
32 |
33 | @Throws(ClassNotFoundException::class) fun String.createBeanDefinition(className: String, classLoader: ClassLoader): AbstractBeanDefinition {
34 | return BeanDefinitionReaderUtils.createBeanDefinition(this, className, classLoader)
35 | }
36 |
37 |
38 | @Throws(BeanDefinitionStoreException::class) fun BeanDefinition.generateBeanName(registry: BeanDefinitionRegistry): String {
39 | return BeanDefinitionReaderUtils.generateBeanName(this, registry)
40 | }
41 |
42 |
43 | @Throws(BeanDefinitionStoreException::class) fun BeanDefinition.generateBeanName(registry: BeanDefinitionRegistry, isInnerBean: Boolean): String {
44 | return BeanDefinitionReaderUtils.generateBeanName(this, registry, isInnerBean)
45 | }
46 |
47 |
48 | @Throws(BeanDefinitionStoreException::class) fun BeanDefinitionHolder.registerBeanDefinition(registry: BeanDefinitionRegistry) {
49 | return BeanDefinitionReaderUtils.registerBeanDefinition(this, registry)
50 | }
51 |
52 |
53 | @Throws(BeanDefinitionStoreException::class) fun AbstractBeanDefinition.registerWithGeneratedName(registry: BeanDefinitionRegistry): String {
54 | return BeanDefinitionReaderUtils.registerWithGeneratedName(this, registry)
55 | }
56 |
--------------------------------------------------------------------------------
/beans/src/main/kotlin/org/kotlinprimavera/beans/namespace.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.beans
18 |
19 | import org.springframework.beans.BeanInstantiationException
20 | import org.springframework.beans.BeanUtils
21 | import org.springframework.beans.BeansException
22 | import org.springframework.beans.PropertyAccessorUtils
23 | import org.springframework.core.MethodParameter
24 | import java.beans.PropertyDescriptor
25 | import java.beans.PropertyEditor
26 | import java.lang.reflect.Constructor
27 | import java.lang.reflect.Method
28 |
29 | /**
30 | * Created by IntelliJ IDEA.
31 | * @author Mario Arias
32 | * Date: 9/06/15
33 | * Time: 11:37 PM
34 | */
35 |
36 |
37 | /**
38 | * For initialize a var with a Not nullable type, specially util for ```@Autowired``` vars
39 | */
40 | fun uninitialized(): T = null as T
41 |
42 | @Throws(BeanInstantiationException::class) fun Class.instantiate(): T {
43 | return BeanUtils.instantiate(this)
44 | }
45 |
46 |
47 | @Throws(BeanInstantiationException::class) fun Class.instantiateClass(): T {
48 | return BeanUtils.instantiateClass(this)
49 | }
50 |
51 |
52 | @Throws(BeanInstantiationException::class) fun Constructor.instantiateClass(vararg args: Any): T {
53 | return BeanUtils.instantiateClass(this, *args)
54 | }
55 |
56 |
57 | @Throws(BeanInstantiationException::class) fun Class<*>.instantiateClass(assignableTo: Class): T {
58 | return BeanUtils.instantiateClass(this, assignableTo)
59 | }
60 |
61 |
62 | fun Class<*>.findMethod(methodName: String, vararg paramTypes: Class<*>): Method {
63 | return BeanUtils.findMethod(this, methodName, *paramTypes)
64 | }
65 |
66 |
67 | fun Class<*>.findDeclaredMethod(methodName: String, vararg paramTypes: Class<*>): Method {
68 | return BeanUtils.findDeclaredMethod(this, methodName, *paramTypes)
69 | }
70 |
71 |
72 | @Throws(IllegalArgumentException::class) fun Class<*>.findMethodWithMinimalParameters(methodName: String): Method {
73 | return BeanUtils.findMethodWithMinimalParameters(this, methodName)
74 | }
75 |
76 |
77 | @Throws(IllegalArgumentException::class) fun Array.findMethodWithMinimalParameters(methodName: String): Method {
78 | return BeanUtils.findMethodWithMinimalParameters(this, methodName)
79 | }
80 |
81 |
82 | @Throws(IllegalArgumentException::class) fun Class<*>.findDeclaredMethodWithMinimalParameters(methodName: String): Method {
83 | return BeanUtils.findDeclaredMethodWithMinimalParameters(this, methodName)
84 | }
85 |
86 |
87 | fun String.resolveSignature(clazz: Class<*>): Method {
88 | return BeanUtils.resolveSignature(this, clazz)
89 | }
90 |
91 |
92 | @Throws(BeansException::class) fun Class<*>.getPropertyDescriptors(): Array {
93 | return BeanUtils.getPropertyDescriptors(this)
94 | }
95 |
96 |
97 | @Throws(BeansException::class) fun Class<*>.getPropertyDescriptor(propertyName: String): PropertyDescriptor {
98 | return BeanUtils.getPropertyDescriptor(this, propertyName)
99 | }
100 |
101 |
102 | @Throws(BeansException::class) fun Method.findPropertyForMethod(): PropertyDescriptor {
103 | return BeanUtils.findPropertyForMethod(this)
104 | }
105 |
106 |
107 | @Throws(BeansException::class) fun Method.findPropertyForMethod(clazz: Class<*>): PropertyDescriptor {
108 | return BeanUtils.findPropertyForMethod(this, clazz)
109 | }
110 |
111 |
112 | fun Class<*>.findEditorByConvention(): PropertyEditor {
113 | return BeanUtils.findEditorByConvention(this)
114 | }
115 |
116 |
117 | fun String.findPropertyType(vararg beanClasses: Class<*>): Class<*> {
118 | return BeanUtils.findPropertyType(this, *beanClasses)
119 | }
120 |
121 |
122 | fun PropertyDescriptor.getWriteMethodParameter(): MethodParameter {
123 | return BeanUtils.getWriteMethodParameter(this)
124 | }
125 |
126 |
127 | fun Class<*>.isSimpleProperty(): Boolean {
128 | return BeanUtils.isSimpleProperty(this)
129 | }
130 |
131 |
132 | fun Class<*>.isSimpleValueType(): Boolean {
133 | return BeanUtils.isSimpleValueType(this)
134 | }
135 |
136 |
137 | @Throws(BeansException::class) fun Any.copyProperties(target: Any) {
138 | return BeanUtils.copyProperties(this, target)
139 | }
140 |
141 | @Throws(BeansException::class) fun Any.copyProperties(target: Any, vararg ignoredProperties: String) {
142 | return BeanUtils.copyProperties(this, target, *ignoredProperties)
143 | }
144 |
145 |
146 | @Throws(BeansException::class) fun Any.copyProperties(target: Any, ignoredProperties: Class<*>) {
147 | return BeanUtils.copyProperties(this, target, ignoredProperties)
148 | }
149 |
150 | fun String.getPropertyName(): String {
151 | return PropertyAccessorUtils.getPropertyName(this)
152 | }
153 |
154 |
155 | fun String.isNestedOrIndexedProperty(): Boolean {
156 | return PropertyAccessorUtils.isNestedOrIndexedProperty(this)
157 | }
158 |
159 |
160 | fun String.getFirstNestedPropertySeparatorIndex(): Int {
161 | return PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(this)
162 | }
163 |
164 |
165 | fun String.getLastNestedPropertySeparatorIndex(): Int {
166 | return PropertyAccessorUtils.getLastNestedPropertySeparatorIndex(this)
167 | }
168 |
169 | fun String.matchesProperty(propertyPath: String): Boolean {
170 | return PropertyAccessorUtils.matchesProperty(this, propertyPath)
171 | }
172 |
173 |
174 | fun String.canonicalPropertyName(): String {
175 | return PropertyAccessorUtils.canonicalPropertyName(this)
176 | }
177 |
178 |
179 | fun Array.canonicalPropertyNames(): Array {
180 | return PropertyAccessorUtils.canonicalPropertyNames(this)
181 | }
--------------------------------------------------------------------------------
/beans/src/test/kotlin/org/kotlinprimavera/beans/BeanUtilsTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.beans
18 |
19 | import org.springframework.beans.BeanInstantiationException
20 | import org.testng.Assert.*
21 | import org.testng.annotations.Test
22 |
23 | /**
24 | * Created by IntelliJ IDEA.
25 | * @author Mario Arias
26 | * Date: 9/06/15
27 | * Time: 11:59 PM
28 | */
29 | public class BeanUtilsTest {
30 |
31 | @Test fun testInstantiate() {
32 | //No Parameters
33 | assertTrue(NoParameters::class.java.instantiate() is NoParameters)
34 |
35 | //Default parameter
36 | val defaultParameter = DefaultParameter::class.java.instantiate()
37 | assertTrue(defaultParameter is DefaultParameter)
38 | assertEquals(defaultParameter.name, "foo")
39 |
40 | //With parameters, will fail
41 | try {
42 | WithParameter::class.java.instantiate()
43 | fail("WithParameter was wrongly instantiated")
44 | } catch(e: BeanInstantiationException) {
45 | assertTrue(e.message!!.startsWith("Failed to instantiate [org.kotlinprimavera.beans.WithParameter]"))
46 | }
47 |
48 | }
49 |
50 | @Test fun testInstantiateClass() {
51 | //No parameters
52 | assertTrue(NoParameters::class.java.instantiateClass() is NoParameters)
53 |
54 | //Default parameter
55 | val defaultParameter = DefaultParameter::class.java.instantiateClass()
56 | assertTrue(defaultParameter is DefaultParameter)
57 | assertEquals(defaultParameter.name, "foo")
58 |
59 | //With parameters, will fail
60 | try {
61 | WithParameter::class.java.instantiateClass()
62 | fail("WithParameter was wrongly instantiated")
63 | } catch(e: BeanInstantiationException) {
64 | assertTrue(e.message!!.startsWith("Failed to instantiate [org.kotlinprimavera.beans.WithParameter]"))
65 | }
66 |
67 | //Assignable type
68 | assertTrue(DefaultParameter::class.java.instantiateClass(TestType::class.java) is TestType)
69 |
70 | //Not assignable, will fail
71 | try {
72 | NoParameters::class.java.instantiateClass(TestType::class.java)
73 | fail("NoParameters was wrongly instantiated")
74 | } catch(e: IllegalArgumentException) {
75 | assertEquals(e.message, "class org.kotlinprimavera.beans.NoParameters is not assignable to interface org.kotlinprimavera.beans.TestType")
76 | }
77 |
78 | //Constructors
79 | assertTrue(NoParameters::class.java.getDeclaredConstructor().instantiateClass() is NoParameters)
80 |
81 | //With Parameters
82 | assertEquals(WithParameter::class.java.getDeclaredConstructor(String::class.java).instantiateClass("baz").name, "baz")
83 | assertEquals(DefaultParameter::class.java.getDeclaredConstructor(String::class.java).instantiateClass("baz").name, "baz")
84 |
85 |
86 | //Default Parameter
87 | assertEquals(DefaultParameter::class.java.getDeclaredConstructor().instantiateClass().name, "foo")
88 |
89 | try {
90 | WithParameter::class.java.getDeclaredConstructor().instantiateClass()
91 | fail("WithParameter was wrongly instantiated")
92 | } catch(e: NoSuchMethodException) {
93 | assertEquals(e.message, "org.kotlinprimavera.beans.WithParameter.()")
94 | }
95 |
96 | try {
97 | DefaultParameter::class.java.getDeclaredConstructor(String::class.java).instantiateClass()
98 | fail("DefaultParameter wrongly instantiated")
99 | } catch(e: BeanInstantiationException) {
100 | assertTrue(e.message!!.startsWith("Failed to instantiate [org.kotlinprimavera.beans.DefaultParameter]: Illegal arguments for constructor"))
101 | }
102 |
103 |
104 | }
105 |
106 | @Test fun testFindMethod() {
107 | val dp = DefaultParameter()
108 | //calling ```invoke``` method
109 | assertEquals(dp.javaClass.findMethod("component1")(dp), "foo")
110 | try {
111 | dp.javaClass.findMethod("component2")(dp)
112 | fail("Method component2 doesn't exist")
113 | } catch(e: IllegalStateException) {
114 |
115 | }
116 | }
117 |
118 | @Test fun testFindDeclaredMethod() {
119 | val dp = DefaultParameter()
120 | //calling ```invoke``` method
121 | assertEquals(dp.javaClass.findDeclaredMethod("component1")(dp), "foo")
122 | try {
123 | dp.javaClass.findDeclaredMethod("component2")(dp)
124 | fail("Method component2 doesn't exist")
125 | } catch(e: IllegalStateException) {
126 |
127 | }
128 | }
129 |
130 | }
131 |
132 |
133 | interface TestType
134 | class NoParameters
135 | data class DefaultParameter(val name: String = "foo") : TestType
136 | data class WithParameter(val name: String)
--------------------------------------------------------------------------------
/beans/src/test/kotlin/org/kotlinprimavera/beans/factory/BeanFactoryTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.beans.factory
18 |
19 | import org.springframework.beans.BeansException
20 | import org.springframework.context.annotation.AnnotationConfigApplicationContext
21 | import org.springframework.context.annotation.Bean
22 | import org.springframework.context.annotation.Configuration
23 | import org.springframework.context.annotation.Scope
24 | import org.testng.Assert.*
25 | import org.testng.annotations.Test
26 |
27 |
28 | class BeanFactoryTest {
29 |
30 | private val context = AnnotationConfigApplicationContext(TestConfig::class.java)
31 |
32 | @Test
33 | fun testGetA() {
34 | val a = context["a"]
35 | assertTrue(a is A)
36 | }
37 |
38 | @Test
39 | fun testGetB() {
40 | try {
41 | context[B::class.java]
42 | } catch(e: BeansException) {
43 | fail()
44 | }
45 | }
46 |
47 | @Test
48 | fun testGetC() {
49 | val c1 = context["c1", C::class.java]
50 | assertEquals(c1.value, 1)
51 | }
52 |
53 | @Test
54 | fun testGetD() {
55 | val dAsAny = context["d", 42, "kotlin"]
56 | assertTrue(dAsAny is D)
57 | val (num, str) = dAsAny as D
58 | assertEquals(num, 42)
59 | assertEquals(str, "kotlin")
60 |
61 | }
62 |
63 | }
64 |
65 | class A {
66 | }
67 |
68 | class B {
69 | }
70 |
71 | class C(val value: Int) {
72 | }
73 |
74 | data class D(val num: Int, val str: String) {
75 | }
76 |
77 |
78 | @Configuration
79 | open class TestConfig {
80 |
81 | @Bean
82 | open fun a(): A {
83 | return A()
84 | }
85 |
86 | @Bean
87 | open fun b(): B {
88 | return B()
89 | }
90 |
91 | @Bean
92 | open fun c1(): C {
93 | return C(1)
94 | }
95 |
96 | @Bean
97 | open fun c2(): C {
98 | return C(2)
99 | }
100 |
101 | @Bean @Scope("prototype")
102 | open fun d(num: Int, str: String): D {
103 | return D(num, str)
104 | }
105 | }
--------------------------------------------------------------------------------
/context/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 | 4.0.0
22 |
23 | org.kotlinprimavera
24 | parent
25 | 0.5
26 |
27 | context
28 | KotlinPrimavera Context Module
29 | jar
30 | 0.5
31 |
32 | src/main/kotlin
33 | src/test/kotlin
34 |
35 |
36 | kotlin-maven-plugin
37 | org.jetbrains.kotlin
38 | ${kotlin.version}
39 |
40 |
41 |
42 | compile
43 | compile
44 |
45 | compile
46 |
47 |
48 |
49 |
50 | test-compile
51 | test-compile
52 |
53 | test-compile
54 |
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/context/src/main/kotlin/org/kotlinprimavera/ui/namespace.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.ui
18 |
19 | import org.springframework.ui.Model
20 | import org.springframework.ui.ModelMap
21 |
22 | /**
23 | * Created by IntelliJ IDEA.
24 | * @author Mario Arias
25 | * Date: 7/09/13
26 | * Time: 1:08
27 | */
28 |
29 | operator fun Model.set(attributeName: String, attributeValue: Any?) {
30 | this.addAttribute(attributeName, attributeValue)
31 | }
32 |
33 | fun Model.addAllAttributes(vararg attributes: Pair): Model {
34 | this.addAllAttributes(mapOf(*attributes))
35 | return this
36 | }
37 |
38 | fun Model.mergeAttributes(vararg attributes: Pair): Model {
39 | this.mergeAttributes(mapOf(*attributes))
40 | return this
41 | }
42 |
43 | operator fun ModelMap.set(attributeName: String, attributeValue: Any?) {
44 | this.addAttribute(attributeName, attributeValue)
45 | }
46 |
47 | fun ModelMap.addAllAttributes(vararg attributes: Pair): ModelMap {
48 | this.addAllAttributes(mapOf(*attributes))
49 | return this
50 | }
51 |
52 | fun ModelMap.mergeAttributes(vararg attributes: Pair): ModelMap {
53 | this.mergeAttributes(mapOf(*attributes))
54 | return this
55 | }
56 |
--------------------------------------------------------------------------------
/core/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 | 4.0.0
22 |
23 | org.kotlinprimavera
24 | parent
25 | 0.5
26 |
27 | core
28 | KotlinPrimavera Core Module
29 | jar
30 | 0.5
31 |
32 |
33 |
34 |
35 | src/main/kotlin
36 | src/test/kotlin
37 |
38 |
39 | kotlin-maven-plugin
40 | org.jetbrains.kotlin
41 | ${kotlin.version}
42 |
43 |
44 | compile
45 | compile
46 |
47 | compile
48 |
49 |
50 |
51 |
52 | test-compile
53 | test-compile
54 |
55 | test-compile
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/org/kotlinprimavera/core/env/namespace.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.core.env
18 |
19 | import org.springframework.core.env.PropertyResolver
20 |
21 | /**
22 | * Created by IntelliJ IDEA.
23 | * @author Mario Arias
24 | * Date: 22/07/14
25 | * Time: 0:21
26 | */
27 |
28 | operator fun PropertyResolver.get(key: String): String? {
29 | return this.getProperty(key)
30 | }
31 |
32 | operator fun PropertyResolver.get(key: String, defaultValue: String): String {
33 | return this.getProperty(key, defaultValue)
34 | }
35 |
36 | operator @Suppress("BASE_WITH_NULLABLE_UPPER_BOUND")
37 | fun PropertyResolver.get(key: String, targetType: Class): T? {
38 | return this.getProperty(key, targetType)
39 | }
40 |
41 | operator fun PropertyResolver.get(key: String, targetType: Class, defaultValue: T): T {
42 | return this.getProperty(key, targetType, defaultValue)
43 | }
44 |
45 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/org/kotlinprimavera/core/style/ToStringCreatorAppendTokens.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.core.style
18 |
19 | import org.springframework.core.style.ToStringCreator
20 |
21 | /**
22 | * Created by IntelliJ IDEA.
23 | * @author Mario Arias
24 | * Date: 29/08/13
25 | * Time: 21:09
26 | */
27 | class ToStringCreatorAppendTokens(private val toStringCreator: ToStringCreator) {
28 |
29 | operator fun set(fieldName: String, value: Byte?) {
30 | toStringCreator.append(fieldName, value)
31 | }
32 |
33 | operator fun set(fieldName: String, value: Short?) {
34 | toStringCreator.append(fieldName, value)
35 | }
36 |
37 | operator fun set(fieldName: String, value: Int?) {
38 | toStringCreator.append(fieldName, value)
39 | }
40 |
41 | operator fun set(fieldName: String, value: Long?) {
42 | toStringCreator.append(fieldName, value)
43 | }
44 |
45 | operator fun set(fieldName: String, value: Float?) {
46 | toStringCreator.append(fieldName, value)
47 | }
48 |
49 | operator fun set(fieldName: String, value: Double?) {
50 | toStringCreator.append(fieldName, value)
51 | }
52 |
53 | operator fun set(fieldName: String, value: Boolean?) {
54 | toStringCreator.append(fieldName, value)
55 | }
56 |
57 | operator fun set(fieldName: String, value: Any?) {
58 | toStringCreator.append(fieldName, value)
59 | }
60 | }
--------------------------------------------------------------------------------
/core/src/main/kotlin/org/kotlinprimavera/core/style/namespace.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.core.style
18 |
19 | import org.springframework.core.style.ToStringCreator
20 | import org.springframework.core.style.ToStringStyler
21 | import org.springframework.core.style.ValueStyler
22 |
23 | /**
24 | * Created by IntelliJ IDEA.
25 | * @author Mario Arias
26 | * Date: 29/08/13
27 | * Time: 21:21
28 | */
29 |
30 | val ToStringCreator.append: ToStringCreatorAppendTokens
31 | get() {
32 | return ToStringCreatorAppendTokens(this)
33 | }
34 |
35 | fun ToStringCreator(obj: Any, body: ToStringCreator.() -> Unit): ToStringCreator {
36 | val creator = ToStringCreator(obj)
37 | creator.body()
38 | return creator
39 | }
40 |
41 | fun ToStringCreator(obj: Any, styler: ValueStyler, body: ToStringCreator.() -> Unit): ToStringCreator {
42 | val creator = ToStringCreator(obj, styler)
43 | creator.body()
44 | return creator
45 | }
46 |
47 | fun ToStringCreator(obj: Any, styler: ToStringStyler, body: ToStringCreator.() -> Unit): ToStringCreator {
48 | val creator = ToStringCreator(obj, styler)
49 | creator.body()
50 | return creator
51 | }
52 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/org/kotlinprimavera/util/namespace.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.util
18 |
19 | import org.funktionale.utils.GetterSetterOperation
20 | import org.springframework.util.StopWatch
21 |
22 | fun stopWatch(id: String = "", body: StopWatch.() -> Unit): StopWatch {
23 | val watch = StopWatch(id)
24 | watch.body()
25 | return watch
26 | }
27 |
28 | /*fun StopWatch.invoke(body:StopWatch.() -> Unit): StopWatch {
29 | this.body()
30 | return this
31 | }*/
32 |
33 |
34 | fun StopWatch.task(name: String = "", body: () -> T): T {
35 | start(name)
36 | val result = body()
37 | stop()
38 | return result
39 | }
40 |
41 | val sysProperty: GetterSetterOperation = GetterSetterOperation(
42 | { k -> System.getProperty(k) },
43 | { k, v -> System.setProperty(k, v) })
44 |
--------------------------------------------------------------------------------
/core/src/test/kotlin/org/kotlinprimavera/core/env/PropertyResolverTests.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.core.env
18 |
19 | import org.springframework.core.env.MutablePropertySources
20 | import org.springframework.core.env.PropertiesPropertySource
21 | import org.springframework.core.env.PropertyResolver
22 | import org.springframework.core.env.PropertySourcesPropertyResolver
23 | import org.testng.Assert.assertEquals
24 | import org.testng.Assert.assertNull
25 | import org.testng.annotations.BeforeMethod
26 | import org.testng.annotations.Test
27 | import java.util.*
28 | import kotlin.properties.Delegates
29 |
30 | /**
31 | * Created by IntelliJ IDEA.
32 | * @author Mario Arias
33 | * Date: 22/07/14
34 | * Time: 0:57
35 | */
36 | class PropertyResolverTests {
37 | private var testProperties: Properties by Delegates.notNull()
38 | private var propertySources: MutablePropertySources by Delegates.notNull()
39 | private var propertyResolver: PropertyResolver by Delegates.notNull()
40 |
41 | @BeforeMethod fun setUp() {
42 | propertySources = MutablePropertySources()
43 | propertyResolver = PropertySourcesPropertyResolver(propertySources)
44 | testProperties = Properties()
45 | propertySources.addFirst(PropertiesPropertySource("testProperties", testProperties))
46 | }
47 |
48 | @Test fun getProperty() {
49 | assertNull(propertyResolver["foo"])
50 | assertNull(propertyResolver["num"])
51 | testProperties["foo"] = "bar"
52 | testProperties["num"] = 5
53 | assertEquals(propertyResolver["foo"], "bar")
54 | assertEquals(propertyResolver["num", Int::class.java], 5)
55 | }
56 |
57 | @Test fun getPropertyWithDefaultValue() {
58 | assertEquals(propertyResolver["foo", "myDefault"], "myDefault")
59 | assertEquals(propertyResolver["num", Int::class.java, 42], 42)
60 | testProperties["foo"] = "bar"
61 | testProperties["num"] = 5
62 | assertEquals(propertyResolver["foo", "myDefault"], "bar")
63 | assertEquals(propertyResolver["num", Int::class.java, 13], 5)
64 | }
65 |
66 | }
--------------------------------------------------------------------------------
/core/src/test/kotlin/org/kotlinprimavera/util/SysPropertyTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.util
18 |
19 | import org.testng.Assert
20 | import org.testng.annotations.Test
21 |
22 |
23 | class SysPropertyTest {
24 | @Test fun setAndGetProperty() {
25 | sysProperty["org.kotlinprimavera.test"] = "kotlin"
26 | Assert.assertEquals(sysProperty["org.kotlinprimavera.test"] , "kotlin")
27 | }
28 | }
--------------------------------------------------------------------------------
/jdbc/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 | 4.0.0
22 |
23 | org.kotlinprimavera
24 | parent
25 | 0.5
26 |
27 | jdbc
28 | KotlinPrimavera JDBC Module
29 | jar
30 | 0.5
31 |
32 |
33 | org.springframework
34 | spring-jdbc
35 | compile
36 |
37 |
38 | org.kotlinprimavera
39 | beans
40 | 0.5
41 |
42 |
43 | org.kotlinprimavera
44 | core
45 | 0.5
46 |
47 |
48 | org.hsqldb
49 | hsqldb
50 | test
51 |
52 |
53 |
54 | src/main/kotlin
55 | src/test/kotlin
56 |
57 |
58 | kotlin-maven-plugin
59 | org.jetbrains.kotlin
60 | ${kotlin.version}
61 |
62 |
63 | compile
64 | compile
65 |
66 | compile
67 |
68 |
69 |
70 |
71 | test-compile
72 | test-compile
73 |
74 | test-compile
75 |
76 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/jdbc/src/main/kotlin/org/kotlinprimavera/jdbc/core/AbstractBlobArgumentSetter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.jdbc.core
18 |
19 | /**
20 | * Created by IntelliJ IDEA.
21 | * @author Mario Arias
22 | * Date: 23/08/13
23 | * Time: 21:27
24 | */
25 |
26 | abstract class AbstractBlobArgumentSetter(override val setter: (Int, R) -> Unit,
27 | override val setter2: (Int, R, Long) -> Unit) : ArgumentSetter, ArgumentSetter2
28 |
29 |
--------------------------------------------------------------------------------
/jdbc/src/main/kotlin/org/kotlinprimavera/jdbc/core/ArgumentSetter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.jdbc.core
18 |
19 | /**
20 | * Created by IntelliJ IDEA.
21 | * @author Mario Arias
22 | * Date: 21/08/13
23 | * Time: 22:04
24 | */
25 | interface ArgumentSetter {
26 |
27 | val setter: (Int, T) -> Unit
28 |
29 | operator fun set(index: Int, t: T) {
30 | setter(index, t)
31 | }
32 | }
--------------------------------------------------------------------------------
/jdbc/src/main/kotlin/org/kotlinprimavera/jdbc/core/ArgumentSetter2.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.jdbc.core
18 |
19 | /**
20 | * Created by IntelliJ IDEA.
21 | * @author Mario Arias
22 | * Date: 21/08/13
23 | * Time: 22:04
24 | */
25 | interface ArgumentSetter2 {
26 |
27 | val setter2: (Int, T, A) -> Unit
28 |
29 | operator fun set(index: Int, a: A, t: T) {
30 | setter2(index, t, a)
31 | }
32 | }
--------------------------------------------------------------------------------
/jdbc/src/main/kotlin/org/kotlinprimavera/jdbc/core/ArgumentWithLengthSetter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.jdbc.core
18 |
19 | /**
20 | * Created by IntelliJ IDEA.
21 | * @author Mario Arias
22 | * Date: 21/08/13
23 | * Time: 22:04
24 | */
25 | class ArgumentWithLengthSetter(override val setter: (Int, T) -> Unit,
26 | override val setter2: (Int, T, Int) -> Unit,
27 | val setterWithLong: (Int, T, Long) -> Unit) : ArgumentSetter, ArgumentSetter2 {
28 |
29 | operator fun set(i: Int, lenght: Long, t: T) {
30 | setterWithLong(i, t, lenght)
31 | }
32 | }
--------------------------------------------------------------------------------
/jdbc/src/main/kotlin/org/kotlinprimavera/jdbc/core/BlobArgumentSetter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.jdbc.core
18 |
19 | import java.io.InputStream
20 | import java.sql.Blob
21 |
22 | /**
23 | * Created by IntelliJ IDEA.
24 | * @author Mario Arias
25 | * Date: 23/08/13
26 | * Time: 21:27
27 | */
28 |
29 | class BlobArgumentSetter(val blobSetter: (Int, Blob) -> Unit,
30 | override val setter: (Int, InputStream) -> Unit,
31 | override val setter2: (Int, InputStream, Long) -> Unit) : AbstractBlobArgumentSetter(setter, setter2) {
32 |
33 | operator fun set(index: Int, blob: Blob) {
34 | blobSetter(index, blob)
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/jdbc/src/main/kotlin/org/kotlinprimavera/jdbc/core/ClobArgumentSetter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.jdbc.core
18 |
19 | import java.io.Reader
20 | import java.sql.Clob
21 |
22 | /**
23 | * Created by IntelliJ IDEA.
24 | * @author Mario Arias
25 | * Date: 23/08/13
26 | * Time: 21:27
27 | */
28 |
29 | class ClobArgumentSetter(val blobSetter: (Int, Clob) -> Unit,
30 | override val setter: (Int, Reader) -> Unit,
31 | override val setter2: (Int, Reader, Long) -> Unit) : AbstractBlobArgumentSetter(setter, setter2) {
32 |
33 | operator fun set(index: Int, clob: Clob) {
34 | blobSetter(index, clob)
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/jdbc/src/main/kotlin/org/kotlinprimavera/jdbc/core/CombinedArgumentSetter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.jdbc.core
18 |
19 | /**
20 | * Created by IntelliJ IDEA.
21 | * @author Mario Arias
22 | * Date: 23/08/13
23 | * Time: 22:07
24 | */
25 | open class CombinedArgumentSetter(override val setter: (Int, T) -> Unit,
26 | override val setter2: (Int, T, A) -> Unit) : ArgumentSetter, ArgumentSetter2
--------------------------------------------------------------------------------
/jdbc/src/main/kotlin/org/kotlinprimavera/jdbc/core/DefaultArgumentSetter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.jdbc.core
18 |
19 | /**
20 | * Created by IntelliJ IDEA.
21 | * @author Mario Arias
22 | * Date: 23/08/13
23 | * Time: 21:01
24 | */
25 | class DefaultArgumentSetter(override val setter: (Int, T) -> Unit) : ArgumentSetter
--------------------------------------------------------------------------------
/jdbc/src/main/kotlin/org/kotlinprimavera/jdbc/core/GetFieldsToken.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.jdbc.core
18 |
19 | /**
20 | * Created by IntelliJ IDEA.
21 | * @author Mario Arias
22 | * Date: 20/08/13
23 | * Time: 22:59
24 | */
25 | class GetFieldsToken(val withFieldName: (String) -> T, val withIndex: (Int) -> T) {
26 |
27 | operator fun get(columnIndex: Int): T {
28 | return withIndex(columnIndex)
29 | }
30 |
31 | operator fun get(columnLabel: String): T {
32 | return withFieldName(columnLabel)
33 | }
34 | }
--------------------------------------------------------------------------------
/jdbc/src/main/kotlin/org/kotlinprimavera/jdbc/core/NClobArgumentSetter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.jdbc.core
18 |
19 | import java.io.Reader
20 | import java.sql.NClob
21 |
22 | /**
23 | * Created by IntelliJ IDEA.
24 | * @author Mario Arias
25 | * Date: 23/08/13
26 | * Time: 21:27
27 | */
28 |
29 | class NClobArgumentSetter(val blobSetter: (Int, NClob) -> Unit,
30 | override val setter: (Int, Reader) -> Unit,
31 | override val setter2: (Int, Reader, Long) -> Unit) : AbstractBlobArgumentSetter(setter, setter2) {
32 |
33 | operator fun set(index: Int, clob: NClob) {
34 | blobSetter(index, clob)
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/jdbc/src/main/kotlin/org/kotlinprimavera/jdbc/core/ObjectArgumentSetter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.jdbc.core
18 |
19 | /**
20 | * Created by IntelliJ IDEA.
21 | * @author Mario Arias
22 | * Date: 24/08/13
23 | * Time: 21:16
24 | */
25 | class ObjectArgumentSetter(setter: (Int, Any) -> Unit,
26 | setter2: (Int, Any, Int) -> Unit,
27 | val setter4: (Int, Any, Int, Int) -> Unit) : CombinedArgumentSetter(setter, setter2) {
28 |
29 | operator fun set(index: Int, targetSqlType: Int, scaleOrLenght: Int, x: Any) {
30 | setter4(index, x, targetSqlType, scaleOrLenght)
31 | }
32 | }
--------------------------------------------------------------------------------
/jdbc/src/main/kotlin/org/kotlinprimavera/jdbc/core/PreparedStatementArgumentsSetter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Mario Arias
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.kotlinprimavera.jdbc.core
18 |
19 |
20 | import java.io.InputStream
21 | import java.io.Reader
22 | import java.math.BigDecimal
23 | import java.net.URL
24 | import java.sql.*
25 | import java.sql.Date
26 | import java.util.*
27 |
28 | /**
29 | * Created by IntelliJ IDEA.
30 | * @author Mario Arias
31 | * Date: 21/08/13
32 | * Time: 22:02
33 | */
34 | class PreparedStatementArgumentsSetter(prepareStatement: PreparedStatement) : PreparedStatement by prepareStatement {
35 |
36 | val array: DefaultArgumentSetter
37 | get() {
38 | return DefaultArgumentSetter { i, v -> setArray(i, v) }
39 | }
40 |
41 | val asciiStream: ArgumentWithLengthSetter
42 | get() {
43 | return ArgumentWithLengthSetter(
44 | { i, v -> setAsciiStream(i, v) },
45 | { i, v, l -> setAsciiStream(i, v, l) },
46 | { i, v, l -> setAsciiStream(i, v, l) })
47 | }
48 |
49 | val bigDecimal: DefaultArgumentSetter
50 | get() {
51 | return DefaultArgumentSetter { i, v -> setBigDecimal(i, v) }
52 | }
53 |
54 | val binaryStream: ArgumentWithLengthSetter
55 | get() {
56 | return ArgumentWithLengthSetter(
57 | { i, v -> setBinaryStream(i, v) },
58 | { i, v, l -> setBinaryStream(i, v, l) },
59 | { i, v, l -> setBinaryStream(i, v, l) })
60 | }
61 |
62 | val blob: BlobArgumentSetter
63 | get() {
64 | return BlobArgumentSetter(
65 | { i, v -> setBlob(i, v) },
66 | { i, v -> setBlob(i, v) },
67 | { i, v, l -> setBlob(i, v, l) })
68 | }
69 |
70 | val boolean: DefaultArgumentSetter
71 | get() {
72 | return DefaultArgumentSetter { i, v -> setBoolean(i, v) }
73 | }
74 |
75 | val byte: DefaultArgumentSetter
76 | get() {
77 | return DefaultArgumentSetter { i, v -> setByte(i, v) }
78 | }
79 |
80 | val bytes: DefaultArgumentSetter
81 | get() {
82 | return DefaultArgumentSetter { i, v -> setBytes(i, v) }
83 | }
84 |
85 | val characterStream: ArgumentWithLengthSetter
86 | get() {
87 | return ArgumentWithLengthSetter(
88 | { i, v -> setCharacterStream(i, v) },
89 | { i, v, l -> setCharacterStream(i, v, l) },
90 | { i, v, l -> setCharacterStream(i, v, l) })
91 | }
92 |
93 | val clob: ClobArgumentSetter
94 | get() {
95 | return ClobArgumentSetter(
96 | { i, b -> setClob(i, b) },
97 | { i, v -> setClob(i, v) },
98 | { i, v, l -> setClob(i, v, l) })
99 | }
100 |
101 | val date: CombinedArgumentSetter
102 | get() {
103 | return CombinedArgumentSetter(
104 | { i, d -> setDate(i, d) },
105 | { i, d, c -> setDate(i, d, c) })
106 | }
107 |
108 | val double: DefaultArgumentSetter
109 | get() {
110 | return DefaultArgumentSetter { i, v -> setDouble(i, v) }
111 | }
112 |
113 | val float: DefaultArgumentSetter
114 | get() {
115 | return DefaultArgumentSetter { i, v -> setFloat(i, v) }
116 | }
117 |
118 | val int: DefaultArgumentSetter
119 | get() {
120 | return DefaultArgumentSetter { i, v -> setInt(i, v) }
121 | }
122 |
123 | val long: DefaultArgumentSetter
124 | get() {
125 | return DefaultArgumentSetter { i, v -> setLong(i, v) }
126 | }
127 |
128 | val nCharacterStream: CombinedArgumentSetter
129 | get() {
130 | return CombinedArgumentSetter(
131 | { i, r -> setNCharacterStream(i, r) },
132 | { i, r, l -> setNCharacterStream(i, r, l) })
133 | }
134 |
135 | val nClob: NClobArgumentSetter
136 | get() {
137 | return NClobArgumentSetter(
138 | { i, b -> setNClob(i, b) },
139 | { i, v -> setNClob(i, v) },
140 | { i, v, l -> setNClob(i, v, l) })
141 | }
142 |
143 | val nString: DefaultArgumentSetter
144 | get() {
145 | return DefaultArgumentSetter { i, v -> setNString(i, v) }
146 | }
147 |
148 | val `null`: CombinedArgumentSetter
149 | get() {
150 | return CombinedArgumentSetter(
151 | { i, s -> setNull(i, s) },
152 | { i, s, t -> setNull(i, s, t) })
153 | }
154 |
155 | val `object`: ObjectArgumentSetter
156 | get() {
157 | return ObjectArgumentSetter(
158 | { i, x -> setObject(i, x) },
159 | { i, x, t -> setObject(i, x, t) },
160 | { i, x, t, s -> setObject(i, x, t, s) }
161 |
162 | )
163 | }
164 |
165 | val ref: DefaultArgumentSetter[
166 | get() {
167 | return DefaultArgumentSetter { i, v -> setRef(i, v) }
168 | }
169 |
170 | val rowId: DefaultArgumentSetter
171 | get() {
172 | return DefaultArgumentSetter { i, v -> setRowId(i, v) }
173 | }
174 |
175 | val sqlXml: DefaultArgumentSetter
176 | get() {
177 | return DefaultArgumentSetter { i, v -> setSQLXML(i, v) }
178 | }
179 |
180 | val string: DefaultArgumentSetter
181 | get() {
182 | return DefaultArgumentSetter { i, v -> setString(i, v) }
183 | }
184 |
185 | val time: CombinedArgumentSetter]