conn = getConnection();
//t.printElapsedTime("Connection took..");
if(conn == null)
{
System.out.println("braking as connection was not yet ready");
throw new PropertyException("Problem getting connection");
}
PreparedStatement ps = null;
//String sql = "SELECT " + colItemKey + "," + colItemType + ", " + colString + ", " + colDate + ", " + colData + ", " + colFloat + ", " + colNumber + " FROM " + tableName + " WHERE " + colItemKey + " LIKE ? AND " + colGlobalKey + " = ?";
String sql = "SELECT " + colItemKey + "," + colItemType + ", " + colString + ", " + colDate + ", " + colData + ", " + colFloat + ", " + colNumber + " FROM " + tableName;
if(type != 10)
{
sql = "SELECT " + colItemKey + "," + colItemType + ", " + colString + ", " + colDate + ", '' AS " + colData + ", " + colFloat + ", " + colNumber + " FROM " + tableName;
}
sql += " WHERE ";
sql += "((" + colItemKey + " NOT LIKE 'content_%' AND ";
sql += "" + colItemKey + " NOT LIKE 'principal_%' AND ";
sql += "" + colItemKey + " NOT LIKE 'repository_%_WYSIWYGConfig' AND ";
sql += "" + colItemKey + " NOT LIKE 'repository_%_StylesXML' AND ";
sql += "" + colItemKey + " NOT LIKE 'repository_%_defaultFolderContentTypeName' AND ";
sql += "" + colItemKey + " NOT LIKE 'repository_%_defaultTemplateRepository' AND ";
sql += "" + colItemKey + " NOT LIKE 'siteNode_%_enabledLanguages' AND ";
sql += "" + colItemKey + " NOT LIKE 'siteNode_%_disabledLanguages') OR ";
sql += "(" + colItemKey + " LIKE 'siteNode_%_enabledLanguages' AND string_val <> '') OR ";
sql += "(" + colItemKey + " LIKE 'siteNode_%_disabledLanguages' AND string_val <> '')) AND ";
sql += "" + colGlobalKey + " = ? ";
//System.out.println("sql:" + sql);
if(logger.isInfoEnabled())
{
logger.info("app:" + CmsPropertyHandler.getApplicationName());
logger.info("operating mode:" + CmsPropertyHandler.getOperatingMode());
}
/*
if(CmsPropertyHandler.getApplicationName().equalsIgnoreCase("deliver") && CmsPropertyHandler.getOperatingMode().equalsIgnoreCase("3"))
{
sql = "SELECT " + colItemKey + "," + colItemType + ", " + colString + ", " + colDate + ", " + colData + ", " + colFloat + ", " + colNumber + " FROM " + tableName;
sql += " WHERE ";
sql += "" + colItemKey + " LIKE ? AND ";
sql += "" + colItemKey + " NOT LIKE 'principal_%_languageCode' AND ";
sql += "" + colItemKey + " NOT LIKE 'principal_%_defaultToolId' AND ";
sql += "" + colItemKey + " NOT LIKE 'content_%_allowedContentTypeNames' AND ";
sql += "" + colItemKey + " NOT LIKE 'content_%_defaultContentTypeName' AND ";
sql += "" + colItemKey + " NOT LIKE 'content_%_initialLanguageId' AND ";
sql += "" + colItemKey + " NOT LIKE 'repository_%_defaultFolderContentTypeName' AND ";
sql += "" + colItemKey + " NOT LIKE 'repository_%_defaultTemplateRepository' AND ";
sql += "" + colItemKey + " NOT LIKE 'repository_%_parentRepository' AND ";
sql += "" + colItemKey + " NOT LIKE 'repository_%_WYSIWYGConfig' AND ";
sql += "" + colItemKey + " NOT LIKE 'repository_%_StylesXML' AND ";
sql += "" + colItemKey + " NOT LIKE 'repository_%_extraProperties' AND ";
sql += "" + colGlobalKey + " = ? ";
}
*/
if(logger.isInfoEnabled())
logger.info("sql:" + sql);
//System.out.println("sql:" + sql);
if (type == 0)
{
//System.out.println("conn:" + conn);
//System.out.println("sql:" + sql);
ps = conn.prepareStatement(sql);
//ps.setString(1, prefix + "%");
//ps.setString(2, globalKey);
ps.setString(1, globalKey);
//System.out.println("arg1:" + prefix + "%");
//System.out.println("arg2:" + globalKey);
}
else
{
sql = sql + " AND " + colItemType + " = ?";
ps = conn.prepareStatement(sql);
ps.setString(1, prefix + "%");
ps.setString(2, globalKey);
ps.setInt(3, type);
//System.out.println("arg1:" + prefix + "%");
//System.out.println("arg2:" + globalKey);
//System.out.println("arg3:" + type);
}
ArrayList list = new ArrayList();
ResultSet rs = ps.executeQuery();
logger.info("All rows " + sql);
int rows = 0;
while (rs.next())
{
rows++;
String key = rs.getString(colItemKey);
int typeId = rs.getInt(colItemType);
//System.out.println("key[" + typeId + "]:" + key);
if(logger.isInfoEnabled())
logger.info("key[" + typeId + "]:" + key);
list.add(key);
if(type == 5 && type5Map == null)
type5Map = new HashMap();
if(type == 5 && typeMap5Fallback == null)
typeMap5Fallback = new HashMap();
if(type == 10 && type10Map == null)
type10Map = new HashMap();
if(type == 10 && typeMap10Fallback == null)
typeMap10Fallback = new HashMap();
currentType5Map = type5Map;
currentType10Map = type10Map;
if(isRecacheCall)
{
currentType5Map = typeMap5Fallback;
currentType10Map = typeMap10Fallback;
}
if(type == 5)
{
synchronized (currentType5Map)
{
currentType5Map.put(key, new Integer(typeId));
}
}
if(type == 10)
{
synchronized (currentType10Map)
{
currentType10Map.put(key, new Integer(typeId));
}
}
Object o = null;
switch (typeId) {
case PropertySet.BOOLEAN:
int boolVal = rs.getInt(colNumber);
o = new Boolean(boolVal == 1);
break;
case PropertySet.DATA:
{
//Ugly fix for old type of column in oracle which we used to run LONG RAW. We converted to blob and the code is different
String columnTypeName = rs.getMetaData().getColumnTypeName(5);
logger.info("columnTypeName: " + columnTypeName);
if(this.driverClassName.indexOf("oracle") > -1 && columnTypeName != null && columnTypeName.indexOf("RAW") == -1)
{
//System.out.println("Getting as blob");
Blob blob = rs.getBlob(colData);
//System.out.println("blob:" + blob);
if(blob != null)
{
try
{
InputStream in = blob.getBinaryStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[(int)blob.length()];
InputStream is = in;
while (is.read(buffer) > 0) {
baos.write(buffer);
}
baos.flush();
String s = baos.toString();
//System.out.println("S: " + s + "...");
o = s.getBytes();
}
catch (Exception e)
{
e.printStackTrace();
}
}
else
{
o = null;
}
}
else
{
//System.out.println("Getting as raw bytes:" + key);
o = rs.getBytes(colData);
}
break;
}
case PropertySet.DATE:
o = rs.getTimestamp(colDate);
break;
case PropertySet.DOUBLE:
o = new Double(rs.getDouble(colFloat));
break;
case PropertySet.INT:
o = new Integer(rs.getInt(colNumber));
break;
case PropertySet.LONG:
o = new Long(rs.getLong(colNumber));
break;
case PropertySet.STRING:
o = rs.getString(colString);
break;
default:
logger.info("JDBCPropertySet doesn't support this type yet:" + key + ":" + typeId);
}
if(type != 10 && valueMapType5 == null)
valueMapType5 = new HashMap();
if(type != 10 && valueMap5Fallback == null)
valueMap5Fallback = new HashMap();
if(type == 10 && valueMapType10 == null)
valueMapType10 = new HashMap();
if(type == 10 && valueMap10Fallback == null)
valueMap10Fallback = new HashMap();
currentValue5Map = valueMapType5;
currentValue10Map = valueMapType10;
if(isRecacheCall)
{
currentValue5Map = valueMap5Fallback;
currentValue10Map = valueMap10Fallback;
}
//System.out.println("Caching:" + key + "=" + o + "(type " + type + ")");
if(type != 10)
{
synchronized (currentValue5Map)
{
currentValue5Map.put(key, o);
}
}
if(type == 10)
{
synchronized (currentValue10Map)
{
currentValue10Map.put(key, o);
}
}
}
logger.warn("All rows in InfoGlueJDBCPropertySet [" + rows + "] took: " + t.getElapsedTime());
allKeysCachedType5 = true;
if(type == 10)
allKeysCachedType10 = true;
if(isRecacheCall)
{
//System.out.println("Switching valueMap from:" + valueMap.hashCode() + " --> " + currentValueMap.hashCode());
type5Map = currentType5Map;
valueMapType5 = currentValue5Map;
typeMap5Fallback = new HashMap();
valueMap5Fallback = new HashMap();
type10Map = currentType10Map;
valueMapType10 = currentValue10Map;
typeMap10Fallback = new HashMap();
valueMap10Fallback = new HashMap();
}
rs.close();
ps.close();
return list;
}
catch (SQLException e)
{
logger.error("Problem getting keys due to an SQL exception:" + e.getCause().getMessage(), e);
throw new PropertyException(e.getMessage());
}
catch (PropertyException pe)
{
//logger.error("Problem getting keys due to unavailable connection:" + e.getCause().getMessage());
throw new PropertyException(pe.getMessage());
}
catch (Throwable tr)
{
logger.error("Problem getting keys:" + tr.getMessage(), tr);
throw new PropertyException(tr.getMessage());
}
/*
catch (UnsupportedEncodingException ue)
{
throw new PropertyException(ue.getMessage());