max wrote:
HbnpojoAuth wrote:
max wrote:
Of all the features you mention only enum is not supported (how do you define what is an enum based on the database metadata?)
I use the metadata, but then again I only support MySQL for now which makes handling this easy (though postgreSQL enums are coming in 8.3).
Ok, so I assume this is some native mysql metadata you look up or are you using plain jdbc metadata?
Apologies for the late reply, for I have been sick throughout the entire festive season.
Regarding mysql enum metadata, the connection driver sucks, you have to use dbmd.getColumns() followed by fieldNames.getString("TYPE_NAME") to determine it's an ENUM, calling getColumnTypeName() returns "String" instead of the right "ENUM".
Thereafter, the following code will fetch all possible enum values:
/**
* Given an enum, it returns all possible values of it. wasScrubbed will be true if enums didn't match completely
* @param conn
* @param tblName
* @param fieldName
* @param wasScrubbed
* @return An arraylist of enum values
* @throws SQLException
**/
public static String[] getEnumValues(final Connection conn, final String tblName, final String fieldName, Boolean[] wasScrubbed) throws SQLException {
Statement stat = null;
ResultSet rs = null;
TreeSet<String> enumset = new TreeSet<String>();
try{
stat = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
rs = stat.executeQuery(String.format("SHOW COLUMNS FROM %s LIKE '%s'", tblName, fieldName));
rs.next();
String enumTypes=rs.getString("type");
enumTypes=enumTypes.substring(enumTypes.indexOf("(") + 1, enumTypes.length() - 1);
String[] result = enumTypes.replaceAll("'", "").split(",");
wasScrubbed[0]=false;
for (int i=0; i < result.length; i++){
String res = cleanEnum(result[i], enumset, i, wasScrubbed);
result[i]=res;
}
return result;
}finally{
if (stat != null){
stat.close();
}
if (rs != null){
rs.close();
}
}
}
There's some extra cleanup routines ("cleanEnum") to make sure enums like:
+01:00, +02:00
are cleaned up to have a valid Java identifier name.
max wrote:
All the other things you mention annotations, complex joins etc. is part of hibernate tools so if you could tell me what is so special compared to the uptodate hibernate tools instead of hibernate synchronizer which have not been maintained in years then it would be great ;)
Quote:
namely: enums were completely unsupported,
Quote:
Hibernate tools does not have that for one (good?) reason, namely that afaik I it is not supported by jdbc metadata to get this info....if that is incorrect then I would love to know how ;)
Feel free to copy my code over to yours, though it looks pretty DB specific thanks to poor JDBC support (eg Postgres is about to introduce proper enum support now but it's pretty different to Mysql - one enum type can be shared across tables).
Quote:
no unit tests generated,
Quote:
you should have fixed our datagen jira issue and it would have been available in hibernate tools then ;)
We haven't got much code that's worth ripping, what we've got to give you as a headstart is a package which generates random data (eg generateRandomString, generateRandomInteger, etc). The rest is probably too specific to your tool to extract. Again feel free to copy it over as an initial starting point (it should have no dependencies on the rest of the code).
Also, would you be so kind to clarify if multiple schema support is present in Hibernate tools? (I mean also bringing in objects representing tables that are in schemas outside of the ones referenced by the default schema). This was one major show-stopper for us in the Joe's Hibernate Synchronizer.
Best (belated) wishes for the new year