Java development blog (tips, notes, …)
"First, solve the problem. Then, write the code." (John Johnson)

    Making functions permanent in Powershell

    2018-04-09 01:00:00 +0000

    I created a function in powershell to access a remote docker host from my windows 10 workstation. You should never just expose the docker socket. Always work with certificates. The official docker documentation has a nice step by step tutorial to do exactly that.

    function docker02 {docker "-H=docker02.mydomain.net:2376" --tlsverify --tlscacert=C:\ca.pem --tlscert=C:\cert.pem  --tlskey=C:\key.pem $args}

    Now I had to insert this command every time I open a new powershell. This annoyed me really fast.

    Powershell supports user profiles.

    You can check the path with:

    $profile

    Check if a profile file already exists:

    test-path $profile

    If “false” use this command:

    new-item -path $profile -itemtype file -force

    Now you just need to insert the function in the profile file:

    powershell_ise $profile

    Source: http://www.gsx.com/blog/bid/81096/enhance-your-powershell-experience-by-automatically-loading-scripts

    Mapping query result to a plain java bean with @SqlResultSetMapping

    2018-01-31 19:00:00 +0000

    I needed some data from a old big oracle database. Most of the time I write or generate a entity class, and fetch the data with a Named Query. But this time I only needed two informations and I didn’t what to use a dozen primary keys and so on to find it. So I used a Native Query.. I know… messy.

    Trying to make it look a little professional, I used a SqlResultSetMapping to map the result to a plain old java bean.

    //Need to be put in an entity class. Any entity class will do
    @SqlResultSetMapping(
            name = EntityClass.RESULT_MAPPING_NAME,
            classes = {
                @ConstructorResult(
                        targetClass = MyPlainBean.class,
                        columns = {
                            @ColumnResult(name = "something"),
                            @ColumnResult(name = "someone")
                        }
                )
            }
    )
    
    //EntityClass is the name of the plain bean - NOT an entity
    
    //Some static final Strings to reference the information. Do not use the same string multiple times!
    public static final String RESULT_MAPPING_NAME  = "aVeryGoodName";
    public static final String NATIVE_SQL_QUERY  = "SELECT  column1 \"something\" column32 \"someone\" where.....";
    
    //The Native Query call
    final Query<MyPlainBean> query = session.createNativeQuery(EntityClass.NATIVE_SQL_QUERY,EntityClass.RESULT_MAPPING_NAME);

    Book recommendation: MetaGame

    2017-09-13 19:00:00 +0000

    Here’s a book recommendation. A science-fiction thriller. The most interesting part was how the writer fused the world with technology. There a nanobots in this world, which send out a “ping”. They sit on everything. Multiple devices can pick up this signal and therefore pinpoint the object. Objects in displays can be overlayed with other objects. Therefor building a world on top the real world… hence meta :) :
    MetaGame: Science-Fiction Thriller

    Mapping query result to a plain java bean with @SqlResultSetMapping

    2017-09-10 19:00:00 +0000

    I needed some data from a old big oracle database. Most of the time I write or generate a entity class, and fetch the data with a Named Query. But this time I only needed two informations and I didn’t what to use a dozen primary keys and so on to find it. So I used a Native Query.. I know… messy.

    Trying to make it look a little professional, I used a SqlResultSetMapping to map the result to a plain old java bean.

    //Need to be put in an entity class. Any entity class will do
    @SqlResultSetMapping(
            name = EntityClass.RESULT_MAPPING_NAME,
            classes = {
                @ConstructorResult(
                        targetClass = MyPlainBean.class,
                        columns = {
                            @ColumnResult(name = "something"),
                            @ColumnResult(name = "someone")
                        }
                )
            }
    )
    
    //EntityClass is the name of the plain bean - NOT an entity
    
    //Some static final Strings to reference the information. Do not use the same string multiple times!
    public static final String RESULT_MAPPING_NAME  = "aVeryGoodName";
    public static final String NATIVE_SQL_QUERY  = "SELECT  column1 \"something\" column32 \"someone\" where.....";
    
    //The Native Query call
    final Query<MyPlainBean> query = session.createNativeQuery(EntityClass.NATIVE_SQL_QUERY,EntityClass.RESULT_MAPPING_NAME);

    Lychee

    2017-09-08 18:00:00 +0000

    “Lychee is a free photo-management tool, which runs on your server or web-space. Installing is a matter of seconds. Upload, manage and share photos like from a native application. Lychee comes with everything you need and all your photos are stored securely.” : https://lychee.electerious.com/

subscribe via RSS