Search in sources :

Example 1 with BaseStringProperty

use of com.xpn.xwiki.objects.BaseStringProperty in project xwiki-platform by xwiki.

the class BaseStringPropertyTest method testHashCode.

@Test
public void testHashCode() {
    final String value = "test value";
    BaseStringProperty p1 = new BaseStringProperty();
    BaseStringProperty p2 = new BaseStringProperty();
    p1.setValue(value);
    p2.setValue(value);
    Assert.assertEquals(p1.hashCode(), p2.hashCode());
}
Also used : BaseStringProperty(com.xpn.xwiki.objects.BaseStringProperty) Test(org.junit.Test)

Example 2 with BaseStringProperty

use of com.xpn.xwiki.objects.BaseStringProperty in project xwiki-platform by xwiki.

the class XWikiHibernateStore method loadXWikiProperty.

private void loadXWikiProperty(PropertyInterface property, XWikiContext context, boolean bTransaction) throws XWikiException {
    try {
        if (bTransaction) {
            checkHibernate(context);
            bTransaction = beginTransaction(false, context);
        }
        Session session = getSession(context);
        try {
            session.load(property, (Serializable) property);
            // safe to assume that a retrieved NULL value should actually be an empty string.
            if (property instanceof BaseStringProperty) {
                BaseStringProperty stringProperty = (BaseStringProperty) property;
                if (stringProperty.getValue() == null) {
                    stringProperty.setValue("");
                }
            }
            ((BaseProperty) property).setValueDirty(false);
        } catch (ObjectNotFoundException e) {
            // Let's accept that there is no data in property tables but log it
            this.logger.error("No data for property [{}] of object id [{}]", property.getName(), property.getId());
        }
        // Without this test ViewEditTest.testUpdateAdvanceObjectProp fails
        if (property instanceof ListProperty) {
            ((ListProperty) property).getList();
        }
        if (bTransaction) {
            endTransaction(context, false, false);
        }
    } catch (Exception e) {
        BaseCollection obj = property.getObject();
        Object[] args = { (obj != null) ? obj.getName() : "unknown", property.getName() };
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_OBJECT, "Exception while loading property {1} of object {0}", e, args);
    } finally {
        try {
            if (bTransaction) {
                endTransaction(context, false, false);
            }
        } catch (Exception e) {
        }
    }
}
Also used : ListProperty(com.xpn.xwiki.objects.ListProperty) BaseStringProperty(com.xpn.xwiki.objects.BaseStringProperty) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) BaseProperty(com.xpn.xwiki.objects.BaseProperty) BaseCollection(com.xpn.xwiki.objects.BaseCollection) XWikiException(com.xpn.xwiki.XWikiException) InitializationException(org.xwiki.component.phase.InitializationException) MigrationRequiredException(com.xpn.xwiki.store.migration.MigrationRequiredException) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) QueryException(org.xwiki.query.QueryException) UnexpectedException(org.xwiki.store.UnexpectedException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) SQLException(java.sql.SQLException) XWikiException(com.xpn.xwiki.XWikiException) Session(org.hibernate.Session)

Aggregations

BaseStringProperty (com.xpn.xwiki.objects.BaseStringProperty)2 XWikiException (com.xpn.xwiki.XWikiException)1 BaseCollection (com.xpn.xwiki.objects.BaseCollection)1 BaseProperty (com.xpn.xwiki.objects.BaseProperty)1 ListProperty (com.xpn.xwiki.objects.ListProperty)1 MigrationRequiredException (com.xpn.xwiki.store.migration.MigrationRequiredException)1 SQLException (java.sql.SQLException)1 ObjectNotFoundException (org.hibernate.ObjectNotFoundException)1 Session (org.hibernate.Session)1 Test (org.junit.Test)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 InitializationException (org.xwiki.component.phase.InitializationException)1 QueryException (org.xwiki.query.QueryException)1 UnexpectedException (org.xwiki.store.UnexpectedException)1