Updateskript für PublicPersonalProfile <-> Owner Assoziation. Version von PublicPersonalProfile auf 6.6.3 angehoben, um
Update für zusätzliche Felder (6.6.2) und Update für Assoziationen getrennt ausführen zu können. git-svn-id: https://svn.libreccm.org/ccm/trunk@1493 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
ea88cfd822
commit
c4118f32d6
|
|
@ -2,7 +2,7 @@
|
||||||
<ccm:application xmlns:ccm="http://ccm.redhat.com/ccm-project"
|
<ccm:application xmlns:ccm="http://ccm.redhat.com/ccm-project"
|
||||||
name="ccm-cms-publicpersonalprofile"
|
name="ccm-cms-publicpersonalprofile"
|
||||||
prettyName="OpenCCM Content Type"
|
prettyName="OpenCCM Content Type"
|
||||||
version="6.6.2"
|
version="6.6.3"
|
||||||
release="1"
|
release="1"
|
||||||
webapp="ROOT">
|
webapp="ROOT">
|
||||||
<ccm:dependencies>
|
<ccm:dependencies>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
<upgrade>
|
<upgrade>
|
||||||
<version from="6.6.1" to="6.6.2">
|
<version from="6.6.1" to="6.6.2">
|
||||||
<script sql="ccm-cms-publicpersonalprofile/upgrade/::database::-6.6.1-6.6.2.sql"/>
|
<script sql="ccm-cms-publicpersonalprofile/upgrade/::database::-6.6.1-6.6.2.sql"/>
|
||||||
|
</version>
|
||||||
|
<version from="6.6.2" to="6.6.3">
|
||||||
|
<script class="com.arsdigita.cms.contenttypes.PublicPersonalProfileOwnerAssocUpgrade"/>
|
||||||
</version>
|
</version>
|
||||||
</upgrade>
|
</upgrade>
|
||||||
|
|
@ -0,0 +1,274 @@
|
||||||
|
package com.arsdigita.cms.contenttypes;
|
||||||
|
|
||||||
|
import com.arsdigita.packaging.Program;
|
||||||
|
import com.arsdigita.runtime.RuntimeConfig;
|
||||||
|
import com.arsdigita.util.jdbc.Connections;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.apache.commons.cli.CommandLine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upgrade for the owner association (6.6.1 to 6.6.2). Warning: Update of
|
||||||
|
* ccm-cms from 6.6.4 to 6.6.5 has be executed before this update.
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class PublicPersonalProfileOwnerAssocUpgrade extends Program {
|
||||||
|
|
||||||
|
public PublicPersonalProfileOwnerAssocUpgrade() {
|
||||||
|
super("PublicPersonalProfileOwnerAssocUpgrade", "1.0.0", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void main(final String[] args) {
|
||||||
|
new PublicPersonalProfileOwnerAssocUpgrade().run(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doRun(final CommandLine cmdLine) {
|
||||||
|
System.out.println("Starting upgrade...");
|
||||||
|
|
||||||
|
List<OldAssocEntry> oldData = new ArrayList<OldAssocEntry>();
|
||||||
|
|
||||||
|
final Connection conn = Connections.acquire(RuntimeConfig.getConfig().
|
||||||
|
getJDBCURL());
|
||||||
|
try {
|
||||||
|
conn.setAutoCommit(false);
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
System.err.println("Failed to configure JDBC connection.");
|
||||||
|
printStackTrace(ex);
|
||||||
|
close(conn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Retrieving old data...");
|
||||||
|
|
||||||
|
try {
|
||||||
|
final Statement stmt = conn.createStatement();
|
||||||
|
final ResultSet oldAssocResult = stmt.executeQuery(
|
||||||
|
"SELECT profile_id, owner_id, owner_order "
|
||||||
|
+ "FROM ct_public_personal_profile_owner_map");
|
||||||
|
|
||||||
|
while (oldAssocResult.next()) {
|
||||||
|
oldData.add(new OldAssocEntry(oldAssocResult.getBigDecimal(1),
|
||||||
|
oldAssocResult.getBigDecimal(2),
|
||||||
|
oldAssocResult.getInt(3)));
|
||||||
|
}
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
System.err.println("Failed to retrieve old data.");
|
||||||
|
printStackTrace(ex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
System.out.println("Droping old table...");
|
||||||
|
final Statement stmt = conn.createStatement();
|
||||||
|
stmt.execute("DROP TABLE ct_public_personal_profile_owner_map");
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
System.err.println("Failed to drop old table.");
|
||||||
|
printStackTrace(ex);
|
||||||
|
rollback(conn);
|
||||||
|
close(conn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
System.out.println("Creating new tables...");
|
||||||
|
final Statement stmt = conn.createStatement();
|
||||||
|
|
||||||
|
stmt.addBatch("CREATE TABLE ct_public_personal_profile_bundles ( "
|
||||||
|
+ "bundle_id integer NOT NULL)");
|
||||||
|
|
||||||
|
stmt.addBatch("CREATE TABLE ct_public_personal_profile_owner_map ( "
|
||||||
|
+ "profile_id integer NOT NULL, "
|
||||||
|
+ "owner_id integer NOT NULL, "
|
||||||
|
+ "owner_order integer)");
|
||||||
|
|
||||||
|
stmt.addBatch("ALTER TABLE ONLY ct_public_personal_profile_bundles "
|
||||||
|
+ "ADD CONSTRAINT ct_pub_per_pro_bun_bun_p_zhc9i "
|
||||||
|
+ "PRIMARY KEY (bundle_id)");
|
||||||
|
|
||||||
|
stmt.addBatch("ALTER TABLE ONLY ct_public_personal_profile_bundles "
|
||||||
|
+ " ADD CONSTRAINT ct_pub_per_pro_bun_bun_f__jr2_ "
|
||||||
|
+ "FOREIGN KEY (bundle_id) "
|
||||||
|
+ "REFERENCES cms_bundles(bundle_id)");
|
||||||
|
|
||||||
|
stmt.addBatch("ALTER TABLE ONLY ct_public_personal_profile_owner_map "
|
||||||
|
+ "ADD CONSTRAINT ct_pub_per_pro_own_map_p_rr7ie "
|
||||||
|
+ "PRIMARY KEY (owner_id, profile_id)");
|
||||||
|
|
||||||
|
stmt.addBatch("ALTER TABLE ONLY ct_public_personal_profile_owner_map "
|
||||||
|
+ "ADD CONSTRAINT ct_pub_per_pro_own_map_f_cd7_1 "
|
||||||
|
+ "FOREIGN KEY (owner_id) "
|
||||||
|
+ "REFERENCES cms_person_bundles(bundle_id)");
|
||||||
|
|
||||||
|
stmt.addBatch(
|
||||||
|
"ALTER TABLE ONLY ct_public_personal_profile_owner_map "
|
||||||
|
+ "ADD CONSTRAINT ct_pub_per_pro_own_map_f_ugs15 "
|
||||||
|
+ "FOREIGN KEY (profile_id) "
|
||||||
|
+ "REFERENCES ct_public_personal_profile_bundles(bundle_id)t");
|
||||||
|
stmt.executeBatch();
|
||||||
|
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
System.err.println("Failed to create new table.");
|
||||||
|
printStackTrace(ex);
|
||||||
|
rollback(conn);
|
||||||
|
close(conn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
System.out.println("Filling new tables with data...");
|
||||||
|
final Statement queryProfilesStmt = conn.createStatement();
|
||||||
|
final Statement stmt = conn.createStatement();
|
||||||
|
|
||||||
|
final ResultSet profilesRs =
|
||||||
|
queryProfilesStmt.executeQuery(
|
||||||
|
"SELECT parent_id "
|
||||||
|
+ "FROM cms_items "
|
||||||
|
+ "JOIN ct_public_personal_profiles "
|
||||||
|
+ "ON cms_items.item_id = ct_public_personal_profiles.profile_id");
|
||||||
|
|
||||||
|
while (profilesRs.next()) {
|
||||||
|
stmt.addBatch(String.format(
|
||||||
|
"INSERT INTO ct_public_personal_profile_bundles (bundle_id) "
|
||||||
|
+ "VALUES (%d)",
|
||||||
|
profilesRs.getInt(1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> processedEntries = new ArrayList<String>();
|
||||||
|
for (OldAssocEntry entry : oldData) {
|
||||||
|
BigDecimal profileBundleId;
|
||||||
|
BigDecimal ownerBundleId;
|
||||||
|
|
||||||
|
profileBundleId = getParentIdFor(entry.getProfileId(), conn);
|
||||||
|
ownerBundleId = getParentIdFor(entry.ownerId, conn);
|
||||||
|
|
||||||
|
if (processedEntries.contains(
|
||||||
|
String.format("%s-%s",
|
||||||
|
profileBundleId.toString(),
|
||||||
|
ownerBundleId.toString()))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
stmt.addBatch(String.format(
|
||||||
|
"INSERT INTO ct_public_personal_profile_owner_map ("
|
||||||
|
+ "profile_id, "
|
||||||
|
+ "owner_id, "
|
||||||
|
+ "owner_order) "
|
||||||
|
+ "VALUES (%s, %s, %d)",
|
||||||
|
profileBundleId.toString(),
|
||||||
|
ownerBundleId.toString(),
|
||||||
|
entry.getOwnerOrder()));
|
||||||
|
|
||||||
|
processedEntries.add(String.format(
|
||||||
|
"%s-%s",
|
||||||
|
profileBundleId.toString(),
|
||||||
|
ownerBundleId.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
stmt.executeBatch();
|
||||||
|
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
System.err.println("Failed to fill tables.");
|
||||||
|
printStackTrace(ex);
|
||||||
|
rollback(conn);
|
||||||
|
close(conn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
conn.commit();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
System.err.println("Failed to commiting changes.");
|
||||||
|
printStackTrace(ex);
|
||||||
|
rollback(conn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class OldAssocEntry {
|
||||||
|
|
||||||
|
private BigDecimal profileId;
|
||||||
|
private BigDecimal ownerId;
|
||||||
|
private Integer ownerOrder;
|
||||||
|
|
||||||
|
public OldAssocEntry(final BigDecimal profileId,
|
||||||
|
final BigDecimal ownerId,
|
||||||
|
final Integer ownerOrder) {
|
||||||
|
this.profileId = profileId;
|
||||||
|
this.ownerId = ownerId;
|
||||||
|
this.ownerOrder = ownerOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getOwnerId() {
|
||||||
|
return ownerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOwnerId(BigDecimal ownerId) {
|
||||||
|
this.ownerId = ownerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getOwnerOrder() {
|
||||||
|
return ownerOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOwnerOrder(Integer ownerOrder) {
|
||||||
|
this.ownerOrder = ownerOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getProfileId() {
|
||||||
|
return profileId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProfileId(BigDecimal profileId) {
|
||||||
|
this.profileId = profileId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void rollback(final Connection conn) {
|
||||||
|
try {
|
||||||
|
conn.rollback();
|
||||||
|
} catch (SQLException ex1) {
|
||||||
|
System.out.println("Rollback failed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void close(final Connection conn) {
|
||||||
|
try {
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
System.err.println("Failed to close JDBC connectio.");
|
||||||
|
printStackTrace(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printStackTrace(final SQLException ex) {
|
||||||
|
ex.printStackTrace(System.err);
|
||||||
|
if (ex.getNextException() != null) {
|
||||||
|
printStackTrace(ex.getNextException());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private BigDecimal getParentIdFor(final BigDecimal id,
|
||||||
|
final Connection conn)
|
||||||
|
throws SQLException {
|
||||||
|
final Statement stmt = conn.createStatement();
|
||||||
|
|
||||||
|
final ResultSet rs = stmt.executeQuery(String.format(
|
||||||
|
"SELECT parent_id FROM cms_items where item_id = %s",
|
||||||
|
id.toString()));
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
return rs.getBigDecimal(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,7 +10,6 @@ import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
|
||||||
import org.apache.commons.cli.CommandLine;
|
import org.apache.commons.cli.CommandLine;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
|
@ -22,11 +21,7 @@ import org.apache.log4j.Logger;
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class GenericContactPersonAssocUpgrade extends Program {
|
public class GenericContactPersonAssocUpgrade extends Program {
|
||||||
|
|
||||||
private static final Logger logger =
|
|
||||||
Logger.getLogger(
|
|
||||||
GenericContactPersonAssocUpgrade.class);
|
|
||||||
|
|
||||||
public GenericContactPersonAssocUpgrade() {
|
public GenericContactPersonAssocUpgrade() {
|
||||||
super("GenericContactPersonAssocUpgrade", "1.0.0", "");
|
super("GenericContactPersonAssocUpgrade", "1.0.0", "");
|
||||||
}
|
}
|
||||||
|
|
@ -50,15 +45,7 @@ public class GenericContactPersonAssocUpgrade extends Program {
|
||||||
printStackTrace(ex);
|
printStackTrace(ex);
|
||||||
close(conn);
|
close(conn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*try {
|
|
||||||
final Statement stmt = conn.createStatement();
|
|
||||||
stmt.execute("SELECT * FROM cms_items");
|
|
||||||
} catch(SQLException ex) {
|
|
||||||
System.err.printlnor("Connection is not usable.", ex);
|
|
||||||
return;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
System.out.println("Retrieving old data...");
|
System.out.println("Retrieving old data...");
|
||||||
try {
|
try {
|
||||||
|
|
@ -94,6 +81,7 @@ public class GenericContactPersonAssocUpgrade extends Program {
|
||||||
try {
|
try {
|
||||||
System.out.println("Creating new tables...");
|
System.out.println("Creating new tables...");
|
||||||
final Statement stmt = conn.createStatement();
|
final Statement stmt = conn.createStatement();
|
||||||
|
|
||||||
stmt.addBatch("CREATE TABLE cms_person_bundles ( "
|
stmt.addBatch("CREATE TABLE cms_person_bundles ( "
|
||||||
+ "bundle_id integer NOT NULL)");
|
+ "bundle_id integer NOT NULL)");
|
||||||
|
|
||||||
|
|
@ -179,7 +167,7 @@ public class GenericContactPersonAssocUpgrade extends Program {
|
||||||
contactsRs.getInt(1)));
|
contactsRs.getInt(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> processedEntries =
|
final List<String> processedEntries =
|
||||||
new ArrayList<String>();
|
new ArrayList<String>();
|
||||||
for (OldAssocEntry entry : oldData) {
|
for (OldAssocEntry entry : oldData) {
|
||||||
BigDecimal personBundleId;
|
BigDecimal personBundleId;
|
||||||
|
|
@ -196,13 +184,14 @@ public class GenericContactPersonAssocUpgrade extends Program {
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt.addBatch(String.format(
|
stmt.addBatch(String.format(
|
||||||
"INSERT INTO cms_person_contact_map (person_id, "
|
"INSERT INTO cms_person_contact_map ("
|
||||||
|
+ "person_id, "
|
||||||
+ "contact_id, "
|
+ "contact_id, "
|
||||||
+ "link_order, "
|
+ "link_order, "
|
||||||
+ "link_key) "
|
+ "link_key) "
|
||||||
+ "VALUES (%s, %s, %d, '%s')",
|
+ "VALUES (%s, %s, %d, '%s')",
|
||||||
personBundleId,
|
personBundleId.toString(),
|
||||||
contactBundleId,
|
contactBundleId.toString(),
|
||||||
entry.getLinkOrder(),
|
entry.getLinkOrder(),
|
||||||
entry.getLinkKey()));
|
entry.getLinkKey()));
|
||||||
|
|
||||||
|
|
@ -305,7 +294,6 @@ public class GenericContactPersonAssocUpgrade extends Program {
|
||||||
ex.printStackTrace(System.err);
|
ex.printStackTrace(System.err);
|
||||||
if (ex.getNextException() != null) {
|
if (ex.getNextException() != null) {
|
||||||
printStackTrace(ex.getNextException());
|
printStackTrace(ex.getNextException());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue