Search in sources :

Example 6 with MdAttributeDAOIF

use of com.runwaysdk.dataaccess.MdAttributeDAOIF in project geoprism-registry by terraframe.

the class PatchLastUpdateDate method doIt.

@Transaction
private void doIt() {
    Date date = new Date();
    MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(GeoVertex.CLASS);
    MdAttributeDAOIF mdAttribute = mdVertex.definesAttribute(GeoVertex.LASTUPDATEDATE);
    MdAttributeDAOIF createDate = mdVertex.definesAttribute(GeoVertex.CREATEDATE);
    long pageSize = 1000;
    long count = 0;
    do {
        StringBuilder builder = new StringBuilder();
        builder.append("SELECT FROM " + mdVertex.getDBClassName());
        builder.append(" WHERE " + mdAttribute.getColumnName() + " IS NULL");
        builder.append(" OR " + createDate.getColumnName() + " IS NULL");
        builder.append(" ORDER BY oid");
        builder.append(" SKIP " + 0 + " LIMIT " + pageSize);
        GraphQuery<VertexObject> query = new GraphQuery<VertexObject>(builder.toString());
        List<VertexObject> results = query.getResults();
        for (VertexObject result : results) {
            result.setValue(GeoVertex.LASTUPDATEDATE, date);
            result.setValue(GeoVertex.CREATEDATE, date);
            result.apply();
        }
        count = this.getCount();
    } while (count > 0);
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) VertexObject(com.runwaysdk.business.graph.VertexObject) GraphQuery(com.runwaysdk.business.graph.GraphQuery) Date(java.util.Date) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 7 with MdAttributeDAOIF

use of com.runwaysdk.dataaccess.MdAttributeDAOIF in project geoprism-registry by terraframe.

the class DHIS2SynchronizationManager method query.

private List<VertexServerGeoObject> query(ServerGeoObjectType got, long skip, long pageSize) {
    MdVertexDAOIF mdVertex = got.getMdVertex();
    MdAttributeDAOIF mdAttribute = MdAttributeDAO.getByKey(GeoVertex.CLASS + "." + GeoVertex.LASTUPDATEDATE);
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT FROM " + mdVertex.getDBClassName());
    statement.append(" ORDER BY " + mdAttribute.getColumnName() + ", oid ASC");
    statement.append(" SKIP " + skip + " LIMIT " + pageSize);
    GraphQuery<VertexObject> query = new GraphQuery<VertexObject>(statement.toString());
    List<VertexObject> vObjects = query.getResults();
    List<VertexServerGeoObject> response = new LinkedList<VertexServerGeoObject>();
    for (VertexObject vObject : vObjects) {
        VertexServerGeoObject vSGO = new VertexServerGeoObject(got, vObject);
        vSGO.setDate(this.date);
        response.add(vSGO);
    }
    return response;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) VertexObject(com.runwaysdk.business.graph.VertexObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) GraphQuery(com.runwaysdk.business.graph.GraphQuery) LinkedList(java.util.LinkedList)

Example 8 with MdAttributeDAOIF

use of com.runwaysdk.dataaccess.MdAttributeDAOIF in project geoprism-registry by terraframe.

the class GeoObjectJsonExporter method query.

public List<VertexServerGeoObject> query() {
    MdVertexDAOIF mdVertex = got.getMdVertex();
    MdAttributeDAOIF mdAttribute = MdAttributeDAO.getByKey(GeoVertex.CLASS + "." + GeoVertex.LASTUPDATEDATE);
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT FROM " + mdVertex.getDBClassName());
    if (this.since != null) {
        statement.append(" WHERE " + mdAttribute.getColumnName() + " >= :lastUpdateDate");
    }
    statement.append(" ORDER BY " + mdAttribute.getColumnName() + ", oid ASC");
    if (this.pageSize != null && this.pageNumber != null && this.pageSize != -1 && this.pageNumber != -1) {
        statement.append(" SKIP " + ((pageNumber - 1) * pageSize) + " LIMIT " + this.pageSize);
    }
    GraphQuery<VertexObject> query = new GraphQuery<VertexObject>(statement.toString());
    if (this.since != null) {
        query.setParameter("lastUpdateDate", this.since);
    }
    List<VertexObject> vObjects = query.getResults();
    List<VertexServerGeoObject> response = new LinkedList<VertexServerGeoObject>();
    for (VertexObject vObject : vObjects) {
        VertexServerGeoObject vSGO = new VertexServerGeoObject(got, vObject);
        vSGO.setDate(ValueOverTime.INFINITY_END_DATE);
        response.add(vSGO);
    }
    return response;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) VertexObject(com.runwaysdk.business.graph.VertexObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) GraphQuery(com.runwaysdk.business.graph.GraphQuery) LinkedList(java.util.LinkedList)

Example 9 with MdAttributeDAOIF

use of com.runwaysdk.dataaccess.MdAttributeDAOIF in project geoprism-registry by terraframe.

the class ServerGeoObjectType method deleteMdAttributeFromAttributeType.

/**
 * Delete the {@link MdAttributeConcreteDAOIF} from the given {
 *
 * @param type
 *          TODO
 * @param mdBusiness
 * @param attributeName
 */
@Transaction
public void deleteMdAttributeFromAttributeType(String attributeName) {
    MdAttributeConcreteDAOIF mdAttributeConcreteDAOIF = getMdAttribute(this.mdBusiness, attributeName);
    if (mdAttributeConcreteDAOIF != null) {
        if (mdAttributeConcreteDAOIF instanceof MdAttributeTermDAOIF || mdAttributeConcreteDAOIF instanceof MdAttributeMultiTermDAOIF) {
            String attributeTermKey = TermConverter.buildtAtttributeKey(this.mdBusiness.getTypeName(), mdAttributeConcreteDAOIF.definesAttribute());
            try {
                Classifier attributeTerm = Classifier.getByKey(attributeTermKey);
                attributeTerm.delete();
            } catch (DataNotFoundException e) {
            }
        }
        mdAttributeConcreteDAOIF.getBusinessDAO().delete();
        Optional<AttributeType> optional = this.type.getAttribute(attributeName);
        if (optional.isPresent()) {
            ListType.deleteMdAttribute(this.universal, optional.get());
        }
    }
    MdAttributeDAOIF mdAttributeDAO = this.mdVertex.definesAttribute(attributeName);
    if (mdAttributeDAO != null) {
        mdAttributeDAO.getBusinessDAO().delete();
    }
}
Also used : DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) MdAttributeTermDAOIF(com.runwaysdk.dataaccess.MdAttributeTermDAOIF) Classifier(net.geoprism.ontology.Classifier) MdAttributeMultiTermDAOIF(com.runwaysdk.dataaccess.MdAttributeMultiTermDAOIF) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 10 with MdAttributeDAOIF

use of com.runwaysdk.dataaccess.MdAttributeDAOIF in project geoprism-registry by terraframe.

the class AbstractGraphPageQuery method getPage.

public Page<T> getPage() {
    int pageSize = 10;
    int pageNumber = 1;
    Long count = this.getCount();
    final MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(this.type);
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT ");
    this.addSelectAttributes(mdVertex, statement);
    statement.append(" FROM " + mdVertex.getDBClassName() + "");
    Map<String, Object> parameters = new HashMap<String, Object>();
    if (criteria.has("filters")) {
        JsonObject filters = criteria.get("filters").getAsJsonObject();
        this.addCriteria(mdVertex, filters, statement, parameters);
    }
    if (criteria.has("sortField") && criteria.has("sortOrder")) {
        String field = criteria.get("sortField").getAsString();
        SortOrder order = criteria.get("sortOrder").getAsInt() == 1 ? SortOrder.ASC : SortOrder.DESC;
        MdAttributeDAOIF mdAttribute = mdVertex.definesAttribute(field);
        statement.append(" ORDER BY " + this.getColumnName(mdAttribute) + " " + order.name());
    } else if (criteria.has("multiSortMeta")) {
        JsonArray sorts = criteria.get("multiSortMeta").getAsJsonArray();
        for (int i = 0; i < sorts.size(); i++) {
            JsonObject sort = sorts.get(i).getAsJsonObject();
            String field = sort.get("field").getAsString();
            SortOrder order = sort.get("order").getAsInt() == 1 ? SortOrder.ASC : SortOrder.DESC;
            MdAttributeDAOIF mdAttribute = mdVertex.definesAttribute(field);
            if (i == 0) {
                statement.append(" ORDER BY " + this.getColumnName(mdAttribute) + " " + order.name());
            } else {
                statement.append(", " + this.getColumnName(mdAttribute) + " " + order.name());
            }
        }
    }
    if (criteria.has("first") && criteria.has("rows")) {
        int first = criteria.get("first").getAsInt();
        int rows = criteria.get("rows").getAsInt();
        statement.append(" SKIP " + first + " LIMIT " + rows);
        pageNumber = (first / rows) + 1;
    }
    final GraphQuery<K> query = new GraphQuery<K>(statement.toString(), parameters);
    return new Page<T>(count, pageNumber, pageSize, this.getResults(query));
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) SortOrder(com.runwaysdk.query.OrderBy.SortOrder) Page(net.geoprism.registry.view.Page) JsonArray(com.google.gson.JsonArray) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) JsonObject(com.google.gson.JsonObject) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Aggregations

MdAttributeDAOIF (com.runwaysdk.dataaccess.MdAttributeDAOIF)32 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)24 GraphQuery (com.runwaysdk.business.graph.GraphQuery)23 VertexObject (com.runwaysdk.business.graph.VertexObject)9 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)9 JsonObject (com.google.gson.JsonObject)7 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)7 LinkedList (java.util.LinkedList)7 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)7 Date (java.util.Date)5 JsonArray (com.google.gson.JsonArray)4 HashMap (java.util.HashMap)4 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)4 MdVertexDAO (com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO)3 Page (net.geoprism.registry.view.Page)3 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)3 GsonBuilder (com.google.gson.GsonBuilder)2 MdAttributeTermDAOIF (com.runwaysdk.dataaccess.MdAttributeTermDAOIF)2 MdEdgeDAOIF (com.runwaysdk.dataaccess.MdEdgeDAOIF)2 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)2