├── .gitignore ├── .travis.yml ├── README.md ├── Release Notes.txt ├── pom.xml └── src ├── main ├── java │ └── org │ │ └── springframework │ │ └── jdbc │ │ └── roma │ │ └── impl │ │ ├── AbstractRowMapper.java │ │ ├── GeneratedRowMapper.java │ │ ├── config │ │ ├── manager │ │ │ ├── BaseConfigManager.java │ │ │ └── ConfigManagerImpl.java │ │ └── provider │ │ │ ├── annotation │ │ │ └── AnnotationBasedConfigProvider.java │ │ │ ├── properties │ │ │ └── PropertiesBasedConfigProvider.java │ │ │ └── xml │ │ │ └── XmlBasedConfigProvider.java │ │ ├── factory │ │ ├── DefaultRowMapperFactory.java │ │ ├── DefaultRowMapperGeneratorFactory.java │ │ ├── RowMapperFactory.java │ │ └── RowMapperFactoryProvider.java │ │ ├── generator │ │ ├── AbstractRowMapperFieldGenerator.java │ │ ├── BlobFieldRowMapperGenerator.java │ │ ├── BooleanFieldRowMapperGenerator.java │ │ ├── ByteFieldRowMapperGenerator.java │ │ ├── CharacterFieldRowMapperGenerator.java │ │ ├── DateFieldRowMapperGenerator.java │ │ ├── DoubleFieldRowMapperGenerator.java │ │ ├── EnumFieldRowMapperGenerator.java │ │ ├── FieldMapperFieldRowMapperGenerator.java │ │ ├── FloatFieldRowMapperGenerator.java │ │ ├── IntegerFieldRowMapperGenerator.java │ │ ├── LongFieldRowMapperGenerator.java │ │ ├── ObjectFieldRowMapperGenerator.java │ │ ├── RowMapperAwareFieldGenerator.java │ │ ├── ShortFieldRowMapperGenerator.java │ │ └── StringFieldRowMapperGenerator.java │ │ ├── ignore │ │ ├── IgnoreManager.java │ │ ├── IgnoreManagerImpl.java │ │ └── PropertyBasedIgnoreConditionAwareProcessor.java │ │ ├── lazy │ │ ├── LazyManager.java │ │ ├── LazyManagerImpl.java │ │ ├── PropertyBasedLazyConditionAwareProcessor.java │ │ └── PropertyBasedLazyLoadConditionAwareProcessor.java │ │ ├── proxy │ │ ├── ProxyHelper.java │ │ ├── ProxyListLoader.java │ │ ├── ProxyMapLoader.java │ │ ├── ProxyObjectLoader.java │ │ └── ProxySetLoader.java │ │ ├── resolver │ │ ├── DefaultColumnNameResolver.java │ │ └── DefaultTableNameResolver.java │ │ ├── service │ │ ├── RowMapperService.java │ │ └── RowMapperServiceImpl.java │ │ └── util │ │ ├── BeanUtil.java │ │ ├── InstanceUtil.java │ │ ├── JdbcUtil.java │ │ ├── ReflectionUtil.java │ │ ├── RowMapperUtil.java │ │ └── SpringUtil.java └── resources │ └── roma-context.xml └── test ├── java └── org │ └── springframework │ └── jdbc │ └── roma │ └── impl │ ├── ContextAwareRomaTest.java │ ├── DbAwareBeanPostProcessor.java │ ├── factory │ └── RowMapperFactoryProviderTest.java │ ├── integration │ ├── BaseRomaIntegrationTest.java │ ├── RowMapperIntegrationTest.java │ ├── custom │ │ ├── BloodTypeEnumMapper.java │ │ ├── MaritalStatusEnumMapper.java │ │ ├── RoleNameFieldMapper.java │ │ ├── RoleObjectCreater.java │ │ ├── UserAccountInfoSqlQueryInfoProvider.java │ │ ├── UserObjectProcessor.java │ │ ├── UserPhoneNumberFieldProvider.java │ │ └── UserRolesLazyConditionProvider.java │ ├── dao │ │ ├── CreditCardInfoDAO.java │ │ ├── PermissionDAO.java │ │ ├── RoleDAO.java │ │ ├── UserDAO.java │ │ └── jdbc │ │ │ ├── BaseJdbcDAO.java │ │ │ ├── CreditCardInfoJdbcDAO.java │ │ │ ├── PermissionJdbcDAO.java │ │ │ ├── RoleJdbcDAO.java │ │ │ └── UserJdbcDAO.java │ └── model │ │ ├── AccountInfo.java │ │ ├── Address.java │ │ ├── BloodType.java │ │ ├── CreditCardInfo.java │ │ ├── Education.java │ │ ├── Gender.java │ │ ├── Language.java │ │ ├── MaritalStatus.java │ │ ├── Occupation.java │ │ ├── Permission.java │ │ ├── Religion.java │ │ ├── Role.java │ │ └── User.java │ ├── service │ └── RowMapperServiceTest.java │ └── util │ ├── ReflectionUtilTest.java │ ├── RowMapperUtilTest.java │ └── SpringUtilTest.java └── resources ├── db ├── db-creation-scripts.sql ├── db-deletion-scripts.sql └── db-insertion-scripts.sql ├── log4j.properties └── roma-test-context.xml /.gitignore: -------------------------------------------------------------------------------- 1 | /.settings/ 2 | /target/ 3 | /.classpath 4 | /.project 5 | /.idea/ 6 | /*.iml 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - openjdk6 4 | script: 5 | mvn clean package 6 | -------------------------------------------------------------------------------- /Release Notes.txt: -------------------------------------------------------------------------------- 1 | 1.0.0-RELEASE: 2 | ======================== 3 | 4 | 2.0.0-RELEASE: 5 | ======================== 6 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/AbstractRowMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl; 18 | 19 | import org.springframework.jdbc.core.JdbcTemplate; 20 | import org.springframework.jdbc.core.RowMapper; 21 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 22 | import org.springframework.jdbc.roma.impl.util.BeanUtil; 23 | 24 | /** 25 | * @author Serkan ÖZAL 26 | */ 27 | public abstract class AbstractRowMapper implements RowMapper { 28 | 29 | protected ConfigManager configManager = BeanUtil.getInstance().getConfigManager(); 30 | protected Class cls; 31 | protected JdbcTemplate jdbcTemplate; 32 | protected T obj; 33 | 34 | public AbstractRowMapper(Class cls) { 35 | this.cls = cls; 36 | } 37 | 38 | public AbstractRowMapper(Class cls, JdbcTemplate jdbcTemplate) { 39 | this.cls = cls; 40 | this.jdbcTemplate = jdbcTemplate; 41 | } 42 | 43 | public AbstractRowMapper(Class cls, ConfigManager configManager) { 44 | this.cls = cls; 45 | this.configManager = configManager; 46 | } 47 | 48 | public AbstractRowMapper(Class cls, JdbcTemplate jdbcTemplate, ConfigManager configManager) { 49 | this.cls = cls; 50 | this.jdbcTemplate = jdbcTemplate; 51 | this.configManager = configManager; 52 | } 53 | 54 | public Class getClazz() { 55 | return cls; 56 | } 57 | 58 | public JdbcTemplate getJdbcTemplate() { 59 | return jdbcTemplate; 60 | } 61 | 62 | public T getObject() { 63 | return obj; 64 | } 65 | 66 | public ConfigManager getConfigManager() { 67 | return configManager; 68 | } 69 | 70 | public void setConfigManager(ConfigManager configManager) { 71 | this.configManager = configManager; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/config/manager/BaseConfigManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.config.manager; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | import org.apache.log4j.Logger; 23 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 24 | import org.springframework.jdbc.roma.api.config.provider.ConfigProvider; 25 | 26 | /** 27 | * @author Serkan ÖZAL 28 | */ 29 | public abstract class BaseConfigManager implements ConfigManager { 30 | 31 | protected final Logger logger = Logger.getLogger(getClass()); 32 | 33 | protected List configProviderList = new ArrayList(); 34 | 35 | public BaseConfigManager() { 36 | init(); 37 | } 38 | 39 | abstract protected void init(); 40 | 41 | protected void addConfigProviderIfAvailable(ConfigProvider configProvider) { 42 | if (configProvider.isAvailable()) { 43 | configProviderList.add(configProvider); 44 | } 45 | } 46 | 47 | @Override 48 | public void addConfigProvider(ConfigProvider configProvider) { 49 | configProviderList.add(configProvider); 50 | } 51 | 52 | @Override 53 | public void removeConfigProvider(ConfigProvider configProvider) { 54 | configProviderList.remove(configProvider); 55 | } 56 | 57 | @Override 58 | public List getAllConfigProviders() { 59 | return configProviderList; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/config/manager/ConfigManagerImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.config.manager; 18 | 19 | import java.lang.reflect.Field; 20 | 21 | import javax.annotation.PostConstruct; 22 | 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.jdbc.roma.api.config.DefaultConfigs; 25 | import org.springframework.jdbc.roma.api.config.provider.ConfigProvider; 26 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperBlobFieldConfig; 27 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperClassConfig; 28 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperClobFieldConfig; 29 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperEnumFieldConfig; 30 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperFieldConfig; 31 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperObjectFieldConfig; 32 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperTimeFieldConfig; 33 | import org.springframework.jdbc.roma.impl.config.provider.annotation.AnnotationBasedConfigProvider; 34 | import org.springframework.jdbc.roma.impl.config.provider.properties.PropertiesBasedConfigProvider; 35 | import org.springframework.jdbc.roma.impl.config.provider.xml.XmlBasedConfigProvider; 36 | import org.springframework.stereotype.Component; 37 | 38 | /** 39 | * @author Serkan ÖZAL 40 | */ 41 | @Component 42 | public class ConfigManagerImpl extends BaseConfigManager { 43 | 44 | @Autowired(required = false) 45 | private DefaultConfigs defaultConfigs; 46 | 47 | @Override 48 | protected void init() { 49 | addConfigProviderIfAvailable(new AnnotationBasedConfigProvider()); 50 | addConfigProviderIfAvailable(new XmlBasedConfigProvider()); 51 | addConfigProviderIfAvailable(new PropertiesBasedConfigProvider()); 52 | } 53 | 54 | @PostConstruct 55 | protected void afterPropertiesSet() { 56 | if (defaultConfigs == null) { 57 | defaultConfigs = new DefaultConfigs(); 58 | } 59 | } 60 | 61 | @Override 62 | public DefaultConfigs getDefaultConfigs() { 63 | return defaultConfigs; 64 | } 65 | 66 | @Override 67 | public RowMapperFieldConfig getRowMapperFieldConfig(Class clazz, String fieldName) { 68 | for (ConfigProvider configProvider : configProviderList) { 69 | RowMapperFieldConfig rmfc = configProvider.getRowMapperFieldConfig(clazz, fieldName); 70 | if (rmfc != null) { 71 | return rmfc; 72 | } 73 | } 74 | return null; 75 | } 76 | 77 | @Override 78 | public RowMapperObjectFieldConfig getRowMapperObjectFieldConfig(Class clazz, String fieldName) { 79 | for (ConfigProvider configProvider : configProviderList) { 80 | RowMapperObjectFieldConfig rmofc = configProvider.getRowMapperObjectFieldConfig(clazz, fieldName); 81 | if (rmofc != null) { 82 | return rmofc; 83 | } 84 | } 85 | return null; 86 | } 87 | 88 | @Override 89 | public RowMapperEnumFieldConfig getRowMapperEnumFieldConfig(Class clazz, String fieldName) { 90 | for (ConfigProvider configProvider : configProviderList) { 91 | RowMapperEnumFieldConfig rmefc = configProvider.getRowMapperEnumFieldConfig(clazz, fieldName); 92 | if (rmefc != null) { 93 | return rmefc; 94 | } 95 | } 96 | return null; 97 | } 98 | 99 | @Override 100 | public RowMapperClobFieldConfig getRowMapperClobFieldConfig(Class clazz, String fieldName) { 101 | for (ConfigProvider configProvider : configProviderList) { 102 | RowMapperClobFieldConfig rmcfc = configProvider.getRowMapperClobFieldConfig(clazz, fieldName); 103 | if (rmcfc != null) { 104 | return rmcfc; 105 | } 106 | } 107 | return null; 108 | } 109 | 110 | @Override 111 | public RowMapperBlobFieldConfig getRowMapperBlobFieldConfig(Class clazz, String fieldName) { 112 | for (ConfigProvider configProvider : configProviderList) { 113 | RowMapperBlobFieldConfig rmbfc = configProvider.getRowMapperBlobFieldConfig(clazz, fieldName); 114 | if (rmbfc != null) { 115 | return rmbfc; 116 | } 117 | } 118 | return null; 119 | } 120 | 121 | @Override 122 | public RowMapperTimeFieldConfig getRowMapperTimeFieldConfig(Class clazz, String fieldName) { 123 | for (ConfigProvider configProvider : configProviderList) { 124 | RowMapperTimeFieldConfig rmtfc = configProvider.getRowMapperTimeFieldConfig(clazz, fieldName); 125 | if (rmtfc != null) { 126 | return rmtfc; 127 | } 128 | } 129 | return null; 130 | } 131 | 132 | @Override 133 | public RowMapperClassConfig getRowMapperClassConfig(Class clazz) { 134 | for (ConfigProvider configProvider : configProviderList) { 135 | RowMapperClassConfig rmcc = configProvider.getRowMapperClassConfig(clazz); 136 | if (rmcc != null) { 137 | return rmcc; 138 | } 139 | } 140 | return null; 141 | } 142 | 143 | @Override 144 | public RowMapperFieldConfig getRowMapperFieldConfig(Field field) { 145 | return getRowMapperFieldConfig(field.getDeclaringClass(), field.getName()); 146 | } 147 | 148 | @Override 149 | public RowMapperObjectFieldConfig getRowMapperObjectFieldConfig(Field field) { 150 | return getRowMapperObjectFieldConfig(field.getDeclaringClass(), field.getName()); 151 | } 152 | 153 | @Override 154 | public RowMapperEnumFieldConfig getRowMapperEnumFieldConfig(Field field) { 155 | return getRowMapperEnumFieldConfig(field.getDeclaringClass(), field.getName()); 156 | } 157 | 158 | @Override 159 | public RowMapperClobFieldConfig getRowMapperClobFieldConfig(Field field) { 160 | return getRowMapperClobFieldConfig(field.getDeclaringClass(), field.getName()); 161 | } 162 | 163 | @Override 164 | public RowMapperBlobFieldConfig getRowMapperBlobFieldConfig(Field field) { 165 | return getRowMapperBlobFieldConfig(field.getDeclaringClass(), field.getName()); 166 | } 167 | 168 | @Override 169 | public RowMapperTimeFieldConfig getRowMapperTimeFieldConfig(Field field) { 170 | return getRowMapperTimeFieldConfig(field.getDeclaringClass(), field.getName()); 171 | } 172 | 173 | } 174 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/config/provider/properties/PropertiesBasedConfigProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.config.provider.properties; 18 | 19 | import org.springframework.jdbc.roma.api.config.provider.ConfigProvider; 20 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperBlobFieldConfig; 21 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperClassConfig; 22 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperClobFieldConfig; 23 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperEnumFieldConfig; 24 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperFieldConfig; 25 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperObjectFieldConfig; 26 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperTimeFieldConfig; 27 | 28 | /** 29 | * @author Serkan ÖZAL 30 | */ 31 | public class PropertiesBasedConfigProvider implements ConfigProvider { 32 | 33 | @Override 34 | public boolean isAvailable() { 35 | return false; 36 | } 37 | 38 | @Override 39 | public RowMapperFieldConfig getRowMapperFieldConfig(Class clazz, String fieldName) { 40 | return null; 41 | } 42 | 43 | @Override 44 | public RowMapperObjectFieldConfig getRowMapperObjectFieldConfig(Class clazz, String fieldName) { 45 | return null; 46 | } 47 | 48 | @Override 49 | public RowMapperEnumFieldConfig getRowMapperEnumFieldConfig(Class clazz, String fieldName) { 50 | return null; 51 | } 52 | 53 | @Override 54 | public RowMapperClobFieldConfig getRowMapperClobFieldConfig(Class clazz, String fieldName) { 55 | return null; 56 | } 57 | 58 | @Override 59 | public RowMapperBlobFieldConfig getRowMapperBlobFieldConfig(Class clazz, String fieldName) { 60 | return null; 61 | } 62 | 63 | @Override 64 | public RowMapperTimeFieldConfig getRowMapperTimeFieldConfig(Class clazz, String fieldName) { 65 | return null; 66 | } 67 | 68 | @Override 69 | public RowMapperClassConfig getRowMapperClassConfig(Class clazz) { 70 | return null; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/config/provider/xml/XmlBasedConfigProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.config.provider.xml; 18 | 19 | import org.springframework.jdbc.roma.api.config.provider.ConfigProvider; 20 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperBlobFieldConfig; 21 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperClassConfig; 22 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperClobFieldConfig; 23 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperEnumFieldConfig; 24 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperFieldConfig; 25 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperObjectFieldConfig; 26 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperTimeFieldConfig; 27 | 28 | /** 29 | * @author Serkan ÖZAL 30 | */ 31 | public class XmlBasedConfigProvider implements ConfigProvider { 32 | 33 | @Override 34 | public boolean isAvailable() { 35 | return false; 36 | } 37 | 38 | @Override 39 | public RowMapperFieldConfig getRowMapperFieldConfig(Class clazz, String fieldName) { 40 | return null; 41 | } 42 | 43 | @Override 44 | public RowMapperObjectFieldConfig getRowMapperObjectFieldConfig(Class clazz, String fieldName) { 45 | return null; 46 | } 47 | 48 | @Override 49 | public RowMapperEnumFieldConfig getRowMapperEnumFieldConfig(Class clazz, String fieldName) { 50 | return null; 51 | } 52 | 53 | @Override 54 | public RowMapperClobFieldConfig getRowMapperClobFieldConfig(Class clazz, String fieldName) { 55 | return null; 56 | } 57 | 58 | @Override 59 | public RowMapperBlobFieldConfig getRowMapperBlobFieldConfig(Class clazz, String fieldName) { 60 | return null; 61 | } 62 | 63 | @Override 64 | public RowMapperTimeFieldConfig getRowMapperTimeFieldConfig(Class clazz, String fieldName) { 65 | return null; 66 | } 67 | 68 | @Override 69 | public RowMapperClassConfig getRowMapperClassConfig(Class clazz) { 70 | return null; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/factory/DefaultRowMapperFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.factory; 18 | 19 | import org.springframework.jdbc.core.JdbcTemplate; 20 | import org.springframework.jdbc.core.RowMapper; 21 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 22 | import org.springframework.jdbc.roma.impl.GeneratedRowMapper; 23 | 24 | /** 25 | * @author Serkan ÖZAL 26 | */ 27 | public class DefaultRowMapperFactory implements RowMapperFactory { 28 | 29 | @Override 30 | public RowMapper getRowMapper(Class clazz, ConfigManager configManager) { 31 | return new GeneratedRowMapper(clazz, configManager); 32 | } 33 | 34 | @Override 35 | public RowMapper getRowMapper(Class clazz, JdbcTemplate jdbcTemplate) { 36 | return new GeneratedRowMapper(clazz, jdbcTemplate); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/factory/DefaultRowMapperGeneratorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.factory; 18 | 19 | import java.lang.reflect.Field; 20 | import java.util.Date; 21 | 22 | import org.apache.log4j.Logger; 23 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 24 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperField.RowMapperFieldMapper; 25 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperBlobFieldConfig; 26 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperFieldConfig; 27 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperObjectFieldConfig; 28 | import org.springframework.jdbc.roma.api.factory.RowMapperFieldGeneratorFactory; 29 | import org.springframework.jdbc.roma.api.generator.RowMapperFieldGenerator; 30 | import org.springframework.jdbc.roma.impl.generator.BlobFieldRowMapperGenerator; 31 | import org.springframework.jdbc.roma.impl.generator.BooleanFieldRowMapperGenerator; 32 | import org.springframework.jdbc.roma.impl.generator.ByteFieldRowMapperGenerator; 33 | import org.springframework.jdbc.roma.impl.generator.CharacterFieldRowMapperGenerator; 34 | import org.springframework.jdbc.roma.impl.generator.DateFieldRowMapperGenerator; 35 | import org.springframework.jdbc.roma.impl.generator.DoubleFieldRowMapperGenerator; 36 | import org.springframework.jdbc.roma.impl.generator.EnumFieldRowMapperGenerator; 37 | import org.springframework.jdbc.roma.impl.generator.FieldMapperFieldRowMapperGenerator; 38 | import org.springframework.jdbc.roma.impl.generator.FloatFieldRowMapperGenerator; 39 | import org.springframework.jdbc.roma.impl.generator.IntegerFieldRowMapperGenerator; 40 | import org.springframework.jdbc.roma.impl.generator.LongFieldRowMapperGenerator; 41 | import org.springframework.jdbc.roma.impl.generator.ObjectFieldRowMapperGenerator; 42 | import org.springframework.jdbc.roma.impl.generator.ShortFieldRowMapperGenerator; 43 | import org.springframework.jdbc.roma.impl.generator.StringFieldRowMapperGenerator; 44 | import org.springframework.jdbc.roma.impl.util.InstanceUtil; 45 | 46 | /** 47 | * @author Serkan ÖZAL 48 | */ 49 | public class DefaultRowMapperGeneratorFactory implements RowMapperFieldGeneratorFactory { 50 | 51 | protected final Logger logger = Logger.getLogger(getClass()); 52 | 53 | private ConfigManager configManager; 54 | 55 | public DefaultRowMapperGeneratorFactory(ConfigManager configManager) { 56 | this.configManager = configManager; 57 | } 58 | 59 | @SuppressWarnings({ "rawtypes", "unchecked" }) 60 | @Override 61 | public RowMapperFieldGenerator createRowMapperFieldGenerator(Field f) { 62 | RowMapperFieldConfig rmfc = configManager.getRowMapperFieldConfig(f); 63 | RowMapperObjectFieldConfig rmofc = configManager.getRowMapperObjectFieldConfig(f); 64 | 65 | /* 66 | if (rmfc == null && rmofc == null) { 67 | return null; 68 | } 69 | */ 70 | 71 | if (rmfc != null) { 72 | Class fieldGenCls = rmfc.getFieldGeneratorClass(); 73 | if (fieldGenCls != null && fieldGenCls.equals(RowMapperFieldGenerator.class) == false) { 74 | try { 75 | return InstanceUtil.getSingleInstance(fieldGenCls); 76 | } 77 | catch (Exception e) { 78 | logger.error("Unable to create instance of class " + fieldGenCls.getName(), e); 79 | } 80 | } 81 | else { 82 | Class fieldMapperCls = rmfc.getFieldMapperClass(); 83 | if (fieldMapperCls != null && fieldMapperCls.equals(RowMapperFieldMapper.class) == false) { 84 | return new FieldMapperFieldRowMapperGenerator(f, configManager, fieldMapperCls); 85 | } 86 | } 87 | } 88 | 89 | RowMapperFieldGenerator rmfg = null; 90 | 91 | Class cls = f.getType(); 92 | RowMapperBlobFieldConfig rmbfc = configManager.getRowMapperBlobFieldConfig(f); 93 | 94 | if (rmbfc != null) { 95 | rmfg = new BlobFieldRowMapperGenerator(f, configManager); 96 | } 97 | else if (rmofc != null) { 98 | rmfg = new ObjectFieldRowMapperGenerator(f, configManager); 99 | } 100 | else if (cls.equals(boolean.class) || cls.equals(Boolean.class)) { 101 | rmfg = new BooleanFieldRowMapperGenerator(f, configManager); 102 | } 103 | else if (cls.equals(byte.class) || cls.equals(Byte.class)) { 104 | rmfg = new ByteFieldRowMapperGenerator(f, configManager); 105 | } 106 | else if (cls.equals(char.class) || cls.equals(Character.class)) { 107 | rmfg = new CharacterFieldRowMapperGenerator(f, configManager); 108 | } 109 | else if (cls.equals(short.class) || cls.equals(Short.class)) { 110 | rmfg = new ShortFieldRowMapperGenerator(f, configManager); 111 | } 112 | else if (cls.equals(int.class) || cls.equals(Integer.class)) { 113 | rmfg = new IntegerFieldRowMapperGenerator(f, configManager); 114 | } 115 | else if (cls.equals(float.class) || cls.equals(Float.class)) { 116 | rmfg = new FloatFieldRowMapperGenerator(f, configManager); 117 | } 118 | else if (cls.equals(long.class) || cls.equals(Long.class)) { 119 | rmfg = new LongFieldRowMapperGenerator(f, configManager); 120 | } 121 | else if (cls.equals(double.class) || cls.equals(Double.class)) { 122 | rmfg = new DoubleFieldRowMapperGenerator(f, configManager); 123 | } 124 | else if (cls.equals(String.class) || cls.equals(String.class)) { 125 | rmfg = new StringFieldRowMapperGenerator(f, configManager); 126 | } 127 | else if (Date.class.isAssignableFrom(cls)) { 128 | rmfg = new DateFieldRowMapperGenerator(f, configManager); 129 | } 130 | else if (cls.isEnum()) { 131 | rmfg = new EnumFieldRowMapperGenerator(f, configManager); 132 | } 133 | else { 134 | rmfg = new ObjectFieldRowMapperGenerator(f, configManager); 135 | } 136 | 137 | return rmfg; 138 | } 139 | 140 | } 141 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/factory/RowMapperFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.factory; 18 | 19 | import org.springframework.jdbc.core.JdbcTemplate; 20 | import org.springframework.jdbc.core.RowMapper; 21 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 22 | 23 | /** 24 | * @author Serkan ÖZAL 25 | */ 26 | public interface RowMapperFactory { 27 | 28 | public RowMapper getRowMapper(Class clazz, ConfigManager configManager); 29 | public RowMapper getRowMapper(Class clazz, JdbcTemplate jdbcTemplate); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/factory/RowMapperFactoryProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.factory; 18 | 19 | /** 20 | * @author Serkan ÖZAL 21 | */ 22 | public class RowMapperFactoryProvider { 23 | 24 | private static RowMapperFactory rowMapperFactory = new DefaultRowMapperFactory(); 25 | 26 | private RowMapperFactoryProvider() { 27 | 28 | } 29 | 30 | public static RowMapperFactory getRowMapperFactory() { 31 | return rowMapperFactory; 32 | } 33 | 34 | public static void setRowMapperFactory(RowMapperFactory rowMapperFactory) { 35 | RowMapperFactoryProvider.rowMapperFactory = rowMapperFactory; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/generator/AbstractRowMapperFieldGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.generator; 18 | 19 | import java.lang.reflect.Field; 20 | 21 | import org.apache.log4j.Logger; 22 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 23 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperClass.RowMapperColumnNameResolver; 24 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperClassConfig; 25 | import org.springframework.jdbc.roma.impl.GeneratedRowMapper; 26 | import org.springframework.jdbc.roma.impl.resolver.DefaultColumnNameResolver; 27 | import org.springframework.jdbc.roma.impl.util.InstanceUtil; 28 | import org.springframework.jdbc.roma.impl.util.ReflectionUtil; 29 | import org.springframework.jdbc.roma.impl.util.RowMapperUtil; 30 | import org.springframework.util.StringUtils; 31 | 32 | /** 33 | * @author Serkan ÖZAL 34 | */ 35 | public abstract class AbstractRowMapperFieldGenerator implements RowMapperAwareFieldGenerator { 36 | 37 | protected final Logger logger = Logger.getLogger(getClass()); 38 | 39 | protected ConfigManager configManager; 40 | protected Field field; 41 | protected Class fieldCls; 42 | protected String columnName; 43 | protected GeneratedRowMapper rowMapper; 44 | protected RowMapperColumnNameResolver columnNameResolver = new DefaultColumnNameResolver(); 45 | 46 | public AbstractRowMapperFieldGenerator(Field field, ConfigManager configManager) { 47 | field.setAccessible(true); 48 | this.field = field; 49 | this.configManager = configManager; 50 | this.fieldCls = field.getType(); 51 | RowMapperClassConfig rmcc = configManager.getRowMapperClassConfig(field.getDeclaringClass()); 52 | if (rmcc != null) { 53 | Class columnNameResolverClass = rmcc.getColumnNameResolverClass(); 54 | if (columnNameResolverClass != null) { 55 | RowMapperColumnNameResolver cnr = InstanceUtil.getSingleInstance(columnNameResolverClass); 56 | if (cnr != null) { 57 | columnNameResolver = cnr; 58 | } 59 | } 60 | } 61 | this.columnName = columnNameResolver.resolveColumnName(field); 62 | } 63 | 64 | @Override 65 | public void assignedToRowMapper(GeneratedRowMapper rowMapper) { 66 | this.rowMapper = rowMapper; 67 | } 68 | 69 | protected String getSetterMethodName(Field f) { 70 | return RowMapperUtil.generateSetterMethodName(f); 71 | } 72 | 73 | abstract protected String doFieldMapping(Field f); 74 | 75 | @Override 76 | public final String generateFieldMapping(Field f) { 77 | return doFieldMapping(f); 78 | } 79 | 80 | protected String wrapWithNullCheck(String generated, String setterMethodName) { 81 | if (ReflectionUtil.isPrimitiveType(field.getType())) { 82 | return generated; 83 | } 84 | else { 85 | return 86 | "if " + "(" + RESULT_SET_ARGUMENT + ".wasNull()" + ")" + "\n" + 87 | "{" + "\n" + 88 | "\t" + GENERATED_OBJECT_NAME + "." + setterMethodName + "(" + "null" + ");" + "\n" + 89 | "}" + "\n" + 90 | "else" + "\n" + 91 | "{" + "\n" + 92 | RowMapperUtil.indent(generated) + "\n" + 93 | "}" + "\n"; 94 | } 95 | } 96 | 97 | protected String wrapWithNullCheck(String generated, String setterMethodName, String defaultValueExpr) { 98 | if (StringUtils.isEmpty(defaultValueExpr)) { 99 | return wrapWithNullCheck(generated, setterMethodName); 100 | } 101 | else { 102 | return 103 | "if " + "(" + RESULT_SET_ARGUMENT + ".wasNull()" + ")" + "\n" + 104 | "{" + "\n" + 105 | "\t" + GENERATED_OBJECT_NAME + "." + setterMethodName + "(" + defaultValueExpr + ");" + "\n" + 106 | "}" + "\n" + 107 | "else" + "\n" + 108 | "{" + "\n" + 109 | RowMapperUtil.indent(generated) + "\n" + 110 | "}" + "\n"; 111 | } 112 | } 113 | 114 | protected String wrapWithExceptionHandling(String generated) { 115 | return 116 | "try" + "\n" + 117 | "{" + "\n" + 118 | RowMapperUtil.indent(generated) + "\n" + 119 | "}" + "\n" + 120 | "catch (Throwable t)" + "\n" + 121 | "{" + "\n" + 122 | "\t" + "t.printStackTrace();\n" + 123 | "}"; 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/generator/BlobFieldRowMapperGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.generator; 18 | 19 | import java.lang.reflect.Field; 20 | 21 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 22 | 23 | /** 24 | * @author Serkan ÖZAL 25 | */ 26 | public class BlobFieldRowMapperGenerator extends AbstractRowMapperFieldGenerator { 27 | 28 | public BlobFieldRowMapperGenerator(Field field, ConfigManager configManager) { 29 | super(field, configManager); 30 | } 31 | 32 | @Override 33 | public String doFieldMapping(Field f) { 34 | String setterMethodName = getSetterMethodName(f); 35 | Class fieldCls = f.getType(); 36 | Class compType = fieldCls.getComponentType(); 37 | if (fieldCls.isArray() && (compType.equals(byte.class) || compType.equals(Byte.class))) { 38 | String blobFieldName = "blob_" + f.getName(); 39 | return 40 | "Blob " + blobFieldName + " = " + 41 | RESULT_SET_ARGUMENT + ".getBlob(\"" + columnName + "\");" + "\n" + 42 | "\t" + "if (" + blobFieldName + " != null)" + "\n" + 43 | "\t" + "{" + "\n" + 44 | "\t" + "\t" + GENERATED_OBJECT_NAME + "." + 45 | setterMethodName + 46 | "(" + 47 | blobFieldName + ".getBytes(1L, (int)" + blobFieldName + ".length())" + 48 | ");" + "\n" + 49 | "\t" + "}"; 50 | } 51 | else { 52 | logger.error("Blob field types can only be \"byte[]\" or \"Byte[]\" !"); 53 | return ""; 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/generator/BooleanFieldRowMapperGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.generator; 18 | 19 | import java.lang.reflect.Field; 20 | 21 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 22 | import org.springframework.jdbc.roma.impl.util.RowMapperUtil; 23 | 24 | /** 25 | * @author Serkan ÖZAL 26 | */ 27 | public class BooleanFieldRowMapperGenerator extends AbstractRowMapperFieldGenerator { 28 | 29 | public BooleanFieldRowMapperGenerator(Field field, ConfigManager configManager) { 30 | super(field, configManager); 31 | } 32 | 33 | @Override 34 | public String doFieldMapping(Field f) { 35 | String setterMethodName = getSetterMethodName(f); 36 | Class paramType = RowMapperUtil.getFieldTypeFromSetterMethod(f, rowMapper.getClazz()); 37 | if (paramType == null) { 38 | logger.warn("Expected setter method " + setterMethodName + " with exactly one parameter couldn't be found for field " + 39 | field.getName() + " at class " + rowMapper.getClazz() + ". So this field will be ignored."); 40 | return ""; 41 | } 42 | String setValueExpr = "false : true"; 43 | if (paramType.equals(Boolean.class)) { 44 | setValueExpr = "Boolean.FALSE : Boolean.TRUE"; 45 | } 46 | return 47 | GENERATED_OBJECT_NAME + "." + 48 | setterMethodName + 49 | "(" + 50 | RESULT_SET_ARGUMENT + ".getInt(\"" + columnName + "\") == 0 ? " + setValueExpr + 51 | ");"; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/generator/ByteFieldRowMapperGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.generator; 18 | 19 | import java.lang.reflect.Field; 20 | 21 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 22 | import org.springframework.jdbc.roma.impl.util.RowMapperUtil; 23 | 24 | /** 25 | * @author Serkan ÖZAL 26 | */ 27 | public class ByteFieldRowMapperGenerator extends AbstractRowMapperFieldGenerator { 28 | 29 | public ByteFieldRowMapperGenerator(Field field, ConfigManager configManager) { 30 | super(field, configManager); 31 | } 32 | 33 | @Override 34 | public String doFieldMapping(Field f) { 35 | String setterMethodName = getSetterMethodName(f); 36 | Class paramType = RowMapperUtil.getFieldTypeFromSetterMethod(f, rowMapper.getClazz()); 37 | if (paramType == null) { 38 | logger.warn("Expected setter method " + setterMethodName + " with exactly one parameter couldn't be found for field " + 39 | field.getName() + " at class " + rowMapper.getClazz() + ". So this field will be ignored."); 40 | return ""; 41 | } 42 | String setValueExpr = RESULT_SET_ARGUMENT + ".getByte(\"" + columnName + "\")"; 43 | if (paramType.equals(Byte.class)) { 44 | setValueExpr = "Byte.valueOf" + "(" + setValueExpr + ")"; 45 | } 46 | return 47 | wrapWithNullCheck( 48 | GENERATED_OBJECT_NAME + "." + setterMethodName + "(" + setValueExpr + ");", 49 | setterMethodName); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/generator/CharacterFieldRowMapperGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.generator; 18 | 19 | import java.lang.reflect.Field; 20 | 21 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 22 | import org.springframework.jdbc.roma.impl.util.RowMapperUtil; 23 | 24 | /** 25 | * @author Serkan ÖZAL 26 | */ 27 | public class CharacterFieldRowMapperGenerator extends AbstractRowMapperFieldGenerator { 28 | 29 | public CharacterFieldRowMapperGenerator(Field field, ConfigManager configManager) { 30 | super(field, configManager); 31 | } 32 | 33 | @Override 34 | public String doFieldMapping(Field f) { 35 | String setterMethodName = getSetterMethodName(f); 36 | Class paramType = RowMapperUtil.getFieldTypeFromSetterMethod(f, rowMapper.getClazz()); 37 | if (paramType == null) { 38 | logger.warn("Expected setter method " + setterMethodName + " with exactly one parameter couldn't be found for field " + 39 | field.getName() + " at class " + rowMapper.getClazz() + ". So this field will be ignored."); 40 | return ""; 41 | } 42 | String tempFieldName = "str_" + columnName; 43 | String setValueExpr = tempFieldName + ".charAt(0)"; 44 | if (paramType.equals(Character.class)) { 45 | setValueExpr = "Character.valueOf" + "(" + setValueExpr + ")"; 46 | } 47 | return 48 | wrapWithNullCheck( 49 | "String " + tempFieldName + " = " + RESULT_SET_ARGUMENT + ".getString(\"" + columnName + "\");" + "\n" + 50 | "if " + "(" + tempFieldName + " != null" + " && " + tempFieldName + ".length() > 0" + ") " + "\n" + 51 | "{" + "\n" + 52 | GENERATED_OBJECT_NAME + "." + 53 | setterMethodName + "(" + setValueExpr + ");" + "\n" + 54 | "}", 55 | setterMethodName); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/generator/DateFieldRowMapperGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.generator; 18 | 19 | import java.lang.reflect.Field; 20 | import java.sql.Timestamp; 21 | import java.util.Date; 22 | 23 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 24 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperTimeFieldConfig; 25 | 26 | /** 27 | * @author Serkan ÖZAL 28 | */ 29 | public class DateFieldRowMapperGenerator extends AbstractRowMapperFieldGenerator { 30 | 31 | private boolean asTimestamp = false; 32 | 33 | public DateFieldRowMapperGenerator(Field field, ConfigManager configManager) { 34 | super(field, configManager); 35 | if (Timestamp.class.isAssignableFrom(field.getType())) { 36 | asTimestamp = true; 37 | } 38 | else { 39 | RowMapperTimeFieldConfig timeFieldConfig = configManager.getRowMapperTimeFieldConfig(field); 40 | if (timeFieldConfig != null && timeFieldConfig.isAsTimestamp()) { 41 | asTimestamp = true; 42 | } 43 | } 44 | } 45 | 46 | @Override 47 | public String doFieldMapping(Field f) { 48 | String setterMethodName = getSetterMethodName(f); 49 | String setValueExpr = null; 50 | if (asTimestamp) { 51 | setValueExpr = RESULT_SET_ARGUMENT + ".getTimestamp(\"" + columnName + "\")"; 52 | } 53 | else { 54 | setValueExpr = RESULT_SET_ARGUMENT + ".getDate(\"" + columnName + "\")"; 55 | } 56 | rowMapper.addAdditionalClass(Date.class); 57 | return 58 | wrapWithNullCheck( 59 | GENERATED_OBJECT_NAME + "." + setterMethodName + "(" + setValueExpr + ");", 60 | setterMethodName); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/generator/DoubleFieldRowMapperGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.generator; 18 | 19 | import java.lang.reflect.Field; 20 | 21 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 22 | import org.springframework.jdbc.roma.impl.util.RowMapperUtil; 23 | 24 | /** 25 | * @author Serkan ÖZAL 26 | */ 27 | public class DoubleFieldRowMapperGenerator extends AbstractRowMapperFieldGenerator { 28 | 29 | public DoubleFieldRowMapperGenerator(Field field, ConfigManager configManager) { 30 | super(field, configManager); 31 | } 32 | 33 | @Override 34 | public String doFieldMapping(Field f) { 35 | String setterMethodName = getSetterMethodName(f); 36 | Class paramType = RowMapperUtil.getFieldTypeFromSetterMethod(f, rowMapper.getClazz()); 37 | if (paramType == null) { 38 | logger.warn("Expected setter method " + setterMethodName + " with exactly one parameter couldn't be found for field " + 39 | field.getName() + " at class " + rowMapper.getClazz() + ". So this field will be ignored."); 40 | return ""; 41 | } 42 | String setValueExpr = RESULT_SET_ARGUMENT + ".getDouble(\"" + columnName + "\")"; 43 | if (paramType.equals(Double.class)) { 44 | setValueExpr = "Double.valueOf" + "(" + setValueExpr + ")"; 45 | } 46 | return 47 | wrapWithNullCheck( 48 | GENERATED_OBJECT_NAME + "." + setterMethodName + "(" + setValueExpr + ");", 49 | setterMethodName); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/generator/FieldMapperFieldRowMapperGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.generator; 18 | 19 | import java.lang.reflect.Field; 20 | 21 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 22 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperField.RowMapperFieldMapper; 23 | import org.springframework.jdbc.roma.api.generator.RowMapperFieldGenerator; 24 | import org.springframework.jdbc.roma.impl.util.RowMapperUtil; 25 | 26 | /** 27 | * @author Serkan ÖZAL 28 | */ 29 | public class FieldMapperFieldRowMapperGenerator extends AbstractRowMapperFieldGenerator { 30 | 31 | @SuppressWarnings("rawtypes") 32 | private Class fieldMapperCls; 33 | 34 | @SuppressWarnings("rawtypes") 35 | public FieldMapperFieldRowMapperGenerator(Field field, ConfigManager configManager, 36 | Class fieldMapperCls) { 37 | super(field, configManager); 38 | this.fieldMapperCls = fieldMapperCls; 39 | } 40 | 41 | @Override 42 | public String doFieldMapping(Field f) { 43 | return 44 | RowMapperUtil.generateGetSingleInstanceCode(fieldMapperCls) + 45 | ".mapField" + 46 | "(" + 47 | "(" + rowMapper.getClazz().getName() + ")" + RowMapperFieldGenerator.GENERATED_OBJECT_NAME + "," + 48 | "\"" + f.getName() + "\"" + "," + 49 | RowMapperFieldGenerator.RESULT_SET_ARGUMENT + ", " + 50 | RowMapperFieldGenerator.ROW_NUM_ARGUMENT + 51 | ");"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/generator/FloatFieldRowMapperGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.generator; 18 | 19 | import java.lang.reflect.Field; 20 | 21 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 22 | import org.springframework.jdbc.roma.impl.util.RowMapperUtil; 23 | 24 | /** 25 | * @author Serkan ÖZAL 26 | */ 27 | public class FloatFieldRowMapperGenerator extends AbstractRowMapperFieldGenerator { 28 | 29 | public FloatFieldRowMapperGenerator(Field field, ConfigManager configManager) { 30 | super(field, configManager); 31 | } 32 | 33 | @Override 34 | public String doFieldMapping(Field f) { 35 | String setterMethodName = getSetterMethodName(f); 36 | Class paramType = RowMapperUtil.getFieldTypeFromSetterMethod(f, rowMapper.getClazz()); 37 | if (paramType == null) { 38 | logger.warn("Expected setter method " + setterMethodName + " with exactly one parameter couldn't be found for field " + 39 | field.getName() + " at class " + rowMapper.getClazz() + ". So this field will be ignored."); 40 | return ""; 41 | } 42 | String setValueExpr = RESULT_SET_ARGUMENT + ".getFloat(\"" + columnName + "\")"; 43 | if (paramType.equals(Float.class)) { 44 | setValueExpr = "Float.valueOf" + "(" + setValueExpr + ")"; 45 | } 46 | return 47 | wrapWithNullCheck( 48 | GENERATED_OBJECT_NAME + "." + setterMethodName + "(" + setValueExpr + ");", 49 | setterMethodName); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/generator/IntegerFieldRowMapperGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.generator; 18 | 19 | import java.lang.reflect.Field; 20 | 21 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 22 | import org.springframework.jdbc.roma.impl.util.RowMapperUtil; 23 | 24 | /** 25 | * @author Serkan ÖZAL 26 | */ 27 | public class IntegerFieldRowMapperGenerator extends AbstractRowMapperFieldGenerator { 28 | 29 | public IntegerFieldRowMapperGenerator(Field field, ConfigManager configManager) { 30 | super(field, configManager); 31 | } 32 | 33 | @Override 34 | public String doFieldMapping(Field f) { 35 | String setterMethodName = getSetterMethodName(f); 36 | Class paramType = RowMapperUtil.getFieldTypeFromSetterMethod(f, rowMapper.getClazz()); 37 | if (paramType == null) { 38 | logger.warn("Expected setter method " + setterMethodName + " with exactly one parameter couldn't be found for field " + 39 | field.getName() + " at class " + rowMapper.getClazz() + ". So this field will be ignored."); 40 | return ""; 41 | } 42 | String setValueExpr = RESULT_SET_ARGUMENT + ".getInt(\"" + columnName + "\")"; 43 | if (paramType.equals(Integer.class)) { 44 | setValueExpr = "Integer.valueOf" + "(" + setValueExpr + ")"; 45 | } 46 | return 47 | wrapWithNullCheck( 48 | GENERATED_OBJECT_NAME + "." + setterMethodName + "(" + setValueExpr + ");", 49 | setterMethodName); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/generator/LongFieldRowMapperGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.generator; 18 | 19 | import java.lang.reflect.Field; 20 | 21 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 22 | import org.springframework.jdbc.roma.impl.util.RowMapperUtil; 23 | 24 | /** 25 | * @author Serkan ÖZAL 26 | */ 27 | public class LongFieldRowMapperGenerator extends AbstractRowMapperFieldGenerator { 28 | 29 | public LongFieldRowMapperGenerator(Field field, ConfigManager configManager) { 30 | super(field, configManager); 31 | } 32 | 33 | @Override 34 | public String doFieldMapping(Field f) { 35 | String setterMethodName = getSetterMethodName(f); 36 | Class paramType = RowMapperUtil.getFieldTypeFromSetterMethod(f, rowMapper.getClazz()); 37 | if (paramType == null) { 38 | logger.warn("Expected setter method " + setterMethodName + " with exactly one parameter couldn't be found for field " + 39 | field.getName() + " at class " + rowMapper.getClazz() + ". So this field will be ignored."); 40 | return ""; 41 | } 42 | String setValueExpr = RESULT_SET_ARGUMENT + ".getLong(\"" + columnName + "\")"; 43 | if (paramType.equals(Long.class)) { 44 | setValueExpr = "Long.valueOf" + "(" + setValueExpr + ")"; 45 | } 46 | return 47 | wrapWithNullCheck( 48 | GENERATED_OBJECT_NAME + "." + setterMethodName + "(" + setValueExpr + ");", 49 | setterMethodName); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/generator/RowMapperAwareFieldGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.generator; 18 | 19 | import org.springframework.jdbc.roma.api.generator.RowMapperFieldGenerator; 20 | import org.springframework.jdbc.roma.impl.GeneratedRowMapper; 21 | 22 | /** 23 | * @author Serkan ÖZAL 24 | */ 25 | public interface RowMapperAwareFieldGenerator extends RowMapperFieldGenerator { 26 | 27 | public void assignedToRowMapper(GeneratedRowMapper rowMapper); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/generator/ShortFieldRowMapperGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.generator; 18 | 19 | import java.lang.reflect.Field; 20 | 21 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 22 | import org.springframework.jdbc.roma.impl.util.RowMapperUtil; 23 | 24 | /** 25 | * @author Serkan ÖZAL 26 | */ 27 | public class ShortFieldRowMapperGenerator extends AbstractRowMapperFieldGenerator { 28 | 29 | public ShortFieldRowMapperGenerator(Field field, ConfigManager configManager) { 30 | super(field, configManager); 31 | } 32 | 33 | @Override 34 | public String doFieldMapping(Field f) { 35 | String setterMethodName = getSetterMethodName(f); 36 | Class paramType = RowMapperUtil.getFieldTypeFromSetterMethod(f, rowMapper.getClazz()); 37 | if (paramType == null) { 38 | logger.warn("Expected setter method " + setterMethodName + " with exactly one parameter couldn't be found for field " + 39 | field.getName() + " at class " + rowMapper.getClazz() + ". So this field will be ignored."); 40 | return ""; 41 | } 42 | String setValueExpr = RESULT_SET_ARGUMENT + ".getShort(\"" + columnName + "\")"; 43 | if (paramType.equals(Short.class)) { 44 | setValueExpr = "Short.valueOf" + "(" + setValueExpr + ")"; 45 | } 46 | return 47 | wrapWithNullCheck( 48 | GENERATED_OBJECT_NAME + "." + setterMethodName + "(" + setValueExpr + ");", 49 | setterMethodName); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/generator/StringFieldRowMapperGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.generator; 18 | 19 | import java.lang.reflect.Field; 20 | 21 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 22 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperClobFieldConfig; 23 | 24 | /** 25 | * @author Serkan ÖZAL 26 | */ 27 | public class StringFieldRowMapperGenerator extends AbstractRowMapperFieldGenerator { 28 | 29 | public StringFieldRowMapperGenerator(Field field, ConfigManager configManager) { 30 | super(field, configManager); 31 | } 32 | 33 | @Override 34 | public String doFieldMapping(Field f) { 35 | String setterMethodName = getSetterMethodName(f); 36 | RowMapperClobFieldConfig clobFieldConfig = configManager.getRowMapperClobFieldConfig(f); 37 | if (clobFieldConfig != null) { 38 | String clobFieldName = "clob_" + f.getName(); 39 | return 40 | "Clob " + clobFieldName + " = " + 41 | RESULT_SET_ARGUMENT + ".getClob(\"" + columnName + "\");" + "\n" + 42 | "\t" + "if (" + clobFieldName + " != null)" + "\n" + 43 | "\t" + "{" + "\n" + 44 | "\t" + "\t" + GENERATED_OBJECT_NAME + "." + 45 | setterMethodName + 46 | "(" + 47 | clobFieldName + ".getSubString(1L, (int)" + clobFieldName + ".length())" + 48 | ");"+ "\n" + 49 | "\t" + "}"; 50 | } 51 | else { 52 | return 53 | GENERATED_OBJECT_NAME + "." + 54 | setterMethodName + 55 | "(" + 56 | RESULT_SET_ARGUMENT + ".getString(\"" + columnName + "\")" + 57 | ");"; 58 | } 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/ignore/IgnoreManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.ignore; 18 | 19 | /** 20 | * @author Serkan ÖZAL 21 | */ 22 | public interface IgnoreManager { 23 | 24 | public void enableIgnoreConditionProperty(String propertyName); 25 | public void disableIgnoreConditionProperty(String propertyName); 26 | public void clearIgnoreConditionProperty(String propertyName); 27 | public boolean getIgnoreConditionProperty(String propertyName); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/ignore/IgnoreManagerImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.ignore; 18 | 19 | import java.util.Map; 20 | import java.util.concurrent.ConcurrentHashMap; 21 | 22 | import org.springframework.stereotype.Component; 23 | 24 | /** 25 | * @author Serkan ÖZAL 26 | */ 27 | @Component 28 | public class IgnoreManagerImpl implements IgnoreManager { 29 | 30 | private Map ignoreConditionPropertyMap = new ConcurrentHashMap(); 31 | 32 | @Override 33 | public synchronized void enableIgnoreConditionProperty(String propertyName) { 34 | ignoreConditionPropertyMap.put(propertyName, true); 35 | } 36 | 37 | @Override 38 | public synchronized void disableIgnoreConditionProperty(String propertyName) { 39 | ignoreConditionPropertyMap.put(propertyName, false); 40 | } 41 | 42 | @Override 43 | public synchronized void clearIgnoreConditionProperty(String propertyName) { 44 | ignoreConditionPropertyMap.remove(propertyName); 45 | } 46 | 47 | @Override 48 | public boolean getIgnoreConditionProperty(String propertyName) { 49 | Boolean propertyValue = ignoreConditionPropertyMap.get(propertyName); 50 | if (propertyValue == null) { 51 | return false; 52 | } 53 | else { 54 | return propertyValue; 55 | } 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/ignore/PropertyBasedIgnoreConditionAwareProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.ignore; 18 | 19 | import org.apache.log4j.Logger; 20 | import org.aspectj.lang.ProceedingJoinPoint; 21 | import org.aspectj.lang.annotation.Around; 22 | import org.aspectj.lang.annotation.Aspect; 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.core.Ordered; 25 | import org.springframework.core.annotation.Order; 26 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperPropertyBasedIgnoreConditionAware; 27 | import org.springframework.stereotype.Component; 28 | 29 | /** 30 | * @author Serkan ÖZAL 31 | */ 32 | @Component 33 | @Aspect 34 | @Order(Ordered.HIGHEST_PRECEDENCE) 35 | public class PropertyBasedIgnoreConditionAwareProcessor { 36 | 37 | private static final Logger logger = Logger.getLogger(PropertyBasedIgnoreConditionAwareProcessor.class); 38 | 39 | @Autowired 40 | private IgnoreManager ignoreManager; 41 | 42 | @Around("@annotation(org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperPropertyBasedIgnoreConditionAware)" + 43 | " and args(propertyBasedIgnoreConditionAware)") 44 | public Object propertyBasedIgnoreConditionAwareInterceptor(ProceedingJoinPoint joinPoint, 45 | RowMapperPropertyBasedIgnoreConditionAware propertyBasedIgnoreConditionAware) throws Throwable { 46 | final String propertyName = propertyBasedIgnoreConditionAware.propertyName(); 47 | try { 48 | if ((propertyBasedIgnoreConditionAware.options() & 49 | RowMapperPropertyBasedIgnoreConditionAware.ENABLE_ON_START) > 0) { 50 | ignoreManager.enableIgnoreConditionProperty(propertyName); 51 | if (logger.isDebugEnabled()) { 52 | logger.debug("Enabled property " + propertyName + " on start of " + joinPoint.toLongString()); 53 | } 54 | } 55 | else if ((propertyBasedIgnoreConditionAware.options() & 56 | RowMapperPropertyBasedIgnoreConditionAware.DISABLE_ON_START) > 0) { 57 | ignoreManager.disableIgnoreConditionProperty(propertyName); 58 | if (logger.isDebugEnabled()) { 59 | logger.debug("Disabled property " + propertyName + " on start of " + joinPoint.toLongString()); 60 | } 61 | } 62 | 63 | return joinPoint.proceed(); 64 | } 65 | finally { 66 | if ((propertyBasedIgnoreConditionAware.options() & 67 | RowMapperPropertyBasedIgnoreConditionAware.ENABLE_ON_FINISH) > 0) { 68 | ignoreManager.enableIgnoreConditionProperty(propertyName); 69 | if (logger.isDebugEnabled()) { 70 | logger.debug("Enabled property " + propertyName + " on finish of " + joinPoint.toLongString()); 71 | } 72 | } 73 | else if ((propertyBasedIgnoreConditionAware.options() & 74 | RowMapperPropertyBasedIgnoreConditionAware.DISABLE_ON_FINISH) > 0) { 75 | ignoreManager.disableIgnoreConditionProperty(propertyName); 76 | if (logger.isDebugEnabled()) { 77 | logger.debug("Disabled property " + propertyName + " on finish of " + joinPoint.toLongString()); 78 | } 79 | } 80 | } 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/lazy/LazyManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.lazy; 18 | 19 | /** 20 | * @author Serkan ÖZAL 21 | */ 22 | public interface LazyManager { 23 | 24 | public void enableLazyConditionProperty(String propertyName); 25 | public void disableLazyConditionProperty(String propertyName); 26 | public void clearLazyConditionProperty(String propertyName); 27 | public boolean getLazyConditionProperty(String propertyName); 28 | 29 | public void enableLazyLoadConditionProperty(String propertyName); 30 | public void disableLazyLoadConditionProperty(String propertyName); 31 | public void clearLazyLoadConditionProperty(String propertyName); 32 | public boolean getLazyLoadConditionProperty(String propertyName); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/lazy/LazyManagerImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.lazy; 18 | 19 | import java.util.Map; 20 | import java.util.concurrent.ConcurrentHashMap; 21 | 22 | import org.springframework.stereotype.Component; 23 | 24 | /** 25 | * @author Serkan ÖZAL 26 | */ 27 | @Component 28 | public class LazyManagerImpl implements LazyManager { 29 | 30 | private Map lazyConditionPropertyMap = new ConcurrentHashMap(); 31 | private Map lazyLoadConditionPropertyMap = new ConcurrentHashMap(); 32 | 33 | @Override 34 | public synchronized void enableLazyConditionProperty(String propertyName) { 35 | lazyConditionPropertyMap.put(propertyName, true); 36 | } 37 | 38 | @Override 39 | public synchronized void disableLazyConditionProperty(String propertyName) { 40 | lazyConditionPropertyMap.put(propertyName, false); 41 | } 42 | 43 | @Override 44 | public synchronized void clearLazyConditionProperty(String propertyName) { 45 | lazyConditionPropertyMap.remove(propertyName); 46 | } 47 | 48 | @Override 49 | public boolean getLazyConditionProperty(String propertyName) { 50 | Boolean propertyValue = lazyConditionPropertyMap.get(propertyName); 51 | if (propertyValue == null) { 52 | return false; 53 | } 54 | else { 55 | return propertyValue; 56 | } 57 | } 58 | 59 | @Override 60 | public synchronized void enableLazyLoadConditionProperty(String propertyName) { 61 | lazyLoadConditionPropertyMap.put(propertyName, true); 62 | } 63 | 64 | @Override 65 | public synchronized void disableLazyLoadConditionProperty(String propertyName) { 66 | lazyLoadConditionPropertyMap.put(propertyName, false); 67 | } 68 | 69 | @Override 70 | public synchronized void clearLazyLoadConditionProperty(String propertyName) { 71 | lazyLoadConditionPropertyMap.remove(propertyName); 72 | } 73 | 74 | @Override 75 | public boolean getLazyLoadConditionProperty(String propertyName) { 76 | Boolean propertyValue = lazyLoadConditionPropertyMap.get(propertyName); 77 | if (propertyValue == null) { 78 | return false; 79 | } 80 | else { 81 | return propertyValue; 82 | } 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/lazy/PropertyBasedLazyConditionAwareProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.lazy; 18 | 19 | import org.apache.log4j.Logger; 20 | import org.aspectj.lang.ProceedingJoinPoint; 21 | import org.aspectj.lang.annotation.Around; 22 | import org.aspectj.lang.annotation.Aspect; 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.core.Ordered; 25 | import org.springframework.core.annotation.Order; 26 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperPropertyBasedLazyConditionAware; 27 | import org.springframework.stereotype.Component; 28 | 29 | /** 30 | * @author Serkan ÖZAL 31 | */ 32 | @Component 33 | @Aspect 34 | @Order(Ordered.HIGHEST_PRECEDENCE) 35 | public class PropertyBasedLazyConditionAwareProcessor { 36 | 37 | private static final Logger logger = Logger.getLogger(PropertyBasedLazyConditionAwareProcessor.class); 38 | 39 | @Autowired 40 | private LazyManager lazyManager; 41 | 42 | @Around("@annotation(org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperPropertyBasedLazyConditionAware)" + 43 | " and args(propertyBasedLazyConditionAware)") 44 | public Object propertyBasedLazyConditionAwareInterceptor(ProceedingJoinPoint joinPoint, 45 | RowMapperPropertyBasedLazyConditionAware propertyBasedLazyConditionAware) throws Throwable { 46 | final String propertyName = propertyBasedLazyConditionAware.propertyName(); 47 | try { 48 | if ((propertyBasedLazyConditionAware.options() & 49 | RowMapperPropertyBasedLazyConditionAware.ENABLE_ON_START) > 0) { 50 | lazyManager.enableLazyConditionProperty(propertyName); 51 | if (logger.isDebugEnabled()) { 52 | logger.debug("Enabled property " + propertyName + " on start of " + joinPoint.toLongString()); 53 | } 54 | } 55 | else if ((propertyBasedLazyConditionAware.options() & 56 | RowMapperPropertyBasedLazyConditionAware.DISABLE_ON_START) > 0) { 57 | lazyManager.disableLazyConditionProperty(propertyName); 58 | if (logger.isDebugEnabled()) { 59 | logger.debug("Disabled property " + propertyName + " on start of " + joinPoint.toLongString()); 60 | } 61 | } 62 | 63 | return joinPoint.proceed(); 64 | } 65 | finally { 66 | if ((propertyBasedLazyConditionAware.options() & 67 | RowMapperPropertyBasedLazyConditionAware.ENABLE_ON_FINISH) > 0) { 68 | lazyManager.enableLazyConditionProperty(propertyName); 69 | if (logger.isDebugEnabled()) { 70 | logger.debug("Enabled property " + propertyName + " on finish of " + joinPoint.toLongString()); 71 | } 72 | } 73 | else if ((propertyBasedLazyConditionAware.options() & 74 | RowMapperPropertyBasedLazyConditionAware.DISABLE_ON_FINISH) > 0) { 75 | lazyManager.disableLazyConditionProperty(propertyName); 76 | if (logger.isDebugEnabled()) { 77 | logger.debug("Disabled property " + propertyName + " on finish of " + joinPoint.toLongString()); 78 | } 79 | } 80 | } 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/lazy/PropertyBasedLazyLoadConditionAwareProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.lazy; 18 | 19 | import org.apache.log4j.Logger; 20 | import org.aspectj.lang.ProceedingJoinPoint; 21 | import org.aspectj.lang.annotation.Around; 22 | import org.aspectj.lang.annotation.Aspect; 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.core.Ordered; 25 | import org.springframework.core.annotation.Order; 26 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperPropertyBasedLazyLoadConditionAware; 27 | import org.springframework.stereotype.Component; 28 | 29 | /** 30 | * @author Serkan ÖZAL 31 | */ 32 | @Component 33 | @Aspect 34 | @Order(Ordered.HIGHEST_PRECEDENCE) 35 | public class PropertyBasedLazyLoadConditionAwareProcessor { 36 | 37 | private static final Logger logger = Logger.getLogger(PropertyBasedLazyLoadConditionAwareProcessor.class); 38 | 39 | @Autowired 40 | private LazyManager lazyManager; 41 | 42 | @Around("@annotation(org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperPropertyBasedLazyLoadConditionAware)" + 43 | " and args(propertyBasedLazyLoadConditionAware)") 44 | public Object propertyBasedLazyConditionAwareInterceptor(ProceedingJoinPoint joinPoint, 45 | RowMapperPropertyBasedLazyLoadConditionAware propertyBasedLazyLoadConditionAware) throws Throwable { 46 | final String propertyName = propertyBasedLazyLoadConditionAware.propertyName(); 47 | try { 48 | if ((propertyBasedLazyLoadConditionAware.options() & 49 | RowMapperPropertyBasedLazyLoadConditionAware.ENABLE_ON_START) > 0) { 50 | lazyManager.enableLazyLoadConditionProperty(propertyName); 51 | if (logger.isDebugEnabled()) { 52 | logger.debug("Enabled property " + propertyName + " on start of " + joinPoint.toLongString()); 53 | } 54 | } 55 | else if ((propertyBasedLazyLoadConditionAware.options() & 56 | RowMapperPropertyBasedLazyLoadConditionAware.DISABLE_ON_START) > 0) { 57 | lazyManager.disableLazyLoadConditionProperty(propertyName); 58 | if (logger.isDebugEnabled()) { 59 | logger.debug("Disabled property " + propertyName + " on start of " + joinPoint.toLongString()); 60 | } 61 | } 62 | 63 | return joinPoint.proceed(); 64 | } 65 | finally { 66 | if ((propertyBasedLazyLoadConditionAware.options() & 67 | RowMapperPropertyBasedLazyLoadConditionAware.ENABLE_ON_FINISH) > 0) { 68 | lazyManager.enableLazyLoadConditionProperty(propertyName); 69 | if (logger.isDebugEnabled()) { 70 | logger.debug("Enabled property " + propertyName + " on finish of " + joinPoint.toLongString()); 71 | } 72 | } 73 | else if ((propertyBasedLazyLoadConditionAware.options() & 74 | RowMapperPropertyBasedLazyLoadConditionAware.DISABLE_ON_FINISH) > 0) { 75 | lazyManager.disableLazyLoadConditionProperty(propertyName); 76 | if (logger.isDebugEnabled()) { 77 | logger.debug("Disabled property " + propertyName + " on finish of " + joinPoint.toLongString()); 78 | } 79 | } 80 | } 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/proxy/ProxyHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.proxy; 18 | 19 | import java.util.List; 20 | import java.util.Map; 21 | import java.util.Set; 22 | 23 | import net.sf.cglib.proxy.Enhancer; 24 | 25 | /** 26 | * @author Serkan ÖZAL 27 | */ 28 | public class ProxyHelper { 29 | 30 | @SuppressWarnings("unchecked") 31 | public static T proxyObject(Class clazz, ProxyObjectLoader loader) { 32 | return (T)Enhancer.create(clazz, loader); 33 | } 34 | 35 | @SuppressWarnings("unchecked") 36 | public static List proxyList(ProxyListLoader loader) { 37 | return (List)Enhancer.create(List.class, loader); 38 | } 39 | 40 | @SuppressWarnings("unchecked") 41 | public static Set proxySet(ProxySetLoader loader) { 42 | return (Set)Enhancer.create(Set.class, loader); 43 | } 44 | 45 | @SuppressWarnings("unchecked") 46 | public static Map proxyMap(ProxyMapLoader loader) { 47 | return (Map)Enhancer.create(Map.class, loader); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/proxy/ProxyListLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.proxy; 18 | 19 | import java.lang.reflect.Method; 20 | import java.lang.reflect.Modifier; 21 | import java.util.HashMap; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | import org.springframework.jdbc.roma.api.generator.RowMapperFieldGenerator; 26 | import org.springframework.jdbc.roma.impl.util.RowMapperUtil; 27 | 28 | import javassist.ClassPool; 29 | import javassist.CtClass; 30 | import javassist.CtField; 31 | import javassist.CtMethod; 32 | 33 | import net.sf.cglib.proxy.LazyLoader; 34 | 35 | /** 36 | * @author Serkan ÖZAL 37 | */ 38 | public abstract class ProxyListLoader implements LazyLoader { 39 | 40 | private static final Map>> proxyListLoaderClassMap = 41 | new HashMap>>(); 42 | 43 | public abstract List load(); 44 | 45 | @Override 46 | public Object loadObject() throws Exception { 47 | return load(); 48 | } 49 | 50 | @SuppressWarnings("rawtypes") 51 | public static ProxyListLoader createProxyListLoader(String loadingCode, String classPath, Object[] parameters) { 52 | return createProxyListLoader(null, loadingCode, classPath, parameters); 53 | } 54 | 55 | @SuppressWarnings({ "rawtypes", "unchecked" }) 56 | public static ProxyListLoader createProxyListLoader(String id, String loadingCode, String classPath, Object[] parameters) { 57 | Class> proxyListLoaderClass = null; 58 | if (id != null) { 59 | proxyListLoaderClass = proxyListLoaderClassMap.get(id); 60 | } 61 | try { 62 | if (proxyListLoaderClass == null) { 63 | ClassPool cp = ClassPool.getDefault(); 64 | CtClass generatedCls = cp.makeClass("ProxyListLoader" + RowMapperUtil.generateRandomClassPostFix()); 65 | generatedCls.defrost(); 66 | generatedCls.setSuperclass((cp.get(ProxyListLoader.class.getName()))); 67 | 68 | for (int i = 0; i < parameters.length; i++) { 69 | String fieldName = parameters[i++].toString(); 70 | Object value = parameters[i]; 71 | if (value == null) { 72 | continue; 73 | } 74 | CtField ctf = new CtField(cp.get(value.getClass().getName()), fieldName, generatedCls); 75 | generatedCls.addField(ctf); 76 | String setterName = "set" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); 77 | CtMethod ctfSetter = 78 | new CtMethod( 79 | CtClass.voidType, 80 | setterName, 81 | new CtClass[] {cp.get(value.getClass().getName())}, 82 | generatedCls); 83 | ctfSetter.setModifiers(Modifier.PUBLIC); 84 | String setterBody = 85 | "{" + "\n" + 86 | "\t" + "this." + fieldName + " = " + "$1;" + "\n" + 87 | "}"; 88 | ctfSetter.setBody(setterBody); 89 | generatedCls.addMethod(ctfSetter); 90 | } 91 | 92 | String variablesCode = ""; 93 | int separatorIndex = loadingCode.indexOf(RowMapperFieldGenerator.VARIABLES_AND_CODE_SEPARATOR); 94 | if (separatorIndex > 0) { 95 | variablesCode = loadingCode.substring(0, separatorIndex); 96 | loadingCode = loadingCode.substring(separatorIndex + 97 | RowMapperFieldGenerator.VARIABLES_AND_CODE_SEPARATOR.length()); 98 | } 99 | CtMethod loadMethod = 100 | new CtMethod( 101 | cp.get(List.class.getName()), 102 | "load", 103 | null, 104 | generatedCls); 105 | loadMethod.setModifiers(Modifier.PUBLIC); 106 | String loadMethodBody = 107 | "{" + "\n" + 108 | "\t" + variablesCode + 109 | "\t" + loadingCode + ";" + 110 | "}"; 111 | loadMethod.setBody(loadMethodBody); 112 | generatedCls.addMethod(loadMethod); 113 | 114 | proxyListLoaderClass = generatedCls.toClass(); 115 | 116 | if (id != null) { 117 | proxyListLoaderClassMap.put(id, proxyListLoaderClass); 118 | } 119 | } 120 | 121 | ProxyListLoader pll = (ProxyListLoader)proxyListLoaderClass.newInstance(); 122 | 123 | for (int i = 0; i < parameters.length; i++) { 124 | String fieldName = parameters[i++].toString(); 125 | Object value = parameters[i]; 126 | if (value == null) { 127 | continue; 128 | } 129 | String setterName = "set" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); 130 | Method setterMethod = pll.getClass().getDeclaredMethod(setterName, value.getClass()); 131 | setterMethod.invoke(pll, value); 132 | } 133 | 134 | return pll; 135 | } 136 | catch (Exception e) { 137 | e.printStackTrace(); 138 | return null; 139 | } 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/proxy/ProxyMapLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.proxy; 18 | 19 | import java.lang.reflect.Method; 20 | import java.lang.reflect.Modifier; 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | 24 | import org.springframework.jdbc.roma.api.generator.RowMapperFieldGenerator; 25 | import org.springframework.jdbc.roma.impl.util.RowMapperUtil; 26 | 27 | import javassist.ClassPool; 28 | import javassist.CtClass; 29 | import javassist.CtField; 30 | import javassist.CtMethod; 31 | 32 | import net.sf.cglib.proxy.LazyLoader; 33 | 34 | /** 35 | * @author Serkan ÖZAL 36 | */ 37 | public abstract class ProxyMapLoader implements LazyLoader { 38 | 39 | private static final Map>> proxyMapLoaderClassMap = 40 | new HashMap>>(); 41 | 42 | public abstract Map load(); 43 | 44 | @Override 45 | public Object loadObject() throws Exception { 46 | return load(); 47 | } 48 | 49 | @SuppressWarnings("rawtypes") 50 | public static ProxyMapLoader createProxyMapLoader(String loadingCode, String classPath, Object[] parameters) { 51 | return createProxyMapLoader(null, loadingCode, classPath, parameters); 52 | } 53 | 54 | @SuppressWarnings({ "rawtypes", "unchecked" }) 55 | public static ProxyMapLoader createProxyMapLoader(String id, String loadingCode, String classPath, Object[] parameters) { 56 | Class> proxyMapLoaderClass = null; 57 | if (id != null) { 58 | proxyMapLoaderClass = proxyMapLoaderClassMap.get(id); 59 | } 60 | try { 61 | if (proxyMapLoaderClass == null) { 62 | ClassPool cp = ClassPool.getDefault(); 63 | CtClass generatedCls = cp.makeClass("ProxyMapLoader" + RowMapperUtil.generateRandomClassPostFix()); 64 | generatedCls.defrost(); 65 | generatedCls.setSuperclass((cp.get(ProxyMapLoader.class.getName()))); 66 | 67 | for (int i = 0; i < parameters.length; i++) { 68 | String fieldName = parameters[i++].toString(); 69 | Object value = parameters[i]; 70 | if (value == null) { 71 | continue; 72 | } 73 | CtField ctf = new CtField(cp.get(value.getClass().getName()), fieldName, generatedCls); 74 | generatedCls.addField(ctf); 75 | String setterName = "set" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); 76 | CtMethod ctfMapter = 77 | new CtMethod( 78 | CtClass.voidType, 79 | setterName, 80 | new CtClass[] {cp.get(value.getClass().getName())}, 81 | generatedCls); 82 | ctfMapter.setModifiers(Modifier.PUBLIC); 83 | String setterBody = 84 | "{" + "\n" + 85 | "\t" + "this." + fieldName + " = " + "$1;" + "\n" + 86 | "}"; 87 | ctfMapter.setBody(setterBody); 88 | generatedCls.addMethod(ctfMapter); 89 | } 90 | 91 | String variablesCode = ""; 92 | int separatorIndex = loadingCode.indexOf(RowMapperFieldGenerator.VARIABLES_AND_CODE_SEPARATOR); 93 | if (separatorIndex > 0) { 94 | variablesCode = loadingCode.substring(0, separatorIndex); 95 | loadingCode = loadingCode.substring(separatorIndex + 96 | RowMapperFieldGenerator.VARIABLES_AND_CODE_SEPARATOR.length()); 97 | } 98 | CtMethod loadMethod = 99 | new CtMethod( 100 | cp.get(Map.class.getName()), 101 | "load", 102 | null, 103 | generatedCls); 104 | loadMethod.setModifiers(Modifier.PUBLIC); 105 | String loadMethodBody = 106 | "{" + "\n" + 107 | "\t" + variablesCode + 108 | "\t" + loadingCode + ";" + 109 | "}"; 110 | loadMethod.setBody(loadMethodBody); 111 | generatedCls.addMethod(loadMethod); 112 | 113 | proxyMapLoaderClass = generatedCls.toClass(); 114 | 115 | if (id != null) { 116 | proxyMapLoaderClassMap.put(id, proxyMapLoaderClass); 117 | } 118 | } 119 | 120 | ProxyMapLoader pll = (ProxyMapLoader)proxyMapLoaderClass.newInstance(); 121 | 122 | for (int i = 0; i < parameters.length; i++) { 123 | String fieldName = parameters[i++].toString(); 124 | Object value = parameters[i]; 125 | if (value == null) { 126 | continue; 127 | } 128 | String setterName = "set" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); 129 | Method setterMethod = pll.getClass().getDeclaredMethod(setterName, value.getClass()); 130 | setterMethod.invoke(pll, value); 131 | } 132 | 133 | return pll; 134 | } 135 | catch (Exception e) { 136 | e.printStackTrace(); 137 | return null; 138 | } 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/proxy/ProxyObjectLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.proxy; 18 | 19 | import java.lang.reflect.Method; 20 | import java.lang.reflect.Modifier; 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | 24 | import org.springframework.jdbc.roma.api.generator.RowMapperFieldGenerator; 25 | import org.springframework.jdbc.roma.impl.util.RowMapperUtil; 26 | 27 | import javassist.ClassPool; 28 | import javassist.CtClass; 29 | import javassist.CtField; 30 | import javassist.CtMethod; 31 | 32 | import net.sf.cglib.proxy.LazyLoader; 33 | 34 | /** 35 | * @author Serkan ÖZAL 36 | */ 37 | public abstract class ProxyObjectLoader implements LazyLoader { 38 | 39 | private static final Map>> proxyObjectLoaderClassMap = 40 | new HashMap>>(); 41 | 42 | public abstract T load(); 43 | 44 | @Override 45 | public T loadObject() throws Exception { 46 | return load(); 47 | } 48 | 49 | @SuppressWarnings("rawtypes") 50 | public static ProxyObjectLoader createProxyObjectLoader(String loadingCode, String classPath, Object[] parameters) { 51 | return createProxyObjectLoader(null, loadingCode, classPath, parameters); 52 | } 53 | 54 | @SuppressWarnings({ "rawtypes", "unchecked" }) 55 | public static ProxyObjectLoader createProxyObjectLoader(String id, String loadingCode, String classPath, Object[] parameters) { 56 | Class> proxyObjectLoaderClass = null; 57 | if (id != null) { 58 | proxyObjectLoaderClass = proxyObjectLoaderClassMap.get(id); 59 | } 60 | try { 61 | if (proxyObjectLoaderClass == null) { 62 | ClassPool cp = ClassPool.getDefault(); 63 | CtClass generatedCls = cp.makeClass("ProxyObjectLoader" + RowMapperUtil.generateRandomClassPostFix()); 64 | generatedCls.defrost(); 65 | generatedCls.setSuperclass((cp.get(ProxyObjectLoader.class.getName()))); 66 | 67 | for (int i = 0; i < parameters.length; i++) { 68 | String fieldName = parameters[i++].toString(); 69 | Object value = parameters[i]; 70 | if (value == null) { 71 | continue; 72 | } 73 | CtField ctf = new CtField(cp.get(value.getClass().getName()), fieldName, generatedCls); 74 | generatedCls.addField(ctf); 75 | String setterName = "set" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); 76 | CtMethod ctfSetter = 77 | new CtMethod( 78 | CtClass.voidType, 79 | setterName, 80 | new CtClass[] {cp.get(value.getClass().getName())}, 81 | generatedCls); 82 | ctfSetter.setModifiers(Modifier.PUBLIC); 83 | String setterBody = 84 | "{" + "\n" + 85 | "\t" + "this." + fieldName + " = " + "$1;" + "\n" + 86 | "}"; 87 | ctfSetter.setBody(setterBody); 88 | generatedCls.addMethod(ctfSetter); 89 | } 90 | 91 | String variablesCode = ""; 92 | int separatorIndex = loadingCode.indexOf(RowMapperFieldGenerator.VARIABLES_AND_CODE_SEPARATOR); 93 | if (separatorIndex > 0) { 94 | variablesCode = loadingCode.substring(0, separatorIndex); 95 | loadingCode = loadingCode.substring(separatorIndex + 96 | RowMapperFieldGenerator.VARIABLES_AND_CODE_SEPARATOR.length()); 97 | } 98 | CtMethod loadMethod = 99 | new CtMethod( 100 | cp.get(Object.class.getName()), 101 | "load", 102 | new CtClass[] {}, 103 | generatedCls); 104 | loadMethod.setModifiers(Modifier.PUBLIC); 105 | String body = 106 | "{" + "\n" + 107 | "\t" + variablesCode + 108 | "\t" + loadingCode + ";" + "\n" + 109 | "}"; 110 | loadMethod.setBody(body); 111 | generatedCls.addMethod(loadMethod); 112 | 113 | proxyObjectLoaderClass = generatedCls.toClass(); 114 | 115 | if (id != null) { 116 | proxyObjectLoaderClassMap.put(id, proxyObjectLoaderClass); 117 | } 118 | } 119 | 120 | ProxyObjectLoader pol = proxyObjectLoaderClass.newInstance(); 121 | 122 | for (int i = 0; i < parameters.length; i++) { 123 | String fieldName = parameters[i++].toString(); 124 | Object value = parameters[i]; 125 | if (value == null) { 126 | continue; 127 | } 128 | String setterName = "set" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); 129 | Method setterMethod = 130 | pol.getClass().getDeclaredMethod(setterName, value.getClass()); 131 | setterMethod.invoke(pol, value); 132 | } 133 | 134 | return pol; 135 | } 136 | catch (Exception e) { 137 | e.printStackTrace(); 138 | return null; 139 | } 140 | } 141 | 142 | } -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/proxy/ProxySetLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.proxy; 18 | 19 | import java.lang.reflect.Method; 20 | import java.lang.reflect.Modifier; 21 | import java.util.HashMap; 22 | import java.util.Set; 23 | import java.util.Map; 24 | 25 | import org.springframework.jdbc.roma.api.generator.RowMapperFieldGenerator; 26 | import org.springframework.jdbc.roma.impl.util.RowMapperUtil; 27 | 28 | import javassist.ClassPool; 29 | import javassist.CtClass; 30 | import javassist.CtField; 31 | import javassist.CtMethod; 32 | 33 | import net.sf.cglib.proxy.LazyLoader; 34 | 35 | /** 36 | * @author Serkan ÖZAL 37 | */ 38 | public abstract class ProxySetLoader implements LazyLoader { 39 | 40 | private static final Map>> proxySetLoaderClassMap = 41 | new HashMap>>(); 42 | 43 | public abstract Set load(); 44 | 45 | @Override 46 | public Object loadObject() throws Exception { 47 | return load(); 48 | } 49 | 50 | @SuppressWarnings("rawtypes") 51 | public static ProxySetLoader createProxySetLoader(String loadingCode, String classPath, Object[] parameters) { 52 | return createProxySetLoader(null, loadingCode, classPath, parameters); 53 | } 54 | 55 | @SuppressWarnings({ "rawtypes", "unchecked" }) 56 | public static ProxySetLoader createProxySetLoader(String id, String loadingCode, String classPath, Object[] parameters) { 57 | Class> proxySetLoaderClass = null; 58 | if (id != null) { 59 | proxySetLoaderClass = proxySetLoaderClassMap.get(id); 60 | } 61 | try { 62 | if (proxySetLoaderClass == null) { 63 | ClassPool cp = ClassPool.getDefault(); 64 | CtClass generatedCls = cp.makeClass("ProxySetLoader" + RowMapperUtil.generateRandomClassPostFix()); 65 | generatedCls.defrost(); 66 | generatedCls.setSuperclass((cp.get(ProxySetLoader.class.getName()))); 67 | 68 | for (int i = 0; i < parameters.length; i++) { 69 | String fieldName = parameters[i++].toString(); 70 | Object value = parameters[i]; 71 | if (value == null) { 72 | continue; 73 | } 74 | CtField ctf = new CtField(cp.get(value.getClass().getName()), fieldName, generatedCls); 75 | generatedCls.addField(ctf); 76 | String setterName = "set" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); 77 | CtMethod ctfSetter = 78 | new CtMethod( 79 | CtClass.voidType, 80 | setterName, 81 | new CtClass[] {cp.get(value.getClass().getName())}, 82 | generatedCls); 83 | ctfSetter.setModifiers(Modifier.PUBLIC); 84 | String setterBody = 85 | "{" + "\n" + 86 | "\t" + "this." + fieldName + " = " + "$1;" + "\n" + 87 | "}"; 88 | ctfSetter.setBody(setterBody); 89 | generatedCls.addMethod(ctfSetter); 90 | } 91 | 92 | String variablesCode = ""; 93 | int separatorIndex = loadingCode.indexOf(RowMapperFieldGenerator.VARIABLES_AND_CODE_SEPARATOR); 94 | if (separatorIndex > 0) { 95 | variablesCode = loadingCode.substring(0, separatorIndex); 96 | loadingCode = loadingCode.substring(separatorIndex + 97 | RowMapperFieldGenerator.VARIABLES_AND_CODE_SEPARATOR.length()); 98 | } 99 | CtMethod loadMethod = 100 | new CtMethod( 101 | cp.get(Set.class.getName()), 102 | "load", 103 | null, 104 | generatedCls); 105 | loadMethod.setModifiers(Modifier.PUBLIC); 106 | String loadMethodBody = 107 | "{" + "\n" + 108 | "\t" + variablesCode + 109 | "\t" + loadingCode + ";" + 110 | "}"; 111 | loadMethod.setBody(loadMethodBody); 112 | generatedCls.addMethod(loadMethod); 113 | 114 | proxySetLoaderClass = generatedCls.toClass(); 115 | 116 | if (id != null) { 117 | proxySetLoaderClassMap.put(id, proxySetLoaderClass); 118 | } 119 | } 120 | 121 | ProxySetLoader pll = (ProxySetLoader)proxySetLoaderClass.newInstance(); 122 | 123 | for (int i = 0; i < parameters.length; i++) { 124 | String fieldName = parameters[i++].toString(); 125 | Object value = parameters[i]; 126 | if (value == null) { 127 | continue; 128 | } 129 | String setterName = "set" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); 130 | Method setterMethod = pll.getClass().getDeclaredMethod(setterName, value.getClass()); 131 | setterMethod.invoke(pll, value); 132 | } 133 | 134 | return pll; 135 | } 136 | catch (Exception e) { 137 | e.printStackTrace(); 138 | return null; 139 | } 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/resolver/DefaultColumnNameResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.resolver; 18 | 19 | import java.lang.reflect.Field; 20 | import java.lang.reflect.Modifier; 21 | import java.sql.Connection; 22 | import java.sql.DatabaseMetaData; 23 | import java.sql.ResultSet; 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | import java.util.Locale; 27 | 28 | import javax.sql.DataSource; 29 | 30 | import org.apache.log4j.Logger; 31 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 32 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperClass.RowMapperColumnNameResolver; 33 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperClass.RowMapperTableNameResolver; 34 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperClassConfig; 35 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperFieldConfig; 36 | import org.springframework.jdbc.roma.impl.util.BeanUtil; 37 | import org.springframework.jdbc.roma.impl.util.InstanceUtil; 38 | import org.springframework.jdbc.roma.impl.util.RowMapperUtil; 39 | import org.springframework.jdbc.roma.impl.util.SpringUtil; 40 | import org.springframework.util.StringUtils; 41 | 42 | /** 43 | * @author Serkan ÖZAL 44 | */ 45 | public class DefaultColumnNameResolver implements RowMapperColumnNameResolver { 46 | 47 | protected static final Logger logger = Logger.getLogger(DefaultColumnNameResolver.class); 48 | 49 | protected ConfigManager configManager = BeanUtil.getInstance().getConfigManager(); 50 | protected RowMapperTableNameResolver tableNameResolver = new DefaultTableNameResolver(); 51 | 52 | @Override 53 | public String resolveColumnName(Field f) { 54 | Connection connection = null; 55 | 56 | try { 57 | f.setAccessible(true); 58 | RowMapperFieldConfig rmfc = configManager.getRowMapperFieldConfig(f); 59 | if (rmfc != null && StringUtils.isEmpty(rmfc.getColumnName()) == false) { 60 | logger.debug("Column name " + rmfc.getColumnName() + 61 | "found from field config for field "+ f.getName() + 62 | " in class " + f.getDeclaringClass().getName()); 63 | return rmfc.getColumnName(); 64 | } 65 | else if (Modifier.isTransient(f.getModifiers())) { 66 | logger.debug("Field " + f.getName() + " in class " + f.getDeclaringClass().getName() + 67 | " is transient and it is being ignored"); 68 | return null; 69 | } 70 | else { 71 | RowMapperClassConfig rmcc = configManager.getRowMapperClassConfig(f.getDeclaringClass()); 72 | if (rmcc == null) { 73 | logger.debug("Unable to find class config for class " + f.getDeclaringClass().getName()); 74 | } 75 | 76 | Class tableNameResolverClass = 77 | rmcc != null ? rmcc.getTableNameResolverClass() : null; 78 | if (tableNameResolverClass != null) { 79 | RowMapperTableNameResolver tnr = InstanceUtil.getSingleInstance(tableNameResolverClass); 80 | if (tnr != null) { 81 | tableNameResolver = tnr; 82 | } 83 | } 84 | String dataSourceName = rmcc != null ? rmcc.getDataSourceName() : null; 85 | if (StringUtils.isEmpty(dataSourceName)) { 86 | dataSourceName = 87 | BeanUtil.getInstance().getConfigManager(). 88 | getDefaultConfigs().getDefaultDataSourceName(); 89 | } 90 | if (StringUtils.isEmpty(dataSourceName)) { 91 | logger.debug("Datasource name is empty"); 92 | return null; 93 | } 94 | 95 | String schemaName = rmcc != null ? rmcc.getSchemaName() : null; 96 | if (StringUtils.isEmpty(schemaName)) { 97 | schemaName = 98 | BeanUtil.getInstance().getConfigManager(). 99 | getDefaultConfigs().getDefaultSchemaName(); 100 | } 101 | 102 | String tableName = tableNameResolver.resolveTableName(f.getDeclaringClass()); 103 | if (StringUtils.isEmpty(tableName)) { 104 | logger.debug("Table name is empty"); 105 | return null; 106 | } 107 | 108 | DataSource ds = SpringUtil.getBean(dataSourceName); 109 | if (ds == null) { 110 | logger.error("Unable to find datasource " + dataSourceName); 111 | return null; 112 | } 113 | 114 | try { 115 | connection = ds.getConnection(); 116 | } 117 | catch (Throwable t) { 118 | logger.error("Unable to get connection from datasource " + dataSourceName, t); 119 | return null; 120 | } 121 | 122 | DatabaseMetaData dsMetadata = null; 123 | try { 124 | dsMetadata = connection.getMetaData(); 125 | } 126 | catch (Throwable t) { 127 | logger.error("Unable to get metadata from datasource " + dataSourceName, t); 128 | return null; 129 | } 130 | 131 | ResultSet resultSet = null; 132 | try { 133 | if (StringUtils.isEmpty(schemaName)) { 134 | resultSet = dsMetadata.getColumns(null, null, tableName.toUpperCase(Locale.ENGLISH), null); 135 | } 136 | else { 137 | resultSet = dsMetadata.getColumns(null, schemaName, tableName.toUpperCase(Locale.ENGLISH), null); 138 | } 139 | } 140 | catch (Throwable t) { 141 | logger.error("Unable to get columns of table " + tableName, t); 142 | return null; 143 | } 144 | 145 | List columnNames = new ArrayList(); 146 | try { 147 | while (resultSet.next()) { 148 | String columnName = resultSet.getString("COLUMN_NAME"); 149 | columnNames.add(columnName); 150 | } 151 | } 152 | catch (Throwable t) { 153 | logger.error("Unable to get columns of table " + tableName, t); 154 | return null; 155 | } 156 | 157 | List possibleColumnNames = RowMapperUtil.generatePossibleColumnNames(f); 158 | if (possibleColumnNames != null) { 159 | for (String possibleColumnName : possibleColumnNames) { 160 | if (columnNames.contains(possibleColumnName)) { 161 | return possibleColumnName; 162 | } 163 | } 164 | } 165 | 166 | return null; 167 | } 168 | } 169 | finally { 170 | if (connection != null) { 171 | try { 172 | connection.close(); 173 | } 174 | catch (Throwable t) { 175 | logger.error("Error occured while closing connection", t); 176 | } 177 | } 178 | } 179 | } 180 | 181 | } 182 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/resolver/DefaultTableNameResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.resolver; 18 | 19 | import java.sql.Connection; 20 | import java.sql.DatabaseMetaData; 21 | import java.sql.ResultSet; 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | import javax.sql.DataSource; 26 | 27 | import org.apache.log4j.Logger; 28 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 29 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperClass.RowMapperTableNameResolver; 30 | import org.springframework.jdbc.roma.api.domain.model.config.RowMapperClassConfig; 31 | import org.springframework.jdbc.roma.impl.util.BeanUtil; 32 | import org.springframework.jdbc.roma.impl.util.RowMapperUtil; 33 | import org.springframework.jdbc.roma.impl.util.SpringUtil; 34 | import org.springframework.util.StringUtils; 35 | 36 | /** 37 | * @author Serkan ÖZAL 38 | */ 39 | public class DefaultTableNameResolver implements RowMapperTableNameResolver { 40 | 41 | protected static final Logger logger = Logger.getLogger(DefaultTableNameResolver.class); 42 | 43 | protected ConfigManager configManager = BeanUtil.getInstance().getConfigManager(); 44 | 45 | @Override 46 | public String resolveTableName(Class clazz) { 47 | Connection connection = null; 48 | try { 49 | RowMapperClassConfig rmcc = configManager.getRowMapperClassConfig(clazz); 50 | if (rmcc == null) { 51 | logger.debug("Unable to find class config for class " + clazz.getName()); 52 | } 53 | 54 | String dataSourceName = rmcc != null ? rmcc.getDataSourceName() : null; 55 | if (StringUtils.isEmpty(dataSourceName)) { 56 | dataSourceName = 57 | BeanUtil.getInstance().getConfigManager(). 58 | getDefaultConfigs().getDefaultDataSourceName(); 59 | } 60 | if (StringUtils.isEmpty(dataSourceName)) { 61 | logger.debug("Datasource name is empty"); 62 | return null; 63 | } 64 | 65 | String schemaName = rmcc != null ? rmcc.getSchemaName() : null; 66 | if (StringUtils.isEmpty(schemaName)) { 67 | schemaName = 68 | BeanUtil.getInstance().getConfigManager(). 69 | getDefaultConfigs().getDefaultSchemaName(); 70 | } 71 | 72 | String tableName = rmcc != null ? rmcc.getTableName() : null; 73 | if (StringUtils.isEmpty(tableName) == false) { 74 | return tableName; 75 | } 76 | 77 | DataSource ds = SpringUtil.getBean(dataSourceName); 78 | if (ds == null) { 79 | logger.error("Unable to find datasource " + dataSourceName); 80 | return null; 81 | } 82 | 83 | try { 84 | connection = ds.getConnection(); 85 | } 86 | catch (Throwable t) { 87 | logger.error("Unable to get connection from datasource " + dataSourceName, t); 88 | return null; 89 | } 90 | 91 | DatabaseMetaData dsMetadata = null; 92 | try { 93 | dsMetadata = connection.getMetaData(); 94 | } 95 | catch (Throwable t) { 96 | logger.error("Unable to get metadata from datasource " + dataSourceName, t); 97 | return null; 98 | } 99 | 100 | ResultSet resultSet = null; 101 | try { 102 | if (StringUtils.isEmpty(schemaName)) { 103 | resultSet = dsMetadata.getTables(null, null, "%", new String[] {"TABLE"}); 104 | } 105 | else { 106 | resultSet = dsMetadata.getTables(null, schemaName, "%", new String[] {"TABLE"}); 107 | } 108 | } 109 | catch (Throwable t) { 110 | logger.error("Unable to get tables of datasource" + dataSourceName, t); 111 | return null; 112 | } 113 | 114 | List tableNames = new ArrayList(); 115 | try { 116 | while (resultSet.next()) { 117 | String tblName = resultSet.getString("TABLE_NAME"); 118 | tableNames.add(tblName); 119 | } 120 | } 121 | catch (Throwable t) { 122 | logger.error("Unable to get tables of datasource" + dataSourceName, t); 123 | return null; 124 | } 125 | 126 | List possibleTableNames = RowMapperUtil.generatePossibleTableNames(clazz); 127 | if (possibleTableNames != null) { 128 | for (String possibleTableName : possibleTableNames) { 129 | if (tableNames.contains(possibleTableName)) { 130 | return possibleTableName; 131 | } 132 | } 133 | } 134 | 135 | return null; 136 | } 137 | finally { 138 | if (connection != null) { 139 | try { 140 | connection.close(); 141 | } 142 | catch (Throwable t) { 143 | logger.error("Error occured while closing connection", t); 144 | } 145 | } 146 | } 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/service/RowMapperService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.service; 18 | 19 | import org.springframework.jdbc.core.JdbcTemplate; 20 | import org.springframework.jdbc.core.RowMapper; 21 | 22 | /** 23 | * @author Serkan ÖZAL 24 | */ 25 | public interface RowMapperService { 26 | 27 | public RowMapper getRowMapper(Class clazz); 28 | public RowMapper getRowMapper(Class clazz, JdbcTemplate jdbcTemplate); 29 | 30 | public void enableLazyConditionProperty(String propertyName); 31 | public void disableLazyConditionProperty(String propertyName); 32 | 33 | public void enableLazyLoadConditionProperty(String propertyName); 34 | public void disableLazyLoadConditionProperty(String propertyName); 35 | 36 | public void enableIgnoreConditionProperty(String propertyName); 37 | public void disableIgnoreConditionProperty(String propertyName); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/service/RowMapperServiceImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.service; 18 | 19 | import java.util.Map; 20 | import java.util.concurrent.ConcurrentHashMap; 21 | 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.context.annotation.DependsOn; 24 | import org.springframework.jdbc.core.JdbcTemplate; 25 | import org.springframework.jdbc.core.RowMapper; 26 | import org.springframework.jdbc.roma.impl.factory.RowMapperFactoryProvider; 27 | import org.springframework.jdbc.roma.impl.ignore.IgnoreManager; 28 | import org.springframework.jdbc.roma.impl.lazy.LazyManager; 29 | import org.springframework.jdbc.roma.impl.util.BeanUtil; 30 | import org.springframework.stereotype.Service; 31 | 32 | /** 33 | * @author Serkan ÖZAL 34 | */ 35 | @Service("rowMapperService") 36 | @DependsOn({"springUtil", "beanUtil"}) 37 | public class RowMapperServiceImpl implements RowMapperService { 38 | 39 | @Autowired 40 | private LazyManager lazyManager; 41 | @Autowired 42 | private IgnoreManager ignoreManager; 43 | 44 | private Map, RowMapper> cachedRowMappers = new ConcurrentHashMap, RowMapper>(); 45 | 46 | @SuppressWarnings("unchecked") 47 | @Override 48 | public RowMapper getRowMapper(Class clazz) { 49 | RowMapper rowMapper = (RowMapper) cachedRowMappers.get(clazz); 50 | if (rowMapper == null) { 51 | rowMapper = 52 | RowMapperFactoryProvider.getRowMapperFactory(). 53 | getRowMapper(clazz, BeanUtil.getInstance().getConfigManager()); 54 | cachedRowMappers.put(clazz, rowMapper); 55 | } 56 | return rowMapper; 57 | } 58 | 59 | @SuppressWarnings("unchecked") 60 | @Override 61 | public RowMapper getRowMapper(Class clazz, JdbcTemplate jdbcTemplate) { 62 | RowMapper rowMapper = (RowMapper) cachedRowMappers.get(clazz); 63 | if (rowMapper == null) { 64 | rowMapper = 65 | RowMapperFactoryProvider.getRowMapperFactory().getRowMapper(clazz, jdbcTemplate); 66 | cachedRowMappers.put(clazz, rowMapper); 67 | } 68 | return rowMapper; 69 | } 70 | 71 | @Override 72 | public void enableLazyConditionProperty(String propertyName) { 73 | lazyManager.enableLazyConditionProperty(propertyName); 74 | } 75 | 76 | @Override 77 | public void disableLazyConditionProperty(String propertyName) { 78 | lazyManager.disableLazyConditionProperty(propertyName); 79 | } 80 | 81 | @Override 82 | public void enableLazyLoadConditionProperty(String propertyName) { 83 | lazyManager.enableLazyLoadConditionProperty(propertyName); 84 | } 85 | 86 | @Override 87 | public void disableLazyLoadConditionProperty(String propertyName) { 88 | lazyManager.disableLazyLoadConditionProperty(propertyName); 89 | } 90 | 91 | @Override 92 | public void enableIgnoreConditionProperty(String propertyName) { 93 | ignoreManager.enableIgnoreConditionProperty(propertyName); 94 | } 95 | 96 | @Override 97 | public void disableIgnoreConditionProperty(String propertyName) { 98 | ignoreManager.disableIgnoreConditionProperty(propertyName); 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/util/BeanUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.util; 18 | 19 | import javax.annotation.PostConstruct; 20 | 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.jdbc.roma.api.config.manager.ConfigManager; 23 | import org.springframework.jdbc.roma.impl.ignore.IgnoreManager; 24 | import org.springframework.jdbc.roma.impl.lazy.LazyManager; 25 | import org.springframework.jdbc.roma.impl.service.RowMapperService; 26 | import org.springframework.stereotype.Component; 27 | 28 | /** 29 | * @author Serkan ÖZAL 30 | */ 31 | @Component 32 | public class BeanUtil { 33 | 34 | private static BeanUtil instance; 35 | 36 | @Autowired 37 | private RowMapperService rowMapperService; 38 | @Autowired 39 | private ConfigManager configManager; 40 | @Autowired 41 | private LazyManager lazyManager; 42 | @Autowired 43 | private IgnoreManager ignoreManager; 44 | 45 | @PostConstruct 46 | protected void afterPropertiesSet() { 47 | instance = this; 48 | } 49 | 50 | public static BeanUtil getInstance() { 51 | return instance; 52 | } 53 | 54 | public RowMapperService getRowMapperService() { 55 | return rowMapperService; 56 | } 57 | 58 | public ConfigManager getConfigManager() { 59 | return configManager; 60 | } 61 | 62 | public LazyManager getLazyManager() { 63 | return lazyManager; 64 | } 65 | 66 | public IgnoreManager getIgnoreManager() { 67 | return ignoreManager; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/util/InstanceUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.util; 18 | 19 | import java.util.Map; 20 | import java.util.concurrent.ConcurrentHashMap; 21 | 22 | import org.apache.log4j.Logger; 23 | 24 | /** 25 | * @author Serkan ÖZAL 26 | */ 27 | public class InstanceUtil { 28 | 29 | private static final Logger logger = Logger.getLogger(InstanceUtil.class); 30 | 31 | private static final Map, Object> singleInstances = new ConcurrentHashMap, Object>(); 32 | 33 | private InstanceUtil() { 34 | 35 | } 36 | 37 | public static T getPrototypeInstance(Class clazz) { 38 | try { 39 | return clazz.newInstance(); 40 | } 41 | catch (Throwable t) { 42 | logger.error("Unable to create instance of class " + clazz.getSimpleName(), t); 43 | return null; 44 | } 45 | } 46 | 47 | @SuppressWarnings("unchecked") 48 | public static T getSingleInstance(Class clazz) { 49 | try { 50 | T instance = (T) singleInstances.get(clazz); 51 | if (instance == null) { 52 | instance = clazz.newInstance(); 53 | singleInstances.put(clazz, instance); 54 | } 55 | return instance; 56 | } 57 | catch (Throwable t) { 58 | logger.error("Unable to create instance of class " + clazz.getSimpleName(), t); 59 | return null; 60 | } 61 | } 62 | 63 | public static T getInstance(Class clazz, boolean single) { 64 | if (single) { 65 | return getSingleInstance(clazz); 66 | } 67 | else { 68 | return getPrototypeInstance(clazz); 69 | } 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/util/JdbcUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.util; 18 | 19 | import java.util.List; 20 | import java.util.Map; 21 | import java.util.concurrent.ConcurrentHashMap; 22 | 23 | import javax.sql.DataSource; 24 | 25 | import org.apache.log4j.Logger; 26 | import org.springframework.jdbc.core.JdbcTemplate; 27 | import org.springframework.jdbc.core.RowMapper; 28 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperSqlProvider.SqlQueryInfo; 29 | import org.springframework.util.StringUtils; 30 | 31 | /** 32 | * @author Serkan ÖZAL 33 | */ 34 | public class JdbcUtil { 35 | 36 | private static final Logger logger = Logger.getLogger(JdbcUtil.class); 37 | 38 | private static final Map jdbcTemplates = new ConcurrentHashMap(); 39 | 40 | private JdbcUtil() { 41 | 42 | } 43 | 44 | public static JdbcTemplate getJdbcTemplate(String dataSourceName) { 45 | JdbcTemplate jdbcTemplate = jdbcTemplates.get(dataSourceName); 46 | if (jdbcTemplate == null) { 47 | if (StringUtils.isEmpty(dataSourceName) || dataSourceName.equals("null")) { 48 | dataSourceName = 49 | BeanUtil.getInstance().getConfigManager(). 50 | getDefaultConfigs().getDefaultDataSourceName(); 51 | } 52 | if (StringUtils.isEmpty(dataSourceName)) { 53 | logger.debug("Datasource name is empty"); 54 | return null; 55 | } 56 | 57 | DataSource ds = SpringUtil.getBean(dataSourceName); 58 | if (ds == null) { 59 | logger.error("Unable to find datasource " + dataSourceName); 60 | return null; 61 | } 62 | 63 | jdbcTemplate = new JdbcTemplate(ds); 64 | jdbcTemplates.put(dataSourceName, jdbcTemplate); 65 | } 66 | return jdbcTemplate; 67 | } 68 | 69 | @SuppressWarnings({ "unchecked", "deprecation" }) 70 | public static T runSql(Class fieldType, JdbcTemplate jdbcTemplate, String sql, Object[] args, RowMapper rowMapper) { 71 | if (fieldType.equals(int.class) || fieldType.equals(Integer.class)) { 72 | return (T)(Integer)jdbcTemplate.queryForInt(sql, args); 73 | } 74 | else if (fieldType.equals(long.class) || fieldType.equals(Long.class)) { 75 | return (T)(Long)jdbcTemplate.queryForLong(sql, args); 76 | } 77 | else if (List.class.isAssignableFrom(fieldType)) { 78 | return (T)jdbcTemplate.query(sql, args, rowMapper); 79 | } 80 | else { 81 | return (T)jdbcTemplate.queryForObject(sql, args, rowMapper); 82 | } 83 | } 84 | 85 | public static T runSql(Class fieldType, JdbcTemplate jdbcTemplate, SqlQueryInfo sqlQueryInfo, RowMapper rowMapper) { 86 | return runSql(fieldType, jdbcTemplate, sqlQueryInfo.sqlQuery, sqlQueryInfo.args, rowMapper); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/util/RowMapperUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.util; 18 | 19 | import java.lang.reflect.Field; 20 | import java.lang.reflect.Method; 21 | import java.sql.ResultSet; 22 | import java.sql.ResultSetMetaData; 23 | import java.util.ArrayList; 24 | import java.util.Arrays; 25 | import java.util.List; 26 | import java.util.UUID; 27 | 28 | import org.apache.log4j.Logger; 29 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperIgnoreField; 30 | 31 | /** 32 | * @author Serkan ÖZAL 33 | */ 34 | public class RowMapperUtil { 35 | 36 | private static final Logger logger = Logger.getLogger(RowMapperUtil.class); 37 | 38 | private RowMapperUtil() { 39 | 40 | } 41 | 42 | public static String getRowMapperArgumentExpression(int argNo) { 43 | return "$" + argNo; 44 | } 45 | 46 | public static String generateRandomClassPostFix() { 47 | return UUID.randomUUID().toString().replace("-", "-"); 48 | } 49 | 50 | public static String getColumnClassName(ResultSet rs, String columnName) { 51 | try { 52 | ResultSetMetaData metadata = rs.getMetaData(); 53 | int columnIndex = rs.findColumn(columnName); 54 | return metadata.getColumnClassName(columnIndex); 55 | } 56 | catch (Throwable t) { 57 | logger.error("Unable to get column class name for column " + columnName, t); 58 | return null; 59 | } 60 | } 61 | 62 | public static String generateGetterMethodName(Field field) { 63 | String fieldName = field.getName(); 64 | return "get" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); 65 | } 66 | 67 | public static String generateSetterMethodName(Field field) { 68 | String fieldName = field.getName(); 69 | return "set" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); 70 | } 71 | 72 | public static Class getFieldTypeFromSetterMethod(Field field, Class clazz) { 73 | String setterMethodName = generateSetterMethodName(field); 74 | Method setterMethod = ReflectionUtil.getMethod(clazz, setterMethodName); 75 | if (setterMethod == null) { 76 | return null; 77 | } 78 | Class[] parameterTypes = setterMethod.getParameterTypes(); 79 | if (parameterTypes.length != 1) { 80 | return null; 81 | } 82 | return parameterTypes[0]; 83 | } 84 | 85 | public static List getAllRowMapperFields(Class cls) { 86 | List fields = ReflectionUtil.getAllFields(cls, false, false, false, null); 87 | if (fields != null) { 88 | List processedFields = new ArrayList(); 89 | for (Field field : fields) { 90 | if (field.isAnnotationPresent(RowMapperIgnoreField.class) == false) { 91 | processedFields.add(field); 92 | } 93 | } 94 | return processedFields; 95 | } 96 | else { 97 | return null; 98 | } 99 | } 100 | 101 | public static List generatePossibleColumnNames(Field f) { 102 | return generatePossibleNames(f.getName()); 103 | } 104 | 105 | public static List generatePossibleTableNames(Class clazz) { 106 | return generatePossibleNames(clazz.getSimpleName()); 107 | } 108 | 109 | public static List generatePossibleNames(String name) { 110 | StringBuilder name1 = new StringBuilder(); 111 | StringBuilder name2 = new StringBuilder(); 112 | StringBuilder name3 = new StringBuilder(); 113 | StringBuilder name4 = new StringBuilder(); 114 | StringBuilder name5 = new StringBuilder(); 115 | StringBuilder name6 = new StringBuilder(); 116 | 117 | boolean previousIsLowerCase = false; 118 | boolean previousIsAlphabetic = false; 119 | for (int i = 0; i < name.length(); i++) { 120 | char c = name.charAt(i); 121 | 122 | boolean currentIsLowerCase = Character.isLowerCase(c); 123 | boolean currentIsAlphabetic = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); 124 | 125 | name1.append(c); 126 | name2.append(Character.toLowerCase(c)); 127 | name3.append(Character.toUpperCase(c)); 128 | 129 | if ( (previousIsAlphabetic && currentIsAlphabetic) && 130 | previousIsLowerCase == true && 131 | currentIsLowerCase == false) { 132 | name4.append("_"); 133 | name5.append("_"); 134 | name6.append("_"); 135 | } 136 | 137 | name4.append(c); 138 | name5.append(Character.toLowerCase(c)); 139 | name6.append(Character.toUpperCase(c)); 140 | 141 | previousIsLowerCase = currentIsLowerCase; 142 | previousIsAlphabetic = currentIsAlphabetic; 143 | } 144 | 145 | return 146 | Arrays.asList( 147 | name1.toString(), 148 | name2.toString(), 149 | name3.toString(), 150 | name4.toString(), 151 | name5.toString(), 152 | name6.toString()); 153 | } 154 | 155 | public static String generateGetInstanceCode(Class clazz, boolean single) { 156 | return 157 | "(" + 158 | "(" + clazz.getName() + ")" + 159 | "InstanceUtil.getInstance" + "(" + clazz.getName() + ".class" + ", " + single + ")" + 160 | ")"; 161 | } 162 | 163 | public static String generateGetPrototypeInstanceCode(Class clazz) { 164 | return 165 | "(" + 166 | "(" + clazz.getName() + ")" + 167 | "InstanceUtil.getSingleInstance" + "(" + clazz.getName() + ".class" + ")" + 168 | ")"; 169 | } 170 | 171 | public static String generateGetSingleInstanceCode(Class clazz) { 172 | return 173 | "(" + 174 | "(" + clazz.getName() + ")" + 175 | "InstanceUtil.getSingleInstance" + "(" + clazz.getName() + ".class" + ")" + 176 | ")"; 177 | } 178 | 179 | public static String indent(String code) { 180 | return "\t" + code.trim().replaceAll("\n", "\n\t"); 181 | } 182 | 183 | } 184 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/jdbc/roma/impl/util/SpringUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.util; 18 | 19 | import org.springframework.aop.framework.Advised; 20 | import org.springframework.beans.BeansException; 21 | import org.springframework.context.ApplicationContext; 22 | import org.springframework.context.ApplicationContextAware; 23 | import org.springframework.stereotype.Component; 24 | 25 | /** 26 | * @author Serkan ÖZAL 27 | */ 28 | @Component 29 | public class SpringUtil implements ApplicationContextAware { 30 | 31 | private static ApplicationContext applicationContext; 32 | 33 | public static ApplicationContext getApplicationContext() { 34 | return applicationContext; 35 | } 36 | 37 | @Override 38 | public void setApplicationContext(ApplicationContext context) throws BeansException { 39 | applicationContext = context; 40 | } 41 | 42 | @SuppressWarnings("unchecked") 43 | public static T getBean(String beanName) { 44 | if (applicationContext == null) { 45 | return null; 46 | } 47 | else { 48 | return (T)applicationContext.getBean(beanName); 49 | } 50 | } 51 | 52 | public static T getBean(Class clazz) { 53 | if (applicationContext == null) { 54 | return null; 55 | } 56 | else { 57 | return (T)applicationContext.getBean(clazz); 58 | } 59 | } 60 | 61 | public static Class getType(String beanName) { 62 | if (applicationContext == null) { 63 | return null; 64 | } 65 | else { 66 | Object bean = applicationContext.getBean(beanName); 67 | if (bean == null) { 68 | return null; 69 | } 70 | if (bean instanceof Advised) { 71 | Advised advised = (Advised) bean; 72 | Class[] proxiedInterfaces = advised.getProxiedInterfaces(); 73 | if (proxiedInterfaces == null || proxiedInterfaces.length == 0) { 74 | return advised.getTargetSource().getTargetClass(); 75 | } 76 | else { 77 | return proxiedInterfaces[0]; 78 | } 79 | } 80 | else { 81 | return bean.getClass(); 82 | } 83 | } 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/main/resources/roma-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/ContextAwareRomaTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl; 18 | 19 | import org.junit.runner.RunWith; 20 | 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.jdbc.roma.impl.service.RowMapperService; 23 | import org.springframework.test.context.ContextConfiguration; 24 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 25 | 26 | /** 27 | * @author Serkan ÖZAL 28 | */ 29 | @RunWith(SpringJUnit4ClassRunner.class) 30 | @ContextConfiguration("classpath:roma-test-context.xml") 31 | public abstract class ContextAwareRomaTest { 32 | 33 | @Autowired 34 | protected RowMapperService rowMapperService; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/DbAwareBeanPostProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl; 18 | 19 | import org.springframework.beans.BeansException; 20 | import org.springframework.beans.factory.config.BeanPostProcessor; 21 | import org.springframework.core.io.ClassPathResource; 22 | import org.springframework.jdbc.core.JdbcTemplate; 23 | import org.springframework.stereotype.Component; 24 | import org.springframework.test.jdbc.JdbcTestUtils; 25 | 26 | /** 27 | * @author Serkan ÖZAL 28 | */ 29 | @Component 30 | public class DbAwareBeanPostProcessor implements BeanPostProcessor { 31 | 32 | @Override 33 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 34 | return bean; 35 | } 36 | 37 | @Override 38 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { 39 | if (bean instanceof JdbcTemplate) { 40 | JdbcTemplate jdbcTemplate = (JdbcTemplate)bean; 41 | // Create tables before Jdbc Template created and so injected to DAO beans. 42 | // So row mappers can connect to database on initialization 43 | JdbcTestUtils.executeSqlScript(jdbcTemplate, new ClassPathResource("/db/db-creation-scripts.sql"), true); 44 | } 45 | return bean; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/factory/RowMapperFactoryProviderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.factory; 18 | 19 | import org.junit.Assert; 20 | import org.junit.Test; 21 | import org.springframework.jdbc.roma.impl.ContextAwareRomaTest; 22 | import org.springframework.jdbc.roma.impl.factory.RowMapperFactoryProvider; 23 | 24 | /** 25 | * @author Serkan ÖZAL 26 | */ 27 | public class RowMapperFactoryProviderTest extends ContextAwareRomaTest { 28 | 29 | @Test 30 | public void getRowMapperFactory() { 31 | Assert.assertNotNull(RowMapperFactoryProvider.getRowMapperFactory()); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/BaseRomaIntegrationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration; 18 | 19 | import org.junit.After; 20 | import org.junit.Before; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.core.io.ClassPathResource; 23 | import org.springframework.jdbc.core.JdbcTemplate; 24 | import org.springframework.jdbc.roma.impl.ContextAwareRomaTest; 25 | import org.springframework.test.jdbc.JdbcTestUtils; 26 | 27 | /** 28 | * @author Serkan ÖZAL 29 | */ 30 | public abstract class BaseRomaIntegrationTest extends ContextAwareRomaTest { 31 | 32 | @Autowired 33 | private JdbcTemplate jdbcTemplate; 34 | 35 | @Before 36 | public void before() { 37 | deleteDB(); 38 | createDB(); 39 | insertDB(); 40 | } 41 | 42 | @After 43 | public void after() { 44 | deleteDB(); 45 | } 46 | 47 | private void createDB() { 48 | JdbcTestUtils.executeSqlScript(jdbcTemplate, new ClassPathResource("/db/db-creation-scripts.sql"), true); 49 | } 50 | 51 | private void insertDB() { 52 | JdbcTestUtils.executeSqlScript(jdbcTemplate, new ClassPathResource("/db/db-insertion-scripts.sql"), true); 53 | } 54 | 55 | private void deleteDB() { 56 | JdbcTestUtils.executeSqlScript(jdbcTemplate, new ClassPathResource("/db/db-deletion-scripts.sql"), true); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/RowMapperIntegrationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration; 18 | 19 | import java.sql.Date; 20 | import java.util.Collections; 21 | import java.util.List; 22 | 23 | import junit.framework.Assert; 24 | 25 | import org.junit.Test; 26 | import org.springframework.beans.factory.annotation.Autowired; 27 | import org.springframework.jdbc.roma.impl.integration.dao.UserDAO; 28 | import org.springframework.jdbc.roma.impl.integration.model.AccountInfo; 29 | import org.springframework.jdbc.roma.impl.integration.model.BloodType; 30 | import org.springframework.jdbc.roma.impl.integration.model.CreditCardInfo; 31 | import org.springframework.jdbc.roma.impl.integration.model.Education; 32 | import org.springframework.jdbc.roma.impl.integration.model.Gender; 33 | import org.springframework.jdbc.roma.impl.integration.model.Language; 34 | import org.springframework.jdbc.roma.impl.integration.model.MaritalStatus; 35 | import org.springframework.jdbc.roma.impl.integration.model.Occupation; 36 | import org.springframework.jdbc.roma.impl.integration.model.Permission; 37 | import org.springframework.jdbc.roma.impl.integration.model.Religion; 38 | import org.springframework.jdbc.roma.impl.integration.model.Role; 39 | import org.springframework.jdbc.roma.impl.integration.model.User; 40 | 41 | /** 42 | * @author Serkan ÖZAL 43 | */ 44 | public class RowMapperIntegrationTest extends BaseRomaIntegrationTest { 45 | 46 | @Autowired 47 | private UserDAO userDAO; 48 | 49 | @SuppressWarnings("deprecation") 50 | @Test 51 | public void usersAndTheirRolesAndTheirPermissionsRetrievedSuccessfully() { 52 | rowMapperService.enableLazyConditionProperty("creditCardInfoLazyCondition"); 53 | 54 | rowMapperService.enableIgnoreConditionProperty("creditCardInfoIgnoreCondition"); 55 | 56 | List userList = userDAO.list(); 57 | 58 | ///////////////////////////////////////////////////////////////////////////// 59 | 60 | Assert.assertNotNull(userList); 61 | Assert.assertEquals(1, userList.size()); 62 | 63 | ///////////////////////////////////////////////////////////////////////////// 64 | 65 | User user = userList.get(0); 66 | 67 | Assert.assertEquals("user", user.getUsername()); 68 | Assert.assertEquals("password", user.getPassword()); 69 | Assert.assertEquals("Serkan", user.getFirstname()); 70 | Assert.assertEquals("OZAL", user.getLastname()); 71 | Assert.assertEquals("Ankara", user.getAddress().getCity()); 72 | Assert.assertEquals("Turkey", user.getAddress().getCountry()); 73 | Assert.assertEquals(true, user.isEnabled()); 74 | Assert.assertEquals(Gender.MALE, user.getGender()); 75 | Assert.assertEquals(Language.TURKISH, user.getLanguage()); 76 | Assert.assertEquals(Occupation.ENGINEER, user.getOccupation()); 77 | Assert.assertEquals(Education.MASTER, user.getEducation()); 78 | Assert.assertEquals(BloodType.TYPE_A_RH_POSITIVE, user.getBloodType()); 79 | Assert.assertEquals(MaritalStatus.SINGLE, user.getMaritalStatus()); 80 | Assert.assertEquals(Religion.MUSLIM, user.getReligion()); 81 | Assert.assertEquals(new Date(1986 - 1900, 9 - 1, 15), user.getBirthDate()); 82 | Assert.assertEquals("+901234567890", user.getPhoneNumber()); 83 | 84 | ///////////////////////////////////////////////////////////////////////////// 85 | 86 | List roleList = user.getRoles(); 87 | 88 | Assert.assertNotNull(roleList); 89 | Assert.assertEquals(2, roleList.size()); 90 | 91 | Role roleAdmin = roleList.get(0); 92 | Role roleMember = roleList.get(1); 93 | 94 | Assert.assertEquals("Admin", roleAdmin.getName()); 95 | Assert.assertEquals("Member", roleMember.getName()); 96 | 97 | ///////////////////////////////////////////////////////////////////////////// 98 | 99 | List adminPermissionList = roleAdmin.getPermissions(); 100 | List memberPermissionList = roleMember.getPermissions(); 101 | 102 | Collections.sort(adminPermissionList); 103 | Collections.sort(memberPermissionList); 104 | 105 | Assert.assertNotNull(adminPermissionList); 106 | Assert.assertNotNull(memberPermissionList); 107 | 108 | Assert.assertEquals(4, adminPermissionList.size()); 109 | Assert.assertEquals(4, memberPermissionList.size()); 110 | 111 | Assert.assertEquals("ADMIN_DELETE_PERM", adminPermissionList.get(0).getName()); 112 | Assert.assertEquals("ADMIN_GET_PERM", adminPermissionList.get(1).getName()); 113 | Assert.assertEquals("ADMIN_LIST_PERM", adminPermissionList.get(2).getName()); 114 | Assert.assertEquals("ADMIN_UPDATE_PERM", adminPermissionList.get(3).getName()); 115 | 116 | Assert.assertEquals("MEMBER_DELETE_PERM", memberPermissionList.get(0).getName()); 117 | Assert.assertEquals("MEMBER_GET_PERM", memberPermissionList.get(1).getName()); 118 | Assert.assertEquals("MEMBER_LIST_PERM", memberPermissionList.get(2).getName()); 119 | Assert.assertEquals("MEMBER_UPDATE_PERM", memberPermissionList.get(3).getName()); 120 | 121 | CreditCardInfo creditCardInfo = user.getCreditCardInfo(); 122 | 123 | Assert.assertNotNull(creditCardInfo); 124 | Assert.assertEquals("1234-5678-9000", creditCardInfo.getCreditCardNumber()); 125 | Assert.assertEquals(123, creditCardInfo.getSecurityCode()); 126 | Assert.assertEquals(new Date(2020 - 1900, 12 - 1, 31), creditCardInfo.getExpirationDate()); 127 | 128 | ///////////////////////////////////////////////////////////////////////////// 129 | 130 | CreditCardInfo secondaryCreditCardInfo = user.getSecondaryCreditCardInfo(); 131 | 132 | Assert.assertNotNull(secondaryCreditCardInfo); 133 | Assert.assertEquals("9876-5432-1000", secondaryCreditCardInfo.getCreditCardNumber()); 134 | Assert.assertEquals(456, secondaryCreditCardInfo.getSecurityCode()); 135 | Assert.assertEquals(new Date(2030 - 1900, 12 - 1, 31), secondaryCreditCardInfo.getExpirationDate()); 136 | 137 | ///////////////////////////////////////////////////////////////////////////// 138 | 139 | CreditCardInfo previousCreditCardInfo = user.getPreviousCreditCardInfo(); 140 | 141 | Assert.assertNull(previousCreditCardInfo); 142 | 143 | ///////////////////////////////////////////////////////////////////////////// 144 | 145 | AccountInfo accountInfo = user.getAccountInfo(); 146 | 147 | Assert.assertNotNull(accountInfo); 148 | Assert.assertEquals("123456789", accountInfo.getIban()); 149 | Assert.assertEquals("1234", accountInfo.getBankCode()); 150 | Assert.assertEquals("56789", accountInfo.getAccountNo()); 151 | Assert.assertEquals("13579", accountInfo.getCustomerNo()); 152 | 153 | ///////////////////////////////////////////////////////////////////////////// 154 | 155 | rowMapperService.disableIgnoreConditionProperty("creditCardInfoIgnoreCondition"); 156 | 157 | rowMapperService.disableLazyConditionProperty("creditCardInfoLazyCondition"); 158 | } 159 | 160 | } 161 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/custom/BloodTypeEnumMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.custom; 18 | 19 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperEnumField; 20 | import org.springframework.jdbc.roma.impl.integration.model.BloodType; 21 | 22 | /** 23 | * @author Serkan ÖZAL 24 | */ 25 | public class BloodTypeEnumMapper implements RowMapperEnumField.NumericEnumMapper { 26 | 27 | @Override 28 | public BloodType map(Integer value) { 29 | for (BloodType bt : BloodType.values()) { 30 | if (bt.getCode() == value) { 31 | return bt; 32 | } 33 | } 34 | return null; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/custom/MaritalStatusEnumMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.custom; 18 | 19 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperEnumField; 20 | import org.springframework.jdbc.roma.impl.integration.model.MaritalStatus; 21 | 22 | /** 23 | * @author Serkan ÖZAL 24 | */ 25 | public class MaritalStatusEnumMapper implements RowMapperEnumField.StringEnumMapper { 26 | 27 | @Override 28 | public MaritalStatus map(String value) { 29 | for (MaritalStatus ms : MaritalStatus.values()) { 30 | if (ms.name().equalsIgnoreCase(value)) { 31 | return ms; 32 | } 33 | } 34 | return null; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/custom/RoleNameFieldMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.custom; 18 | 19 | import java.sql.ResultSet; 20 | import java.sql.SQLException; 21 | 22 | import org.apache.log4j.Logger; 23 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperField.RowMapperFieldMapper; 24 | import org.springframework.jdbc.roma.impl.integration.model.Role; 25 | 26 | /** 27 | * @author Serkan ÖZAL 28 | */ 29 | public class RoleNameFieldMapper implements RowMapperFieldMapper { 30 | 31 | private static final Logger logger = Logger.getLogger(RoleNameFieldMapper.class); 32 | 33 | @Override 34 | public void mapField(Role role, String fieldName, ResultSet rs, int rowNum) { 35 | try { 36 | role.setName(rs.getString("name")); 37 | } 38 | catch (SQLException e) { 39 | logger.error("Error occured while mapping field " + fieldName + " in Role object from resultset", e); 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/custom/RoleObjectCreater.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.custom; 18 | 19 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperClass.RowMapperObjectCreater; 20 | import org.springframework.jdbc.roma.impl.integration.model.Role; 21 | 22 | /** 23 | * @author Serkan ÖZAL 24 | */ 25 | public class RoleObjectCreater implements RowMapperObjectCreater { 26 | 27 | @Override 28 | public Role createObject(Class clazz) { 29 | return new Role(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/custom/UserAccountInfoSqlQueryInfoProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.custom; 18 | 19 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperSqlProvider.RowMapperSqlQueryInfoProvider; 20 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperSqlProvider.SqlQueryInfo; 21 | import org.springframework.jdbc.roma.impl.integration.model.User; 22 | 23 | /** 24 | * @author Serkan ÖZAL 25 | */ 26 | public class UserAccountInfoSqlQueryInfoProvider implements RowMapperSqlQueryInfoProvider { 27 | 28 | @Override 29 | public SqlQueryInfo provideSqlQueryInfo(User user, String fieldName) { 30 | return 31 | new SqlQueryInfo( 32 | "SELECT a.* FROM ACCOUNT_INFO a WHERE a.ID IN " + 33 | "(" + 34 | "SELECT ua.account_info_id FROM USER_ACCOUNT_INFO ua WHERE ua.user_id = ?" + 35 | ")", 36 | new Object[] { user.getId() }); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/custom/UserObjectProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.custom; 18 | 19 | import java.sql.ResultSet; 20 | import java.util.Calendar; 21 | 22 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperClass.RowMapperObjectProcessor; 23 | import org.springframework.jdbc.roma.impl.integration.model.User; 24 | 25 | /** 26 | * @author Serkan ÖZAL 27 | */ 28 | public class UserObjectProcessor implements RowMapperObjectProcessor { 29 | 30 | @SuppressWarnings("deprecation") 31 | @Override 32 | public void processObject(User user, ResultSet rs, int rowNum) { 33 | if (user.getBirthDate() != null) { 34 | user.setAge((byte)(Calendar.getInstance().getTime().getYear() - user.getBirthDate().getYear())); 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/custom/UserPhoneNumberFieldProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.custom; 18 | 19 | import java.sql.ResultSet; 20 | import java.sql.SQLException; 21 | 22 | import org.apache.log4j.Logger; 23 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperCustomProvider.RowMapperFieldProvider; 24 | import org.springframework.jdbc.roma.impl.integration.model.User; 25 | 26 | /** 27 | * @author Serkan ÖZAL 28 | */ 29 | public class UserPhoneNumberFieldProvider implements RowMapperFieldProvider { 30 | 31 | private final static Logger logger = Logger.getLogger(UserPhoneNumberFieldProvider.class); 32 | 33 | @Override 34 | public String provideField(User user, String fieldName, ResultSet rs, int rowNum) { 35 | try { 36 | return rs.getString("phone_number"); 37 | } 38 | catch (SQLException e) { 39 | logger.error("Error occured while mapping field " + fieldName + " in User object from resultset", e); 40 | return null; 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/custom/UserRolesLazyConditionProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.custom; 18 | 19 | import java.sql.ResultSet; 20 | 21 | import org.apache.log4j.Logger; 22 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperLazyCondition.RowMapperLazyConditionProvider; 23 | import org.springframework.jdbc.roma.impl.integration.model.User; 24 | 25 | /** 26 | * @author Serkan ÖZAL 27 | */ 28 | public class UserRolesLazyConditionProvider implements RowMapperLazyConditionProvider { 29 | 30 | private final static Logger logger = Logger.getLogger(UserRolesLazyConditionProvider.class); 31 | 32 | @Override 33 | public boolean evaluateCondition(User user, String fieldName, ResultSet rs, int rowNum) { 34 | boolean conditionResult = user.getId() % 2 == 0; 35 | logger.debug("Evaluated lazy condition of field " + "\"" + fieldName + "\"" + 36 | " for user with id " + "\"" + user.getId() + "\"" + " as " + "\"" + conditionResult + "\""); 37 | return conditionResult; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/dao/CreditCardInfoDAO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.dao; 18 | 19 | import java.util.List; 20 | 21 | import org.springframework.jdbc.roma.impl.integration.model.CreditCardInfo; 22 | 23 | /** 24 | * @author Serkan ÖZAL 25 | */ 26 | public interface CreditCardInfoDAO { 27 | 28 | public CreditCardInfo get(Long id); 29 | public void add(CreditCardInfo creditCardInfo) throws Exception; 30 | public List list(); 31 | public void addUserCreditCardInfo(Long userId, CreditCardInfo creditCardInfo) throws Exception; 32 | public CreditCardInfo getUserCreditCardInfo(Long userId); 33 | public CreditCardInfo getUserSecondaryCreditCardInfo(Long userId); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/dao/PermissionDAO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.dao; 18 | 19 | import java.util.List; 20 | 21 | import org.springframework.jdbc.roma.impl.integration.model.Permission; 22 | 23 | /** 24 | * @author Serkan ÖZAL 25 | */ 26 | public interface PermissionDAO { 27 | 28 | public Permission get(Long id); 29 | public void add(Permission perm) throws Exception; 30 | public List list(); 31 | public List getRolePermissionList(Long roleId); 32 | public void addRolePermission(Long roleId, Permission perm) throws Exception; 33 | public List getUserPermissionList(Long userId); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/dao/RoleDAO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.dao; 18 | 19 | import java.util.List; 20 | 21 | import org.springframework.jdbc.roma.impl.integration.model.Role; 22 | 23 | /** 24 | * @author Serkan ÖZAL 25 | */ 26 | public interface RoleDAO { 27 | 28 | public Role get(Long id); 29 | public void add(Role role) throws Exception; 30 | public List list(); 31 | public List getUserRoleList(Long userId); 32 | public void addUserRole(Long userId, Role role) throws Exception; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/dao/UserDAO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.dao; 18 | 19 | import java.util.List; 20 | 21 | import org.springframework.jdbc.roma.impl.integration.model.User; 22 | 23 | /** 24 | * @author Serkan ÖZAL 25 | */ 26 | public interface UserDAO { 27 | 28 | public User get(Long id); 29 | public void add(User user) throws Exception; 30 | public List list(); 31 | public List getUserListForRole(Long roleId); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/dao/jdbc/BaseJdbcDAO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.dao.jdbc; 18 | 19 | import org.apache.log4j.Logger; 20 | import org.springframework.beans.factory.annotation.Autowired; 21 | import org.springframework.jdbc.core.JdbcTemplate; 22 | import org.springframework.jdbc.roma.impl.service.RowMapperService; 23 | 24 | /** 25 | * @author Serkan ÖZAL 26 | */ 27 | public class BaseJdbcDAO { 28 | 29 | protected final Logger logger = Logger.getLogger(getClass()); 30 | 31 | @Autowired 32 | protected JdbcTemplate jdbcTemplate; 33 | 34 | @Autowired 35 | protected RowMapperService rowMapperService; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/dao/jdbc/CreditCardInfoJdbcDAO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.dao.jdbc; 18 | 19 | import java.util.List; 20 | 21 | import javax.annotation.PostConstruct; 22 | 23 | import org.springframework.dao.EmptyResultDataAccessException; 24 | import org.springframework.jdbc.core.RowMapper; 25 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperPropertyBasedLazyConditionAware; 26 | import org.springframework.jdbc.roma.impl.integration.dao.CreditCardInfoDAO; 27 | import org.springframework.jdbc.roma.impl.integration.model.CreditCardInfo; 28 | import org.springframework.stereotype.Repository; 29 | 30 | /** 31 | * @author Serkan ÖZAL 32 | */ 33 | @Repository(value="creditCardInfoDAO") 34 | public class CreditCardInfoJdbcDAO extends BaseJdbcDAO implements CreditCardInfoDAO { 35 | 36 | private RowMapper creditCardInfoRowMapper; 37 | 38 | @PostConstruct 39 | protected void init() { 40 | creditCardInfoRowMapper = rowMapperService.getRowMapper(CreditCardInfo.class); 41 | } 42 | 43 | @Override 44 | public CreditCardInfo get(Long id) { 45 | try { 46 | logger.debug("Getting credit card info with id " + id); 47 | return 48 | jdbcTemplate.queryForObject( 49 | "SELECT c.* FROM CREDIT_CARD_INFO c WHERE c.id = ?", creditCardInfoRowMapper, id); 50 | } 51 | catch (EmptyResultDataAccessException e) { 52 | return null; 53 | } 54 | } 55 | 56 | @Override 57 | public void add(CreditCardInfo creditCardInfo) throws Exception { 58 | jdbcTemplate.update( 59 | "INSERT INTO CREDIT_CARD_INFO (credit_card_number, security_code, expiration_date) " + 60 | "VALUES (?, ?, ?) ", 61 | creditCardInfo.getCreditCardNumber(), creditCardInfo.getSecurityCode(), creditCardInfo.getExpirationDate()); 62 | } 63 | 64 | @Override 65 | public List list() { 66 | logger.debug("Listing all credit card infos"); 67 | return jdbcTemplate.query("SELECT c.* FROM CREDIT_CARD_INFO c", creditCardInfoRowMapper); 68 | } 69 | 70 | @Override 71 | public void addUserCreditCardInfo(Long userId, CreditCardInfo creditCardInfo) throws Exception { 72 | jdbcTemplate.update( 73 | "INSERT INTO USER_CREDIT_CARD_INFO (user_id, credit_card_info_id) " + 74 | "VALUES (?, ?) ", userId, creditCardInfo.getId()); 75 | } 76 | 77 | @Override 78 | public CreditCardInfo getUserCreditCardInfo(Long userId) { 79 | logger.debug("Getting credit card info for user with id " + userId); 80 | return 81 | jdbcTemplate.queryForObject( 82 | "SELECT c.* FROM CREDIT_CARD_INFO c WHERE c.id = " + 83 | "(" + 84 | "SELECT uc.credit_card_info_id FROM USER_CREDIT_CARD_INFO uc WHERE uc.user_id = " + userId + 85 | ")", 86 | creditCardInfoRowMapper); 87 | } 88 | 89 | @Override 90 | @RowMapperPropertyBasedLazyConditionAware( 91 | propertyName = "creditCardInfoLazyCondition", 92 | options = RowMapperPropertyBasedLazyConditionAware.ENABLE_ON_START | 93 | RowMapperPropertyBasedLazyConditionAware.DISABLE_ON_FINISH) 94 | public CreditCardInfo getUserSecondaryCreditCardInfo(Long userId) { 95 | logger.debug("Getting secondary credit card info for user with id " + userId); 96 | return 97 | jdbcTemplate.queryForObject( 98 | "SELECT c.* FROM CREDIT_CARD_INFO c WHERE c.id = " + 99 | "(" + 100 | "SELECT uc.credit_card_info_id FROM USER_SECONDARY_CREDIT_CARD_INFO uc WHERE uc.user_id = " + userId + 101 | ")", 102 | creditCardInfoRowMapper); 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/dao/jdbc/PermissionJdbcDAO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.dao.jdbc; 18 | 19 | import java.util.List; 20 | 21 | import javax.annotation.PostConstruct; 22 | 23 | import org.springframework.dao.EmptyResultDataAccessException; 24 | import org.springframework.jdbc.core.RowMapper; 25 | import org.springframework.jdbc.roma.impl.integration.dao.PermissionDAO; 26 | import org.springframework.jdbc.roma.impl.integration.model.Permission; 27 | import org.springframework.stereotype.Repository; 28 | 29 | /** 30 | * @author Serkan ÖZAL 31 | */ 32 | @Repository(value="permissionDAO") 33 | public class PermissionJdbcDAO extends BaseJdbcDAO implements PermissionDAO { 34 | 35 | private RowMapper permRowMapper; 36 | 37 | @PostConstruct 38 | protected void init() { 39 | permRowMapper = rowMapperService.getRowMapper(Permission.class); 40 | } 41 | 42 | @Override 43 | public Permission get(Long id) { 44 | try { 45 | return 46 | jdbcTemplate.queryForObject( 47 | "SELECT p.* FROM PERMISSION p WHERE p.id = ?", permRowMapper, id); 48 | } 49 | catch (EmptyResultDataAccessException e) { 50 | return null; 51 | } 52 | } 53 | 54 | @Override 55 | public void add(Permission perm) throws Exception { 56 | jdbcTemplate.update( 57 | "INSERT INTO PERMISSION (name) " + 58 | "VALUES (?) ", 59 | perm.getId(), perm.getName()); 60 | } 61 | 62 | @Override 63 | public List list() { 64 | return jdbcTemplate.query("SELECT p.* FROM PERMISSION p ORDER BY p.name", permRowMapper); 65 | } 66 | 67 | @Override 68 | public List getRolePermissionList(Long roleId) { 69 | return 70 | jdbcTemplate.query( 71 | "SELECT p.* FROM PERMISSION p WHERE p.id IN " + 72 | "(" + 73 | "SELECT rp.permission_id FROM ROLE_PERMISSION rp WHERE rp.role_id = " + roleId + 74 | ") ORDER BY p.name", 75 | permRowMapper); 76 | } 77 | 78 | @Override 79 | public void addRolePermission(Long roleId, Permission perm) throws Exception { 80 | jdbcTemplate.update( 81 | "INSERT INTO ROLE_PERMISSION (role_id, permission_id) " + 82 | "VALUES (?, ?) ", roleId, perm.getId()); 83 | } 84 | 85 | @Override 86 | public List getUserPermissionList(Long userId) { 87 | return 88 | jdbcTemplate.query( 89 | "SELECT p.* FROM PERMISSION p WHERE p.id IN " + 90 | "(" + 91 | "SELECT rp.permission_id FROM ROLE_PERMISSION rp WHERE rp.role_id IN " + 92 | "(" + 93 | "SELECT ur.ROLE_ID FROM USER_ROLE ur WHERE ur.user_id = " + userId + 94 | ")" + 95 | ") ORDER BY p.name", 96 | permRowMapper); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/dao/jdbc/RoleJdbcDAO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.dao.jdbc; 18 | 19 | import java.util.List; 20 | 21 | import javax.annotation.PostConstruct; 22 | 23 | import org.springframework.dao.EmptyResultDataAccessException; 24 | import org.springframework.jdbc.core.RowMapper; 25 | import org.springframework.jdbc.roma.impl.integration.dao.RoleDAO; 26 | import org.springframework.jdbc.roma.impl.integration.model.Role; 27 | import org.springframework.stereotype.Repository; 28 | 29 | /** 30 | * @author Serkan ÖZAL 31 | */ 32 | @Repository(value="roleDAO") 33 | public class RoleJdbcDAO extends BaseJdbcDAO implements RoleDAO { 34 | 35 | private RowMapper roleRowMapper; 36 | 37 | @PostConstruct 38 | protected void init() { 39 | roleRowMapper = rowMapperService.getRowMapper(Role.class); 40 | } 41 | 42 | @Override 43 | public Role get(Long id) { 44 | try { 45 | return jdbcTemplate.queryForObject("SELECT r.* FROM ROLE r WHERE r.id = ?", roleRowMapper, id); 46 | } 47 | catch (EmptyResultDataAccessException e) { 48 | return null; 49 | } 50 | } 51 | 52 | @Override 53 | public void add(Role role) throws Exception { 54 | jdbcTemplate.update("INSERT INTO ROLE (name) VALUES (?)", role.getName()); 55 | } 56 | 57 | @Override 58 | public List list() { 59 | return jdbcTemplate.query("SELECT r.* FROM ROLE r ORDER BY r.name", roleRowMapper); 60 | } 61 | 62 | @Override 63 | public List getUserRoleList(Long userId) { 64 | return 65 | jdbcTemplate.query( 66 | "SELECT r.* FROM ROLE r WHERE r.id IN " + 67 | "(" + 68 | "SELECT ur.role_id FROM USER_ROLE ur WHERE ur.user_id = " + userId + 69 | ") ORDER BY r.name", 70 | roleRowMapper); 71 | } 72 | 73 | @Override 74 | public void addUserRole(Long userId, Role role) throws Exception { 75 | jdbcTemplate.update( 76 | "INSERT INTO USER_ROLE (user_id, role_id) VALUES (?, ?) ", 77 | userId, role.getId()); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/dao/jdbc/UserJdbcDAO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.dao.jdbc; 18 | 19 | import java.sql.Types; 20 | import java.util.List; 21 | 22 | import javax.annotation.PostConstruct; 23 | 24 | import org.springframework.dao.EmptyResultDataAccessException; 25 | import org.springframework.jdbc.core.RowMapper; 26 | import org.springframework.jdbc.roma.impl.integration.dao.UserDAO; 27 | import org.springframework.jdbc.roma.impl.integration.model.User; 28 | import org.springframework.stereotype.Repository; 29 | 30 | /** 31 | * @author Serkan ÖZAL 32 | */ 33 | @Repository(value="userDAO") 34 | public class UserJdbcDAO extends BaseJdbcDAO implements UserDAO { 35 | 36 | private RowMapper userRowMapper; 37 | 38 | @PostConstruct 39 | public void init() { 40 | userRowMapper = rowMapperService.getRowMapper(User.class); 41 | } 42 | 43 | @Override 44 | public User get(Long id) { 45 | try { 46 | return 47 | jdbcTemplate.queryForObject( 48 | "SELECT u.* FROM USER u WHERE u.id = ?", userRowMapper, id); 49 | } 50 | catch (EmptyResultDataAccessException e) { 51 | return null; 52 | } 53 | } 54 | 55 | @Override 56 | public void add(User user) throws Exception { 57 | jdbcTemplate.update( 58 | "INSERT INTO USER " + 59 | "(" + 60 | "username, password, firstname, lastname, enabled, gender, " + 61 | "language, occupation, education, blood_type, marital_status" + 62 | ") " + 63 | "VALUES (?, ?, ?, ?, ?, ?, ?, ?)", 64 | new Object[] { 65 | user.getUsername(), user.getPassword(), 66 | user.getFirstname(), user.getLastname(), 67 | user.isEnabled() ? 1 : 0, 68 | user.getGender() == null ? 0 : user.getGender().ordinal(), 69 | user.getLanguage() == null ? 0 : user.getLanguage().getCode(), 70 | user.getOccupation() == null ? 0 : user.getOccupation().getCode(), 71 | user.getEducation() == null ? 0 : user.getEducation().name(), 72 | user.getBloodType() == null ? 0 : user.getBloodType().getCode(), 73 | user.getMaritalStatus() == null ? null : user.getMaritalStatus().name(), 74 | user.getReligion() == null ? null : user.getReligion().name(), 75 | user.getBirthDate() == null ? null : user.getBirthDate(), 76 | }, 77 | new int[] { 78 | Types.VARCHAR, 79 | Types.VARCHAR, 80 | Types.VARCHAR, 81 | Types.VARCHAR, 82 | Types.NUMERIC, 83 | Types.NUMERIC, 84 | Types.NUMERIC, 85 | Types.NUMERIC, 86 | Types.VARCHAR, 87 | Types.NUMERIC, 88 | Types.VARCHAR, 89 | Types.VARCHAR, 90 | Types.DATE 91 | }); 92 | } 93 | 94 | @Override 95 | public List list() { 96 | return jdbcTemplate.query("SELECT u.* FROM USER u ORDER BY u.username", userRowMapper); 97 | } 98 | 99 | @Override 100 | public List getUserListForRole(Long roleId) { 101 | return 102 | jdbcTemplate.query( 103 | "SELECT u.* FROM USER u WHERE u.id IN " + 104 | "(" + 105 | "SELECT ur.user_id FROM USER_ROLE ur WHERE ur.role_id = " + roleId + 106 | ") ORDER BY u.username", 107 | userRowMapper); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/model/AccountInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.model; 18 | 19 | /** 20 | * @author Serkan ÖZAL 21 | */ 22 | public class AccountInfo { 23 | 24 | private Long id; 25 | private String iban; 26 | private String bankCode; 27 | private String accountNo; 28 | private String customerNo; 29 | 30 | public Long getId() { 31 | return id; 32 | } 33 | 34 | public void setId(Long id) { 35 | this.id = id; 36 | } 37 | 38 | public String getIban() { 39 | return iban; 40 | } 41 | 42 | public void setIban(String iban) { 43 | this.iban = iban; 44 | } 45 | 46 | public String getBankCode() { 47 | return bankCode; 48 | } 49 | 50 | public void setBankCode(String bankCode) { 51 | this.bankCode = bankCode; 52 | } 53 | 54 | public String getAccountNo() { 55 | return accountNo; 56 | } 57 | 58 | public void setAccountNo(String accountNo) { 59 | this.accountNo = accountNo; 60 | } 61 | 62 | public String getCustomerNo() { 63 | return customerNo; 64 | } 65 | 66 | public void setCustomerNo(String customerNo) { 67 | this.customerNo = customerNo; 68 | } 69 | 70 | @Override 71 | public String toString() { 72 | return 73 | "IBAN = " + iban + ", " + 74 | "Bank Code = " + bankCode + ", " + 75 | "Account No = " + accountNo + ", " + 76 | "Customer No = " + customerNo; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/model/Address.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.model; 18 | 19 | /** 20 | * @author Serkan ÖZAL 21 | */ 22 | public class Address { 23 | 24 | private String city; 25 | private String country; 26 | 27 | public Address() { 28 | 29 | } 30 | 31 | public Address(String city, String country) { 32 | this.city = city; 33 | this.country = country; 34 | } 35 | 36 | public String getCity() { 37 | return city; 38 | } 39 | 40 | public void setCity(String city) { 41 | this.city = city; 42 | } 43 | 44 | public String getCountry() { 45 | return country; 46 | } 47 | 48 | public void setCountry(String country) { 49 | this.country = country; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return city + ", " + country; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/model/BloodType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.model; 18 | 19 | /** 20 | * @author Serkan ÖZAL 21 | */ 22 | public enum BloodType { 23 | 24 | TYPE_A_RH_POSITIVE(1), 25 | TYPE_A_RH_NEGATIVE(2), 26 | TYPE_B_RH_POSITIVE(3), 27 | TYPE_B_RH_NEGATIVE(4), 28 | TYPE_AB_RH_POSITIVE(5), 29 | TYPE_AB_RH_NEGATIVE(6), 30 | TYPE_0_RH_POSITIVE(7), 31 | TYPE_0_RH_NEGATIVE(8); 32 | 33 | int code; 34 | 35 | BloodType(int code) { 36 | this.code = code; 37 | } 38 | 39 | public int getCode() { 40 | return code; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/model/CreditCardInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.model; 18 | 19 | import java.util.Date; 20 | 21 | /** 22 | * @author Serkan ÖZAL 23 | */ 24 | public class CreditCardInfo { 25 | 26 | private Long id; 27 | private String creditCardNumber; 28 | private int securityCode; 29 | private Date expirationDate; 30 | 31 | public Long getId() { 32 | return id; 33 | } 34 | 35 | public void setId(Long id) { 36 | this.id = id; 37 | } 38 | 39 | public String getCreditCardNumber() { 40 | return creditCardNumber; 41 | } 42 | 43 | public void setCreditCardNumber(String creditCardNumber) { 44 | this.creditCardNumber = creditCardNumber; 45 | } 46 | 47 | public int getSecurityCode() { 48 | return securityCode; 49 | } 50 | 51 | public void setSecurityCode(int securityCode) { 52 | this.securityCode = securityCode; 53 | } 54 | 55 | public Date getExpirationDate() { 56 | return expirationDate; 57 | } 58 | 59 | public void setExpirationDate(Date expirationDate) { 60 | this.expirationDate = expirationDate; 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | return 66 | "Card Number = " + creditCardNumber + ", " + 67 | "Security Code = " + securityCode + ", " + 68 | "Expiration Date = " + expirationDate; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/model/Education.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.model; 18 | 19 | /** 20 | * @author Serkan ÖZAL 21 | */ 22 | public enum Education { 23 | 24 | PRIMARY_SCHOOL, 25 | SECONDARY_SCHOOL, 26 | HIGH_SCHOOL, 27 | BACHELOR, 28 | MASTER, 29 | PHD, 30 | ASSOCIATE_PROFESSOR, 31 | PROFESSOR, 32 | OTHER; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/model/Gender.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.model; 18 | 19 | /** 20 | * @author Serkan ÖZAL 21 | */ 22 | public enum Gender { 23 | 24 | FEMALE, 25 | MALE 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/model/Language.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.model; 18 | 19 | /** 20 | * @author Serkan ÖZAL 21 | */ 22 | public enum Language { 23 | 24 | TURKISH(1), 25 | ENGLISH(2), 26 | GERMAN(3), 27 | FRENCH(4), 28 | ITALIAN(5), 29 | SPANISH(6), 30 | RUSSIAN(7), 31 | CHINESE(8), 32 | JAPANESE(9), 33 | ARABIC(10), 34 | OTHER(11); 35 | 36 | int code; 37 | 38 | Language(int code) { 39 | this.code = code; 40 | } 41 | 42 | public int getCode() { 43 | return code; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/model/MaritalStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.model; 18 | 19 | /** 20 | * @author Serkan ÖZAL 21 | */ 22 | public enum MaritalStatus { 23 | 24 | SINGLE, 25 | ENGAGED, 26 | MARRIED, 27 | DIVORCED; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/model/Occupation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.model; 18 | 19 | /** 20 | * @author Serkan ÖZAL 21 | */ 22 | public enum Occupation { 23 | 24 | OTHER(0), 25 | ARCHITECT(100), 26 | DOCTOR(200), 27 | ENGINEER(300), 28 | LAWYER(400), 29 | MUSICIAN(500), 30 | STUDENT(600), 31 | TEACHER(700); 32 | 33 | int code; 34 | 35 | Occupation(int code) { 36 | this.code = code; 37 | } 38 | 39 | public int getCode() { 40 | return code; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/model/Permission.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.model; 18 | 19 | /** 20 | * @author Serkan ÖZAL 21 | */ 22 | public class Permission implements Comparable { 23 | 24 | private Long id; 25 | private String name; 26 | 27 | public Long getId() { 28 | return id; 29 | } 30 | 31 | public void setId(Long id) { 32 | this.id = id; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "Name: " + name; 46 | } 47 | 48 | @Override 49 | public int compareTo(Permission o) { 50 | return name.compareTo(o.name); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/model/Religion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.model; 18 | 19 | /** 20 | * @author Serkan ÖZAL 21 | */ 22 | public enum Religion { 23 | 24 | MUSLIM, 25 | JEWISH, 26 | CHRISTIAN_CAHTOLICS, 27 | CHRISTIAN_ORTHODOX, 28 | CHRISTIAN_PROTESTANT, 29 | ATHEIST, 30 | OTHER; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/integration/model/Role.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.integration.model; 18 | 19 | import java.util.List; 20 | 21 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperClass; 22 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperField; 23 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperLazyCondition; 24 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperLazyCondition.RowMapperExpressionBasedLazyConditionProvider; 25 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperObjectField; 26 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperSqlProvider; 27 | import org.springframework.jdbc.roma.impl.integration.custom.RoleNameFieldMapper; 28 | import org.springframework.jdbc.roma.impl.integration.custom.RoleObjectCreater; 29 | 30 | /** 31 | * @author Serkan ÖZAL 32 | */ 33 | @RowMapperClass(objectCreater = RoleObjectCreater.class) 34 | public class Role { 35 | 36 | private Long id; 37 | @RowMapperField(fieldMapper = RoleNameFieldMapper.class) 38 | private String name; 39 | @RowMapperObjectField( 40 | provideViaSqlProvider = 41 | @RowMapperSqlProvider( 42 | provideSql = 43 | "SELECT p.* FROM PERMISSION p WHERE p.ID IN " + 44 | "(" + 45 | "SELECT rp.PERMISSION_ID FROM role_permission rp WHERE rp.ROLE_ID = ${id}" + 46 | ") ORDER BY p.name", 47 | entityType = Permission.class), 48 | lazy = true, 49 | lazyCondition = 50 | @RowMapperLazyCondition( 51 | provideViaExpressionBasedProvider = 52 | @RowMapperExpressionBasedLazyConditionProvider( 53 | expression = "${name}.equals(\"Member\")"))) 54 | private List permissions; 55 | 56 | public Long getId() { 57 | return id; 58 | } 59 | 60 | public void setId(Long id) { 61 | this.id = id; 62 | } 63 | 64 | public String getName() { 65 | return name; 66 | } 67 | 68 | public void setName(String name) { 69 | this.name = name; 70 | } 71 | 72 | public List getPermissions() { 73 | return permissions; 74 | } 75 | 76 | public void setPermissions(List permissions) { 77 | this.permissions = permissions; 78 | } 79 | 80 | public void addPermission(Permission permission) { 81 | permissions.add(permission); 82 | } 83 | 84 | public void removePermission(Permission permission) { 85 | permissions.remove(permission); 86 | } 87 | 88 | @Override 89 | public String toString() { 90 | return "Name: " + name; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/service/RowMapperServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.service; 18 | 19 | import org.junit.Assert; 20 | import org.junit.Test; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.jdbc.roma.api.config.provider.annotation.RowMapperField; 23 | import org.springframework.jdbc.roma.impl.ContextAwareRomaTest; 24 | import org.springframework.jdbc.roma.impl.service.RowMapperService; 25 | 26 | /** 27 | * @author Serkan ÖZAL 28 | */ 29 | public class RowMapperServiceTest extends ContextAwareRomaTest { 30 | 31 | @Autowired 32 | private RowMapperService rowMapperService; 33 | 34 | @Test 35 | public void getRowMapper() { 36 | Assert.assertNotNull(rowMapperService.getRowMapper(SampleClass.class)); 37 | } 38 | 39 | public static class SampleClass { 40 | 41 | @RowMapperField(columnName="id") 42 | private Long id; 43 | @RowMapperField(columnName="name") 44 | private String name; 45 | 46 | public Long getId() { 47 | return id; 48 | } 49 | 50 | public void setId(Long id) { 51 | this.id = id; 52 | } 53 | 54 | public String getName() { 55 | return name; 56 | } 57 | 58 | public void setName(String name) { 59 | this.name = name; 60 | } 61 | 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/util/ReflectionUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.util; 18 | 19 | import java.io.Serializable; 20 | import java.util.List; 21 | 22 | import junit.framework.Assert; 23 | 24 | import org.junit.Test; 25 | import org.springframework.jdbc.roma.impl.util.ReflectionUtil; 26 | 27 | /** 28 | * @author Serkan ÖZAL 29 | */ 30 | public class ReflectionUtilTest { 31 | 32 | @SuppressWarnings("serial") 33 | public static class SampleClass implements Comparable, Serializable { 34 | 35 | private int i; 36 | private String s; 37 | 38 | public SampleClass() { 39 | 40 | } 41 | 42 | public SampleClass(int i) { 43 | this.i = i; 44 | } 45 | 46 | public SampleClass(String s) { 47 | this.s = s; 48 | } 49 | 50 | public SampleClass(int i, String s) { 51 | this.i = i; 52 | this.s = s; 53 | } 54 | 55 | public int getI() { 56 | return i; 57 | } 58 | 59 | public void setI(int i) { 60 | this.i = i; 61 | } 62 | 63 | public String getS() { 64 | return s; 65 | } 66 | 67 | public void setS(String s) { 68 | this.s = s; 69 | } 70 | 71 | @Override 72 | public int compareTo(SampleClass o) { 73 | if (i < o.i) { 74 | return -1; 75 | } 76 | else if (i > o.i) { 77 | return +1; 78 | } 79 | else { 80 | return 0; 81 | } 82 | } 83 | } 84 | 85 | @Test 86 | public void getField() { 87 | Assert.assertEquals("i", ReflectionUtil.getField(SampleClass.class, "i").getName()); 88 | } 89 | 90 | @Test 91 | public void getAllFields() { 92 | Assert.assertEquals(2, ReflectionUtil.getAllFields(SampleClass.class).size()); 93 | } 94 | 95 | @Test 96 | public void isPrimitiveType() { 97 | Assert.assertTrue(ReflectionUtil.isPrimitiveType(int.class)); 98 | Assert.assertFalse(ReflectionUtil.isPrimitiveType(Integer.class)); 99 | Assert.assertFalse(ReflectionUtil.isPrimitiveType(SampleClass.class)); 100 | } 101 | 102 | @Test 103 | public void isNonPrimitiveType() { 104 | Assert.assertFalse(ReflectionUtil.isNonPrimitiveType(int.class)); 105 | Assert.assertTrue(ReflectionUtil.isNonPrimitiveType(Integer.class)); 106 | Assert.assertTrue(ReflectionUtil.isNonPrimitiveType(SampleClass.class)); 107 | } 108 | 109 | @Test 110 | public void isComplexType() { 111 | Assert.assertTrue(ReflectionUtil.isComplexType(String.class)); 112 | Assert.assertTrue(ReflectionUtil.isComplexType(SampleClass.class)); 113 | } 114 | 115 | @Test 116 | public void isCollectionType() { 117 | Assert.assertFalse(ReflectionUtil.isCollectionType(String.class)); 118 | Assert.assertTrue(ReflectionUtil.isCollectionType(List.class)); 119 | } 120 | 121 | @Test 122 | public void getNonPrimitiveType() { 123 | Assert.assertEquals(Boolean.class, ReflectionUtil.getNonPrimitiveType(boolean.class)); 124 | Assert.assertEquals(Byte.class, ReflectionUtil.getNonPrimitiveType(byte.class)); 125 | Assert.assertEquals(Character.class, ReflectionUtil.getNonPrimitiveType(char.class)); 126 | Assert.assertEquals(Short.class, ReflectionUtil.getNonPrimitiveType(short.class)); 127 | Assert.assertEquals(Integer.class, ReflectionUtil.getNonPrimitiveType(int.class)); 128 | Assert.assertEquals(Float.class, ReflectionUtil.getNonPrimitiveType(float.class)); 129 | Assert.assertEquals(Long.class, ReflectionUtil.getNonPrimitiveType(long.class)); 130 | Assert.assertEquals(Double.class, ReflectionUtil.getNonPrimitiveType(double.class)); 131 | Assert.assertEquals(String.class, ReflectionUtil.getNonPrimitiveType(String.class)); 132 | } 133 | 134 | @Test 135 | public void isDecimalType() { 136 | Assert.assertTrue(ReflectionUtil.isDecimalType(byte.class)); 137 | Assert.assertTrue(ReflectionUtil.isDecimalType(short.class)); 138 | Assert.assertTrue(ReflectionUtil.isDecimalType(int.class)); 139 | Assert.assertTrue(ReflectionUtil.isDecimalType(long.class)); 140 | Assert.assertFalse(ReflectionUtil.isCollectionType(double.class)); 141 | } 142 | 143 | } 144 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/util/RowMapperUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.util; 18 | 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | import junit.framework.Assert; 23 | 24 | import org.junit.Test; 25 | import org.springframework.jdbc.roma.impl.util.RowMapperUtil; 26 | 27 | /** 28 | * @author Serkan ÖZAL 29 | */ 30 | public class RowMapperUtilTest { 31 | 32 | @Test 33 | public void generateRandomClassPostFix() { 34 | String generatedPostFix; 35 | 36 | generatedPostFix = RowMapperUtil.generateRandomClassPostFix(); 37 | Assert.assertNotNull(generatedPostFix); 38 | Assert.assertEquals(36, generatedPostFix.length()); 39 | 40 | Map generatedPostFixMap = new HashMap(); 41 | for (int i = 0; i < 100; i++) { 42 | generatedPostFix = RowMapperUtil.generateRandomClassPostFix(); 43 | Assert.assertFalse(generatedPostFixMap.containsKey(generatedPostFix)); 44 | generatedPostFixMap.put(generatedPostFix, generatedPostFix); 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/jdbc/roma/impl/util/SpringUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 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.springframework.jdbc.roma.impl.util; 18 | 19 | import junit.framework.Assert; 20 | 21 | import org.junit.Test; 22 | import org.springframework.jdbc.roma.impl.ContextAwareRomaTest; 23 | import org.springframework.jdbc.roma.impl.service.RowMapperService; 24 | import org.springframework.jdbc.roma.impl.util.SpringUtil; 25 | 26 | /** 27 | * @author Serkan ÖZAL 28 | */ 29 | public class SpringUtilTest extends ContextAwareRomaTest { 30 | 31 | @Test 32 | public void getBean() { 33 | Assert.assertNotNull(SpringUtil.getBean("rowMapperService")); 34 | } 35 | 36 | @Test 37 | public void getType() { 38 | Assert.assertTrue(RowMapperService.class.isAssignableFrom(SpringUtil.getBean("rowMapperService").getClass())); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/test/resources/db/db-creation-scripts.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE USER 2 | ( 3 | id SERIAL NOT NULL, 4 | username VARCHAR(50) NOT NULL, 5 | password VARCHAR(128) NOT NULL, 6 | firstname VARCHAR(128) NOT NULL, 7 | lastname VARCHAR(128) NOT NULL, 8 | phone_number VARCHAR(20), 9 | city VARCHAR(20), 10 | country VARCHAR(50), 11 | enabled INTEGER NOT NULL, 12 | gender INTEGER NOT NULL, 13 | language INTEGER, 14 | occupation INTEGER, 15 | education VARCHAR(20), 16 | blood_type INTEGER, 17 | marital_status VARCHAR(20), 18 | religion VARCHAR(20), 19 | birth_date DATE 20 | ); 21 | 22 | ALTER TABLE USER ADD CONSTRAINT PK_USER PRIMARY KEY 23 | ( 24 | id 25 | ); 26 | 27 | CREATE TABLE ROLE 28 | ( 29 | id SERIAL NOT NULL, 30 | name VARCHAR(100) NOT NULL 31 | ); 32 | 33 | ALTER TABLE ROLE ADD CONSTRAINT PK_ROLE PRIMARY KEY 34 | ( 35 | id 36 | ); 37 | 38 | CREATE TABLE PERMISSION 39 | ( 40 | id SERIAL NOT NULL, 41 | name VARCHAR(100) NOT NULL 42 | ); 43 | 44 | ALTER TABLE PERMISSION ADD CONSTRAINT PK_PERMISSION PRIMARY KEY 45 | ( 46 | id 47 | ); 48 | 49 | CREATE TABLE CREDIT_CARD_INFO 50 | ( 51 | id SERIAL NOT NULL, 52 | credit_card_number VARCHAR(20) NOT NULL, 53 | security_code INTEGER NOT NULL, 54 | expiration_date DATE NOT NULL 55 | ); 56 | 57 | ALTER TABLE CREDIT_CARD_INFO ADD CONSTRAINT PK_CREDIT_CARD_INFO PRIMARY KEY 58 | ( 59 | id 60 | ); 61 | 62 | CREATE TABLE ACCOUNT_INFO 63 | ( 64 | id SERIAL NOT NULL, 65 | iban VARCHAR(30) NOT NULL, 66 | bank_code VARCHAR(20) NOT NULL, 67 | account_no VARCHAR(20) NOT NULL, 68 | customer_no VARCHAR(20) NOT NULL 69 | ); 70 | 71 | ALTER TABLE ACCOUNT_INFO ADD CONSTRAINT PK_ACCOUNT_INFO PRIMARY KEY 72 | ( 73 | id 74 | ); 75 | 76 | CREATE TABLE USER_ROLE 77 | ( 78 | user_id INTEGER NOT NULL, 79 | role_id INTEGER NOT NULL 80 | ); 81 | 82 | ALTER TABLE USER_ROLE ADD CONSTRAINT PK_USER_ROLE PRIMARY KEY 83 | ( 84 | user_id, 85 | role_id 86 | ); 87 | 88 | CREATE TABLE ROLE_PERMISSION 89 | ( 90 | role_id INTEGER NOT NULL, 91 | permission_id INTEGER NOT NULL 92 | ); 93 | 94 | ALTER TABLE ROLE_PERMISSION ADD CONSTRAINT PK_ROLE_PERMISSION PRIMARY KEY 95 | ( 96 | role_id, 97 | permission_id 98 | ); 99 | 100 | CREATE TABLE USER_CREDIT_CARD_INFO 101 | ( 102 | user_id INTEGER NOT NULL, 103 | credit_card_info_id INTEGER NOT NULL 104 | ); 105 | 106 | ALTER TABLE USER_CREDIT_CARD_INFO ADD CONSTRAINT PK_USER_CREDIT_CARD_INFO PRIMARY KEY 107 | ( 108 | user_id, 109 | credit_card_info_id 110 | ); 111 | 112 | CREATE TABLE USER_SECONDARY_CREDIT_CARD_INFO 113 | ( 114 | user_id INTEGER NOT NULL, 115 | credit_card_info_id INTEGER NOT NULL 116 | ); 117 | 118 | ALTER TABLE USER_SECONDARY_CREDIT_CARD_INFO ADD CONSTRAINT PK_USER_SECONDARY_CREDIT_CARD_INFO PRIMARY KEY 119 | ( 120 | user_id, 121 | credit_card_info_id 122 | ); 123 | 124 | CREATE TABLE USER_ACCOUNT_INFO 125 | ( 126 | user_id INTEGER NOT NULL, 127 | account_info_id INTEGER NOT NULL 128 | ); 129 | 130 | ALTER TABLE USER_ACCOUNT_INFO ADD CONSTRAINT PK_USER_ACCOUNT_INFO PRIMARY KEY 131 | ( 132 | user_id, 133 | account_info_id 134 | ); 135 | -------------------------------------------------------------------------------- /src/test/resources/db/db-deletion-scripts.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE USER_ROLE; 2 | DROP TABLE ROLE_PERMISSION; 3 | DROP TABLE USER_CREDIT_CARD_INFO; 4 | DROP TABLE USER_SECONDARY_CREDIT_CARD_INFO; 5 | DROP TABLE USER_ACCOUNT_INFO; 6 | 7 | DROP TABLE USER; 8 | DROP TABLE ROLE; 9 | DROP TABLE PERMISSION; 10 | DROP TABLE CREDIT_CARD_INFO; 11 | DROP TABLE ACCOUNT_INFO; 12 | -------------------------------------------------------------------------------- /src/test/resources/db/db-insertion-scripts.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO USER (ID, USERNAME, PASSWORD, FIRSTNAME, LASTNAME, CITY, COUNTRY, ENABLED, GENDER, LANGUAGE, OCCUPATION, EDUCATION, BLOOD_TYPE, MARITAL_STATUS, RELIGION, BIRTH_DATE, PHONE_NUMBER) VALUES (1, 'user', 'password', 'Serkan', 'OZAL', 'Ankara', 'Turkey', 1, 1, 1, 300, 'MASTER', 1, 'SINGLE', 'MUSLIM', '1986-09-15', '+901234567890'); 2 | 3 | INSERT INTO ROLE (ID, NAME) VALUES(1, 'Member'); 4 | INSERT INTO ROLE (ID, NAME) VALUES(2, 'Admin'); 5 | 6 | INSERT INTO USER_ROLE (USER_ID, ROLE_ID) VALUES (1, 1); 7 | INSERT INTO USER_ROLE (USER_ID, ROLE_ID) VALUES (1, 2); 8 | 9 | INSERT INTO CREDIT_CARD_INFO (ID, CREDIT_CARD_NUMBER, SECURITY_CODE, EXPIRATION_DATE) VALUES(1, '1234-5678-9000', '123', '2020-12-31'); 10 | INSERT INTO CREDIT_CARD_INFO (ID, CREDIT_CARD_NUMBER, SECURITY_CODE, EXPIRATION_DATE) VALUES(2, '9876-5432-1000', '456', '2030-12-31'); 11 | 12 | INSERT INTO USER_CREDIT_CARD_INFO (USER_ID, CREDIT_CARD_INFO_ID) VALUES (1, 1); 13 | INSERT INTO USER_SECONDARY_CREDIT_CARD_INFO (USER_ID, CREDIT_CARD_INFO_ID) VALUES (1, 2); 14 | 15 | INSERT INTO ACCOUNT_INFO (ID, IBAN, BANK_CODE, ACCOUNT_NO, CUSTOMER_NO) VALUES(1, '123456789', '1234', '56789', '13579'); 16 | 17 | INSERT INTO USER_ACCOUNT_INFO (USER_ID, ACCOUNT_INFO_ID) VALUES (1, 1); 18 | 19 | INSERT INTO PERMISSION (NAME) VALUES('MEMBER_GET_PERM'); 20 | INSERT INTO PERMISSION (NAME) VALUES('MEMBER_LIST_PERM'); 21 | INSERT INTO PERMISSION (NAME) VALUES('MEMBER_UPDATE_PERM'); 22 | INSERT INTO PERMISSION (NAME) VALUES('MEMBER_DELETE_PERM'); 23 | INSERT INTO PERMISSION (NAME) VALUES('ADMIN_GET_PERM'); 24 | INSERT INTO PERMISSION (NAME) VALUES('ADMIN_LIST_PERM'); 25 | INSERT INTO PERMISSION (NAME) VALUES('ADMIN_UPDATE_PERM'); 26 | INSERT INTO PERMISSION (NAME) VALUES('ADMIN_DELETE_PERM'); 27 | 28 | INSERT INTO ROLE_PERMISSION (SELECT r.ID, p.ID FROM PERMISSION p, ROLE r WHERE p.NAME LIKE 'MEMBER_%' AND r.NAME = 'Member'); 29 | INSERT INTO ROLE_PERMISSION (SELECT r.ID, p.ID FROM PERMISSION p, ROLE r WHERE p.NAME LIKE 'ADMIN_%' AND r.NAME = 'Admin'); 30 | 31 | COMMIT; 32 | -------------------------------------------------------------------------------- /src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=INFO, console 2 | 3 | log4j.appender.console=org.apache.log4j.ConsoleAppender 4 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.console.layout.ConversionPattern= %d %t %p [%c{4}] %m%n 6 | 7 | log4j.logger.org.springframework.jdbc.roma=DEBUG 8 | -------------------------------------------------------------------------------- /src/test/resources/roma-test-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | --------------------------------------------------------------------------------