Example usage for org.apache.commons.dbutils QueryLoader instance

List of usage examples for org.apache.commons.dbutils QueryLoader instance

Introduction

In this page you can find the example usage for org.apache.commons.dbutils QueryLoader instance.

Prototype

QueryLoader instance

To view the source code for org.apache.commons.dbutils QueryLoader instance.

Click Source Link

Document

The Singleton instance of this class.

Usage

From source file:com.nessacademy.connection.QueryInstance.java

public String getQuery(String query) {
    this.queryLoader = QueryLoader.instance();
    try {/* w w w . ja va 2  s  .  c o  m*/
        Map<String, String> queries = queryLoader.load(SQL_FILE);
        return queries.get(query);
    } catch (IOException ex) {
        Logger.getLogger(QueryInstance.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:by.jdbc.dbutils.QueryLoaderTest.java

public void testLoad() throws IOException {
    try {/*ww  w .ja  v a 2  s  .c o m*/
        QueryLoader loader = QueryLoader.instance();
        Map<String, String> q = loader.load(QUERIES);
        Map<String, String> q2 = loader.load(QUERIES);

        loader.unload(QUERIES);
        Map<String, String> q3 = loader.load(QUERIES);

    } catch (IllegalArgumentException e) {
        // TODO Figure out why the Maven build can't find the properties
        // file.  The tests run fine in Eclipse so just catch this
        // exception for now.
    }
}

From source file:net.sf.diningout.sql.Queries.java

private Queries(String file) {
    file = DIR + file + ".xml";
    try {// w ww  . ja va  2  s. c o  m
        mQueries = QueryLoader.instance().load(file);
    } catch (IOException e) {
        exception(e);
        throw new IllegalArgumentException(file + " is not accessible", e);
    }
}

From source file:ca.on.gov.jus.icon.common.util.JDBCUtils.java

/**
 * Loads a Map of query names to SQL values.
 * The Maps are cached so a subsequent request to load queries
 * from the same path will return the cached Map.
 * /*from   w ww  .j a v a  2s.  co  m*/
 * The default "/SQLStatements.properties" path will be used
 * if the propFilePath parameter is set to null.
 * 
 * Note: The property file path not a file system path
 * If you had a jarred SQLStatements.properties file in the
 * ca.olgc.ci.common package you would pass
 * "/ca/olgc/ci/common/SQLStatements.properties" to this method. 
 * 
 * @param        propFilePath      The path that the ClassLoader will use to find the file.
 * @return       Map            Collection of SQL statements.
 * @exception    IOException      Thrown if loading the properties file fails.
 */
static public Map getAllSQLStatements(String propFilePath) throws IOException {
    Map sqlStatments = null;

    // Use the default property file path if it is not provided.
    if (propFilePath == null) {
        propFilePath = SQL_STATEMENTS_PROP_FILE;
    }

    // Get the singleton Query Loader object.
    QueryLoader loader = QueryLoader.instance();

    // Get the collection of SQL statements from the Query Loader.
    sqlStatments = loader.load(propFilePath);

    return sqlStatments;
}

From source file:net.orpiske.ssps.common.db.version.DbVersionDao.java

/**
 * Constructor//from  w  w w  .j av a  2 s  .  c  o m
 * @param databaseManager The database manager
 * @throws net.orpiske.ssps.common.db.exceptions.DatabaseInitializationException if it fails to read the queries for this 
 * DAO.
 */
public DbVersionDao(final DatabaseManager databaseManager) throws DatabaseInitializationException {
    super(databaseManager);

    QueryLoader queryLoader = QueryLoader.instance();

    try {
        queries = queryLoader.load("/net/orpiske/ssps/common/db/version/DbVersion.properties");
    } catch (IOException e) {
        throw new DatabaseInitializationException("Unable to load queries: " + e.getMessage(), e);
    }
}

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

/**
 * Constructor//from  www. j  ava  2 s .c o  m
 * @param databaseManager The database manager
 * @throws DatabaseInitializationException if it fails to read the queries for this 
 * DAO.
 */
public SoftwareInventoryDao(final DatabaseManager databaseManager) throws DatabaseInitializationException {
    super(databaseManager);

    QueryLoader queryLoader = QueryLoader.instance();

    try {
        queries = queryLoader.load("/net/orpiske/ssps/common/registry/SoftwareInventory.properties");
    } catch (IOException e) {
        throw new DatabaseInitializationException("Unable to load queries: " + e.getMessage(), e);
    }
}

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

/**
 * Constructor/*from  ww w  .  ja v a2  s .  c om*/
 * @param databaseManager The database manager
 * @throws net.orpiske.ssps.common.db.exceptions.DatabaseInitializationException if it fails to read the queries for this 
 * DAO.
 */
public DependencyCacheDao(final DatabaseManager databaseManager) throws DatabaseInitializationException {
    super(databaseManager);

    QueryLoader queryLoader = QueryLoader.instance();

    try {
        queries = queryLoader.load("/net/orpiske/ssps/common/dependencies/cache/DependencyCache.properties");
    } catch (IOException e) {
        throw new DatabaseInitializationException("Unable to load queries: " + e.getMessage(), e);
    }
}

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

/**
 * Constructor//from ww  w .j a va  2s. co  m
 * @param databaseManager The database manager
 * @throws net.orpiske.ssps.common.db.exceptions.DatabaseInitializationException if it fails to read the queries for this 
 * DAO.
 */
public PackageCacheDao(final DatabaseManager databaseManager) throws DatabaseInitializationException {
    super(databaseManager);

    QueryLoader queryLoader = QueryLoader.instance();

    try {
        queries = queryLoader.load("/net/orpiske/ssps/common/repository/search/cache/PackageCache.properties");
    } catch (IOException e) {
        throw new DatabaseInitializationException("Unable to load queries: " + e.getMessage(), e);
    }
}

From source file:org.rti.zcore.dar.dao.DarFormDAO.java

/**
 * Create record. Create a transaction to ensure data integrity, create/set eventId,
 * creates a TimsSessionSubject stub to store patient,uuid if PatientRegistration form.
 * create the encounter, handle updates to patient status and (if form 1, event)
 * Extended Lab Tests - update extendedLabId in labtest table
 * Update values in patient table//from   w w  w .  j  a v  a 2 s. co m
 * Commit transaction
 *
 * @param conn
 * @param formObj - must have created/modified info already initialized
 * @param userName
 * @param siteId
 * @param formDef
 * @param currentFlowId
 * @param formBean null for patient bridge tables.
 */
public static EncounterData create(Connection conn, BaseEncounter formObj, String userName, Long siteId,
        Form formDef, Long currentFlowId, Map formBean) throws Exception {

    Map queries = QueryLoader.instance().load("/" + Constants.SQL_PATIENT_PROPERTIES);
    Map genQueries = QueryLoader.instance().load("/" + Constants.SQL_GENERATED_PROPERTIES);
    Long patientId = null;
    Long eventId = null;
    Event event = null;
    String eventUuid = null;
    Long encounterId = null;
    Boolean newEvent = null;
    String formName = StringManipulation.fixClassname(formDef.getName());
    EncounterData formData = (EncounterData) formObj;
    SessionSubject sessionPatient = (SessionSubject) formData.getSessionPatient();
    String patientUuid = null;
    if (sessionPatient != null) {
        patientUuid = sessionPatient.getUuid();
    }

    /*       if (Constants.DATABASE_TYPE.equals("mssql")) {
             DatabaseUtils.create(conn, "SET IDENTITY_INSERT " + formDef.getName() +  " ON");
          }*/

    conn.setAutoCommit(false);
    //log.debug("commit status: " + conn.getAutoCommit());
    // start the transaction
    String sql = "START TRANSACTION;";
    // ArrayList array = new ArrayList();
    try {
        // Don't do this in Derby - not necessary
        if (Constants.DATABASE_TYPE.equals("mysql")) {
            DatabaseUtils.create(conn, sql);
        }
        /**
         * Persist the encounter
         */
        encounterId = createEncounter(conn, genQueries, formData, formDef, userName, siteId, formBean);

        formData.setId(encounterId);
        // todo: the vo's siteId is probably already set. Delete next line?
        formData.setSiteId(siteId);
        formData.setFormName(formName);

        int formId = formDef.getId().intValue();

        /**
         * Commit the transaction
         */
        if (Constants.DATABASE_TYPE.equals("mysql")) {
            sql = "COMMIT";
            DatabaseUtils.create(conn, sql);
            conn.commit();
        } else {
            conn.setAutoCommit(true);
        }
        //log.debug("Commit status: " + conn.getAutoCommit());
    } catch (Exception e) {
        if (Constants.DATABASE_TYPE.equals("mysql")) {
            sql = "ROLLBACK";
            DatabaseUtils.create(conn, sql);
        } else {
            conn.rollback();
        }
        log.error("Rolling back transation due to error: " + e);
        e.printStackTrace();
        throw new SQLException("Error saving this record.", e.getMessage());
    } finally {
        if (Constants.DATABASE_TYPE.equals("mssql")) {
            DatabaseUtils.create(conn, "SET IDENTITY_INSERT " + formDef.getName() + " OFF");
        }
    }
    return formData;
}

From source file:org.rti.zcore.dar.dao.InventoryDAO.java

/**
 * Creates Out-of-stock record./*from   ww  w .  jav a2 s .c om*/
 * @param conn
 * @param formDef
 * @param formId
 * @param patientId
 * @param siteId
 * @param username
 * @param sessionPatient
 * @param vo
 * @param itemId
 * @param quantityDispensed
 * @param visitDateD
 * @throws ClassNotFoundException
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws IOException
 * @throws Exception
 */
public static void createOutOfStockRecord(Connection conn, Form formDef, String formId, Long patientId,
        Long siteId, String username, SessionSubject sessionPatient, EncounterData vo, Long itemId,
        Integer quantityDispensed, Date visitDateD) throws ClassNotFoundException, InstantiationException,
        IllegalAccessException, InvocationTargetException, IOException, Exception {
    Long encounterId;
    Form formDef2 = (Form) DynaSiteObjects.getForms().get(new Long("161"));
    String classname = "org.rti.zcore.dar.gen.StockControl";
    Class formClass = Class.forName(classname);
    BaseEncounter stockControl = (BaseEncounter) formClass.newInstance();
    // don't set patient_id or pregnancy_id - this will cause constraint errors when a patient is deleted.
    stockControl.setPatientId(null);
    stockControl.setPregnancyId(null);
    stockControl.setFormId(formDef2.getId());
    stockControl.setDateVisit(visitDateD);
    // current flow is set in the session by BasePatientAction
    // but we need the flow of the form
    stockControl.setFlowId(formDef.getFlow().getId());
    Map stockControlMap = new HashMap();
    stockControlMap.put("date_of_record", visitDateD.toString());
    stockControlMap.put("item_id", itemId.toString());
    stockControlMap.put("type_of_change", "3279"); //type_of_change
    stockControlMap.put("change_value", quantityDispensed.toString()); //change_value
    stockControlMap.put("balance", "0"); //balance
    stockControlMap.put("last_patient_item_id", vo.getId()); //last_patient_item_id
    EncounterData vo2 = PopulatePatientRecord.populateEncounterData(formDef, formId, siteId, username,
            stockControl, stockControlMap);
    Map genQueries = QueryLoader.instance().load("/" + Constants.SQL_GENERATED_PROPERTIES);

    /**
     * Persist the encounter
     */
    encounterId = org.rti.zcore.dao.FormDAO.createEncounter(conn, genQueries, vo2, formDef2, username, siteId,
            stockControlMap);
}