summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngel Avila2012-09-26 20:03:14 (EDT)
committerRoberto E. Escobar2012-09-26 20:03:14 (EDT)
commiteb434bc677092be7aca916a201e837e26f438ea2 (patch)
tree4308fd799b862dc1d02865df5dbaa6f5a36bbd0e
parent4b11cd1017a6993ab62e31b41f60347a5dbebe95 (diff)
downloadorg.eclipse.osee-eb434bc677092be7aca916a201e837e26f438ea2.zip
org.eclipse.osee-eb434bc677092be7aca916a201e837e26f438ea2.tar.gz
org.eclipse.osee-eb434bc677092be7aca916a201e837e26f438ea2.tar.bz2
feature[ats_11NH1]: Create server operation to Purge Attribute Types
-rw-r--r--plugins/org.eclipse.osee.orcs.db/OSGI-INF/purge.attribute.type.console.command.xml11
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/PurgeAttributeTypeDatabaseTxCallable.java110
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/console/PurgeAttributeTypeCommand.java89
3 files changed, 210 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.orcs.db/OSGI-INF/purge.attribute.type.console.command.xml b/plugins/org.eclipse.osee.orcs.db/OSGI-INF/purge.attribute.type.console.command.xml
new file mode 100644
index 0000000..2672c64
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/OSGI-INF/purge.attribute.type.console.command.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.osee.orcs.db.internal.console.PurgeAttributeTypeCommand">
+ <implementation class="org.eclipse.osee.orcs.db.internal.console.PurgeAttributeTypeCommand"/>
+ <service>
+ <provide interface="org.eclipse.osee.console.admin.ConsoleCommand"/>
+ </service>
+ <reference bind="setLogger" cardinality="1..1" interface="org.eclipse.osee.logger.Log" name="Log" policy="static"/>
+ <reference bind="setDatabaseService" cardinality="1..1" interface="org.eclipse.osee.framework.database.IOseeDatabaseService" name="IOseeDatabaseService" policy="static"/>
+ <reference bind="setCachingService" cardinality="1..1" interface="org.eclipse.osee.framework.core.services.IOseeCachingService" name="IOseeCachingService" policy="static"/>
+ <reference bind="setIdentityService" cardinality="1..1" interface="org.eclipse.osee.framework.core.services.IdentityService" name="IdentityService" policy="static"/>
+</scr:component>
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/PurgeAttributeTypeDatabaseTxCallable.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/PurgeAttributeTypeDatabaseTxCallable.java
new file mode 100644
index 0000000..df19046
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/PurgeAttributeTypeDatabaseTxCallable.java
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.db.internal.callable;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.osee.console.admin.Console;
+import org.eclipse.osee.database.schema.DatabaseTxCallable;
+import org.eclipse.osee.framework.core.exception.OseeArgumentException;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.model.cache.AttributeTypeCache;
+import org.eclipse.osee.framework.core.model.type.AttributeType;
+import org.eclipse.osee.framework.core.services.IdentityService;
+import org.eclipse.osee.framework.database.IOseeDatabaseService;
+import org.eclipse.osee.framework.database.core.IOseeStatement;
+import org.eclipse.osee.framework.database.core.OseeConnection;
+import org.eclipse.osee.logger.Log;
+
+/**
+ * @author Angel Avila
+ */
+public final class PurgeAttributeTypeDatabaseTxCallable extends DatabaseTxCallable<Object> {
+ private static final String RETRIEVE_GAMMAS_OF_ATTR_TYPE_TXS =
+ "SELECT gamma_id FROM osee_attribute WHERE attr_type_id = ?";
+
+ private static final String DELETE_BY_GAMMAS = "DELETE FROM %s WHERE gamma_id = ?";
+ private static final String DELETE_FROM_CONFLICT_TABLE_SOURCE_SIDE =
+ "DELETE FROM osee_conflict WHERE source_gamma_id = ?";
+ private static final String DELETE_FROM_CONFLICT_TABLE_DEST_SIDE =
+ "DELETE FROM osee_conflict WHERE dest_gamma_id = ?";
+
+ private final AttributeTypeCache attributeCache;
+ private final String[] typesToPurge;
+ private final boolean forcePurge;
+ private final IdentityService identityService;
+ private final Console console;
+
+ public PurgeAttributeTypeDatabaseTxCallable(Log logger, IOseeDatabaseService databaseService, IdentityService identityService, AttributeTypeCache attributeCache, Console console, boolean force, String... typesToPurge) {
+ super(logger, databaseService, "Purge Attribute Type");
+ this.identityService = identityService;
+ this.attributeCache = attributeCache;
+ this.console = console;
+ this.forcePurge = force;
+ this.typesToPurge = typesToPurge;
+ }
+
+ @Override
+ protected Object handleTxWork(OseeConnection connection) throws OseeCoreException {
+ console.writeln();
+ console.writeln(!forcePurge ? "Attribute Types:" : "Purging attribute types:");
+
+ List<Long> types = convertTypeNamesToUuids();
+ boolean found = !types.isEmpty();
+ if (forcePurge && found) {
+ console.writeln("Removing from osee_* tables...");
+ processDeletes(connection, retrieveGammaIds(types));
+ }
+
+ console.writeln((found && !forcePurge) ? "To >DELETE Attribute DATA!< add --force to confirm." : "Operation finished.");
+ return null;
+ }
+
+ private List<Long> convertTypeNamesToUuids() throws OseeCoreException {
+ List<Long> guids = new ArrayList<Long>();
+ for (String typeName : typesToPurge) {
+ try {
+ AttributeType type = attributeCache.getBySoleName(typeName);
+ console.writeln("Type [%s] found. Guid: [%s]", typeName, type.getGuid());
+ guids.add(type.getGuid());
+ } catch (OseeArgumentException ex) {
+ console.writeln("Type [%s] NOT found.", typeName);
+ console.writeln(ex);
+ }
+ }
+ return guids;
+ }
+
+ private List<Integer[]> retrieveGammaIds(List<Long> types) throws OseeCoreException {
+ List<Integer[]> gammas = new ArrayList<Integer[]>(50000);
+ IOseeStatement chStmt = getDatabaseService().getStatement();
+ try {
+ for (Long attributeTypeId : types) {
+ chStmt.runPreparedQuery(RETRIEVE_GAMMAS_OF_ATTR_TYPE_TXS, identityService.getLocalId(attributeTypeId));
+ while (chStmt.next()) {
+ gammas.add(new Integer[] {chStmt.getInt("gamma_id")});
+ }
+ }
+ } finally {
+ chStmt.close();
+ }
+
+ return gammas;
+ }
+
+ private void processDeletes(OseeConnection connection, List<Integer[]> gammas) throws OseeCoreException {
+ getDatabaseService().runBatchUpdate(connection, String.format(DELETE_BY_GAMMAS, "osee_txs"), gammas);
+ getDatabaseService().runBatchUpdate(connection, String.format(DELETE_BY_GAMMAS, "osee_txs_archived"), gammas);
+ getDatabaseService().runBatchUpdate(connection, String.format(DELETE_BY_GAMMAS, "osee_attribute"), gammas);
+ getDatabaseService().runBatchUpdate(connection, String.format(DELETE_FROM_CONFLICT_TABLE_SOURCE_SIDE), gammas);
+ getDatabaseService().runBatchUpdate(connection, String.format(DELETE_FROM_CONFLICT_TABLE_DEST_SIDE), gammas);
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/console/PurgeAttributeTypeCommand.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/console/PurgeAttributeTypeCommand.java
new file mode 100644
index 0000000..79dae7d
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/console/PurgeAttributeTypeCommand.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.db.internal.console;
+
+import java.util.concurrent.Callable;
+import org.eclipse.osee.console.admin.Console;
+import org.eclipse.osee.console.admin.ConsoleCommand;
+import org.eclipse.osee.console.admin.ConsoleParameters;
+import org.eclipse.osee.framework.core.services.IOseeCachingService;
+import org.eclipse.osee.framework.core.services.IdentityService;
+import org.eclipse.osee.framework.database.IOseeDatabaseService;
+import org.eclipse.osee.logger.Log;
+import org.eclipse.osee.orcs.db.internal.callable.PurgeAttributeTypeDatabaseTxCallable;
+
+/**
+ * @author Angel Avila
+ */
+public class PurgeAttributeTypeCommand implements ConsoleCommand {
+
+ private Log logger;
+ private IOseeDatabaseService dbService;
+ private IOseeCachingService cachingService;
+ private IdentityService identityService;
+
+ public Log getLogger() {
+ return logger;
+ }
+
+ public void setLogger(Log logger) {
+ this.logger = logger;
+ }
+
+ public IOseeDatabaseService getDatabaseService() {
+ return dbService;
+ }
+
+ public void setDatabaseService(IOseeDatabaseService dbService) {
+ this.dbService = dbService;
+ }
+
+ public IOseeCachingService getCachingService() {
+ return cachingService;
+ }
+
+ public void setCachingService(IOseeCachingService cachingService) {
+ this.cachingService = cachingService;
+ }
+
+ public IdentityService getIdentityService() {
+ return identityService;
+ }
+
+ public void setIdentityService(IdentityService identityService) {
+ this.identityService = identityService;
+ }
+
+ @Override
+ public String getName() {
+ return "db_purge_attribute_type";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Purges attribute types from the database";
+ }
+
+ @Override
+ public String getUsage() {
+ return "[force=<TRUE|FALSE>] attrTypes=<ATTRIBUTE_TYPE_NAMES,...>";
+ }
+
+ @Override
+ public Callable<?> createCallable(Console console, ConsoleParameters params) {
+ boolean force = params.getBoolean("force");
+ String[] typesToPurge = params.getArray("attrTypes");
+
+ return new PurgeAttributeTypeDatabaseTxCallable(getLogger(), getDatabaseService(), getIdentityService(),
+ getCachingService().getAttributeTypeCache(), console, force, typesToPurge);
+ }
+
+}