/* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ package connectivity.tools;
/** implements a small Customer Relationship Management database * * Not finished, by far. Feel free to add features as you need them.
*/ publicclass CRMDatabase
{ privatestaticfinal String INTEGER = "INTEGER"; privatestaticfinal String VARCHAR50 = "VARCHAR(50)"; privatefinal XMultiServiceFactory m_orb; privatefinal HsqlDatabase m_database; privatefinal Connection m_connection;
/** constructs the CRM database
*/ public CRMDatabase( XMultiServiceFactory _orb, boolean _withUI ) throws Exception
{
m_orb = _orb;
m_database = new HsqlDatabase( m_orb );
if ( _withUI )
{ final XComponentLoader loader = UnoRuntime.queryInterface( XComponentLoader.class,
m_orb.createInstance( "com.sun.star.frame.Desktop" ) );
PropertyValue[] loadArgs = new PropertyValue[] { new PropertyValue( "PickListEntry", 0, false, PropertyState.DIRECT_VALUE )
};
loader.loadComponentFromURL( m_database.getDocumentURL(), "_blank", 0, loadArgs );
getDocumentUI().connect();
m_connection = new Connection( getDocumentUI().getActiveConnection() );
} else
{
m_connection = m_database.defaultConnection();
}
createTables();
createQueries();
}
/** * creates a CRMDatabase from an existing document, given by URL
*/ public CRMDatabase( XMultiServiceFactory _orb, final String _existingDocumentURL ) throws Exception
{
m_orb = _orb;
table = new HsqlTableDescriptor( "customers", new HsqlColumnDescriptor[] { new HsqlColumnDescriptor( "ID",INTEGER, HsqlColumnDescriptor.PRIMARY ), new HsqlColumnDescriptor( "Name",VARCHAR50), new HsqlColumnDescriptor( "Address",VARCHAR50), new HsqlColumnDescriptor( "City",VARCHAR50), new HsqlColumnDescriptor( "Postal",VARCHAR50), new HsqlColumnDescriptor( "Comment","LONGVARCHAR")} );
m_database.createTable( table, true );
m_database.executeSQL( "INSERT INTO \"customers\" VALUES(1,'Food, Inc.','Down Under','Melbourne','509','Preferred') " );
m_database.executeSQL( "INSERT INTO \"customers\" VALUES(2,'Simply Delicious','Down Under','Melbourne','518',null) " );
m_database.executeSQL( "INSERT INTO \"customers\" VALUES(3,'Pure Health','10 Fish St.','San Francisco','94107',null) " );
m_database.executeSQL( "INSERT INTO \"customers\" VALUES(4,'Milk And More','Arlington Road 21','Dublin','31021','Good one.') " );
table = new HsqlTableDescriptor( "orders", new HsqlColumnDescriptor[] { new HsqlColumnDescriptor( "ID",INTEGER, HsqlColumnDescriptor.PRIMARY ), new HsqlColumnDescriptor( "CustomerID",INTEGER, HsqlColumnDescriptor.REQUIRED, "customers", "ID" ), new HsqlColumnDescriptor( "OrderDate", "DATE" ), new HsqlColumnDescriptor( "ShipDate", "DATE" ) } );
m_database.createTable( table, true );
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.