Merge "Issue #2361 fix saving hydro table objects" into development

Former-commit-id: bded464ccf [formerly 8a326cda9dd0b801f0bbaf779d6548f42078c0a5]
Former-commit-id: cf261df489
This commit is contained in:
Richard Peter 2013-11-08 13:26:06 -06:00 committed by Gerrit Code Review
commit 9bb4f8dd7f
8 changed files with 168 additions and 141 deletions

View file

@ -25,16 +25,14 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.JAXBException;
import com.raytheon.uf.common.dataquery.db.QueryResult;
import com.raytheon.uf.common.dataquery.db.QueryResultRow;
import com.raytheon.uf.common.dataquery.requests.QlServerRequest;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
import com.raytheon.uf.common.dataquery.requests.SaveOrUpdateRequest;
import com.raytheon.uf.common.message.response.AbstractResponseMessage;
import com.raytheon.uf.common.message.response.ResponseMessageError;
import com.raytheon.uf.common.message.response.ResponseMessageGeneric;
import com.raytheon.uf.common.serialization.SerializationUtil;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.exception.VizServerSideException;
import com.raytheon.uf.viz.core.requests.ThriftClient;
@ -49,6 +47,7 @@ import com.raytheon.uf.viz.core.requests.ThriftClient;
* ------------ ---------- ----------- --------------------------
* 10/15/2008 1615 bphillip Initial Creation
* 12/11/2008 1777 bphillip Added insert/update functionality
* Nov 08, 2013 2361 njensen Refactored/improved saveOrUpdateList()
*
* </pre>
*
@ -319,44 +318,11 @@ public class DirectDbQuery {
*/
private int saveOrUpdateList(List<Object> objList, String database)
throws VizException {
SaveOrUpdateRequest req = new SaveOrUpdateRequest();
req.setDbName(database);
req.setObjectsToUpdate(objList);
constraints.put("database", new RequestConstraint(database));
for (int i = 0; i < objList.size(); i++) {
String xml = null;
try {
xml = SerializationUtil.marshalToXml(objList.get(i));
} catch (JAXBException e) {
throw new VizException(
"Unable to marshal object. Save Failed.", e);
}
// xml = xml.replaceAll("\"", "<quote>");
// xml = xml.replaceAll("\n", "");
constraints.put("obj" + String.valueOf(i), new RequestConstraint(
xml));
}
// set mode
constraints.put("mode", new RequestConstraint("saveOrUpdateObject"));
// create and send request
QlServerRequest request = new QlServerRequest(constraints);
int retVal = 0;
AbstractResponseMessage response = (AbstractResponseMessage) ThriftClient
.sendRequest(request);
if (constraints.containsKey("mode")) {
constraints.remove("mode");
}
if (response instanceof ResponseMessageGeneric) {
retVal = (Integer) ((ResponseMessageGeneric) response)
.getContents();
} else if (response instanceof ResponseMessageError) {
ResponseMessageError rme = (ResponseMessageError) response;
VizServerSideException innerException = new VizServerSideException(
rme.toString());
throw new VizServerSideException(rme.getErrorMsg(), innerException);
}
return retVal;
Object result = ThriftClient.sendRequest(req);
return (Integer) result;
}
}

View file

@ -51,6 +51,7 @@ import com.raytheon.uf.edex.database.query.DatabaseQuery;
* 14Nov2008 1709 MW Fegan Initial creation.
* 14Apr2011 5163 cjeanbap NWRWAVES Setting AFOS text triggers in AWIPS II
* 04/24/13 1949 rjpeter Removed @Override on delete.
* Nov 08, 2013 2361 njensen Chaged method signature of saveOrUpdate(Object)
* </pre>
*
* @author mfegan
@ -127,9 +128,10 @@ public class SubscriptionDAO extends CoreDao {
}
@Override
public void saveOrUpdate(PersistableDataObject obj) {
public void saveOrUpdate(Object obj) {
super.saveOrUpdate(obj);
sendSubscriptionNotifyMessage(String.valueOf(obj.getIdentifier()));
sendSubscriptionNotifyMessage(String
.valueOf(((PersistableDataObject) obj).getIdentifier()));
}
@Override

View file

@ -0,0 +1,72 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.dataquery.requests;
import java.util.List;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.raytheon.uf.common.serialization.comm.IServerRequest;
/**
* Request for saving or updating objects in the database. Assumes that all the
* objects in the list belong to the same database, and that the DAO for that
* database knows how to handle those objects.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Nov 8, 2013 2361 njensen Initial creation
*
* </pre>
*
* @author njensen
* @version 1.0
*/
@DynamicSerialize
public class SaveOrUpdateRequest implements IServerRequest {
@DynamicSerializeElement
protected String dbName;
@DynamicSerializeElement
protected List<Object> objectsToUpdate;
public String getDbName() {
return dbName;
}
public void setDbName(String dbName) {
this.dbName = dbName;
}
public List<Object> getObjectsToUpdate() {
return objectsToUpdate;
}
public void setObjectsToUpdate(List<Object> objectsToUpdate) {
this.objectsToUpdate = objectsToUpdate;
}
}

View file

@ -43,6 +43,12 @@
<constructor-arg ref="timeQueryHandlerSet"/>
</bean>
<bean id="saveOrUpdateHandler" class="com.raytheon.uf.edex.database.handlers.SaveOrUpdateHandler" />
<bean factory-bean="handlerRegistry" factory-method="register">
<constructor-arg value="com.raytheon.uf.common.dataquery.requests.SaveOrUpdateRequest"/>
<constructor-arg ref="saveOrUpdateHandler"/>
</bean>
<bean id="pluginFactory" class="com.raytheon.uf.edex.database.plugin.PluginFactory" factory-method="getInstance"/>
<bean id="pluginFactoryRegisteredToDataURIUtil"

View file

@ -28,7 +28,6 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler;
import com.raytheon.uf.edex.database.dao.DaoConfig;
import com.raytheon.uf.edex.database.tasks.HqlQueryTask;
import com.raytheon.uf.edex.database.tasks.HqlStatementTask;
import com.raytheon.uf.edex.database.tasks.SaveOrUpdateTask;
import com.raytheon.uf.edex.database.tasks.SqlQueryTask;
import com.raytheon.uf.edex.database.tasks.SqlStatementTask;
@ -41,6 +40,7 @@ import com.raytheon.uf.edex.database.tasks.SqlStatementTask;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 16, 2011 #8070 ekladstrup Initial creation
* Nov 08, 2013 2361 njensen Removed saveOrUpdate mode
*
* </pre>
*
@ -126,15 +126,6 @@ public class QlServerRequestHandler implements IRequestHandler<QlServerRequest>
} else if (mode.equals("hqlstatement")) {
HqlStatementTask task = new HqlStatementTask(query, dbName);
result = task.execute();
} else if (mode.equals("saveOrUpdateObject")) {
SaveOrUpdateTask task = new SaveOrUpdateTask(dbName);
for (String key : map.keySet()) {
String value = map.get(key).getConstraintValue();
if (key.startsWith("obj")) {
task.addObject(value);
}
}
result = task.execute();
}
// instead of placing a single value in an arraylist, just return the

View file

@ -94,6 +94,7 @@ import com.raytheon.uf.edex.database.query.DatabaseQuery;
* 5/14/08 1076 brockwoo Fix for distinct with multiple properties
* Oct 10, 2012 1261 djohnson Incorporate changes to DaoConfig, add generic to {@link IPersistableDataObject}.
* Apr 15, 2013 1868 bsteffen Rewrite mergeAll in PluginDao.
* Nov 08, 2013 2361 njensen Changed method signature of saveOrUpdate to take Objects, not PersistableDataObjects
*
* </pre>
*
@ -182,7 +183,7 @@ public class CoreDao extends HibernateDaoSupport {
* @param obj
* The object to be persisted to the database
*/
public <T> void saveOrUpdate(final PersistableDataObject<T> obj) {
public void saveOrUpdate(final Object obj) {
txTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {

View file

@ -0,0 +1,76 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.edex.database.handlers;
import java.util.List;
import com.raytheon.uf.common.dataquery.requests.SaveOrUpdateRequest;
import com.raytheon.uf.common.serialization.comm.IRequestHandler;
import com.raytheon.uf.edex.database.dao.CoreDao;
import com.raytheon.uf.edex.database.dao.DaoConfig;
/**
* Handler for a SaveOrUpdateRequest that saves the objects to the specified
* database.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Nov 8, 2013 2361 njensen Initial creation
*
* </pre>
*
* @author njensen
* @version 1.0
*/
public class SaveOrUpdateHandler implements
IRequestHandler<SaveOrUpdateRequest> {
@Override
public Object handleRequest(SaveOrUpdateRequest request) throws Exception {
String dbName = request.getDbName();
if (dbName == null) {
throw new IllegalArgumentException("Database name cannot be null");
}
CoreDao dao = new CoreDao(DaoConfig.forDatabase(dbName));
List<Object> objs = request.getObjectsToUpdate();
// This was originally written to replace the saveOrUpdate part of
// QlServerRequestHandler. To match that behavior, we're not putting
// try/catch around each call to saveOrUpdate, and we're only returning
// a count of the objects saved/updated.
// TODO contemplate better behavior
int count = 0;
if (objs != null) {
for (Object obj : objs) {
dao.saveOrUpdate(obj);
count++;
}
}
return count;
}
}

View file

@ -1,87 +0,0 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.edex.database.tasks;
import java.util.ArrayList;
import java.util.List;
import com.raytheon.uf.common.dataplugin.persist.PersistableDataObject;
import com.raytheon.uf.common.serialization.SerializationUtil;
import com.raytheon.uf.edex.database.dao.CoreDao;
import com.raytheon.uf.edex.database.dao.DaoConfig;
/**
* Task to execute an insert or update to the database
*
* <pre>
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 12/11/2008 1777 bphillip Initial Creation
*
* </pre>
*
* @author bphillip
* @version 1.0
*/
public class SaveOrUpdateTask {
/** The database name to insert into */
private String dbName;
/** The marshalled objects * */
private List<String> marshalledObjects;
/**
* Creates a new SaveOrUpdateTask object
*
* @param dbName
* The database name
*/
public SaveOrUpdateTask(String dbName) {
this.dbName = dbName;
marshalledObjects = new ArrayList<String>();
}
/**
* Adds a marshalled object to the list
*
* @param marshalledObject
* The marshalled object xml
*/
public void addObject(String marshalledObject) {
marshalledObjects.add(marshalledObject);
}
public Object execute() throws Exception {
CoreDao dao = new CoreDao(DaoConfig.forDatabase(dbName));
PersistableDataObject currentObject = null;
for (String xml : marshalledObjects) {
xml = xml.replaceAll("<quote>", "\"");
currentObject = (PersistableDataObject) SerializationUtil
.unmarshalFromXml(xml);
dao.saveOrUpdate(currentObject);
}
return marshalledObjects.size();
}
}