Example usage for java.sql SQLException SQLException

List of usage examples for java.sql SQLException SQLException

Introduction

In this page you can find the example usage for java.sql SQLException SQLException.

Prototype

public SQLException(String reason, Throwable cause) 

Source Link

Document

Constructs a SQLException object with a given reason and cause.

Usage

From source file:net.orpiske.ssps.common.db.SimpleRsHandler.java

@Override
public T handle(ResultSet rs) throws SQLException {

    // No records to handle :O
    if (!rs.next()) {
        return null;
    }//  ww w .  j a va 2 s  . c  om

    ResultSetMetaData meta = rs.getMetaData();

    for (int i = 1; i <= meta.getColumnCount(); i++) {
        Object value = rs.getObject(i);
        String name = meta.getColumnName(i);

        try {
            /*
             * We convert the column name to a more appropriate and java like name 
             * because some columns are usually named as some_thing whereas Java 
             * properties are named someThing. This call does this conversion.
             */
            String javaProperty = NameConverter.sqlToProperty(name);

            PropertyUtils.setSimpleProperty(dto, javaProperty, value);
        } catch (Exception e) {
            throw new SQLException("Unable to set property " + name + " for bean" + dto.getClass(), e);
        }
    }

    return dto;
}

From source file:org.mayocat.shop.catalog.store.jdbi.mapper.FeatureMapper.java

@Override
public Feature map(int index, ResultSet resultSet, StatementContext ctx) throws SQLException {
    Feature feature = new Feature();
    feature.setId((UUID) resultSet.getObject("id"));
    feature.setParentId((UUID) resultSet.getObject("parent_id"));
    feature.setSlug(resultSet.getString("slug"));
    feature.setTitle(resultSet.getString("title"));
    feature.setFeature(resultSet.getString("feature"));
    feature.setFeatureSlug(resultSet.getString("feature_slug"));

    if (MapperUtils.hasColumn("localization_data", resultSet)
            && !Strings.isNullOrEmpty(resultSet.getString("localization_data"))) {
        ObjectMapper mapper = new ObjectMapper();
        try {/*from  w w  w . java 2 s  .c o  m*/
            Map<Locale, Map<String, Object>> localizedVersions = Maps.newHashMap();
            Map[] data = mapper.readValue(resultSet.getString("localization_data"), Map[].class);
            for (Map map : data) {
                localizedVersions.put(Locale.forLanguageTag((String) map.get("locale")),
                        (Map) map.get("entity"));
            }
            feature.setLocalizedVersions(localizedVersions);
        } catch (IOException e) {
            throw new SQLException("Failed to de-serialize localization JSON data", e);
        }
    }

    return feature;
}

From source file:org.mayocat.attachment.store.jdbi.mapper.LoadedAttachmentMapper.java

@Override
public LoadedAttachment map(int index, ResultSet resultSet, StatementContext ctx) throws SQLException {
    LoadedAttachment attachment = new LoadedAttachment();
    attachment.setId((UUID) resultSet.getObject("id"));
    attachment.setTitle(resultSet.getString("title"));
    attachment.setDescription(resultSet.getString("description"));
    attachment.setSlug(resultSet.getString("slug"));
    attachment.setData(new AttachmentData(resultSet.getBinaryStream("data")));
    attachment.setExtension(resultSet.getString("extension"));
    attachment.setParentId((UUID) resultSet.getObject("parent_id"));

    ObjectMapper mapper = new ObjectMapper();

    if (!Strings.isNullOrEmpty(resultSet.getString("metadata"))) {
        try {//from  w ww . j  av a 2s .c om

            Map<String, Map<String, Object>> metadata = mapper.readValue(resultSet.getString("metadata"),
                    new TypeReference<Map<String, Map<String, Object>>>() {
                    });
            attachment.setMetadata(metadata);
        } catch (IOException e) {
            throw new SQLException("Failed to de-serialize localization JSON data", e);
        }
    }

    if (MapperUtils.hasColumn("localization_data", resultSet)
            && !Strings.isNullOrEmpty(resultSet.getString("localization_data"))) {
        try {
            Map<Locale, Map<String, Object>> localizedVersions = Maps.newHashMap();
            Map[] data = mapper.readValue(resultSet.getString("localization_data"), Map[].class);
            for (Map map : data) {
                localizedVersions.put(LocaleUtils.toLocale((String) map.get("locale")),
                        (Map) map.get("entity"));
            }
            attachment.setLocalizedVersions(localizedVersions);
        } catch (IOException e) {
            throw new SQLException("Failed to de-serialize localization JSON data", e);
        }
    }

    return attachment;
}

From source file:org.mayocat.cms.pages.store.jdbi.mapper.PageMapper.java

@Override
public Page map(int index, ResultSet resultSet, StatementContext ctx) throws SQLException {
    Page page = new Page((UUID) resultSet.getObject("id"));
    if (resultSet.getObject("published") != null) {
        page.setPublished(resultSet.getBoolean("published"));
    }/*from  w  ww. java  2  s. c  o m*/
    page.setTitle(resultSet.getString("title"));
    page.setSlug(resultSet.getString("slug"));
    page.setContent(resultSet.getString("content"));

    page.setFeaturedImageId((UUID) resultSet.getObject("featured_image_id"));

    if (!Strings.isNullOrEmpty(resultSet.getString("localization_data"))) {
        ObjectMapper mapper = new ObjectMapper();
        try {
            Map<Locale, Map<String, Object>> localizedVersions = Maps.newHashMap();
            Map[] data = mapper.readValue(resultSet.getString("localization_data"), Map[].class);
            for (Map map : data) {
                try {
                    localizedVersions.put(LocaleUtils.toLocale((String) map.get("locale")),
                            (Map) map.get("entity"));
                } catch (IllegalArgumentException e) {
                    // Invalid locale, just ignore it
                }
            }
            page.setLocalizedVersions(localizedVersions);
        } catch (IOException e) {
            throw new SQLException("Failed to de-serialize localization JSON data", e);
        }
    }

    String model = resultSet.getString("model");
    if (!Strings.isNullOrEmpty(model)) {
        page.setModel(model);
    }

    return page;
}

From source file:org.mayocat.shop.shipping.store.jdbi.mapper.CarrierMapper.java

@Override
public Carrier map(int index, ResultSet r, StatementContext ctx) throws SQLException {
    Carrier carrier = null;//from  w w w.  ja  v a 2 s  . c o m
    UUID thisRowId = (UUID) r.getObject("id");
    if (ctx.getAttribute("__accumulator") != null) {
        carrier = (Carrier) ctx.getAttribute("__accumulator");
        if (!carrier.getId().equals(thisRowId)) {
            carrier = new Carrier();
        }
    }
    if (carrier == null) {
        carrier = new Carrier();
    }
    carrier.setId(thisRowId);
    carrier.setTitle(r.getString("title"));
    carrier.setDescription(r.getString("description"));
    carrier.setId((UUID) r.getObject("id"));
    carrier.setTenantId((UUID) r.getObject("tenant_id"));
    carrier.setMinimumDays(r.getInt("minimum_days"));
    carrier.setMaximumDays(r.getInt("maximum_days"));
    carrier.setStrategy(Strategy.fromJson(r.getString("strategy")));
    carrier.setPerShipping(r.getBigDecimal("per_shipping"));
    carrier.setPerItem(r.getBigDecimal("per_item"));
    carrier.setPerAdditionalUnit(r.getBigDecimal("per_additional_unit"));

    ObjectMapper objectMapper = new ObjectMapper();
    try {
        carrier.setDestinations(objectMapper.<List<String>>readValue(r.getString("destinations"),
                new TypeReference<List<String>>() {
                }));
    } catch (IOException e) {
        throw new SQLException("Failed to de-serialize carrier destinations", e);
    }

    if (r.getBigDecimal("price") != null) {
        CarrierRule rule = new CarrierRule();
        rule.setUpToValue(r.getBigDecimal("up_to_value"));
        rule.setPrice(r.getBigDecimal("price"));
        carrier.addRule(rule);
    }

    if (r.getBigDecimal("vat_rate") != null) {
        carrier.setVatRate(r.getBigDecimal("vat_rate"));
    }

    ctx.setAttribute("__accumulator", carrier);
    return carrier;
}

From source file:net.orpiske.ssps.common.registry.MultiRsHandler.java

@Override
protected SoftwareInventoryDto handleRow(ResultSet rs) throws SQLException {
    SoftwareInventoryDto dto = new SoftwareInventoryDto();

    ResultSetMetaData meta = rs.getMetaData();

    for (int i = 1; i <= meta.getColumnCount(); i++) {
        Object value = rs.getObject(i);
        String name = meta.getColumnName(i);

        try {/*from   w w  w .jav a2  s  .co  m*/
            /*
             * We convert the column name to a more appropriate and java like name 
             * because some columns are usually named as some_thing whereas Java 
             * properties are named someThing. This call does this conversion.
             */
            String javaProperty = NameConverter.sqlToProperty(name);

            if (javaProperty.equals("version")) {
                Version version = Version.toVersion((String) value);

                PropertyUtils.setSimpleProperty(dto, javaProperty, version);
            } else {
                PropertyUtils.setSimpleProperty(dto, javaProperty, value);
            }
        } catch (Exception e) {
            throw new SQLException("Unable to set property " + name + " for bean" + dto.getClass(), e);
        }
    }

    return dto;
}

From source file:net.orpiske.ssps.common.dependencies.cache.MultiRsHandler.java

@Override
protected DependencyCacheDto handleRow(ResultSet rs) throws SQLException {
    DependencyCacheDto dto = new DependencyCacheDto();

    ResultSetMetaData meta = rs.getMetaData();

    for (int i = 1; i <= meta.getColumnCount(); i++) {
        Object value = rs.getObject(i);
        String name = meta.getColumnName(i);

        try {/* w w w.  j  a  va  2  s. c o  m*/
            /*
             * We convert the column name to a more appropriate and java like name 
             * because some columns are usually named as some_thing whereas Java 
             * properties are named someThing. This call does this conversion.
             */
            String javaProperty = NameConverter.sqlToProperty(name);

            if (javaProperty.equals("version")) {
                Version version = Version.toVersion((String) value);

                PropertyUtils.setSimpleProperty(dto, javaProperty, version);
            } else {
                PropertyUtils.setSimpleProperty(dto, javaProperty, value);
            }
        } catch (Exception e) {
            throw new SQLException("Unable to set property " + name + " for bean" + dto.getClass(), e);
        }
    }

    return dto;
}

From source file:net.orpiske.ssps.common.repository.search.cache.MultiRsHandler.java

@Override
protected PackageInfo handleRow(ResultSet rs) throws SQLException {
    PackageInfo dto = new PackageInfo();

    ResultSetMetaData meta = rs.getMetaData();

    for (int i = 1; i <= meta.getColumnCount(); i++) {
        Object value = rs.getObject(i);
        String name = meta.getColumnName(i);

        try {/*  www. j a va2s.c  om*/
            /*
             * We convert the column name to a more appropriate and java like name 
             * because some columns are usually named as some_thing whereas Java 
             * properties are named someThing. This call does this conversion.
             */
            String javaProperty = NameConverter.sqlToProperty(name);

            if (javaProperty.equals("version")) {
                Version version = Version.toVersion((String) value);

                PropertyUtils.setSimpleProperty(dto, javaProperty, version);
            } else {
                PropertyUtils.setSimpleProperty(dto, javaProperty, value);
            }
        } catch (Exception e) {
            throw new SQLException("Unable to set property " + name + " for bean" + dto.getClass(), e);
        }
    }

    return dto;
}

From source file:net.orpiske.ssps.common.registry.SoftwareInventoryRsHandler.java

@Override
public SoftwareInventoryDto handle(ResultSet rs) throws SQLException {

    // No records to handle :O
    if (!rs.next()) {
        return null;
    }/*from  ww w  .  j a v  a 2  s  .c o m*/

    ResultSetMetaData meta = rs.getMetaData();

    for (int i = 1; i <= meta.getColumnCount(); i++) {
        Object value = rs.getObject(i);
        String name = meta.getColumnName(i);

        try {
            /*
             * We convert the column name to a more appropriate and java like name 
             * because some columns are usually named as some_thing whereas Java 
             * properties are named someThing. This call does this conversion.
             */
            String javaProperty = NameConverter.sqlToProperty(name);

            if (javaProperty.equals("version")) {
                Version version = Version.toVersion((String) value);

                PropertyUtils.setSimpleProperty(dto, javaProperty, version);
            } else {
                PropertyUtils.setSimpleProperty(dto, javaProperty, value);
            }

        } catch (Exception e) {
            throw new SQLException("Unable to set property " + name + " for bean" + dto.getClass(), e);
        }
    }

    return dto;
}

From source file:net.orpiske.ssps.common.repository.search.cache.PackageCacheRsHandler.java

@Override
public PackageInfo handle(ResultSet rs) throws SQLException {

    // No records to handle :O
    if (!rs.next()) {
        return null;
    }// w w w .  j a  va2 s.  c o  m

    ResultSetMetaData meta = rs.getMetaData();

    for (int i = 1; i <= meta.getColumnCount(); i++) {
        Object value = rs.getObject(i);
        String name = meta.getColumnName(i);

        try {
            /*
             * We convert the column name to a more appropriate and java like name 
             * because some columns are usually named as some_thing whereas Java 
             * properties are named someThing. This call does this conversion.
             */
            String javaProperty = NameConverter.sqlToProperty(name);

            if (javaProperty.equals("version")) {
                Version version = Version.toVersion((String) value);

                PropertyUtils.setSimpleProperty(dto, javaProperty, version);
            } else {
                PropertyUtils.setSimpleProperty(dto, javaProperty, value);
            }

        } catch (Exception e) {
            throw new SQLException("Unable to set property " + name + " for bean" + dto.getClass(), e);
        }
    }

    return dto;
}