Example usage for org.springframework.dao DataAccessResourceFailureException DataAccessResourceFailureException

List of usage examples for org.springframework.dao DataAccessResourceFailureException DataAccessResourceFailureException

Introduction

In this page you can find the example usage for org.springframework.dao DataAccessResourceFailureException DataAccessResourceFailureException.

Prototype

public DataAccessResourceFailureException(String msg) 

Source Link

Document

Constructor for DataAccessResourceFailureException.

Usage

From source file:org.opennms.ng.dao.support.PropertiesGraphDao.java

private String getReportProperty(Properties props, String key, String suffix, boolean required) {

    String propertyName;//w  w  w.  java2s  . com
    String graphName;
    if (key != null) {
        propertyName = "report." + key + "." + suffix;
        graphName = key;
    } else {
        propertyName = "report." + suffix;
        // It's lightly evil to know this from this method, but we can be
        // confident that report.id will exist
        graphName = props.getProperty("report.id");
    }

    String property = props.getProperty(propertyName);
    if (property == null && required == true) {
        throw new DataAccessResourceFailureException("Properties for " + "report '" + graphName
                + "' must contain \'" + propertyName + "\' property");
    }

    return property;
}

From source file:org.opennms.ng.dao.support.PropertiesGraphDao.java

private Integer getIntegerReportProperty(Properties props, String key, String suffix, boolean required) {
    String value = getReportProperty(props, key, suffix, required);
    if (value == null) {
        return null;
    }/*ww w . j av a  2s  .co m*/

    try {
        return new Integer(value);
    } catch (NumberFormatException e) {
        throw new DataAccessResourceFailureException("Property value for '" + suffix + "' on report '" + key
                + "' must be an integer.  '" + value + "' is not a valid value");
    }
}

From source file:com.orange.mmp.midlet.MidletManager.java

/**
 * Get Midlet for download./*ww  w  .  j  a va 2s.c o m*/
 * @param appId            The midlet main application ID
 * @param mobile          The mobile to use
 * @param isMidletSigned   Boolean indicating if the midlet is signed (true), unsigned (false), to sign (null)
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public ByteArrayOutputStream getJar(String appId, Mobile mobile, Boolean isMidletSigned) throws MMPException {
    if (appId == null)
        appId = ServiceManager.getInstance().getDefaultService().getId();

    //Search in Cache first
    String jarKey = appId + isMidletSigned + mobile.getKey();

    if (this.midletCache.isKeyInCache(jarKey)) {
        return (ByteArrayOutputStream) this.midletCache.get(jarKey).getValue();
    }

    Object extraCSSJadAttr = null;

    //Not found, build the JAR
    ByteArrayOutputStream output = null;
    ZipOutputStream zipOut = null;
    ZipInputStream zipIn = null;
    InputStream resourceStream = null;
    try {
        Midlet midlet = new Midlet();
        midlet.setType(mobile.getMidletType());
        Midlet[] midlets = (Midlet[]) DaoManagerFactory.getInstance().getDaoManager().getDao("midlet")
                .find(midlet);
        if (midlets.length == 0)
            throw new MMPException("Midlet type not found : " + mobile.getMidletType());
        else
            midlet = midlets[0];

        //Get navigation widget
        Widget appWidget = WidgetManager.getInstance().getWidget(appId, mobile.getBranchId());
        if (appWidget == null) {
            // Use Default if not found
            appWidget = WidgetManager.getInstance().getWidget(appId);
        }
        List<URL> embeddedResources = WidgetManager.getInstance().findWidgetResources("/m4m/", "*", appId,
                mobile.getBranchId(), false);
        output = new ByteArrayOutputStream();
        zipOut = new ZipOutputStream(output);
        zipIn = new ZipInputStream(new FileInputStream(new File(new URI(midlet.getJarLocation()))));

        ZipEntry entry;
        while ((entry = zipIn.getNextEntry()) != null) {
            zipOut.putNextEntry(entry);

            // Manifest found, modify it before delivery
            if (entry.getName().equals(Constants.JAR_MANIFEST_ENTRY) && appWidget != null) {
                Manifest midletManifest = new Manifest(zipIn);

                // TODO ? Remove optional permissions if midlet is not signed
                if (isMidletSigned != null && !isMidletSigned)
                    midletManifest.getMainAttributes().remove(Constants.JAD_PARAMETER_OPT_PERMISSIONS);

                midletManifest.getMainAttributes().putValue(Constants.JAD_PARAMETER_APPNAME,
                        appWidget.getName());
                String launcherLine = midletManifest.getMainAttributes()
                        .getValue(Constants.JAD_PARAMETER_LAUNCHER);
                Matcher launcherLineMatcher = launcherPattern.matcher(launcherLine);
                if (launcherLineMatcher.matches()) {
                    midletManifest.getMainAttributes().putValue(Constants.JAD_PARAMETER_LAUNCHER,
                            appWidget.getName().concat(", ").concat(launcherLineMatcher.group(2)).concat(", ")
                                    .concat(launcherLineMatcher.group(3)));
                } else
                    midletManifest.getMainAttributes().putValue(Constants.JAD_PARAMETER_LAUNCHER,
                            appWidget.getName());

                // Add/Modify/Delete MANIFEST parameters according to mobile rules
                JadAttributeAction[] jadActions = mobile.getJadAttributeActions();
                for (JadAttributeAction jadAction : jadActions) {
                    if (jadAction.getInManifest().equals(ApplyCase.ALWAYS)
                            || (isMidletSigned != null && isMidletSigned
                                    && jadAction.getInManifest().equals(ApplyCase.SIGNED))
                            || (isMidletSigned != null && !isMidletSigned
                                    && jadAction.getInManifest().equals(ApplyCase.UNSIGNED))) {
                        Attributes.Name attrName = new Attributes.Name(jadAction.getAttribute());
                        boolean exists = midletManifest.getMainAttributes().get(attrName) != null;
                        if (jadAction.isAddAction() || jadAction.isModifyAction()) {
                            if (exists || !jadAction.isStrict())
                                midletManifest.getMainAttributes().putValue(jadAction.getAttribute(),
                                        jadAction.getValue());
                        } else if (jadAction.isDeleteAction() && exists)
                            midletManifest.getMainAttributes().remove(attrName);
                    }
                }

                //Retrieve MeMo CSS extra attribute
                extraCSSJadAttr = midletManifest.getMainAttributes()
                        .get(new Attributes.Name(Constants.JAD_PARAMETER_MEMO_EXTRA_CSS));

                midletManifest.write(zipOut);
            }
            //Other files of Midlet
            else {
                IOUtils.copy(zipIn, zipOut);
            }
            zipIn.closeEntry();
            zipOut.closeEntry();
        }

        if (embeddedResources != null) {
            for (URL resourceUrl : embeddedResources) {
                resourceStream = resourceUrl.openConnection().getInputStream();
                String resourcePath = resourceUrl.getPath();
                entry = new ZipEntry(resourcePath.substring(resourcePath.lastIndexOf("/") + 1));
                entry.setTime(MIDLET_LAST_MODIFICATION_DATE);
                zipOut.putNextEntry(entry);
                IOUtils.copy(resourceStream, zipOut);
                zipOut.closeEntry();
                resourceStream.close();
            }
        }

        //Put JAR in cache for next uses
        this.midletCache.set(new Element(jarKey, output));

        //If necessary, add special CSS file if specified in JAD attributes
        if (extraCSSJadAttr != null) {
            String extraCSSSheetName = (String) extraCSSJadAttr;
            //Get resource stream
            resourceStream = WidgetManager.getInstance().getWidgetResource(
                    extraCSSSheetName + "/" + this.cssSheetsBundleName, mobile.getBranchId());

            if (resourceStream == null)
                throw new DataAccessResourceFailureException("no CSS sheet named " + extraCSSSheetName + " in "
                        + this.cssSheetsBundleName + " special bundle");

            //Append CSS sheet file into JAR
            entry = new ZipEntry(new File(extraCSSSheetName).getName());
            entry.setTime(MidletManager.MIDLET_LAST_MODIFICATION_DATE);
            zipOut.putNextEntry(entry);
            IOUtils.copy(resourceStream, zipOut);
            zipOut.closeEntry();
            resourceStream.close();
        }

        return output;

    } catch (IOException ioe) {
        throw new MMPException(ioe);
    } catch (URISyntaxException use) {
        throw new MMPException(use);
    } catch (DataAccessException dae) {
        throw new MMPException(dae);
    } finally {
        try {
            if (output != null)
                output.close();
            if (zipIn != null)
                zipIn.close();
            if (zipOut != null)
                zipOut.close();
            if (resourceStream != null)
                resourceStream.close();
        } catch (IOException ioe) {
            //NOP
        }
    }
}

From source file:com.thinkbiganalytics.feedmgr.nifi.controllerservice.DBCPConnectionPoolService.java

/**
 * Executes the specified SELECT query in the context of the specified controller service.
 *
 * @param serviceProperties properties describing the data source and the query
 * @return the query results/*from   ww  w  .j a va  2 s . c om*/
 * @throws DataAccessException if the query cannot be executed
 */
@Nonnull
private QueryResult executeQueryForControllerService(
        @Nonnull final ExecuteQueryControllerServiceRequest serviceProperties) {
    final Map<String, String> properties = serviceProperties.useEnvironmentProperties()
            ? nifiControllerServiceProperties.mergeNifiAndEnvProperties(
                    serviceProperties.getControllerServiceDTO().getProperties(),
                    serviceProperties.getControllerServiceName())
            : serviceProperties.getControllerServiceDTO().getProperties();

    final PoolingDataSourceService.DataSourceProperties dataSourceProperties = getDataSourceProperties(
            properties, serviceProperties);

    if (evaluateWithUserDefinedDatasources(dataSourceProperties, serviceProperties)) {
        log.info("Execute query against Controller Service: {} ({}) with uri of {}.  ",
                serviceProperties.getControllerServiceName(), serviceProperties.getControllerServiceId(),
                dataSourceProperties.getUrl());
        final DataSource dataSource = PoolingDataSourceService.getDataSource(dataSourceProperties);
        return new QueryRunner(dataSource).query(serviceProperties.getQuery());
    } else {
        throw new DataAccessResourceFailureException(
                "Unable to determine connection properties for controller service: "
                        + serviceProperties.getControllerServiceName() + "("
                        + serviceProperties.getControllerServiceId() + ")");
    }
}

From source file:org.opennms.netmgt.dao.support.PropertiesGraphDao.java

/**
 * @param type//w  ww . jav  a  2 s. c o  m
 *            - a PrefabGraphType in which graphs
 *            found in 'properties' will be stored
 * @param properties
 *            - a properties object, usually loaded from a File or
 *            InputStream, with graph definitions in it
 * @return A list of the graphs found.  THIS LIST MAY CONTAIN NULL ENTRIES, one for each
 * graph in a multi-graph file that failed to load (e.g. missing properties).  Other than
 * logging an error, this is the only way this method indicates a problem with just one graph
 * The only cause for a real exception is if there's neither a "reports" nor a "report.id" 
 * property, which cannot be recovered from   
 */
private List<PrefabGraph> loadPrefabGraphDefinitions(PrefabGraphTypeDao type, Properties properties) {
    Assert.notNull(properties, "properties argument cannot be null");

    List<PrefabGraph> result = new ArrayList<PrefabGraph>();

    String listString = properties.getProperty(DEFAULT_GRAPH_LIST_KEY); // Optional

    String[] list;

    if (listString != null) {
        list = BundleLists.parseBundleList(listString);
    } else {
        // A report-per-file properties file; just use the report.id
        // At this stage, if there was no "reports", then there *must* be
        // a report.id, otherwise we're pooched
        list = new String[1];
        try {
            list[0] = getProperty(properties, "report.id");
        } catch (DataAccessResourceFailureException e) {
            // Special case; if this exception is thrown, then report.id
            // was missing
            // But, we need to be more clear in the report (no report.id
            // *or* "reports" property).  However, we shouldn't throw
            // an exception, because that would break loading of all 
            // graphs if just one file was broken
            throw new DataAccessResourceFailureException(
                    "Properties must " + "contain a 'report.id' property " + "or a 'reports' property");
        }
    }

    for (String name : list) {
        try {
            PrefabGraph graph = makePrefabGraph(name, properties, type.getNextOrdering());
            result.add(graph);
        } catch (DataAccessResourceFailureException e) {
            LOG.error("Failed to load report '{}'", name, e);
            result.add(null); //Add a null, indicating a broken graph
        }
    }
    return result;
}

From source file:org.opennms.netmgt.dao.support.PropertiesGraphDao.java

private Integer getIntegerReportProperty(Properties props, String key, String suffix, boolean required) {
    String value = getReportProperty(props, key, suffix, required);
    if (value == null) {
        return null;
    }//w w  w . j a v a  2s. com

    try {
        return Integer.valueOf(value);
    } catch (NumberFormatException e) {
        throw new DataAccessResourceFailureException("Property value for '" + suffix + "' on report '" + key
                + "' must be an integer.  '" + value + "' is not a valid value");
    }
}

From source file:org.springframework.batch.item.database.JpaItemWriter.java

/**
 * Merge all provided items that aren't already in the persistence context
 * and then flush the entity manager./*  www  .  j  a va2 s  .  com*/
 *
 * @see org.springframework.batch.item.ItemWriter#write(java.util.List)
 */
@Override
public void write(List<? extends T> items) {
    EntityManager entityManager = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
    if (entityManager == null) {
        throw new DataAccessResourceFailureException("Unable to obtain a transactional EntityManager");
    }
    doWrite(entityManager, items);
    entityManager.flush();
}

From source file:org.springframework.data.mongodb.crossstore.MongoChangeSetPersister.java

public Object getPersistentId(ChangeSetBacked entity, ChangeSet cs) throws DataAccessException {
    log.debug("getPersistentId called on " + entity);
    if (entityManagerFactory == null) {
        throw new DataAccessResourceFailureException("EntityManagerFactory cannot be null");
    }/*  w  ww .  j  a v  a  2  s  .  c o m*/
    Object o = entityManagerFactory.getPersistenceUnitUtil().getIdentifier(entity);
    return o;
}

From source file:org.springframework.jdbc.core.metadata.GenericTableMetaDataProvider.java

private TableMetaData findTableMetaData(@Nullable String schemaName, @Nullable String tableName,
        Map<String, TableMetaData> tableMeta) {

    if (schemaName != null) {
        TableMetaData tmd = tableMeta.get(schemaName.toUpperCase());
        if (tmd == null) {
            throw new DataAccessResourceFailureException("Unable to locate table meta data for '" + tableName
                    + "' in the '" + schemaName + "' schema");
        }/* w w  w .ja  v  a 2  s  .co  m*/
        return tmd;
    } else if (tableMeta.size() == 1) {
        return tableMeta.values().iterator().next();
    } else {
        TableMetaData tmd = tableMeta.get(getDefaultSchema());
        if (tmd == null) {
            tmd = tableMeta.get(this.userName != null ? this.userName.toUpperCase() : "");
        }
        if (tmd == null) {
            tmd = tableMeta.get("PUBLIC");
        }
        if (tmd == null) {
            tmd = tableMeta.get("DBO");
        }
        if (tmd == null) {
            throw new DataAccessResourceFailureException(
                    "Unable to locate table meta data for '" + tableName + "' in the default schema");
        }
        return tmd;
    }
}