Example usage for javax.persistence PersistenceException PersistenceException

List of usage examples for javax.persistence PersistenceException PersistenceException

Introduction

In this page you can find the example usage for javax.persistence PersistenceException PersistenceException.

Prototype

public PersistenceException(Throwable cause) 

Source Link

Document

Constructs a new PersistenceException exception with the specified cause.

Usage

From source file:oscar.oscarEncounter.data.EctFormData.java

public static ArrayList<PatientForm> getGroupedPatientFormsAsArrayList(String demoNo, String formName,
        String table, String jsp) {
    table = StringUtils.trimToNull(table);
    if (table == null)
        return (new ArrayList<PatientForm>());

    ArrayList<PatientForm> forms = new ArrayList<PatientForm>();

    Connection c = null;//from  w  ww .j  a  v a 2 s .  c  o  m
    try {
        c = DbConnectionFilter.getThreadLocalDbConnection();

        if (!table.equals("form")) {
            String sql = "SELECT max(ID) ID, demographic_no, formCreated, date(formEdited) 'lastEdited', max(formEdited) 'frmEdited' FROM "
                    + table + " WHERE demographic_no=" + demoNo + " group by lastEdited";

            Statement s = c.createStatement();
            ResultSet rs = s.executeQuery(sql);

            while (rs.next()) {
                PatientForm frm = new PatientForm(formName, rs.getInt("ID"), rs.getInt("demographic_no"),
                        rs.getDate("formCreated"), rs.getTimestamp("frmEdited"), jsp);
                forms.add(frm);
            }
        } else {
            String sql = "SELECT form_no, demographic_no, form_date from " + table + " where demographic_no="
                    + demoNo + " order by form_no desc";

            Statement s = c.createStatement();
            ResultSet rs = s.executeQuery(sql);

            while (rs.next()) {
                PatientForm frm = new PatientForm(formName, rs.getInt("form_no"), rs.getInt("demographic_no"),
                        rs.getDate("form_date"), rs.getDate("form_date"));
                forms.add(frm);
            }
        }
    } catch (SQLException e) {
        logger.error("Unexpected error.", e);
        throw (new PersistenceException(e));
    } finally {
        SqlUtils.closeResources(c, null, null);
    }

    return (forms);
}

From source file:oscar.oscarEncounter.data.EctFormData.java

public static ArrayList<PatientForm> getPatientFormsAsArrayList(String demoNo, String formName, String table) {
    table = StringUtils.trimToNull(table);
    if (table == null)
        return (new ArrayList<PatientForm>());

    ArrayList<PatientForm> forms = new ArrayList<PatientForm>();

    Connection c = null;/*from w  w w  .  j a v  a2s  .c  o m*/
    try {
        c = DbConnectionFilter.getThreadLocalDbConnection();

        if (!table.equals("form")) {
            String sql = "SELECT ID, demographic_no, formCreated, formEdited FROM " + table
                    + " WHERE demographic_no=" + demoNo + " ORDER BY ID DESC";

            Statement s = c.createStatement();
            ResultSet rs = s.executeQuery(sql);

            while (rs.next()) {
                PatientForm frm = new PatientForm(formName, rs.getInt("ID"), rs.getInt("demographic_no"),
                        rs.getDate("formCreated"), rs.getTimestamp("formEdited"));
                forms.add(frm);
            }
        } else {
            String sql = "SELECT form_no, demographic_no, form_date from " + table + " where demographic_no="
                    + demoNo + " order by form_no desc";

            Statement s = c.createStatement();
            ResultSet rs = s.executeQuery(sql);

            while (rs.next()) {
                PatientForm frm = new PatientForm(formName, rs.getInt("form_no"), rs.getInt("demographic_no"),
                        rs.getDate("form_date"), rs.getDate("form_date"));
                forms.add(frm);
            }
        }
    } catch (SQLException e) {
        logger.error("Unexpected error.", e);
        throw (new PersistenceException(e));
    } finally {
        SqlUtils.closeResources(c, null, null);
    }

    return (forms);
}

From source file:oscar.util.SqlUtils.java

/**
 * deprecated use jpa native queries instead
 */// w  w w . jav a2 s .  com
public static List<Integer> selectIntList(String sqlCommand) {
    Connection c = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        c = DbConnectionFilter.getThreadLocalDbConnection();
        ps = c.prepareStatement(sqlCommand);
        rs = ps.executeQuery();

        ArrayList<Integer> al = new ArrayList<Integer>();

        while (rs.next())
            al.add(rs.getInt(1));

        return (al);
    } catch (SQLException e) {
        throw (new PersistenceException(e));
    } finally {
        closeResources(c, ps, rs);
    }
}

From source file:oscar.util.SqlUtils.java

/**
 * deprecated use jpa native queries instead
 *///from  ww  w. j  a  v  a  2 s .co m
public static List<String> selectStringList(String sqlCommand) {
    Connection c = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        c = DbConnectionFilter.getThreadLocalDbConnection();
        ps = c.prepareStatement(sqlCommand);
        rs = ps.executeQuery();

        ArrayList<String> al = new ArrayList<String>();

        while (rs.next())
            al.add(rs.getString(1));

        return (al);
    } catch (SQLException e) {
        throw (new PersistenceException(e));
    } finally {
        closeResources(c, ps, rs);
    }
}

From source file:oscar.util.SqlUtils.java

public static int update(String sqlCommand) {
    Connection c = null;/*ww w  .ja v  a2  s. com*/
    Statement s = null;
    try {
        c = DbConnectionFilter.getThreadLocalDbConnection();
        s = c.createStatement();
        return (s.executeUpdate(sqlCommand));
    } catch (SQLException e) {
        throw (new PersistenceException(e));
    } finally {
        closeResources(c, s, null);
    }
}

From source file:oscar.util.SqlUtils.java

public static String getCurrentDatabaseName() {
    Connection c = null;//from   w  ww.j  a v a  2 s .  c  om
    try {
        c = DbConnectionFilter.getThreadLocalDbConnection();
        Statement s = c.createStatement();
        ResultSet rs = s.executeQuery("select database()");
        rs.next();
        return (rs.getString(1));
    } catch (SQLException e) {
        throw (new PersistenceException(e));
    } finally {
        closeResources(c, null, null);
    }
}

From source file:uk.ac.ebi.bioinvindex.persistence.OntologyEntryPersister.java

/**
 * Searches by accession and source's accession. 
 * //from  www  .  j  a v  a 2 s .  com
 */
@SuppressWarnings("unchecked")
@Override
protected OE lookup(OE object) {
    String acc = StringUtils.trimToNull(object.getAcc());

    if (acc == null || acc.contains("NULL-ACCESSION"))
        // Assume it's a new term
        return null;

    ReferenceSource source = object.getSource();

    if (source == null) {
        throw new PersistenceException("Source is null for term " + object + "!!!");
    }

    return ((OntologyEntryDAO<OE>) dao).getOntologyEntryByAccAndRefSource(acc, object.getSource().getAcc());
}