aboutsummaryrefslogtreecommitdiffstats
path: root/ui-ci/src
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-07-12 00:54:52 +0300
committerMichael Lando <ml636r@att.com>2017-07-12 01:55:12 +0300
commitdd60339b06d252fcb1382aa97ab3d65b37dad021 (patch)
treec1551ce67cd77ca810ad5f579eb3617af86be85f /ui-ci/src
parentab146a193c43e9be0e9efeac7bab2690a7ba2d33 (diff)
[sdc] rebase update
Change-Id: I8f1fc7150975122dd9f3f4e653b9983064b399a6 Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'ui-ci/src')
-rw-r--r--ui-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/setup/MobProxy.java20
-rw-r--r--ui-ci/src/main/java/org/openecomp/sdc/ci/tests/verificator/CustomizationUUIDVerificator.java20
2 files changed, 40 insertions, 0 deletions
diff --git a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/setup/MobProxy.java b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/setup/MobProxy.java
index 6251d1e8b0..bab4508716 100644
--- a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/setup/MobProxy.java
+++ b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/setup/MobProxy.java
@@ -1,3 +1,23 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.openecomp.sdc.ci.tests.execute.setup;
import java.net.InetSocketAddress;
diff --git a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/verificator/CustomizationUUIDVerificator.java b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/verificator/CustomizationUUIDVerificator.java
index 9cb305deae..1824266f0c 100644
--- a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/verificator/CustomizationUUIDVerificator.java
+++ b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/verificator/CustomizationUUIDVerificator.java
@@ -1,3 +1,23 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.openecomp.sdc.ci.tests.verificator;
import static org.testng.AssertJUnit.assertTrue;
' href='#n249'>249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739
/*-
 * ============LICENSE_START=======================================================
 * Integrity Audit
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.policy.common.ia;

import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.LockTimeoutException;
import javax.persistence.Persistence;
import javax.persistence.PersistenceUnitUtil;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import javax.persistence.metamodel.ManagedType;
import javax.persistence.metamodel.Metamodel;

//import org.apache.log4j.Logger;

import org.onap.policy.common.ia.jpa.IntegrityAuditEntity;
import org.onap.policy.common.logging.flexlogger.FlexLogger; 
import org.onap.policy.common.logging.flexlogger.Logger;

/**
 * class DbDAO provides the inteface to the DBs for the purpose of audits.
 * 
 */
public class DbDAO {
	private static final Logger logger = FlexLogger.getLogger(DbDAO.class.getName());
	private String resourceName;
	private String persistenceUnit;
	private String dbDriver;
	private String dbUrl;
	private String dbUser;
	private String dbPwd;
	private String siteName;
	private String nodeType;
	private Properties properties=null;
	
	private EntityManagerFactory emf;
	
	/*
	 * Supports designation serialization.
	 */
    private static final Object lock = new Object();

	
	/**
	 * DbDAO Constructor
     * @param resourceName
     * @param persistenceUnit
     * @param properties
     * @throws Exception
     */
	public DbDAO(String resourceName, String persistenceUnit, Properties properties) throws Exception {
		logger.debug("DbDAO contructor: enter");
		
		validateProperties(resourceName, persistenceUnit, properties);
		
		emf = Persistence.createEntityManagerFactory(persistenceUnit, properties);
		
		register();
		
		logger.debug("DbDAO contructor: exit");
	}
	
	/**
	 * validateProperties will validate the properties
	 * @param resourceName
	 * @param persistenceUnit
	 * @param properties
	 * @throws IntegrityAuditPropertiesException
	 */
	private void validateProperties(String resourceName, String persistenceUnit, Properties properties) throws IntegrityAuditPropertiesException{
		String badparams="";
		if(IntegrityAudit.parmsAreBad(resourceName, persistenceUnit, properties, badparams)){
			String msg = "DbDAO: Bad parameters: badparams" + badparams;
			throw new IntegrityAuditPropertiesException(msg);
		}
		this.resourceName = resourceName;
		this.persistenceUnit = persistenceUnit;
		this.dbDriver = properties.getProperty(IntegrityAuditProperties.DB_DRIVER).trim();
		this.dbUrl = properties.getProperty(IntegrityAuditProperties.DB_URL).trim();
		this.dbUser = properties.getProperty(IntegrityAuditProperties.DB_USER).trim();
		this.dbPwd = properties.getProperty(IntegrityAuditProperties.DB_PWD).trim();
		this.siteName = properties.getProperty(IntegrityAuditProperties.SITE_NAME).trim();
		this.nodeType = properties.getProperty(IntegrityAuditProperties.NODE_TYPE).trim();
		this.properties = properties;
		logger.debug("DbDAO.assignProperties: exit:" 
				+ "\nresourceName: " + this.resourceName
				+ "\npersistenceUnit: " + this.persistenceUnit
				+ "\nproperties: " + this.properties);
	}
	
	/**
	 * getAllMyEntries gets all the DB entries for a particular class
	 * @param className
	 * @return
	 */
	public HashMap<Object, Object> getAllMyEntries(String className) {
		logger.debug("getAllMyEntries: Entering, className="
				+ className);
		HashMap<Object, Object> resultMap = new HashMap<Object,Object>();
		EntityManager em = emf.createEntityManager();
		try{
			CriteriaBuilder cb = em.getCriteriaBuilder();
			CriteriaQuery<Object> cq = cb.createQuery();
			Root<?> rootEntry = cq.from(Class.forName(className));
			CriteriaQuery<Object> all = cq.select(rootEntry);
			TypedQuery<Object> allQuery = em.createQuery(all);
			List<Object> objectList = allQuery.getResultList();
			//Now create the map

			PersistenceUnitUtil util = emf.getPersistenceUnitUtil();
			for (Object o: objectList){
				Object key = util.getIdentifier(o);
				resultMap.put(key, o);
			}
		}catch(Exception e){
			String msg = "getAllEntries encountered exception: " + e;
			logger.error(msg);
			System.out.println(new Date());
			e.printStackTrace();
		}
		em.close();
		logger.debug("getAllMyEntries: Exit, resultMap.keySet()=" + resultMap.keySet());
		return resultMap;		
	}
	
	/**
	 * getAllMyEntries gets all entries for a class
	 * @param className
	 * @param keySet
	 * @return
	 */
	public HashMap<Object, Object> getAllMyEntries(String className, HashSet<Object> keySet){
		logger.debug("getAllMyEntries: Entering, className="
				+ className + ",\n keySet=" + keySet);

		HashMap<Object, Object> resultMap = new HashMap<Object,Object>();
		EntityManager em = emf.createEntityManager();
		try{
			Class<?> clazz = Class.forName(className);
			for(Object key : keySet){
				Object entry = em.find(clazz, key);
				resultMap.put(key, entry);
			}
		}catch(Exception e){
			String msg = "getAllMyEntries encountered exception: " + e;
			logger.error(msg);
			System.out.println(new Date());
			e.printStackTrace();
		}
		em.close();

		logger.debug("getAllMyEntries: Returning resultMap, size=" + resultMap.size());
		return resultMap;
	}
	
	/**
	 * getAllEntries gets all entriesfor a particular persistence unit adn className
	 * @param persistenceUnit
	 * @param properties
	 * @param className
	 * @return
	 */
	public HashMap<Object,Object> getAllEntries(String persistenceUnit, Properties properties, String className){
		
		logger.debug("getAllEntries: Entering, persistenceUnit="
				+ persistenceUnit + ",\n className=" + className);
		HashMap<Object, Object> resultMap = new HashMap<Object,Object>();

		EntityManagerFactory theEmf = Persistence.createEntityManagerFactory(persistenceUnit, properties);
		EntityManager em = theEmf.createEntityManager();
		try{
			CriteriaBuilder cb = em.getCriteriaBuilder();
			CriteriaQuery<Object> cq = cb.createQuery();
			Root<?> rootEntry = cq.from(Class.forName(className));
			CriteriaQuery<Object> all = cq.select(rootEntry);
			TypedQuery<Object> allQuery = em.createQuery(all);
			List<Object> objectList = allQuery.getResultList();

			PersistenceUnitUtil util = theEmf.getPersistenceUnitUtil();
			for (Object o: objectList){
				Object key = util.getIdentifier(o);
				resultMap.put(key, o);
			}
		}catch(Exception e){
			String msg = "getAllEntries encountered exception:" + e;
			logger.error(msg);
			System.out.println(new Date());
			e.printStackTrace();
		}
		em.close();
		
		logger.debug("getAllEntries: Returning resultMap, size=" + resultMap.size());
		
		return resultMap;		
	}
	

	/**
	 * getAllEntries gest all entries for a persistence unit
	 * @param persistenceUnit
	 * @param properties
	 * @param className
	 * @param keySet
	 * @return
	 */

	public HashMap<Object,Object> getAllEntries(String persistenceUnit, Properties properties, String className, HashSet<Object> keySet){
		logger.debug("getAllEntries: Entering, persistenceUnit="
				+ persistenceUnit + ",\n properties= " + properties + ",\n className=" + className + ",\n keySet= " + keySet);
		EntityManagerFactory theEmf = Persistence.createEntityManagerFactory(persistenceUnit, properties);
		EntityManager em = theEmf.createEntityManager();
		HashMap<Object, Object> resultMap = new HashMap<Object,Object>();
		try{
			Class<?> clazz = Class.forName(className);
			for(Object key : keySet){
				Object entry = em.find(clazz, key);
				resultMap.put(key, entry);
			}
		}catch(Exception e){
			String msg = "getAllEntries encountered exception: " + e;
			logger.error(msg);
			System.out.println(new Date());
			e.printStackTrace();
		}
		em.close();
		logger.debug("getAllEntries: Exit, resultMap, size=" + resultMap.size());
		return resultMap;	
	}
	
	/**
	 * getIntegrityAuditEntities() Get all the IntegrityAuditEntities for a particular persistence unit
	 * and node type
	 * @param persistenceUnit
	 * @param nodeType
	 * @return
	 * @throws DbDaoTransactionException
	 */
	@SuppressWarnings("unchecked")
	public List<IntegrityAuditEntity> getIntegrityAuditEntities(String persistenceUnit, String nodeType) throws DbDaoTransactionException {
		logger.debug("getIntegrityAuditEntities: Entering, persistenceUnit="
				+ persistenceUnit + ",\n nodeType= " + nodeType);
		try{
			EntityManager em = emf.createEntityManager();
			// Start a transaction
			EntityTransaction et = em.getTransaction();

			et.begin();

			// if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not found, create a new entry
			Query iaequery = em.createQuery("Select i from IntegrityAuditEntity i where i.persistenceUnit=:pu and i.nodeType=:nt");
			iaequery.setParameter("pu", persistenceUnit);
			iaequery.setParameter("nt", nodeType);

			List<IntegrityAuditEntity> iaeList = iaequery.getResultList();

			// commit transaction
			et.commit();
			em.close();
			logger.debug("getIntegrityAuditEntities: Exit, iaeList=" + iaeList);
			return iaeList;
		}catch (Exception e){
			String msg = "DbDAO: " + "getIntegrityAuditEntities() " + "ecountered a problem in execution: ";
			logger.error(msg + e);
			System.out.println(new Date());
			e.printStackTrace();
			throw new DbDaoTransactionException(e);
		}
		
	}
	
	/**
	 * getMyIntegrityAuditEntity() gets my IntegrityAuditEntity
	 * @return
	 * @throws DbDaoTransactionException
	 */
	public IntegrityAuditEntity getMyIntegrityAuditEntity() throws DbDaoTransactionException{
		try{
			EntityManager em = emf.createEntityManager();

			// Start a transaction
			EntityTransaction et = em.getTransaction();

			et.begin();

			// if IntegrityAuditEntity entry exists for resourceName and PU, retrieve it
			Query iaequery = em.createQuery("Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu");
			iaequery.setParameter("rn", this.resourceName);
			iaequery.setParameter("pu", this.persistenceUnit);

			@SuppressWarnings("rawtypes")
			List iaeList = iaequery.getResultList();
			IntegrityAuditEntity iae = null;

			if(!iaeList.isEmpty()){
				//ignores multiple results
				iae = (IntegrityAuditEntity) iaeList.get(0);
				// refresh the object from DB in case cached data was returned
				em.refresh(iae);
				logger.info("Resource: " + this.resourceName + " with PersistenceUnit: " + this.persistenceUnit
						+ " exists");
			}else{
				// If it does not exist, log an error
				logger.error("Attempting to setLastUpdated"
						+ " on an entry that does not exist:"
						+" resource " + this.resourceName + " with PersistenceUnit: " + this.persistenceUnit);
			}

			// close the transaction
			et.commit();
			// close the EntityManager
			em.close();
			
			return iae;
		}catch (Exception e){
			String msg = "DbDAO: " + "setLastUpdated() " + "ecountered a problem in execution: ";
			logger.error(msg + e);
			System.out.println(new Date());
			e.printStackTrace();
			throw new DbDaoTransactionException(e);
		}	
	}

	
	/**
	 * getIntegrityAuditEntity() gets the IntegrityAuditEntity with a particular ID
	 * @param id
	 * @return
	 * @throws DbDaoTransactionException
	 */
	public IntegrityAuditEntity getIntegrityAuditEntity(long id) throws DbDaoTransactionException{
		try{
			EntityManager em = emf.createEntityManager();

			// Start a transaction
			EntityTransaction et = em.getTransaction();

			et.begin();

			IntegrityAuditEntity iae = em.find(IntegrityAuditEntity.class, id);

			et.commit();
			em.close();

			return iae;
		}catch (Exception e){
			String msg = "DbDAO: " + "getIntegrityAuditEntity() " + "ecountered a problem in execution: ";
			logger.error(msg + e);
			System.out.println(new Date());
			e.printStackTrace();
			throw new DbDaoTransactionException(e);
		}
	}
	
	/**
	 * getPersistenceClassNames() gets all the persistence class names.
	 * @return
	 */
	public HashSet<String> getPersistenceClassNames(){
		logger.debug("DbDAO: getPersistenceClassNames() entry");
		HashSet<String> returnList = new HashSet<String>();
		final Metamodel mm = emf.getMetamodel();
		logger.debug("\n" + persistenceUnit +" persistence unit classes:");
		for (final ManagedType<?> managedType : mm.getManagedTypes()) {
			Class<?> c = managedType.getJavaType();
			logger.debug("    " + c.getSimpleName());
			returnList.add(c.getName()); //the full class name needed to make a query using jpa
		}
		logger.debug("DbDAO: getPersistenceClassNames() exit");
		return returnList;
	}
	
	/**
	 * Register the IntegrityAudit instance
	 */
	private void register() throws DbDaoTransactionException {
		try{
			EntityManager em = emf.createEntityManager();

			// Start a transaction
			EntityTransaction et = em.getTransaction();

			et.begin();

			// if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not found, create a new entry
			Query iaequery = em.createQuery("Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu");
			iaequery.setParameter("rn", this.resourceName);
			iaequery.setParameter("pu", this.persistenceUnit);

			@SuppressWarnings("rawtypes")
			List iaeList = iaequery.getResultList();
			IntegrityAuditEntity iae = null;

			//If it already exists, we just want to update the properties and lastUpdated date
			if(!iaeList.isEmpty()){
				//ignores multiple results
				iae = (IntegrityAuditEntity) iaeList.get(0);
				// refresh the object from DB in case cached data was returned
				em.refresh(iae);
				logger.info("Resource: " + this.resourceName + " with PersistenceUnit: " + this.persistenceUnit 
						+ " exists and entry be updated");
			}else{
				// If it does not exist, we also must add teh resourceName, persistenceUnit and designated values
				logger.info("Adding resource " + resourceName + " with PersistenceUnit: " + this.persistenceUnit
						+ " to IntegrityAuditEntity table");  	
				iae = new IntegrityAuditEntity();
				iae.setResourceName(this.resourceName);
				iae.setPersistenceUnit(this.persistenceUnit);
				iae.setDesignated(false);
			}
			//update/set properties in entry
			iae.setSite(this.siteName);
			iae.setNodeType(this.nodeType);
			iae.setLastUpdated(new Date());
			iae.setJdbcDriver(this.dbDriver);
			iae.setJdbcPassword(this.dbPwd);
			iae.setJdbcUrl(dbUrl);
			iae.setJdbcUser(dbUser);

			em.persist(iae);
			// flush to the DB
			em.flush();

			// commit transaction
			et.commit();
			em.close();
		}catch (Exception e){
			String msg = "DbDAO: " + "register() " + "ecountered a problem in execution: ";
			logger.error(msg + e);
			System.out.println(new Date());
			e.printStackTrace();
			throw new DbDaoTransactionException(e);
		}

	}
	
	public void setDesignated(boolean designated) throws DbDaoTransactionException{
		setDesignated(this.resourceName, this.persistenceUnit, designated);
	}
	

	public void setDesignated(String rName, String pUnit, boolean desig) throws DbDaoTransactionException{
		logger.debug("setDesignated: enter, resourceName: " + rName + ", persistenceUnit: " 
				+ pUnit + ", designated: " + desig);
		try{

			EntityManager em = emf.createEntityManager();

			// Start a transaction
			EntityTransaction et = em.getTransaction();

			et.begin();

			// if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not found, create a new entry
			Query iaequery = em.createQuery("Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu");
			iaequery.setParameter("rn", rName);
			iaequery.setParameter("pu", pUnit);

			@SuppressWarnings("rawtypes")
			List iaeList = iaequery.getResultList();
			IntegrityAuditEntity iae = null;

			if(!iaeList.isEmpty()){
				//ignores multiple results
				iae = (IntegrityAuditEntity) iaeList.get(0);
				// refresh the object from DB in case cached data was returned
				em.refresh(iae);
				logger.info("Resource: " + rName + " with PersistenceUnit: " + pUnit 
						+ " exists and designated be updated");
				iae.setDesignated(desig);

				em.persist(iae);
				// flush to the DB
				em.flush();
			}else{
				// If it does not exist, log an error
				logger.error("Attempting to setDesignated("
						+ desig + ") on an entry that does not exist:"
						+" resource " + rName + " with PersistenceUnit: " + pUnit);
			}

			// close the transaction
			et.commit();
			// close the EntityManager
			em.close();
		}catch (Exception e){
			String msg = "DbDAO: " + "setDesignated() " + "ecountered a problem in execution: ";
			logger.error(msg + e);
			System.out.println(new Date());
			e.printStackTrace();
			throw new DbDaoTransactionException(e);
		}

	}
	
	public void setLastUpdated() throws DbDaoTransactionException{
		logger.debug("setLastUpdated: enter, resourceName: " + this.resourceName + ", persistenceUnit: " 
				+ this.persistenceUnit);
		try{
			EntityManager em = emf.createEntityManager();

			// Start a transaction
			EntityTransaction et = em.getTransaction();

			et.begin();

			// if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not found, create a new entry
			Query iaequery = em.createQuery("Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu");
			iaequery.setParameter("rn", this.resourceName);
			iaequery.setParameter("pu", this.persistenceUnit);

			@SuppressWarnings("rawtypes")
			List iaeList = iaequery.getResultList();
			IntegrityAuditEntity iae = null;

			if(!iaeList.isEmpty()){
				//ignores multiple results
				iae = (IntegrityAuditEntity) iaeList.get(0);
				// refresh the object from DB in case cached data was returned
				em.refresh(iae);
				logger.info("Resource: " + this.resourceName + " with PersistenceUnit: " + this.persistenceUnit
						+ " exists and lastUpdated be updated");
				iae.setLastUpdated(new Date());

				em.persist(iae);
				// flush to the DB
				em.flush();
			}else{
				// If it does not exist, log an error
				logger.error("Attempting to setLastUpdated"
						+ " on an entry that does not exist:"
						+" resource " + this.resourceName + " with PersistenceUnit: " + this.persistenceUnit);
			}

			// close the transaction
			et.commit();
			// close the EntityManager
			em.close();
		}catch (Exception e){
			String msg = "DbDAO: " + "setLastUpdated() " + "ecountered a problem in execution: ";
			logger.error(msg + e);
			System.out.println(new Date());
			e.printStackTrace();
			throw new DbDaoTransactionException(e);
		}

	}
	
	/**
	 * Normally this method should only be used in a JUnit test environment.
	 * Manually deletes all PDP records in droolspdpentity table.
	 */
	public int deleteAllIntegrityAuditEntities() throws DbDaoTransactionException {
		
		try{
			
			if (!IntegrityAudit.isUnitTesting) {
				String msg = "DbDAO: " + "deleteAllIntegrityAuditEntities() " + "should only be invoked during JUnit testing";
				logger.error(msg);
				throw new DbDaoTransactionException(msg);
			}
			
			EntityManager em = emf.createEntityManager();
			// Start a transaction
			EntityTransaction et = em.getTransaction();

			et.begin();

			// if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not found, create a new entry
			Query iaequery = em.createQuery("Delete from IntegrityAuditEntity");

			int returnCode = iaequery.executeUpdate();

			// commit transaction
			et.commit();
			em.close();
			
			logger.info("deleteAllIntegrityAuditEntities: returnCode=" + returnCode);

			return returnCode;

		}catch (Exception e){
			String msg = "DbDAO: " + "deleteAllIntegrityAuditEntities() " + "encountered a problem in execution: ";
			logger.error(msg + e);
			System.out.println(new Date());
			e.printStackTrace();
			throw new DbDaoTransactionException(e);
		}
		
	}
	
	/**
	 * Changes designation to specified resourceName
	 * 
	 * static lock object in conjunction with synchronized keyword ensures that
	 * designation changes are done serially within a resource. I.e. static lock
	 * ensures that multiple instantiations of DbDAO don't interleave
	 * changeDesignated() invocations and potentially produce simultaneous
	 * designations.
	 * 
	 * Optimistic locking (the default, versus pessimistic) is sufficient to
	 * avoid simultaneous designations from interleaved changeDesignated()
	 * invocations from different resources (entities), because it prevents
	 * "dirty" and "non-repeatable" reads.
	 * 
	 * See http://www.objectdb.com/api/java/jpa/LockModeType
	 * 
	 * and
	 * 
	 * http://stackoverflow.com/questions/2120248/how-to-synchronize-a-static-
	 * variable-among-threads-running-different-instances-o
	 */
	public void changeDesignated(String resourceName, String persistenceUnit,
			String nodeType) throws DbDaoTransactionException {

		if (logger.isDebugEnabled()) {
			logger.debug("changeDesignated: Entering, resourceName="
					+ resourceName + ", persistenceUnit=" + persistenceUnit
					+ ", nodeType=" + nodeType);
		}

		long startTime = System.currentTimeMillis();

		synchronized (lock) {

			EntityManager em = null;
			try {

				em = emf.createEntityManager();
				em.getTransaction().begin();

				/*
				 * Define query
				 */
				Query query = em
						.createQuery("Select i from IntegrityAuditEntity i where i.persistenceUnit=:pu and i.nodeType=:nt");
				query.setParameter("pu", persistenceUnit);
				query.setParameter("nt", nodeType);

				/*
				 * Execute query using pessimistic write lock.  This ensures that if anyone else is currently reading
				 * the records we'll throw a LockTimeoutException.
				 */
				@SuppressWarnings("unchecked")
				List<IntegrityAuditEntity> integrityAuditEntityList = (List<IntegrityAuditEntity>) query
						.getResultList();
				for (Object o : integrityAuditEntityList) {
					if (o instanceof IntegrityAuditEntity) {
						IntegrityAuditEntity integrityAuditEntity = (IntegrityAuditEntity) o;
						if (integrityAuditEntity.getResourceName().equals(
								resourceName)) {
							if (logger.isDebugEnabled()) {
								logger.debug("changeDesignated: Designating resourceName="
										+ integrityAuditEntity
												.getResourceName());
							}
							integrityAuditEntity.setDesignated(true);
						} else {
							if (logger.isDebugEnabled()) {
								logger.debug("changeDesignated: Removing designation from resourceName="
										+ integrityAuditEntity
												.getResourceName());
							}
							integrityAuditEntity.setDesignated(false);
						}
					}
				}
				
				if (logger.isDebugEnabled()) {
					logger.debug("changeDesignated: Committing designation to resourceName="
							+ resourceName);
				}
				em.getTransaction().commit();

				/*
				 * If we get a LockTimeoutException, no harm done really. We'll
				 * probably be successful on the next attempt. The odds of
				 * another DbDAO instance on this entity or another entity
				 * attempting a simultaneous IntegrityAuditEntity table
				 * read/update are pretty slim (we're only in this method for
				 * two or three milliseconds)
				 */
			} catch (LockTimeoutException e) {
				em.getTransaction().rollback();
				String msg = "DbDAO: " + "changeDesignated() "
						+ "caught LockTimeoutException, message=" + e.getMessage();
				logger.error(msg + e);
				System.out.println(new Date());
				e.printStackTrace();
				throw new DbDaoTransactionException(msg, e);
			} catch (Exception e) {
				em.getTransaction().rollback();
				String msg = "DbDAO: " + "changeDesignated() "
						+ "caught Exception, message=" + e.getMessage();
				logger.error(msg + e);
				System.out.println(new Date());
				e.printStackTrace();
				throw new DbDaoTransactionException(msg, e);
			}

		} // end synchronized block

		if (logger.isDebugEnabled()) {
			logger.debug("changeDesignated: Exiting; time expended="
					+ (System.currentTimeMillis() - startTime) + "ms");
		}

	}


}