/* (non-Javadoc) * @see org.dspace.browse.BrowseDAO#doValueQuery() */ public List<String[]> doValueQuery() throws BrowseException { String query = getQuery(); Object[] params = getQueryParams(); log.debug(LogManager.getHeader(context, "executing_value_query", "query=" + query)); TableRowIterator tri = null; try { // now run the query tri = DatabaseManager.query(context, query, params); // go over the query results and process List<String[]> results = new ArrayList<String[]>(); while (tri.hasNext()) { TableRow row = tri.next(); String valueResult = row.getStringColumn("value"); String authorityResult = row.getStringColumn("authority"); if (enableBrowseFrequencies) { long frequency = row.getLongColumn("num"); results.add(new String[] {valueResult, authorityResult, String.valueOf(frequency)}); } else results.add(new String[] {valueResult, authorityResult, ""}); } return results; } catch (SQLException e) { log.error("caught exception: ", e); throw new BrowseException(e); } finally { if (tri != null) { tri.close(); } } }
/** * Constructor to load the object from the database. * * @param row database row from which to populate object. */ public MetadataField(TableRow row) { if (row != null) { this.fieldID = row.getIntColumn("metadata_field_id"); this.schemaID = row.getIntColumn("metadata_schema_id"); this.element = row.getStringColumn("element"); this.qualifier = row.getStringColumn("qualifier"); this.scopeNote = row.getStringColumn("scope_note"); this.row = row; } }
List<DCValue> get(Context c, int resourceId, int resourceTypeId, Logger log) throws SQLException { if (metadata == null) { metadata = new ArrayList<DCValue>(); // Get Dublin Core metadata TableRowIterator tri = retrieveMetadata(resourceId, resourceTypeId); if (tri != null) { try { while (tri.hasNext()) { TableRow resultRow = tri.next(); // Get the associated metadata field and schema information int fieldID = resultRow.getIntColumn("metadata_field_id"); MetadataField field = MetadataField.find(c, fieldID); if (field == null) { log.error("Loading item - cannot find metadata field " + fieldID); } else { MetadataSchema schema = MetadataSchema.find(c, field.getSchemaID()); if (schema == null) { log.error( "Loading item - cannot find metadata schema " + field.getSchemaID() + ", field " + fieldID); } else { // Make a DCValue object DCValue dcv = new DCValue(); dcv.element = field.getElement(); dcv.qualifier = field.getQualifier(); dcv.value = resultRow.getStringColumn("text_value"); dcv.language = resultRow.getStringColumn("text_lang"); // dcv.namespace = schema.getNamespace(); dcv.schema = schema.getName(); dcv.authority = resultRow.getStringColumn("authority"); dcv.confidence = resultRow.getIntColumn("confidence"); // Add it to the list metadata.add(dcv); } } } } finally { // close the TableRowIterator to free up resources if (tri != null) { tri.close(); } } } } return metadata; }
/** * Construct the metadata object from the matching database row. * * @param row database row to use for contents */ public RevisionToken(TableRow row) { if (row != null) { revisionTokenId = row.getIntColumn("revision_token_id"); tipo = row.getStringColumn("tipo"); email = row.getStringColumn("email"); token = row.getStringColumn("token"); handleRevisado = row.getStringColumn("handle_revisado"); workspaceId = row.getStringColumn("workspace_id"); revisionId = row.getStringColumn("revision_id"); this.row = row; } }
private void populateEPersonFromTableRow(EPerson eperson, TableRow row) { UUID uuid = UUID.fromString(row.getStringColumn("uuid")); for (EPersonMetadataField f : EPersonMetadataField.values()) { eperson.setMetadata(f, row.getStringColumn(f.toString())); } eperson.setIdentifier(new ObjectIdentifier(uuid)); eperson.setCanLogIn(row.getBooleanColumn("can_log_in")); eperson.setRequireCertificate(row.getBooleanColumn("require_certificate")); eperson.setSelfRegistered(row.getBooleanColumn("self_registered")); }
/* (non-Javadoc) * @see org.dspace.browse.BrowseDAO#doValueQuery() */ public List doValueQuery() throws BrowseException { String query = getQuery(); Object[] params = getQueryParams(); log.debug(LogManager.getHeader(context, "executing_value_query", "query=" + query)); TableRowIterator tri = null; try { // now run the query tri = DatabaseManager.query(context, query, params); // go over the query results and process List results = new ArrayList(); while (tri.hasNext()) { TableRow row = tri.next(); String stringResult = row.getStringColumn("value"); results.add(stringResult); } return results; } catch (SQLException e) { log.error("caught exception: ", e); throw new BrowseException(e); } finally { if (tri != null) { tri.close(); } } }
/** * Perform a database query to obtain the string array of values corresponding to the passed * parameters. This is only really called from <code> * getMetadata(schema, element, qualifier, lang); * </code> which will obtain the value from cache if available first. * * @param schema * @param element * @param qualifier * @param lang */ @Override public List<DCValue> getMetadata( Item item, String schema, String element, String qualifier, String lang) { List<DCValue> metadata = new ArrayList<DCValue>(); try { TableRowIterator tri; if (qualifier == null) { Object[] params = {item.getID(), element, schema}; tri = DatabaseManager.query(context, getByMetadataElement, params); } else if (Item.ANY.equals(qualifier)) { Object[] params = {item.getID(), element, schema}; tri = DatabaseManager.query(context, getByMetadataAnyQualifier, params); } else { Object[] params = {item.getID(), element, qualifier, schema}; tri = DatabaseManager.query(context, getByMetadata, params); } while (tri.hasNext()) { TableRow tr = tri.next(); DCValue dcv = new DCValue(); dcv.schema = schema; dcv.element = element; dcv.qualifier = qualifier; dcv.language = lang; dcv.value = tr.getStringColumn("text_value"); metadata.add(dcv); } } catch (SQLException sqle) { throw new RuntimeException(sqle); } return metadata; }
/** Return the list of running applications. */ public static List<AbstractDSpaceWebapp> getApps() { ArrayList<AbstractDSpaceWebapp> apps = new ArrayList<AbstractDSpaceWebapp>(); TableRowIterator tri; Context context = null; HttpMethod request = null; try { context = new Context(); tri = DatabaseManager.queryTable(context, "Webapp", "SELECT * FROM Webapp"); for (TableRow row : tri.toList()) { DSpaceWebapp app = new DSpaceWebapp(); app.kind = row.getStringColumn("AppName"); app.url = row.getStringColumn("URL"); app.started = row.getDateColumn("Started"); app.uiQ = row.getBooleanColumn("isUI"); HttpClient client = new HttpClient(); request = new HeadMethod(app.url); int status = client.executeMethod(request); request.getResponseBody(); if (status != HttpStatus.SC_OK) { DatabaseManager.delete(context, row); context.commit(); continue; } apps.add(app); } } catch (SQLException e) { log.error("Unable to list running applications", e); } catch (HttpException e) { log.error("Failure checking for a running webapp", e); } catch (IOException e) { log.error("Failure checking for a running webapp", e); } finally { if (null != request) { request.releaseConnection(); } if (null != context) { context.abort(); } } return apps; }
@Override public void loadMetadata(Item item) { MetadataFieldDAO mfDAO = MetadataFieldDAOFactory.getInstance(context); MetadataSchemaDAO msDAO = MetadataSchemaDAOFactory.getInstance(context); try { TableRowIterator tri = DatabaseManager.queryTable( context, "metadatavalue", "SELECT * FROM MetadataValue " + "WHERE item_id = ? " + "ORDER BY metadata_field_id, place", item.getID()); List<DCValue> metadata = new ArrayList<DCValue>(); for (TableRow row : tri.toList()) { // Get the associated metadata field and schema information int fieldID = row.getIntColumn("metadata_field_id"); MetadataField field = mfDAO.retrieve(fieldID); if (field == null) { log.error("Loading item - cannot find metadata field " + fieldID); } else { MetadataSchema schema = msDAO.retrieve(field.getSchemaID()); // Make a DCValue object DCValue dcv = new DCValue(); dcv.schema = schema.getName(); dcv.element = field.getElement(); dcv.qualifier = field.getQualifier(); dcv.language = row.getStringColumn("text_lang"); dcv.value = row.getStringColumn("text_value"); // Add it to the item metadata.add(dcv); } } item.setMetadata(metadata); } catch (SQLException sqle) { throw new RuntimeException(sqle); } }
public static boolean estaFinalizado(Context context, String token) throws SQLException { TableRow qResult = DatabaseManager.querySingle( context, "SELECT revision_id FROM revision_token WHERE token = ?", token); if (qResult != null && qResult.getStringColumn("revision_id") != null) { return true; } return false; }
public static boolean IsInstitution(Context context, String ip) throws SQLException { String sql = "select ip_range from stats.ip_institution"; TableRowIterator iterator = DatabaseManager.query(context, sql); while (iterator.hasNext()) { TableRow row = iterator.next(); String range = row.getStringColumn("ip_range"); if (ip.indexOf(range) == 0) return true; } return false; }
private void populateCollectionFromTableRow(Collection c, TableRow row) { Bitstream logo = null; Item templateItem = null; // Get the logo bitstream if (!row.isColumnNull("logo_bitstream_id")) { int id = row.getIntColumn("logo_bitstream_id"); logo = bitstreamDAO.retrieve(id); } // Get the template item if (!row.isColumnNull("template_item_id")) { templateItem = itemDAO.retrieve(row.getIntColumn("template_item_id")); } UUID uuid = UUID.fromString(row.getStringColumn("uuid")); c.setIdentifier(new ObjectIdentifier(uuid)); c.setLogoBitstream(logo); c.setTemplateItem(templateItem); c.setWorkflowGroup(1, groupFromColumn(row, "workflow_step_1")); c.setWorkflowGroup(2, groupFromColumn(row, "workflow_step_2")); c.setWorkflowGroup(3, groupFromColumn(row, "workflow_step_3")); c.setSubmitters(groupFromColumn(row, "submitter")); c.setAdministrators(groupFromColumn(row, "admin")); for (CollectionMetadataField field : CollectionMetadataField.values()) { String value = row.getStringColumn(field.toString()); if (value == null) { c.setMetadata(field.toString(), ""); } else { c.setMetadata(field.toString(), value); } } }
private void populateItemFromTableRow(Item item, TableRow row) { UUID uuid = UUID.fromString(row.getStringColumn("uuid")); int submitterId = row.getIntColumn("submitter_id"); int owningCollectionId = row.getIntColumn("owning_collection"); boolean inArchive = row.getBooleanColumn("in_archive"); boolean withdrawn = row.getBooleanColumn("withdrawn"); Date lastModified = row.getDateColumn("last_modified"); item.setIdentifier(new ObjectIdentifier(uuid)); item.setSubmitter(submitterId); item.setOwningCollectionId(owningCollectionId); item.setArchived(inArchive); item.setWithdrawn(withdrawn); item.setLastModified(lastModified); }
/* (non-Javadoc) * @see org.dspace.browse.BrowseDAO#doMaxQuery(java.lang.String, java.lang.String, int) */ public String doMaxQuery(String column, String table, int itemID) throws BrowseException { TableRowIterator tri = null; try { String query = "SELECT max(" + column + ") FROM " + table + " WHERE item_id = ?"; Object[] params = {new Integer(itemID)}; tri = DatabaseManager.query(context, query, params); TableRow row; if (tri.hasNext()) { row = tri.next(); return row.getStringColumn("max"); } else { return null; } } catch (SQLException e) { throw new BrowseException(e); } finally { if (tri != null) { tri.close(); } } }
/** * get name of group * * @return name */ public String getName() { return myRow.getStringColumn("name"); }
public void updateMetadata() throws SQLException, AuthorizeException { // Map counting number of values for each element/qualifier. // Keys are Strings: "element" or "element.qualifier" // Values are Integers indicating number of values written for a // element/qualifier Map<String, Integer> elementCount = new HashMap<String, Integer>(); modifiedMetadata = false; // Arrays to store the working information required int[] placeNum = new int[getMetadata().size()]; boolean[] storedDC = new boolean[getMetadata().size()]; MetadataField[] dcFields = new MetadataField[getMetadata().size()]; // Work out the place numbers for the in memory DC for (int dcIdx = 0; dcIdx < getMetadata().size(); dcIdx++) { DCValue dcv = getMetadata().get(dcIdx); // Work out the place number for ordering int current = 0; // Key into map is "element" or "element.qualifier" String key = dcv.element + ((dcv.qualifier == null) ? "" : ("." + dcv.qualifier)); Integer currentInteger = elementCount.get(key); if (currentInteger != null) { current = currentInteger.intValue(); } current++; elementCount.put(key, Integer.valueOf(current)); // Store the calculated place number, reset the stored flag, and cache the metadatafield placeNum[dcIdx] = current; storedDC[dcIdx] = false; dcFields[dcIdx] = getMetadataField(dcv); if (dcFields[dcIdx] == null) { // Bad DC field, log and throw exception log.warn("Invalid metadata field: [" + dcv.getField() + "] : [" + dcv.value + "]"); throw new SQLException("Invalid metadata field: [" + dcv.getField() + "]"); } } // Now the precalculations are done, iterate through the existing metadata // looking for matches TableRowIterator tri = retrieveMetadata(); if (tri != null) { try { while (tri.hasNext()) { TableRow tr = tri.next(); // Assume that we will remove this row, unless we get a match boolean removeRow = true; // Go through the in-memory metadata, unless we've already decided to keep this row for (int dcIdx = 0; dcIdx < getMetadata().size() && removeRow; dcIdx++) { // Only process if this metadata has not already been matched to something in the DB if (!storedDC[dcIdx]) { boolean matched = true; DCValue dcv = getMetadata().get(dcIdx); // Check the metadata field is the same if (matched && dcFields[dcIdx].getFieldID() != tr.getIntColumn("metadata_field_id")) { matched = false; } // Check the place is the same if (matched && placeNum[dcIdx] != tr.getIntColumn("place")) { matched = false; } // Check the text is the same if (matched) { String text = tr.getStringColumn("text_value"); if (dcv.value == null && text == null) { matched = true; } else if (dcv.value != null && dcv.value.equals(text)) { matched = true; } else { matched = false; } } // Check the language is the same if (matched) { String lang = tr.getStringColumn("text_lang"); if (dcv.language == null && lang == null) { matched = true; } else if (dcv.language != null && dcv.language.equals(lang)) { matched = true; } else { matched = false; } } // check that authority and confidence match if (matched) { String auth = tr.getStringColumn("authority"); int conf = tr.getIntColumn("confidence"); if (!((dcv.authority == null && auth == null) || (dcv.authority != null && auth != null && dcv.authority.equals(auth)) && dcv.confidence == conf)) { matched = false; } } // If the db record is identical to the in memory values if (matched) { // Flag that the metadata is already in the DB storedDC[dcIdx] = true; // Flag that we are not going to remove the row removeRow = false; } } } // If after processing all the metadata values, we didn't find a match // delete this row from the DB if (removeRow) { DatabaseManager.delete(ourContext, tr); modifiedMetadata = true; } } } finally { tri.close(); } } // Add missing in-memory DC for (int dcIdx = 0; dcIdx < getMetadata().size(); dcIdx++) { // Only write values that are not already in the db if (!storedDC[dcIdx]) { DCValue dcv = getMetadata().get(dcIdx); // Write DCValue MetadataValue metadata = new MetadataValue(); metadata.setResourceId(getID()); metadata.setResourceTypeId(getType()); metadata.setFieldId(dcFields[dcIdx].getFieldID()); metadata.setValue(dcv.value); metadata.setLanguage(dcv.language); metadata.setPlace(placeNum[dcIdx]); metadata.setAuthority(dcv.authority); metadata.setConfidence(dcv.confidence); metadata.create(ourContext); modifiedMetadata = true; } } if (modifiedMetadata) { ourContext.addEvent( new Event( Event.MODIFY_METADATA, getType(), getID(), getDetails(), getIdentifiers(ourContext))); modifiedMetadata = false; } }
private static void loadParameters( PreparedStatement statement, Collection<ColumnInfo> columns, TableRow row) throws SQLException { int count = 0; for (ColumnInfo info : columns) { count++; String column = info.getCanonicalizedName(); int jdbctype = info.getType(); if (row.isColumnNull(column)) { statement.setNull(count, jdbctype); } else { switch (jdbctype) { case Types.BOOLEAN: case Types.BIT: statement.setBoolean(count, row.getBooleanColumn(column)); break; case Types.INTEGER: if (isOracle) { statement.setLong(count, row.getLongColumn(column)); } else { statement.setInt(count, row.getIntColumn(column)); } break; case Types.NUMERIC: case Types.DECIMAL: statement.setLong(count, row.getLongColumn(column)); // FIXME should be BigDecimal if TableRow supported that break; case Types.BIGINT: statement.setLong(count, row.getLongColumn(column)); break; case Types.CLOB: if (isOracle) { // Support CLOBs in place of TEXT columns in Oracle statement.setString(count, row.getStringColumn(column)); } else { throw new IllegalArgumentException("Unsupported JDBC type: " + jdbctype); } break; case Types.VARCHAR: statement.setString(count, row.getStringColumn(column)); break; case Types.DATE: statement.setDate(count, new java.sql.Date(row.getDateColumn(column).getTime())); break; case Types.TIME: statement.setTime(count, new Time(row.getDateColumn(column).getTime())); break; case Types.TIMESTAMP: statement.setTimestamp(count, new Timestamp(row.getDateColumn(column).getTime())); break; default: throw new IllegalArgumentException("Unsupported JDBC type: " + jdbctype); } } } }
public String getRoleId() { return myRow.getStringColumn("role_id"); }