Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

fix for #3244. more config options. embedded derby included. #3453

Merged
merged 1 commit into from
Nov 27, 2015

Conversation

mdbergmann
Copy link
Contributor

I've closed the old PR.
This one has only a bug fix and minor changes.

@teichsta
Copy link
Member

@lewie could you please have a look at this one? Thanks, Thomas E.-E.

@teichsta teichsta added this to the 1.8.0 milestone Nov 25, 2015
@lewie
Copy link
Contributor

lewie commented Nov 26, 2015

@teichsta,
JPA persistence works as expected with PostgreSQL 9.4.5.

The only but known Bug is the missing Implementation of Item types 'Call' and 'Location'.

Rgds
Helmut

@mdbergmann
Copy link
Contributor Author

I'm unaware of those types.
But it should be a simple fix.
Can I update this PR?

@lewie
Copy link
Contributor

lewie commented Nov 26, 2015

@lewie
Copy link
Contributor

lewie commented Nov 26, 2015

See org.openhab.core.library.items.LocationItem and org.openhab.library.tel.items.CallItem.

@teichsta
Copy link
Member

Can I update this PR?

yes, you can … it's "just" a branch in your repository!

@mdbergmann
Copy link
Contributor Author

Any idea why the import for CallItem and CallType fails?

[ERROR] /Users/mbergmann/Development/MySources/openhab/bundles/persistence/org.openhab.persistence.jpa/java/org/openhab/persistence/jpa/internal/JpaHistoricItem.java:[26]
[ERROR] import org.openhab.library.tel.items.CallItem;

@mdbergmann
Copy link
Contributor Author

OK, sorry. Got it. An entry in manifest was missing.

@mdbergmann
Copy link
Contributor Author

I have a weird thing here.
The PointType.toString() gives me an output like this:
PointType 3vals toString(): 1,20°N, 2,30°W, 3,40 m

Feeding this back to PointType.valueOf() doesn't work.
Looking at the source code of PointType I don't understand what's happening here.
The BigDecimal.toPlainString() shouldn't give such an output.

See the test code:

    @Test
    public void testPointTypeToStringAndBack2Vals() throws Exception {
        PointType type = new PointType(new DecimalType(1.2), new DecimalType(2.3));
        System.out.println("PointType 2vals toString(): " + type.toString());
        PointType type2 = new PointType(type.toString());

        assertTrue(type.getLatitude().doubleValue() == type2.getLatitude().doubleValue());
        assertTrue(type.getLongitude().doubleValue() == type2.getLongitude().doubleValue());
    }

@watou
Copy link
Contributor

watou commented Nov 26, 2015

I fixed this and merged the change #3410 9 days ago for availability in 1.8. Could you rebase your PR and try again?

@mdbergmann
Copy link
Contributor Author

All right now.
I've added support for LocationItem and CallItem.
There are now some more enhancements, like the ability to override the syncmapping property, new version of openjpa and I've included the embedded derby driver.

@lewie
Copy link
Contributor

lewie commented Nov 26, 2015

@mdbergmann,
LocationItem and CallItem works well now.

Got Errors while restoring PercentType, so based on this PR I changed fromPersistedItem in JpaHistoricItem and it runs well now, if you want you can use my changes:

    public static HistoricItem fromPersistedItem(JpaPersistentItem pItem, Item item) {
        State state;
        if (item instanceof NumberItem) {
            state = DecimalType.valueOf(pItem.getValue());
        } else if (item instanceof DimmerItem) {
            state = PercentType.valueOf(pItem.getValue());
        } else if (item instanceof SwitchItem) {
            state = OnOffType.valueOf(pItem.getValue());
        } else if (item instanceof ContactItem) {
            state = OpenClosedType.valueOf(pItem.getValue());
        } else if (item instanceof RollershutterItem) {
            state = PercentType.valueOf(pItem.getValue());
        } else if (item instanceof ColorItem) {
            state = HSBType.valueOf(pItem.getValue());
        } else if (item instanceof DateTimeItem) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(new Date(Long.valueOf(pItem.getValue())));
            state = new DateTimeType(cal);
        } else if (item instanceof LocationItem) {
            PointType pType = null;
            String[] comps = pItem.getValue().split(";");
            if (comps.length >= 2) {
                pType = new PointType(DecimalType.valueOf(comps[0]), DecimalType.valueOf(comps[1]));

                if (comps.length == 3) {
                    pType.setAltitude(DecimalType.valueOf(comps[2]));
                }
            }
            state = pType;

        } else if (item instanceof CallItem) {
            state = new CallType(pItem.getValue());
        } else {
            state = new StringType(pItem.getValue());
        }

        return new JpaHistoricItem(item.getName(), state, pItem.getTimestamp());
    }

@mdbergmann
Copy link
Contributor Author

OK, done. Thanks.

@mdbergmann
Copy link
Contributor Author

@lewie
Alright, wait a sec.
I'd like to remove all but the embedded derby driver.
You hint is great that all drivers are OSGi bundles and can just be dropped in addons.

fix typo. tabs to spaces.

added support for persisting LocationItem and CallItem.

update of openjpa to 2.4.0. added embedded derby driver.

added more config options for jpa persistence.

fix for JpaPersistentItem, primary key must not be initialized with a value.

applied fix for Issue openhab#3437

Removed all but the embedded derby driver. Other database driver jars can be dropped into addons folder.
@mdbergmann
Copy link
Contributor Author

Alright. This should now be it.

teichsta added a commit that referenced this pull request Nov 27, 2015
@teichsta teichsta merged commit 5f9c55e into openhab:master Nov 27, 2015
@teichsta
Copy link
Member

Thanks guys! @mdbergmann could you please change the title of the PR finally. For the release notes the current title would be misleading since the update of the postgresql driver didn't actually happen :-)

@mdbergmann mdbergmann changed the title fix for #3244. New version of PostgreSQL (9.4) driver. fix for #3244. more config options. embedded derby included. Nov 27, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants