Announcement Announcement Module
Collapse
No announcement yet.
Transactions are not rolling back JDBC Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #31
    RAFDAOImpl.java part 1...

    Code:
    package com.myCompany.service;
    
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.List;
    
    import javax.sql.DataSource;
    
    import org.apache.log4j.Logger;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.jdbc.core.BatchPreparedStatementSetter;
    import org.springframework.jdbc.core.JdbcTemplate;
    import org.springframework.jdbc.core.RowMapper;
    import org.springframework.jdbc.core.support.JdbcDaoSupport;
    import org.springframework.stereotype.Component;
    import org.springframework.stereotype.Repository;
    import org.springframework.transaction.annotation.Isolation;
    import org.springframework.transaction.annotation.Propagation;
    import org.springframework.transaction.annotation.Transactional;
    
    import com.myCompany.net.commons.Util;
    import com.myCompany.net.domain.Customer;
    import com.myCompany.net.domain.Recommendation;
    import com.myCompany.net.domain.Recommendee;
    import com.myCompany.net.integration.DataFeed;
    
    
    @Component
    public class RAFDAOImpl implements IRAFDAO {
    
    	private static final Logger LOGGER = Logger.getLogger(RAFDAOImpl.class);
    
    	private static final String RECOMMENDATION_EXPIRY_DAYS = "60";
    	private static final String SQL_REPLACE_INSERT_CUSTOMER = "replace into customer (ref_number, email, first_name, last_name, dob) values (?, ?, ?, ?, ?)";
    	private static final String SQL_UPDATE_CUSOMTER_REFERENCE_FROM_FEED =  "UPDATE customer c " +
    															"SET c.ref_number = (SELECT d.cust_num " +
    															"                    FROM data_feed d " +
    															"                    WHERE d.dob = c.dob" +
    															"					 AND lower(d.surname) = lower(c.last_name)	) " + 
    															"WHERE EXISTS " +
    															"  	(SELECT d.cust_num " +
    															"   FROM data_feed d " +
    															"   WHERE d.dob = c.dob" +
    															"	AND lower(d.surname) = lower(c.last_name)	)";
    	
    	private static final String SQL_UPDATE_FRIEND_APPROVED_STATUS_FROM_FEED = "UPDATE friend f " +
    																	"SET f.status = 'APR' " + 
    																	"WHERE EXISTS " +
    																	"  	(SELECT d.cust_num " +
    																	"   FROM data_feed d " +
    																	"   WHERE lower(d.email) = lower(f.email)" +
    																	"		AND ( " +
    																	"				d.paid_flag = 'Y'" +
    																	"				AND d.campaign_code not in ('EMMOTMGM', 'MGMWEBM', 'D125-AA', 'D144-AA', 'EMPETMGM', 'MGMWEBP')" +
    																	"			 OR	(" +
    																	"				d.last_payment is not null " +
    																	"				AND d.last_payment != '1901-01-01'" +
    																	"				AND d.last_payment != '001-01-01'" +
    																	"				AND DATE_ADD(d.inception_date, Interval 15 Day) < CURRENT_DATE" +
    																	"				)" +
    																	"			)" +
    																	"	)" +
    																	"AND f.status = 'PND' ";
    	
    	private static final String SQL_UPDATE_FRIEND_CANCEL_STATUS_FROM_FEED = "UPDATE friend f " +
    																			"SET f.status = 'CAN' " + 
    																			"WHERE EXISTS " +
    																			"  	(SELECT d.cust_num " +
    																			"   FROM data_feed d " +
    																			"   WHERE lower(d.email) = lower(f.email)" +
    																			"	AND d.transaction_status != 'GI'" +
    																			"	AND d.campaign_code in ('EMMOTMGM', 'MGMWEBM', 'D125-AA', 'D144-AA', 'EMPETMGM', 'MGMWEBP')	" +
    																			"	)" +
    																			"AND f.status = 'PND' ";
    	
    	private static final String SQL_EXPIRE_RECOMMENDATIONS = "UPDATE friend f SET f.status = 'EXP' WHERE datediff(CURRENT_DATE, f.date) > ? AND f.status != 'EXP'";
    	private static final String SQL_PROMOTE_ALL_APPROVED_AS_COMPLETED = "UPDATE friend f SET f.status = 'COM' WHERE f.status = 'APR'";
    	private static final String SQL_QUERY_DATA_FEED_VALID_CUSTOMER1 = "select count(*) from data_feed where lower(surname) = ? and dob = ?";
    	private static final String SQL_QUERY_DATA_FEED_VALID_CUSTOMER2 = "select count(*) from data_feed where lower(first_name) = ? and lower(surname) = ? and dob = ?";
    	private static final String SQL_QUERY_DATA_FEED1 = "select cust_num from data_feed where lower(surname) = ? and dob = ?";
    	private static final String SQL_QUERY_DATA_FEED2 = "select cust_num from data_feed where lower(first_name) = ? and lower(surname) = ? and dob = ?";
    	private static final String SQL_QUERY_FRIEND = "select count(*) from friend where lower(email) = ? and status not in ('EXP', 'CAN')";
    	private static final String SQL_INSERT_FREINDS = "insert into friend (email, first_name, last_name, date, customer_email, car, home, pet, status) values (?, ?, ?, ?, ?, ?, ?, ?, 'PND')";
    	
    	
    	private JdbcTemplate jdbcTemplate;
    	
    	@Autowired
    	public void setDataSource(DataSource dataSource) {
    		this.jdbcTemplate = new JdbcTemplate(dataSource);
    	}
    
    	
    	public String getCustomerRefNumber(final String customerFirstName, final String customerLastName, final String dobString) {
    		String customerReferenceNumber = null;
    		
    	
    		if(Util.isNullOrEmpty(customerLastName) || Util.isNullOrEmpty(dobString)) return "Unconfirmed";
    		int customerCount = getJdbcTemplate().queryForInt(SQL_QUERY_DATA_FEED_VALID_CUSTOMER1, new Object[]{customerLastName.toLowerCase(), dobString});
    		if(customerCount == 0) return "Unconfirmed";
    		else if (customerCount == 1) {
    			customerReferenceNumber = (String)getJdbcTemplate().queryForObject(SQL_QUERY_DATA_FEED1, new Object[]{customerLastName.toLowerCase(), dobString}, String.class);
    			return customerReferenceNumber;
    		} else {//assuming >1
    			customerCount = getJdbcTemplate().queryForInt(SQL_QUERY_DATA_FEED_VALID_CUSTOMER2, new Object[]{customerFirstName.toLowerCase(), customerLastName.toLowerCase(), dobString});
    			if(customerCount == 1) {
    				customerReferenceNumber = (String)getJdbcTemplate().queryForObject(SQL_QUERY_DATA_FEED2, new Object[]{customerFirstName.toLowerCase(), customerLastName.toLowerCase(), dobString}, String.class);
    				return customerReferenceNumber;
    			} else {
    				return "Unconfirmed";
    			}
    		}
    	}
    	
    	
    	@Override	
    	public int saveOrUpdateCustomer(final Customer customer) {		
    		final String email = customer.getEmail().toLowerCase();
    		final String firstName = customer.getFirstName().toLowerCase();
    		final String lastName = customer.getLastName().toLowerCase();
    		final String customerDobStr = customer.getDob();
    		
    		int customerCount = 0;
    			String customerReferenceNumber = getCustomerRefNumber(firstName, lastName, customerDobStr);
    			if(!"Unconfirmed".equals(customerReferenceNumber)) {
    				customerCount = getJdbcTemplate().update(SQL_REPLACE_INSERT_CUSTOMER, new Object[]{customerReferenceNumber, email, firstName, lastName, customerDobStr});
    			}
    		
    			Customer nullCust=null;
    			return customerCount;
    	}
    	
    	
    	@Override	
    	public void dummyInserCustomer() {		
    		final String email = "[email protected]";
    		final String firstName = "darren";
    		final String lastName = "carr";
    		final String customerDobStr = "13/13/1979";
    		
    		getJdbcTemplate().update(SQL_REPLACE_INSERT_CUSTOMER, new Object[]{"123456", email, firstName, lastName, customerDobStr});
    	}
    
    	@Override
    	public boolean friendAlreadyExist(final List<Recommendee> recomendations) {
    		
    		int friendCount = 0;
    		boolean matchFound = false;
    		for (Recommendee recomendation : recomendations) {
    			String friendsEmail = recomendation.getEmail().toLowerCase();
    			
    			friendCount = getJdbcTemplate().queryForInt(SQL_QUERY_FRIEND, new Object[]{friendsEmail});
    			if(friendCount > 0) matchFound = true;
    		}	
    		return matchFound;
    	}
    	
    
    	@Transactional
    	public void addFriends(final Recommendation recomendations,Customer customer) {
    		
    		final String customerEmail = recomendations.getCustomer().getEmail();
    		final String recommededCar = recomendations.isRecommededProductCar() ? "Y" : "N";
    		final String recommededHome = recomendations.isRecommededProductHome() ? "Y" : "N";
    		final String recommededPet = recomendations.isRecommededProductPet() ? "Y" : "N";
    		final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    		
    		getJdbcTemplate().batchUpdate(SQL_INSERT_FREINDS, new BatchPreparedStatementSetter() {
    			@Override
    			public void setValues(PreparedStatement ps, int i) throws SQLException {
    				Recommendee feed = recomendations.getRecommendee().get(i);
    				ps.setString(1, feed.getEmail());
    				ps.setString(2, feed.getFirstName());
    				ps.setString(3, feed.getLastName());
    				ps.setString(4, dateFormat.format(new Date()));
    				ps.setString(5, customerEmail);
    				ps.setString(6, recommededCar);
    				ps.setString(7, recommededHome);
    				ps.setString(8, recommededPet);
    			}
    			
    			@Override
    			public int getBatchSize() {
    				return recomendations.getRecommendee().size();
    			}
    		});
    	
    		int i =0;
    		if(i==0) throw new RuntimeException("Throwing exception!");
    		saveOrUpdateCustomer(customer);
    	}
    Last edited by DJC_Spring; Jun 29th, 2011, 10:10 AM.

    Comment


    • #32
      RAFDAOImpl.java part2...

      Code:
        
      
      @Override
      	public int[] storeDataFeed(final List<DataFeed> dataFeed) {
      		
      		long startTime = System.currentTimeMillis();
      		StringBuffer sql = new StringBuffer(512); 
      		sql.append("INSERT IGNORE INTO DATA_FEED ")
      					.append("(CUST_NUM, TITLE, FIRST_NAME, SURNAME, EMAIL, BUSINESS_CLASS, INCEPTION_DATE, CAMPAIGN_CODE, PAID_FLAG, LAST_PAYMENT")
      					.append(", MARKETING, GENDER, PREMIUM, VEHICLE_REF, MODEL, PET_TYPE, PET_NAME, RISK, ADDRESS_1, ADDRESS_2, ADDRESS_3, ADDRESS_4")
      					.append(", ADDRESS_5, ADDRESS_6, POSTCODE, POLICY_NUM, TRANSACTION_STATUS, RESPONSE_IND, MAINTENANCE_DATE, DOB, NAME_LINE, SALUTATION) ")
      				.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
      	 
      		int[] recordsUpdated = getJdbcTemplate().batchUpdate(sql.toString(), new BatchPreparedStatementSetter() {
      	 
      			@Override
      			public void setValues(PreparedStatement ps, int i) throws SQLException {
      				DataFeed feed = dataFeed.get(i);
      				ps.setString(1, feed.getCustomerReference());
      				ps.setString(2, feed.getPrefix());
      				ps.setString(3, feed.getForenames());
      				ps.setString(4, feed.getSurname());
      				ps.setString(5, feed.getEmail_Address());
      				ps.setString(6, feed.getProduct());
      				ps.setString(7, feed.getPolicy_Incepton_Date());
      				ps.setString(8, feed.getCampaign_code());
      				ps.setString(9, feed.getPaid_To_Date_Flag());
      				ps.setString(10, feed.getLast_Payment_Date());
      				ps.setString(11, feed.getMarketing_Consent_Flag());
      				ps.setString(12, feed.getGender());
      				ps.setString(13, feed.getAnnual_Premium());
      				ps.setString(14, feed.getVehicle_Reg());
      				ps.setString(15, feed.getVehicle_Description());
      				ps.setString(16, feed.getPet_type());
      				ps.setString(17, feed.getPets_name());
      				ps.setString(18, feed.getRisk_correspondence_Diff_Ind());
      				ps.setString(19, feed.getAddress_line_1());
      				ps.setString(20, feed.getAddress_line_2());
      				ps.setString(21, feed.getAddress_line_3());
      				ps.setString(22, feed.getAddress_line_4());
      				ps.setString(23, feed.getAddress_line_5());
      				ps.setString(24, feed.getAddress_line_6());
      				ps.setString(25, feed.getPostcode());
      				ps.setString(26, feed.getPolicy_number());
      				ps.setString(27, feed.getPolicy_Status());
      				ps.setString(28, feed.getResponse_Ind());
      				ps.setString(29, feed.getMaint_Date());
      				ps.setString(30, feed.getDate_of_birth());
      				ps.setString(31, feed.getName_line());
      				ps.setString(32, feed.getSalutation());
      			}
      		 
      			@Override
      			public int getBatchSize() {
      				return dataFeed.size();
      			}
      		});
      		
      		 
      		getJdbcTemplate().update(SQL_UPDATE_CUSOMTER_REFERENCE_FROM_FEED);
      		getJdbcTemplate().update(SQL_UPDATE_FRIEND_APPROVED_STATUS_FROM_FEED);
      		getJdbcTemplate().update(SQL_UPDATE_FRIEND_CANCEL_STATUS_FROM_FEED);
      		
      	    System.out.println("Time taken to complete the insert" + (startTime - System.currentTimeMillis()) + " ms.");
      		return recordsUpdated;
      	}
      	
      	@Override
      	public List<Recommendee> getAllRecommendee() {
      		@SuppressWarnings("unchecked")
      		List<Recommendee> recommendee = getJdbcTemplate().query("select * from friend",
      				new RecommendeeRowMapper());
      		
      		return recommendee;
      	}
      	
      	@Override
      	public Customer getCustomer(final String email) {
      		Customer actor = (Customer)this.jdbcTemplate.queryForObject(
      		        "select ref_number, first_name, last_name, email from customer where email = ?",
      		        new Object[]{email},
      		        new RowMapper() {
      		            public Customer mapRow(ResultSet rs, int rowNum) throws SQLException {
      		            	Customer actor = new Customer();
      		            	actor.setCustomerRefNumber(rs.getString("ref_number"));
      		                actor.setFirstName(rs.getString("first_name"));
      		                actor.setLastName(rs.getString("last_name"));
      		                actor.setEmail(rs.getString("email"));
      		                return actor;
      		            }
      		        });
      		
      		return actor;
      	}
      	
      	@Override
      	public List<Recommendee> getPendingRecommendeeForToday() {
      		@SuppressWarnings("unchecked")
      		List<Recommendee> recommendee = getJdbcTemplate().query("select * from friend where status = 'PND' and date >= CURRENT_DATE",
      				new RowMapper(){
      				@Override
      				public Recommendee mapRow(ResultSet rs, int rowNum) throws SQLException {
      					Recommendee recommendee = new Recommendee();
      		            recommendee.setFirstName(rs.getString("first_name"));
      		            recommendee.setLastName(rs.getString("last_name"));
      		            recommendee.setDate(rs.getString("date"));
      		            recommendee.setEmail(rs.getString("email"));
      		            recommendee.setRecommenderEmail(rs.getString("customer_email"));
      		            return recommendee;
      		        }
      		});
      		
      		return recommendee;
      	}
      	
      	@Override
      	public List<Recommendee> getAllApprovedRecommendee() {
      		@SuppressWarnings("unchecked")
      		List<Recommendee> recommendee = getJdbcTemplate().query("select * from friend where status = 'APR'",
      		        new RecommendeeRowMapper());
      		
      		return recommendee;
      	}
      	
      	@Override
      	public void markAllApprovedAsCompleted() {
      		getJdbcTemplate().update(SQL_PROMOTE_ALL_APPROVED_AS_COMPLETED);
      	}
      	
      	@Override	
      	public List<Customer> getAllCustomer() {
      		@SuppressWarnings("unchecked")
      		List<Customer> customers = getJdbcTemplate().query("select * from customer",
      		        new RowMapper() {
      					@Override
      					 public Customer mapRow(ResultSet rs, int rowNum) throws SQLException {
      						Customer customer = new Customer();
      		                customer.setFirstName(rs.getString("first_name"));
      		                customer.setLastName(rs.getString("last_name"));
      		                customer.setEmail(rs.getString("email"));
      		                return customer;
      		            }
      				});
      		
      		return customers;
      	}
      
      	private JdbcTemplate getJdbcTemplate() {
      		return this.jdbcTemplate;
      	}
      
      	@Override
      	public void expireRecommendations() {
      		int recordCount = getJdbcTemplate().update(SQL_EXPIRE_RECOMMENDATIONS, new Object[]{RECOMMENDATION_EXPIRY_DAYS});
      		LOGGER.debug("***** Records effected = " + recordCount + "******************");
      		System.out.println("***** Records effected = " + recordCount + "******************");
      	}
      	
      	private class RecommendeeRowMapper implements RowMapper {
      		@Override
      		public Recommendee mapRow(ResultSet rs, int rowNum) throws SQLException {
              	Recommendee recommendee = new Recommendee();
                  recommendee.setFirstName(rs.getString("first_name"));
                  recommendee.setLastName(rs.getString("last_name"));
                  recommendee.setDate(rs.getString("date"));
                  recommendee.setEmail(rs.getString("email"));
                  recommendee.setRecommenderEmail(rs.getString("customer_email"));
                  return recommendee;
              }
      	}
      }
      Last edited by DJC_Spring; Jun 29th, 2011, 10:12 AM.

      Comment


      • #33
        RAFServiceImpl.java

        Code:
        package com.myCompany.service;
        
        import java.util.List;
        
        import javax.sql.DataSource;
        
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.jdbc.core.JdbcTemplate;
        import org.springframework.stereotype.Component;
        import org.springframework.transaction.annotation.Isolation;
        import org.springframework.transaction.annotation.Propagation;
        import org.springframework.transaction.annotation.Transactional;
        
        import com.myCompany.net.domain.Customer;
        import com.myCompany.net.domain.Recommendation;
        import com.myCompany.net.domain.Recommendee;
        import com.myCompany.net.integration.DataFeed;
        
        @Component
        public class RAFServiceImpl implements IRAFService {
        	
        	private JdbcTemplate jdbcTemplate;
        	private IRAFDAO rafDao;
        		
        	@Autowired
        	public RAFServiceImpl(IRAFDAO rafDao) {
        		this.rafDao = rafDao;
        	}
        	
        	@Autowired
        	public void setDataSource(DataSource dataSource) {
        		this.jdbcTemplate = new JdbcTemplate(dataSource);
        	}
        
        	public String getCustomerRefNumber(final String customerFirstName, final String customerLastName, final String dobString) {
        		return rafDao.getCustomerRefNumber(customerFirstName, customerLastName, dobString);
        	}
        
        	@Override	
        	public int saveOrUpdateCustomer(final Customer customer) {
        		return rafDao.saveOrUpdateCustomer(customer);
        	}
        	
        	@Override	
        	public void dummyInserCustomer() {		
        		rafDao.dummyInserCustomer();
        	}
        
        	@Override
        	public boolean friendAlreadyExist(final List<Recommendee> recomendations) {
        		
        		return rafDao.friendAlreadyExist(recomendations);
        		
        	}
        
        	@Override
        	public void addFriends(final Recommendation recomendations,Customer customer) {
        		rafDao.addFriends(recomendations, customer);
        	}
        	
        	@Override
        	public int[] storeDataFeed(final List<DataFeed> dataFeed) {
        		return rafDao.storeDataFeed(dataFeed);
        	}
        	
        	@Override
        	public List<Recommendee> getAllRecommendee() {
        		return rafDao.getAllRecommendee();
        
        	}
        	
        	@Override
        	public Customer getCustomer(final String email) {
        		return rafDao.getCustomer(email);
        	}
        	
        	@Override
        	public List<Recommendee> getPendingRecommendeeForToday() {
        		return rafDao.getPendingRecommendeeForToday();
        	}
        	
        	@Override
        	public List<Recommendee> getAllApprovedRecommendee() {
        		return rafDao.getAllApprovedRecommendee();
        	}
        	
        	@Override
        	public void markAllApprovedAsCompleted() {
        		rafDao.markAllApprovedAsCompleted();
        	}
        	
        	@Override	
        	public List<Customer> getAllCustomer() {
        		return rafDao.getAllCustomer();
        	}
        
        	private JdbcTemplate getJdbcTemplate() {
        		return this.jdbcTemplate;
        	}
        
        	@Override
        	public void expireRecommendations() {
        		rafDao.expireRecommendations();		
        	}
        	
        }
        Last edited by DJC_Spring; Jun 29th, 2011, 10:13 AM.

        Comment


        • #34
          Maven Redeploy

          Code:
          [INFO] 
          NOTE: Maven is executing in offline mode. Any artifacts not already in your local
          repository will be inaccessible.
          
          [INFO] Scanning for projects...
          [INFO] ------------------------------------------------------------------------
          [INFO] Building Unnamed - RAF:RAF:war:0.0.1-SNAPSHOT
          [INFO]    task-segment: [tomcat:redeploy]
          [INFO] ------------------------------------------------------------------------
          [INFO] Preparing tomcat:redeploy
          [INFO] [resources:resources {execution: default-resources}]
          [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
          [INFO] Copying 2 resources
          [WARNING] POM for 'org.brickred:socialauth:pom:1.2-beta1:compile' is invalid.
          
          Its dependencies (if any) will NOT be available to the current build.
          [WARNING] POM for 'org.brickred:socialauth-spring:pom:1.2-beta1:compile' is invalid.
          
          Its dependencies (if any) will NOT be available to the current build.
          [WARNING] POM for 'org.brickred:socialauth-seam:pom:1.2-beta1:compile' is invalid.
          
          Its dependencies (if any) will NOT be available to the current build.
          [INFO] [compiler:compile {execution: default-compile}]
          [INFO] Nothing to compile - all classes are up to date
          [INFO] [resources:testResources {execution: default-testResources}]
          [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
          [INFO] Copying 0 resource
          [INFO] [compiler:testCompile {execution: default-testCompile}]
          [INFO] Not compiling test sources
          [INFO] [surefire:test {execution: default-test}]
          [INFO] Tests are skipped.
          [INFO] [war:war {execution: default-war}]
          [INFO] Packaging webapp
          [INFO] Assembling webapp[RAF] in [C:\Java\development\workspace\RAFWeb\target\RAFWeb]
          [INFO] Dependency[Dependency {groupId=org.springframework, artifactId=spring-aop, version=3.0.5.RELEASE, type=jar}] has changed (was Dependency {groupId=org.springframework, artifactId=spring-aop, version=3.0.5.RELEASE, type=jar}).
          [INFO] Dependency[Dependency {groupId=org.springframework, artifactId=spring-context, version=3.0.5.RELEASE, type=jar}] has changed (was Dependency {groupId=org.springframework, artifactId=spring-context, version=3.0.5.RELEASE, type=jar}).
          [INFO] Dependency[Dependency {groupId=org.springframework, artifactId=spring-webmvc, version=3.0.5.RELEASE, type=jar}] has changed (was Dependency {groupId=org.springframework, artifactId=spring-webmvc, version=3.0.5.RELEASE, type=jar}).
          [INFO] Dependency[Dependency {groupId=org.slf4j, artifactId=slf4j-api, version=1.6.1, type=jar}] has changed (was Dependency {groupId=org.slf4j, artifactId=slf4j-api, version=1.6.1, type=jar}).
          [INFO] Dependency[Dependency {groupId=org.slf4j, artifactId=jcl-over-slf4j, version=1.6.1, type=jar}] has changed (was Dependency {groupId=org.slf4j, artifactId=jcl-over-slf4j, version=1.6.1, type=jar}).
          [INFO] Dependency[Dependency {groupId=org.slf4j, artifactId=slf4j-log4j12, version=1.6.1, type=jar}] has changed (was Dependency {groupId=org.slf4j, artifactId=slf4j-log4j12, version=1.6.1, type=jar}).
          [INFO] Dependency[Dependency {groupId=log4j, artifactId=log4j, version=1.2.16, type=jar}] has changed (was Dependency {groupId=log4j, artifactId=log4j, version=1.2.16, type=jar}).
          [INFO] Dependency[Dependency {groupId=javax.validation, artifactId=validation-api, version=1.0.0.GA, type=jar}] has changed (was Dependency {groupId=javax.validation, artifactId=validation-api, version=1.0.0.GA, type=jar}).
          [INFO] Dependency[Dependency {groupId=org.hibernate, artifactId=hibernate-validator, version=4.1.0.Final, type=jar}] has changed (was Dependency {groupId=org.hibernate, artifactId=hibernate-validator, version=4.1.0.Final, type=jar}).
          [INFO] Dependency[Dependency {groupId=joda-time, artifactId=joda-time, version=1.6.2, type=jar}] has changed (was Dependency {groupId=joda-time, artifactId=joda-time, version=1.6.2, type=jar}).
          [INFO] Dependency[Dependency {groupId=joda-time, artifactId=joda-time-jsptags, version=1.0.2, type=jar}] has changed (was Dependency {groupId=joda-time, artifactId=joda-time-jsptags, version=1.0.2, type=jar}).
          [INFO] Dependency[Dependency {groupId=taglibs, artifactId=standard, version=1.1.2, type=jar}] has changed (was Dependency {groupId=taglibs, artifactId=standard, version=1.1.2, type=jar}).
          [INFO] Dependency[Dependency {groupId=javax.servlet, artifactId=jstl, version=1.2, type=jar}] has changed (was Dependency {groupId=javax.servlet, artifactId=jstl, version=1.2, type=jar}).
          [INFO] Dependency[Dependency {groupId=commons-dbcp, artifactId=commons-dbcp, version=1.4, type=jar}] has changed (was Dependency {groupId=commons-dbcp, artifactId=commons-dbcp, version=1.4, type=jar}).
          [INFO] Dependency[Dependency {groupId=org.springframework, artifactId=spring-jdbc, version=2.0.6, type=jar}] has changed (was Dependency {groupId=org.springframework, artifactId=spring-jdbc, version=2.0.6, type=jar}).
          [INFO] Dependency[Dependency {groupId=javax.mail, artifactId=mail, version=1.4.1, type=jar}] has changed (was Dependency {groupId=javax.mail, artifactId=mail, version=1.4.1, type=jar}).
          [INFO] Dependency[Dependency {groupId=org.brickred, artifactId=socialauth, version=1.2-beta1, type=jar}] has changed (was Dependency {groupId=org.brickred, artifactId=socialauth, version=1.2-beta1, type=jar}).
          [INFO] Dependency[Dependency {groupId=org.brickred, artifactId=socialauth-spring, version=1.2-beta1, type=jar}] has changed (was Dependency {groupId=org.brickred, artifactId=socialauth-spring, version=1.2-beta1, type=jar}).
          [INFO] Dependency[Dependency {groupId=org.brickred, artifactId=socialauth-seam, version=1.2-beta1, type=jar}] has changed (was Dependency {groupId=org.brickred, artifactId=socialauth-seam, version=1.2-beta1, type=jar}).
          [INFO] Dependency[Dependency {groupId=cglib, artifactId=cglib-nodep, version=2.2, type=jar}] has changed (was Dependency {groupId=cglib, artifactId=cglib-nodep, version=2.2, type=jar}).
          [INFO] Dependency[Dependency {groupId=org.openid4java, artifactId=openid4java, version=0.9.5, type=jar}] has changed (was Dependency {groupId=org.openid4java, artifactId=openid4java, version=0.9.5, type=jar}).
          [INFO] Dependency[Dependency {groupId=it.tidalwave.bluebill, artifactId=json, version=1.0.9, type=jar}] has changed (was Dependency {groupId=it.tidalwave.bluebill, artifactId=json, version=1.0.9, type=jar}).
          [INFO] Dependency[Dependency {groupId=org.json, artifactId=json, version=20080701, type=jar}] has changed (was Dependency {groupId=org.json, artifactId=json, version=20080701, type=jar}).
          [INFO] Dependency[Dependency {groupId=com.cedarsoft, artifactId=serialization, version=3.0.0, type=jar}] has changed (was Dependency {groupId=com.cedarsoft, artifactId=serialization, version=3.0.0, type=jar}).
          [INFO] Dependency[Dependency {groupId=org.springframework, artifactId=spring-tx, version=3.0.5.RELEASE, type=jar}] has changed (was Dependency {groupId=org.springframework, artifactId=spring-tx, version=3.0.5.RELEASE, type=jar}).
          [INFO] Dependency[Dependency {groupId=com.mysema.spring, artifactId=spring-tx-annotations, version=0.1.0, type=jar}] has changed (was Dependency {groupId=com.mysema.spring, artifactId=spring-tx-annotations, version=0.1.0, type=jar}).
          [INFO] Processing war project
          [INFO] Copying webapp resources[C:\Java\development\workspace\RAFWeb\src\main\webapp]
          [INFO] Webapp assembled in[269 msecs]
          [INFO] Building war: C:\Java\development\workspace\RAFWeb\target\RAFWeb.war
          [INFO] [tomcat:redeploy {execution: default-cli}]
          [INFO] Deploying war to http://localhost:8080/RAFWeb  
          [INFO] OK - Undeployed application at context path /RAFWeb
          [INFO] OK - Deployed application at context path /RAFWeb
          [INFO] ------------------------------------------------------------------------
          [INFO] BUILD SUCCESSFUL
          [INFO] ------------------------------------------------------------------------
          [INFO] Total time: 9 seconds
          [INFO] Finished at: Wed Jun 29 12:30:30 BST 2011
          [INFO] Final Memory: 18M/67M
          [INFO] ------------------------------------------------------------------------
          Last edited by DJC_Spring; Jun 29th, 2011, 10:14 AM.

          Comment


          • #35
            Tomcat v7.0 Log (Redeploy) - transaction Stuff found

            Code:
            12:34:06,526 INFO  [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1035ff9: defining beans [recommendationController,successController,recommendationValidator,asyncWorker,scheduledProcessor,RAFDAOImpl,RAFServiceImpl,eventDispatcher,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.scheduling.annotation.internalAsyncAnnotationProcessor,org.springframework.scheduling.annotation.internalScheduledAnnotationProcessor,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor#0,org.springframework.web.servlet.config.viewControllerHandlerAdapter,org.springframework.web.servlet.config.viewControllerHandlerMapping,org.springframework.web.servlet.handler.MappedInterceptor#1,validator,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,localeResolver,dataSource,transactionManager,messageSource,properties,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,springApplicationContext,emailService,org.springframework.web.servlet.handler.SimpleMappingExceptionResolver#0,viewResolver,socialAuthProperties,scopedTarget.socialAuthTemplate,socialAuthTemplate,socialAuthWebController]; root of factory hierarchy
            
            12:34:07,038 DEBUG [DefaultAnnotationHandlerMapping] Rejected bean name 'org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor#0': no URL paths identified
            12:34:07,130 DEBUG [DefaultListableBeanFactory] Creating shared instance of singleton bean 'org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor#0'
            12:34:07,130 DEBUG [DefaultListableBeanFactory] Creating instance of bean 'org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor#0'
            12:34:07,131 DEBUG [DefaultListableBeanFactory] Eagerly caching bean 'org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor#0' to allow for resolving potential circular references
            12:34:07,138 DEBUG [DefaultListableBeanFactory] Creating shared instance of singleton bean 'transactionManager'
            12:34:07,138 DEBUG [DefaultListableBeanFactory] Creating instance of bean 'transactionManager'
            12:34:07,145 DEBUG [DefaultListableBeanFactory] Eagerly caching bean 'transactionManager' to allow for resolving potential circular references
            12:34:07,148 DEBUG [DefaultListableBeanFactory] Invoking afterPropertiesSet() on bean with name 'transactionManager'
            12:34:07,154 DEBUG [DefaultListableBeanFactory] Finished creating instance of bean 'transactionManager'
            12:34:07,158 DEBUG [DefaultListableBeanFactory] Finished creating instance of bean 'org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor#0'
            12:34:07,192 DEBUG [DefaultListableBeanFactory] Returning cached instance of singleton bean 'transactionManager'

            Comment


            • #36
              Your service isn't transactional... There is no @Transactional annotation to be found on your service implementation. Also it should be the service layer that is transactional NOT your dao layer. Next to that you don't want to use autocommit, if you need to enable that you can be sure you have a problem with your transaction management..

              Comment


              • #37
                Hi Marten,

                Thanks once again for helping and I did not post the correct code, as I was in having a play around trying to get the thing working.

                The service method now has

                Code:
                @Override
                @Transactional
                public void addFriends(final Recommendation recomendations,Customer customer) {
                		rafDao.addFriends(recomendations, customer);	
                
                }
                Still no joy.. I just dont know what to do next?

                I did notice that the namespace (http://www.springframework.org/schem...ing-tx-3.0.xsd) was not clicking through in eclipse (page not found)0, so I moved it towards the top and it is ok now.

                Code:
                <beans xmlns="http://www.springframework.org/schema/beans"
                	   	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"	   	
                	   	xmlns:aop="http://www.springframework.org/schema/aop" 
                	   	xmlns:tx="http://www.springframework.org/schema/tx"
                		xmlns:context="http://www.springframework.org/schema/context"
                		xmlns:mvc="http://www.springframework.org/schema/mvc" 
                		xmlns:task="http://www.springframework.org/schema/task"
                		xsi:schemaLocation="http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
                		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
                							http://www.springframework.org/schema/beans	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                							http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
                							http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
                		 					http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
                Ive also ensured I everything is the same version

                so my pom file has

                Code:
                	<dependency>
                   <groupId>org.springframework</groupId>
                   <artifactId>spring-tx</artifactId>
                   <version>3.0.0.RELEASE</version>
                </dependency>
                
                Any other ideas?
                Last edited by DJC_Spring; Jun 29th, 2011, 09:58 AM.

                Comment


                • #38
                  To Marten and dlmiles,

                  IT IS NOW WORKING !! See below..

                  Code:
                  15:32:42,038 DEBUG [DataSourceTransactionManager] Initiating transaction rollback
                  15:32:42,039 DEBUG [DataSourceTransactionManager] Rolling back JDBC transaction on Connection [jdbc:mysql://localhost:3306/raf, UserName=root@localhost, MySQL-AB JDBC Driver]
                  15:32:42,041 DEBUG [DataSourceTransactionManager] Releasing JDBC Connection [jdbc:mysql://localhost:3306/raf, UserName=root@localhost, MySQL-AB JDBC Driver] after transaction
                  15:32:42,042 DEBUG [DataSourceUtils] Returning JDBC Connection to DataSource
                  15:32:42,042 DEBUG [SimpleMappingExceptionResolver] Resolving exception from handler [[email protected]e9]: java.lang.RuntimeException: Throwing exception!
                  15:32:42,042 DEBUG [SimpleMappingExceptionResolver] Resolving to default view 'uncaughtException' for exception of type [java.lang.RuntimeException]
                  15:32:42,042 DEBUG [SimpleMappingExceptionResolver] Exposing Exception as model attribute 'exception'
                  15:32:42,044 DEBUG [DispatcherServlet] Handler execution resulted in exception - forwarding to resolved error view: ModelAndView: reference to view with name 'uncaughtException'; model is {exception=java.lang.RuntimeException: Throwing exception!}
                  java.lang.RuntimeException: Throwing exception!

                  I finally got it working and cant tell you how pleased I am!

                  I had a play around with the namespaces in raf-servlet and ensured everyrthing was on the same version.

                  Code:
                  xsi:schemaLocation="http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
                  		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
                  							http://www.springframework.org/schema/beans	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                  							http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
                  							http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
                  		 					http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
                  I then ensured that all dependencies in my pom had the same Spring version 3.0.5.RELEASE.

                  Code:
                  	<properties>
                  		<org.springframework.version>3.0.5.RELEASE</org.springframework.version>
                  		<org.slf4j.version>1.6.1</org.slf4j.version>
                  	</properties>
                  		
                  		
                  	<dependencies>
                  	
                  	
                  
                  		<!--  Spring -->
                  		<dependency>
                  			<groupId>org.springframework</groupId>
                  			<artifactId>spring-aop</artifactId>
                  			<version>${org.springframework.version}</version>
                  			<exclusions>
                  				<!-- Exclude Commons Logging in favor of SLF4j -->
                  				<exclusion>
                  					<groupId>commons-logging</groupId>
                  					<artifactId>commons-logging</artifactId>
                  				</exclusion>
                  			</exclusions>
                  		</dependency>
                  		
                  		<dependency>
                  			<groupId>org.springframework</groupId>
                  			<artifactId>spring-context</artifactId>
                  			<version>${org.springframework.version}</version>
                  			<exclusions>
                  				<!-- Exclude Commons Logging in favor of SLF4j -->
                  				<exclusion>
                  					<groupId>commons-logging</groupId>
                  					<artifactId>commons-logging</artifactId>
                  				</exclusion>
                  			</exclusions>
                  		</dependency>
                  		
                  		<dependency>
                  			<groupId>org.springframework</groupId>
                  			<artifactId>spring-webmvc</artifactId>
                  			<version>${org.springframework.version}</version>
                  		</dependency>
                  		
                  		<dependency>
                  			<groupId>org.springframework</groupId>
                  			<artifactId>spring-jdbc</artifactId>
                  			<version>${org.springframework.version}</version>
                  		</dependency>
                  		
                  		<dependency>
                  	   		<groupId>org.springframework</groupId>
                  	   		<artifactId>spring-tx</artifactId>
                  	   		<version>${org.springframework.version}</version>  
                  		</dependency>
                  		
                  		<dependency>
                  	   		<groupId>org.springframework</groupId>
                  	  	 	<artifactId>spring-beans</artifactId>
                  	   		<version>${org.springframework.version}</version>
                     		</dependency>
                     		
                     		<dependency>
                  		    <groupId>org.springframework</groupId>
                  		    <artifactId>spring-expression</artifactId>
                  		    <version>${org.springframework.version}</version>
                  		</dependency>

                  I also cleared out my Springframework folder in the .m2 repository and did a fresh maven update from eclipse. And hey presto!

                  My Summary is that

                  1) My config was incorrect and I had mutliple beans due to the context scanning and bean declaration. Thank you to Marten and dlmiles

                  2) Some sort of behind the scenes dependancy incompatability using different Spring versions ! A big notice was that of the spring-jdbc artifact.

                  Guys Im really greatful for your help and advise on this, you have been superb. Ive learnt a lot and cant thank you enough !!!
                  Last edited by DJC_Spring; Jun 29th, 2011, 10:00 AM.

                  Comment

                  Working...
                  X