dc.executeStatement(
"alter table links drop column locked");
}
protected void associateContentlets() throws DotDataException {
DotConnect dc = new DotConnect();
final int limit=1000;
Logger.info(this,"creating version_info records for contentlets");
// first working and (optionally) live
String contentlets;
if(DbConnectionFactory.isOracle()){
contentlets =
"select * from ( "+
" select identifier,inode,live,locked,mod_user,mod_date,deleted,language_id,row_number() over (order by inode) rn "+
" from contentlet where working = 1 "+
") where rn >= ? and rn < ? order by identifier asc, language_id asc, mod_date desc";
}else if(DbConnectionFactory.isMsSql()){
contentlets = " SELECT TOP "+ limit + " * FROM (SELECT identifier,inode,live,locked,mod_user,mod_date,deleted,language_id,ROW_NUMBER() "
+ " OVER (order by mod_date) AS RowNumber FROM contentlet where working="+DbConnectionFactory.getDBTrue()
+ ") temp WHERE RowNumber > ? order by RowNumber, identifier asc, language_id asc, mod_date desc";
}else{
contentlets = "select identifier,inode,live,locked,mod_user,mod_date,deleted,language_id from contentlet "
+ " where working="+DbConnectionFactory.getDBTrue()+" order by identifier asc, language_id asc, mod_date desc limit ? offset ? ";
}
int offset=0;
boolean notDone;
String lastId="";
long lastLang=-1;
do {
dc.setSQL(contentlets);
if(DbConnectionFactory.isMsSql()){
dc.addParam(offset);
} else if(DbConnectionFactory.isOracle()) {
dc.addParam(offset);
dc.addParam(offset+limit);
} else{
dc.addParam(limit);
dc.addParam(offset);
}
offset=offset+limit;
List<Map<String,Object>> results=dc.loadObjectResults();
notDone=results.size()>0;
for(Map<String,Object> rr : results) {
String identifier=(String)rr.get("identifier");
String inode=(String)rr.get("inode");
long langId=Long.parseLong(rr.get("language_id").toString());
if(UtilMethods.isSet(identifier) && !(langId==lastLang && identifier.equals(lastId)) ) {
lastLang=langId;
lastId=identifier;
boolean live = false;
boolean locked = false;
boolean deleted = false;
String liveStr=rr.get("live").toString().trim();
String lockedStr=rr.get("locked").toString().trim();
String deletedStr=rr.get("deleted").toString().trim();
if(liveStr.equalsIgnoreCase("true") || liveStr.equalsIgnoreCase("false"))
live = Boolean.parseBoolean(liveStr);
else if(liveStr.equals("1") || liveStr.equals("0"))
live = Integer.parseInt(liveStr)==1;
if(lockedStr.equalsIgnoreCase("true") || lockedStr.equalsIgnoreCase("false"))
locked = Boolean.parseBoolean(lockedStr);
else if(lockedStr.equals("1") || lockedStr.equals("0"))
locked = Integer.parseInt(lockedStr)==1;
if(deletedStr.equalsIgnoreCase("true") || deletedStr.equalsIgnoreCase("false"))
deleted = Boolean.parseBoolean(deletedStr);
else if(deletedStr.equals("1") || deletedStr.equals("0"))
deleted = Integer.parseInt(deletedStr)==1;
String mod_user=(String)rr.get("mod_user");
java.util.Date mod_date=(java.util.Date)rr.get("mod_date");
String insert="";
insert="insert into contentlet_version_info(identifier,locked_on,locked_by,deleted,lang,working_inode"+(live?",live_inode":"")+") values " +
"(?,?,?,?,?,?"+(live?",?":"")+")";
dc.setSQL(insert);
dc.addParam(identifier.trim());
if(locked) {
dc.addParam(mod_date);
dc.addParam(mod_user);
}
else {
dc.addParam(new java.util.Date());
dc.addObject(null);
}
dc.addParam(deleted);
dc.addParam(langId);
dc.addParam(inode);
if(live)
dc.addParam(inode);
try {
dc.loadResult();
} catch (DotDataException e) {
e.printStackTrace();
}
}
}
} while(notDone);
// now live not working
if(DbConnectionFactory.isOracle()){
contentlets =
"select * from ( "+
" select identifier,inode,language_id,mod_date,row_number() over (order by inode) rn "+
" from contentlet where working = 0 and live = 1 "+
") where rn >= ? and rn < ? order by identifier asc, language_id asc, mod_date desc";
}else if(DbConnectionFactory.isMsSql()){
contentlets = " SELECT TOP " + limit + " * FROM (SELECT identifier,inode,language_id,mod_date,ROW_NUMBER() "
+ " OVER (order by mod_date) AS RowNumber FROM contentlet where working = "+DbConnectionFactory.getDBFalse()
+ " and live ="+ DbConnectionFactory.getDBTrue()+ ") temp WHERE RowNumber > ? order by RowNumber, identifier asc, language_id asc, mod_date desc";
}else{
contentlets = "select identifier,inode,language_id from contentlet "
+ " where working="+DbConnectionFactory.getDBFalse()+" and live="+DbConnectionFactory.getDBTrue()
+ " order by identifier asc, language_id asc, mod_date desc limit ? offset ? ";
}
lastId="";
lastLang=-1;
offset=0;
do {
dc.setSQL(contentlets);
if(DbConnectionFactory.isMsSql()){
dc.addParam(offset);
}else if(DbConnectionFactory.isOracle()) {
dc.addParam(offset);
dc.addParam(offset+limit);
}else{
dc.addParam(limit);
dc.addParam(offset);
}
offset=offset+limit;
List<Map<String,Object>> results=dc.loadObjectResults();
notDone=results.size()>0;
for(Map<String,Object> rr : results) {
String identifier=(String)rr.get("identifier");
String inode=(String)rr.get("inode");
long langId=Long.parseLong(rr.get("language_id").toString());
if(UtilMethods.isSet(identifier) && !(langId==lastLang && identifier.equals(lastId))) {
lastId=identifier;
lastLang=langId;
dc.setSQL("update contentlet_version_info set live_inode=? where identifier=? and lang=?");
dc.addParam(inode);
dc.addParam(identifier);
dc.addParam(langId);
dc.loadResult();
}
}
} while(notDone);
}