Skip to content

Instantly share code, notes, and snippets.

View gabanox's full-sized avatar

Gabriel Ramirez gabanox

View GitHub Profile
@gabanox
gabanox / remove_additional_spaces.sql
Created March 25, 2013 19:09
Eliminar espacios adicionales de una cadena
select regexp_replace('my text with aditional spaces', '\s{1}+', ' ') from dual;
@gabanox
gabanox / gist:5593578
Last active December 17, 2015 10:19
Credenciales de Acceso AWS
User Name Access Key Id Secret Access Key
curso5 AKIAJV2OXYVX6MVRU6XA XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
curso4 AKIAIN6FMANDLENBRD6A XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
curso3 AKIAJKPS4Y6YRW4CDRLA XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
curso2 AKIAJ2QGVRB5IGVFBQKQ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
curso1 AKIAJTAMNVGFK3L6Z43Q XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
@gabanox
gabanox / backbone model validation
Last active December 24, 2015 02:39
Simple model validation
Simple model validation
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<bean id="founder" class="com.socialfoundry.model.Founder"/>
<bean id="project" class="com.socialfoundry.model.Project"/>
public List<Contact> findAll() {
String sql = "select id, first_name, last_name, birth_date from contact";
return jdbcTemplate.query(sql, new ContactMapper());
}
public List<Contact> findAllWithDetail() {
String sql = "select c.id, c.first_name, c.last_name, c.birth_date" +
", t.id as contact_tel_id, t.tel_type, t.tel_number from contact c " +
"left join contact_tel_detail t on c.id = t.contact_id";
return jdbcTemplate.query(sql, new ContactWithDetailExtractor());
private static final class ContactWithDetailExtractor implements ResultSetExtractor<List<Contact>> {
public List<Contact> extractData(ResultSet rs) throws SQLException,
DataAccessException {
Map<Long, Contact> map = new HashMap<Long, Contact>();
Contact contact = null;
while (rs.next()) {
Long id = rs.getLong("id");
contact = map.get(id);
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd">
DELIMITER //
CREATE FUNCTION getFirstNameById(in_id INT)
RETURNS VARCHAR(60)
BEGIN
RETURN (SELECT first_name FROM CONTACT WHERE id = in_id);
END //
DELIMITER ;
public List<Contact> findAll() {
return sessionFactory.getCurrentSession().createQuery("from Contact c").list();
}
public List<Contact> findAllWithDetail() {
return sessionFactory.getCurrentSession().getNamedQuery("Contact.findAllWithDetail").list();
}
public Contact findById(Long id) {
return (Contact) sessionFactory.getCurrentSession().
package com.company.hibernate.dao;
import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;