Changeset 5422
- Timestamp:
- Sep 22, 2010, 10:01:44 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/config/dist/mysql-queries.xml
r4888 r5422 163 163 </query> 164 164 165 <query id="CHANGE_DATEVALUES_VALUE_COLUMN" type="SQL"> 166 <sql> 167 ALTER TABLE [DateValues] 168 MODIFY COLUMN [value] date NOT NULL 169 </sql> 170 <description> 171 An SQL query that changes the 'DateValues.value' 172 column to a date-only column type. 173 </description> 174 </query> 165 175 166 176 </predefined-queries> -
trunk/config/dist/postgres-queries.xml
r4888 r5422 28 28 --> 29 29 <predefined-queries> 30 <query id="CHANGE_DATEVALUES_VALUE_COLUMN" type="SQL"> 31 <sql> 32 ALTER TABLE [DateValues] 33 ALTER COLUMN [value] TYPE date 34 </sql> 35 <description> 36 An SQL query that changes the 'DateValues.value' 37 column to a date-only column type. 38 </description> 39 </query> 30 40 31 41 </predefined-queries> -
trunk/src/core/net/sf/basedb/core/DateUtil.java
r4889 r5422 24 24 25 25 import java.text.SimpleDateFormat; 26 import java.util.Calendar; 26 27 import java.util.Date; 27 28 … … 74 75 return value == null ? null : (Date)value.clone(); 75 76 } 76 77 78 /** 79 Truncate the given date so that only the date part 80 remains. The time part is set to 00:00:00.0 81 @param value The date to truncate, can be null 82 @return A new date with time part set to 0 or null 83 @since 2.16 84 */ 85 public static Date truncate(Date value) 86 { 87 if (value == null) return null; 88 Calendar cal = Calendar.getInstance(); 89 cal.setTime(value); 90 cal.set(Calendar.HOUR, 0); 91 cal.set(Calendar.MINUTE, 0); 92 cal.set(Calendar.SECOND, 0); 93 cal.set(Calendar.MILLISECOND, 0); 94 return cal.getTime(); 95 } 96 77 97 private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); 78 98 79 99 /** 80 Parses a string to create a <code>Date</code> . This method supports100 Parses a string to create a <code>Date</code> without time. This method supports 81 101 date in yyyy-MM-dd format or as long timevalues. 82 102 … … 121 141 } 122 142 143 144 private static final SimpleDateFormat TIMESTAMP_FORMAT = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); 145 146 /** 147 Parses a string to create a <code>Date</code> including time. This method 148 supports date in yyyy-MM-dd hh:mm:ss format or as long timevalues. 149 150 @param value the <code>String</code> to be parsed 151 @return a <code>Date</code> object 152 @throws InvalidDataException if <code>value</code> isn't a valid date. 153 @since 2.16 154 */ 155 public static Date parseTimestamp(String value) 156 throws InvalidDataException 157 { 158 Date result = null; 159 if (value != null) 160 { 161 try 162 { 163 result = TIMESTAMP_FORMAT.parse(value); 164 } 165 catch (Exception ex) 166 { 167 try 168 { 169 result = new Date(new Long(value)); 170 } 171 catch (Exception ex2) 172 { 173 throw new InvalidDataException("The value "+value+" is not a valid date."); 174 } 175 } 176 } 177 return result; 178 } 179 180 /** 181 Formats a timestamp in yyyy-MM-dd hh:mm:ss format. 182 @param d The date to format. 183 @return Formated date as a String 184 @since 2.16 185 */ 186 public static String formatTimestamp(Date d) 187 { 188 return TIMESTAMP_FORMAT.format(d); 189 } 190 191 123 192 } -
trunk/src/core/net/sf/basedb/core/Install.java
r5406 r5422 115 115 method. 116 116 */ 117 public static final int NEW_SCHEMA_VERSION = Integer.valueOf(8 4).intValue();117 public static final int NEW_SCHEMA_VERSION = Integer.valueOf(85).intValue(); 118 118 119 119 public static synchronized void createTables(boolean update, final ProgressReporter progress) -
trunk/src/core/net/sf/basedb/core/Type.java
r5384 r5422 33 33 import net.sf.basedb.core.data.StringParameterValueData; 34 34 import net.sf.basedb.core.data.BooleanParameterValueData; 35 import net.sf.basedb.core.data.TimestampParameterValueData; 35 36 import net.sf.basedb.core.hibernate.TypeWrapper; 36 37 … … 54 55 Integer type. 55 56 */ 56 INT(TypeWrapper.INTEGER, 1, Integer.class, "int", "Integer", "IntegerValues", true, true )57 INT(TypeWrapper.INTEGER, 1, Integer.class, "int", "Integer", "IntegerValues", true, true, false) 57 58 { 58 59 ParameterValueData<Integer> newParameterValueData() … … 79 80 Long integer type. 80 81 */ 81 LONG(TypeWrapper.LONG, 2, Long.class, "long", "Long", "LongValues", true, true )82 LONG(TypeWrapper.LONG, 2, Long.class, "long", "Long", "LongValues", true, true, false) 82 83 { 83 84 ParameterValueData<Long> newParameterValueData() … … 104 105 Float type. 105 106 */ 106 FLOAT(TypeWrapper.FLOAT, 3, Float.class, "float", "Float", "FloatValues", true, true )107 FLOAT(TypeWrapper.FLOAT, 3, Float.class, "float", "Float", "FloatValues", true, true, false) 107 108 { 108 109 ParameterValueData<Float> newParameterValueData() … … 131 132 Double type. 132 133 */ 133 DOUBLE(TypeWrapper.DOUBLE, 4, Double.class, "double", "Double", "DoubleValues", true, true )134 DOUBLE(TypeWrapper.DOUBLE, 4, Double.class, "double", "Double", "DoubleValues", true, true, false) 134 135 { 135 136 ParameterValueData<Double> newParameterValueData() … … 159 160 @see #TEXT 160 161 */ 161 STRING(TypeWrapper.STRING, 5, String.class, "string", "String", "StringValues", true, false )162 STRING(TypeWrapper.STRING, 5, String.class, "string", "String", "StringValues", true, false, false) 162 163 { 163 164 ParameterValueData<String> newParameterValueData() … … 181 182 @see #STRING 182 183 */ 183 TEXT(TypeWrapper.TEXT, 6, String.class, "text", "Text", "TextValues", false, false )184 TEXT(TypeWrapper.TEXT, 6, String.class, "text", "Text", "TextValues", false, false, false) 184 185 { 185 186 ParameterValueData<String> newParameterValueData() … … 202 203 Boolean type. 203 204 */ 204 BOOLEAN(TypeWrapper.BOOLEAN, 7, Boolean.class, "boolean", "Boolean", "BooleanValues", false, false )205 BOOLEAN(TypeWrapper.BOOLEAN, 7, Boolean.class, "boolean", "Boolean", "BooleanValues", false, false, false) 205 206 { 206 207 ParameterValueData<Boolean> newParameterValueData() … … 231 232 The parameter is a date value. 232 233 */ 233 DATE(TypeWrapper.DATE, 8, Date.class, "date", "Date", "DateValues", true, false )234 DATE(TypeWrapper.DATE, 8, Date.class, "date", "Date", "DateValues", true, false, true) 234 235 { 235 236 ParameterValueData<Date> newParameterValueData() … … 244 245 public int sizeOf(Object value) 245 246 { 247 return value == null ? 0 : 4; 248 } 249 }, 250 251 /** 252 The parameter is a date+time value. 253 @since 2.16 254 */ 255 TIMESTAMP(TypeWrapper.TIMESTAMP, 9, Date.class, "timestamp", "Timestamp", "TimestampValues", false, false, true) 256 { 257 ParameterValueData<Date> newParameterValueData() 258 { 259 return new TimestampParameterValueData(); 260 } 261 public Object parseString(String value) 262 throws InvalidDataException 263 { 264 return DateUtil.parseTimestamp(value); 265 } 266 public int sizeOf(Object value) 267 { 246 268 return value == null ? 0 : 8; 247 269 } 248 270 }; 249 271 272 250 273 private static final Map<Integer, Type> valueMapping = new HashMap<Integer, Type>(); 251 274 private static final Map<String, Type> stringMapping = new HashMap<String, Type>(); … … 271 294 private final boolean canEnumerate; 272 295 private final boolean isNumerical; 296 private final boolean isTemporal; 273 297 274 298 private Type(TypeWrapper typeWrapper, int value, Class<?> valueClass, 275 String stringValue, String displayValue, String tableName, boolean canEnumerate, boolean isNumerical )299 String stringValue, String displayValue, String tableName, boolean canEnumerate, boolean isNumerical, boolean isTemporal) 276 300 { 277 301 this.typeWrapper = typeWrapper; … … 283 307 this.canEnumerate = canEnumerate; 284 308 this.isNumerical = isNumerical; 309 this.isTemporal = isTemporal; 285 310 } 286 311 … … 384 409 } 385 410 411 /** 412 If the values of this type are date/time related. 413 @return TRUE if the values are temporal, FALSE otherwise 414 @since 2.16 415 */ 416 public boolean isTemporal() 417 { 418 return isTemporal; 419 } 420 421 386 422 /** 387 423 Check if an object is a value of the correct type. Null is allowed. -
trunk/src/core/net/sf/basedb/core/Update.java
r5406 r5422 45 45 import net.sf.basedb.core.data.ChangeHistoryDetailData; 46 46 import net.sf.basedb.core.data.DataCubeData; 47 import net.sf.basedb.core.data.DateParameterValueData; 47 48 import net.sf.basedb.core.data.ExperimentData; 48 49 import net.sf.basedb.core.data.FileData; … … 62 63 import net.sf.basedb.core.data.RoleKeyData; 63 64 import net.sf.basedb.core.data.SchemaVersionData; 65 import net.sf.basedb.core.data.TimestampParameterValueData; 64 66 import net.sf.basedb.core.data.TransformationData; 65 67 import net.sf.basedb.core.data.keyring.PluginKeys; … … 914 916 date to the creation date for all existing jobs that is in WAITING status 915 917 or higher. 918 </td> 919 </tr> 920 <tr> 921 <td>85</td> 922 <td> 923 Added {@link TimestampParameterValueData}. The update will change the 924 {@link DateParameterValueData} to a date-only column type. 916 925 </td> 917 926 </tr> … … 1252 1261 "--Updating schema version: " + schemaVersion + " -> 84..."); 1253 1262 schemaVersion = updateToSchemaVersion84(session); 1263 } 1264 1265 if (schemaVersion < 85) 1266 { 1267 if (progress != null) progress.display((int)(84*progress_factor), 1268 "--Updating schema version: " + schemaVersion + " -> 85..."); 1269 schemaVersion = updateToSchemaVersion85(session); 1254 1270 } 1255 1271 … … 2922 2938 } 2923 2939 2924 2940 /** 2941 Change the date type for the DateValues.values column,. 2942 */ 2943 private static int updateToSchemaVersion85(org.hibernate.Session session) 2944 throws BaseException 2945 { 2946 final int schemaVersion = 85; 2947 org.hibernate.Transaction tx = null; 2948 try 2949 { 2950 tx = HibernateUtil.newTransaction(session); 2951 2952 // Load and execute the query 2953 org.hibernate.Query query = HibernateUtil.getPredefinedSQLQuery(session, "CHANGE_DATEVALUES_VALUE_COLUMN"); 2954 /* 2955 ALTER TABLE [DateValues] 2956 MODIFY COLUMN [value] date NOT NULL 2957 */ 2958 query.executeUpdate(); 2959 2960 // Update the schema version number 2961 setSchemaVersion(session, schemaVersion); 2962 2963 // Commit the changes 2964 HibernateUtil.commit(tx); 2965 log.info("updateToSchemaVersion85: OK"); 2966 } 2967 catch (BaseException ex) 2968 { 2969 if (tx != null) HibernateUtil.rollback(tx); 2970 log.error("updateToSchemaVersion85: FAILED", ex); 2971 throw ex; 2972 } 2973 return schemaVersion; 2974 } 2925 2975 2926 2976 /** -
trunk/src/core/net/sf/basedb/core/data/DateParameterValueData.java
r4889 r5422 27 27 import java.util.Date; 28 28 29 import net.sf.basedb.core.DateUtil; 30 29 31 /** 30 32 Date parameter value. … … 51 53 @hibernate.bag table="`DateValues`" lazy="true" cascade="all" 52 54 @hibernate.collection-key column="`id`" 53 @hibernate.collection-element column="`value`" type=" timestamp" not-null="true"55 @hibernate.collection-element column="`value`" type="date" not-null="true" 54 56 */ 55 57 public List<Date> getValues() … … 66 68 } 67 69 70 71 /** 72 Overrides the parent method since we want to get rid of the 73 time part of the date. 74 */ 75 @Override 76 public void replaceValues(List<?> values) 77 { 78 List<Date> current = getValues(); 79 current.clear(); 80 if (values != null) 81 { 82 for (Object v : values) 83 { 84 current.add(DateUtil.truncate((Date)v)); 85 } 86 } 87 } 88 89 /** 90 Overrides the parent method since we want to get rid of the 91 time part of the date. 92 */ 93 @Override 94 public void setSingleValue(Object value) 95 { 96 List<Date> current = getValues(); 97 current.clear(); 98 current.add(DateUtil.truncate((Date)value)); 99 } 100 68 101 public String toString() 69 102 { -
trunk/src/core/net/sf/basedb/core/hibernate/TypeWrapper.java
r5346 r5422 31 31 import org.hibernate.type.StringType; 32 32 import org.hibernate.type.TextType; 33 import org.hibernate.type.TimestampType; 33 34 34 35 /** … … 71 72 new TypeWrapper<DateType>(new DateType()); 72 73 74 public static final TypeWrapper<TimestampType> TIMESTAMP = 75 new TypeWrapper<TimestampType>(new TimestampType()); 76 73 77 74 78 private final T hibernateType; -
trunk/src/test/TestAnnotation.java
r5060 r5422 60 60 int doubleId = TestAnnotationType.test_create("Size", Type.DOUBLE, meterId, 8.13454646d, null, Item.ARRAYDESIGN, 1, null, true); 61 61 int dateId = TestAnnotationType.test_create(null, Type.DATE, 0, new Date(), null, Item.ARRAYDESIGN, 1, null, true); 62 int timestampId = TestAnnotationType.test_create(null, Type.TIMESTAMP, 0, new Date(), null, Item.ARRAYDESIGN, 1, null, true); 62 63 int textId = TestAnnotationType.test_create(null, Type.TEXT, 0, "default value", null, Item.ARRAYDESIGN, 1, null, true); 63 64 int stringId = TestAnnotationType.test_create(null, Type.STRING, 0, "default value", null, Item.ARRAYDESIGN, 1, null, true); … … 75 76 int doubleAnnotationId2 = test_annotatate(Item.ARRAYDESIGN, arrayDesignId2, doubleId, millimeterId, 11.365789456857d); 76 77 int dateAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, dateId, 0, new Date()); 78 int timestampAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, timestampId, 0, new Date()); 77 79 int textAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, textId, 0, "a text annotation"); 78 80 int stringAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, stringId, 0, "a string annotation"); 79 81 int booleanAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, booleanId, 0, false); 80 82 int enumAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, enumId, 0, 4); 81 test_list_annotations(Item.ARRAYDESIGN, arrayDesignId, 9);83 test_list_annotations(Item.ARRAYDESIGN, arrayDesignId, 10); 82 84 test_list_annotations(Item.ARRAYDESIGN, arrayDesignId2, 2); 83 85 … … 90 92 // Test: list inherited annotations and annotation sets 91 93 test_list_inherited_annotations(Item.RAWBIOASSAY, rawBioAssayId, 2); 92 test_list_allinherited_annotations(Item.RAWBIOASSAY, rawBioAssayId, 9);94 test_list_allinherited_annotations(Item.RAWBIOASSAY, rawBioAssayId, 10); 93 95 test_list_inherited_annotationsets(Item.RAWBIOASSAY, rawBioAssayId, 1); 94 96 test_list_inheriting_annotationsets(Item.ARRAYDESIGN, arrayDesignId, 1); … … 103 105 test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, doubleId); 104 106 test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, dateId); 107 test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, timestampId); 105 108 test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, textId); 106 109 test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, stringId); … … 117 120 TestAnnotationType.test_delete(doubleId); 118 121 TestAnnotationType.test_delete(dateId); 122 TestAnnotationType.test_delete(timestampId); 119 123 TestAnnotationType.test_delete(textId); 120 124 TestAnnotationType.test_delete(stringId); -
trunk/src/test/TestAnnotationType.java
r5340 r5422 55 55 int id_double = test_create("Size", Type.DOUBLE, meterId, 8.13459187745, null, Item.SAMPLE, 1, null, false); 56 56 int id_date = test_create(null, Type.DATE, 0, new Date(), null, Item.SAMPLE, 1, null, false); 57 int id_timestamp = test_create(null, Type.TIMESTAMP, 0, new Date(), null, Item.SAMPLE, 1, null, false); 57 58 int id_text = test_create(null, Type.TEXT, 0, "default value", null, Item.SAMPLE, 1, null, false); 58 59 int id_string = test_create(null, Type.STRING, 0, "default value", null, Item.SAMPLE, 1, null, false); … … 65 66 test_load(id_double); 66 67 test_load(id_date); 68 test_load(id_timestamp); 67 69 test_load(id_text); 68 70 test_load(id_string); … … 96 98 test_delete(id_double); 97 99 test_delete(id_date); 100 test_delete(id_timestamp); 98 101 test_delete(id_text); 99 102 test_delete(id_string);
Note: See TracChangeset
for help on using the changeset viewer.