DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

The Latest Databases Topics

article thumbnail
Spring Security 4: JDBC Authentication and Authorization in MySQL
I am going to explain how to use Spring Security in a Spring MVC Application to authenticate and authorize users against user details stored in a MySQL Database.
September 18, 2015
by Priyadarshini Balachandran
· 192,635 Views · 10 Likes
article thumbnail
Microservices Versus Microsegmentation
An exploration of the difference between the concepts of microservices and microsegmentation.
September 17, 2015
by Lori MacVittie
· 7,084 Views · 5 Likes
article thumbnail
Receive Notifications when a Table Record Changes with C#
The SQLDependency object represents a query notification dependency between an application and an instance of SQL Server. An application can create a SqlDependency object and register to receive notifications via the OnChangeEventHandler event handler every time a record is changed. However, what it cannot do, is returning the values for the inserted, modified or deleted record. So, supposing our application has a cache containing record monitored from SqlDependency, for every notification, in order to refresh the cache we have to execute again our select. SqlTableDependency SqlTableDependency is a generic C# component used to receive events containing the values for the modified, inserted or delete record. So, supposing our application has a cache filled with data got from a specific table, when its content change, we will receive an event containing a C# object with all property filled with column table values. How it Works When instantiated, SqlTableDependency create for us, a series of database objects, used to monitor a predefined table. The main object are: Queue: containg a message with the modified record values. Service Broker: insert the message in the queue. Table Trigger: for each insert, update or delete operation, prepare the an XML message and use the Service Broker to insert it in the queue. Watch Dog Time Out SqlTableDependency implement the IDisposable interface, in order to remove the database object created. Infact it is a good practice is to wrap SqlTableDependency within a using statement or, alternatively, call the Stop() method once we do not need any more notifications. So, when the application will not disconnect abruptly, this approach is enough to remove the SqlTableDependency infrastructure (Trigger, Service Broker service, Queue). However, when the application exits abruptly – that is not calling the Stop() method or not implementing the using statement - we need a way for cleaning up the SqlTableDependency infrastructure. The Start() method, has watchDogTimeOut optional parameter used to remove all the database objects. Its default value is 180 seconds: after this amount of time, if there are no listeners waiting for notifications, the SqlTableDependency infrastructure will be removed. How to Use In this example I created a very simple WPF application with a grid, simulating some stocks value. Let's start assuming the following database table: CREATE TABLE [dbo].[Stocks]( [Code] [nvarchar](50) NULL, [Name] [nvarchar](50) NULL, [Price] [decimal](18, 0) NULL) GO INSERT [dbo].[Stocks] ([Code], [Name], [Price]) VALUES (N'MCD', N'McDonald Corp', CAST(333 AS Decimal(18, 0))) INSERT [dbo].[Stocks] ([Code], [Name], [Price]) VALUES (N'NKE', N'Nike Inc', CAST(240 AS Decimal(18, 0))) INSERT [dbo].[Stocks] ([Code], [Name], [Price]) VALUES (N'DIS', N'Walt Disney Co', CAST(130 AS Decimal(18, 0))) INSERT [dbo].[Stocks] ([Code], [Name], [Price]) VALUES (N'UTX', N'United Technologies Corp', CAST(130 AS Decimal(18, 0))) INSERT [dbo].[Stocks] ([Code], [Name], [Price]) VALUES (N'MSFT', N'Microsoft Corp', CAST(130 AS Decimal(18, 0))) INSERT [dbo].[Stocks] ([Code], [Name], [Price]) VALUES (N'PFE', N'Pfizer Inc', CAST(130 AS Decimal(18, 0))) INSERT [dbo].[Stocks] ([Code], [Name], [Price]) VALUES (N'INTC', N'Intel Corp', CAST(130 AS Decimal(18, 0))) INSERT [dbo].[Stocks] ([Code], [Name], [Price]) VALUES (N'KO', N'Coca Cola Co', CAST(130 AS Decimal(18, 0))) GO This table is constantly updated with new stock values. We want keep update our grid without use of any polling system. So, what we need is a notification coming from the database every time a record in the table has been changed. We install the SqlTableDependency package from visual studio using the following command: PM> Install-Package SqlTableDependency Now we define a C# model mapping the interested table columns. public class Stock { public decimal Price { get; set; } public string Symbol { get; set; } public string Name { get; set; } } As you can see, model's properties name can have a different table column name. In this case, we need a mapper to correclty bind the values: var mapper = new ModelToTableMapper(); mapper.AddMapping(model => model.Symbol, "Code"); Finally we create our SqlTableDependency: _dependency = new SqlTableDependency(_connectionString, "Stocks", mapper); _dependency.OnChanged += _dependency_OnChanged; _dependency.OnError += _dependency_OnError; _dependency.Start(); Below the complete code: public partial class Window1 : Window { private IList _stocks; private readonly string _connectionString = "data source=.;initial catalog=TableDependencyDB;integrated security=True"; private readonly SqlTableDependency _dependency; public Window1() { this.InitializeComponent(); this.McDataGrid.ItemsSource = LoadCollectionData(); this.Closing += Window1_Closing; var mapper = new ModelToTableMapper(); mapper.AddMapping(model => model.Symbol, "Code"); _dependency = new SqlTableDependency(_connectionString, "Stocks", mapper); _dependency.OnChanged += _dependency_OnChanged; _dependency.OnError += _dependency_OnError; _dependency.Start(); } private void Window1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { _dependency.Stop(); } private void _dependency_OnError(object sender, TableDependency.EventArgs.ErrorEventArgs e) { throw e.Error; } private void _dependency_OnChanged(object sender, TableDependency.EventArgs.RecordChangedEventArgs e) { if (_stocks != null) { if (e.ChangeType != ChangeType.None) { switch (e.ChangeType) { case ChangeType.Delete: _stocks.Remove(_stocks.FirstOrDefault(c => c.Symbol == e.Entity.Symbol)); break; case ChangeType.Insert: _stocks.Add(e.Entity); break; case ChangeType.Update: var customerIndex = _stocks.IndexOf(_stocks.FirstOrDefault(c => c.Symbol == e.Entity.Symbol)); if (customerIndex >= 0) _stocks[customerIndex] = e.Entity; break; } this.McDataGrid.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() => { this.McDataGrid.Items.Refresh(); })); } } } private IEnumerable LoadCollectionData() { _stocks = new List(); using (var sqlConnection = new SqlConnection(_connectionString)) { sqlConnection.Open(); using (var sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandText = "SELECT * FROM [Stocks]"; using (var sqlDataReader = sqlCommand.ExecuteReader()) { while (sqlDataReader.Read()) { var code = sqlDataReader.GetString(sqlDataReader.GetOrdinal("Code")); var name = sqlDataReader.GetString(sqlDataReader.GetOrdinal("Name")); var price = sqlDataReader.GetDecimal(sqlDataReader.GetOrdinal("Price")); _stocks.Add(new Stock { Symbol = code, Name = name, Price = price }); } } } } return _stocks; } } As you can see from the code, only an initial select is performed to retrieve and populate the grid. Subsequent updates are done using the SqlTableDependency event handler: its receives a model object containing info about the record changed that we use to update our cache.
September 16, 2015
by Christian Del Bianco
· 141,390 Views · 5 Likes
article thumbnail
Data Conversion for SQL Server Integration Services (SSIS)
In the series of step by step lessons of SSIS (SQL Server Integration Services), this is part six in which we are going to learn a new control: Data Conversion.
September 15, 2015
by Rajat Jaiswal
· 18,097 Views · 1 Like
article thumbnail
Stored Functions as Stored Procedures in PostgreSQL PL/pgSQL
In this post, I look at a few tactics that can make the use of a stored function in PostgreSQL feel like using a stored procedure.
September 14, 2015
by Dustin Marx
· 68,765 Views · 2 Likes
article thumbnail
MySQL is a Great NoSQL Database
At Wix engineering, we’ve found that in most cases we don’t need a NoSQL database, and that MySQL is a great NoSQL database if it’s used appropriately.
September 12, 2015
by Aviran Mordo
· 19,597 Views · 6 Likes
article thumbnail
How to Set Up a Private Maven Repository in Amazon S3
Learn how to use Amazon S3 to keep private Maven artifacts to ensure your .jar files are visible only by your team.
September 9, 2015
by Yegor Bugayenko
· 9,581 Views · 3 Likes
article thumbnail
What is NW.js?
NW.js is a framework for building desktop applications with HTML, CSS, and JavaScript. It was created by Roger Wang at Intel’s Open Source Technology Center in China, and worked by combining the Node.js programming framework with Chromium’s (then) browser engine - Webkit, hence the original name Node Webkit. By combining Node.js with Chromium, Roger found a way to create applications that could not only load a local web site within an application window, but also could interact with the Operating System via a JavaScript API. This JavaScript API could control visual aspects like window dimensions, toolbar and menu items, as well as provide access to local files on the desktop. These are things that can’t be done with a hosted web site, or even a locally hosted web site. Below is an example of how an example application works. In the example illustrated above, the application’s files resemble those of a simple web site. The index.html web page is like most other web pages that you’ve seen - there is some HTML code for the page’s content, a link tag for the CSS stylesheet, and a script tag for the JavaScript. At this stage it’s identical to a website, and if you were to open it in a web browser it would work the same as it would in NW.js. There is also a CSS stylesheet for styling the contents of the index.html file, and an app.js file for executing JavaScript, in this case calling a simple dialog box with the text “from NW.js” inside of it. You’ll also notice a package.json file as well. This is the manifest file used by Node.js to load applications and libraries, and NW.js uses it to store configuration information about the desktop application. It is required by NW.js for the application to load. The NW.js application is able to load an application with a given path of the folder where the files live. It looks for the package.json file, which points to the index.html file to load, and thus loads the web page into what looks like a web browser embedded inside of an application window. This is what you can expect to see: The example application above could load inside of a web browser without any modifications, but where NW.js differs from a web browser is that where an app.js file could only interact with the index.html’s contents in the context of a web browser, NW.js allows the app.js file to interact with the Operating System through a custom JavaScript API, as well as through Node.js. This is unlike web frameworks where the front-end code and the back-end code traditionally exist and execute in separate places. The idea of front-end and back-end code existing and executing in the same place is the key concept to grasp here. In web applications, the back-end code is running from a server, and the page that is delivered to the browser on the user’s computer is limited as to what it can do on a user’s computer, due to the browser’s content security policy. With an NW.js desktop app, because the user has explicitly executed the application and it is running in a local context, then the content security does not apply. Also, the application has access to both the page as well as the computer’s resources, through an API to interact with the Operating System, allowing the code to interact not only with the front-end part of the application, but also the back-end part of the application (the computer in this case as no external server serves the desktop app). In the next section we’ll explore how this works in a bit more detail. Interacting with the Operating System NW.js provides a JavaScript API for interacting with the Operating System, so that you can do the following: Control the size and behavior of the application’s window Display a native toolbar on the application window, with menu items Add context menus in the application window area on right-click Add a tray application item in the Operating System’s tray menu Access the Operating System clipboard; read the contents and even set the contents as well Open file, folders and URLs on the computer using their default applications Insert notifications via the Operating System’s notification system. As you can see from the list, there are a lot of things that you can do within NW.js that web browsers cannot do. For example, web browsers do not have direct access to files on the desktop or the contents of the clipboard, due to security restrictions that web browsers implement to protect users from sites with malicious intent. In the case of NW.js, because the application runs on the user’s computer, it is granted a level of access where the user trusts the application, and therefore it can do a lot more things[p1] .These features allow the developer to create desktop applications that fit well into how the user’s Operating System works, and don’t stick out like a sore thumb to the user.You can think of NW.js as being like an application with an embedded web browser, that allows the contents of the site to also have access to the computer. Below is a diagram illustrating this: The JavaScript API for these features provided by NW.js can be accessed by the same JavaScript file that is interacting with the front-end web page inside of the application, again blurring the lines between front-end and back-end code, a concept that is unusual for those who are used to building web applications. The JavaScript API for the Operating System isn’t the only back-end API exposed to the developer, it can also use Node.js. Using Node.js with the application Node.js is a server-side programming framework that was created by Ryan Dahl back in 2009. It uses the V8 JavaScript engine used by the Google Chrome web browser along with some other components to let developers write server-side programs using JavaScript. Since its creation, Node.js has become a very popular programming framework, spawning a number of web frameworks, robotics tools, and in the case of NW.js, desktop application frameworks. The popularity of Node.js is down to a number of factors; JavaScript as a programming language is very common among web developers, and that lowers the barrier for developers to pick it up and work with it. Secondly, the package manager for Node.js (NPM) has made it easy for users to create modules that can be easily installed and loaded into applications. Thirdly, the evented architecture of Node.js makes it fast and well suited for particular kinds of applications. NW.js provides access to Node.js’ API in the application, as well as leveraging modules that are installed with NPM. By doing this, not only can developers use a server-side programming framework that uses the same language as the front-end, but they can also leverage the huge and growing ecosystem of modules that exist in NPM. What is most interesting is that the Node.js code can be called in the same place as the JavaScript code that is interacting with the front-end of the application. This is a unique aspect of the way that NW.js combines Node.js with Chromium, and something that you’ll want to keep in mind when you’re working with NW.js applications. Building the application for multiple OSes One of the most useful features of NW.js is that you can build native executable applications for Windows, Mac OS X, and Linux using a single codebase for your desktop application. This is a time saver when trying to develop an application that has to work across multiple platforms. This also means that you can have greater control over how the application looks and feels, more so than you can when trying to support a website for multiple web browsers. The native executable is able to run on its own, and does not require the user to have any other software installed on his or her computer. This makes it easy to distribute the application to users, including on App Stores where some NW.js apps are sold. The process of building an application for a specific operating system involves a few command line arguments, but there are some tools that simplify the process for you, such as the node-webkit-buildertool, illustrated in the example below: Using the hello worldexample app shown in Fig 1, we’re able to use nodewebkit-builder’s nwbuild command to automate the steps of building the application for both Mac OS X and Windows. This can save a lot of time (especially if you’re having to make both 32-bit and 64-bit builds of the application), and prevent mistakes from being made when building the application. There is also the ability to build the application so that the source code is compiled. This protects the source code so that other developers can’t inspect the code and reverse-engineer it. If you have an application and you’re concerned that other developers might try to copy it, then this option offers the ability to protect your application. With features like this, NW.js is a sophisticated tool for creating desktop applications, and knowing how it works under the hood helps you to understand what kind of applications you can build with it.
September 8, 2015
by Paul Jensen
· 37,663 Views · 5 Likes
article thumbnail
Get Last Record in Each MySQL Group
In this tutorial we will look at how you can use MySQL at getting the last record in a Group By of records.
September 4, 2015
by Paul Underwood
· 106,641 Views · 5 Likes
article thumbnail
Retrieving Table Metadata from SQL Server Catalog Views
SQL Server Catalog Views can be queried easily, and being able to retrieve this metadata can be very useful in various situations.
September 3, 2015
by Daniel D'agostino
· 32,282 Views · 2 Likes
article thumbnail
Using GNU Profiling (gprof) With ARM Cortex-M
Guide on how to use GNU gprof for profiling embedded applications on ARM Cortex-M microcontrollers, including setup, implementation, and analysis of profiling data.
September 3, 2015
by Erich Styger
· 9,554 Views · 2 Likes
article thumbnail
Diagramming Microservices With the C4 Model
Learn how to diagram a microservices architecture with the C4 model with these tips.
September 1, 2015
by Simon Brown
· 15,994 Views · 4 Likes
article thumbnail
SolrCloud Rebalance API
An innovative approach that helps with an effective index and a dynamic config management system for massive multi-tenant search infrastructure in SolrCloud.
August 28, 2015
by Radu Gheorghe
· 4,914 Views · 2 Likes
article thumbnail
Configuring Spring Boot for MySQL
Spring Boot has support for MySQL and a number of other popular relational databases.
August 28, 2015
by John Thompson
· 169,975 Views · 8 Likes
article thumbnail
Redirect Logging Output to Standard Error with Logback
Learn how to redirect a logging output to a standard error in Logback.
August 27, 2015
by Hubert Klein Ikkink
· 5,834 Views · 3 Likes
article thumbnail
MongoDB 3.1.7 is Released
As a reminder, 3.1.7 is a development release and is not intended for production use. The 3.1 series will evolve into 3.2, which will be for production.
August 26, 2015
by Francesca Krihely
· 6,127 Views · 1 Like
article thumbnail
Call Stored Procedures with Hibernate and PostgreSQL
Using PostgreSQL, learn how to call stored procedures from Hibernate
August 25, 2015
by Emmanouil Gkatziouras DZone Core CORE
· 49,936 Views · 4 Likes
article thumbnail
How to Import a Oracle Database Dump File
Here is an example on how to import a Oracle database dump file (a binary file that's exported from a Oracle database using the Oracle data pump utility).
August 24, 2015
by Zemian Deng
· 50,407 Views · 1 Like
article thumbnail
How to Check Oracle Database Tablespace
When creating a new users in Oracle database (new schema), you need to verify the existing tablespace availability. This query will show you what's there and how much space are free to use.
August 22, 2015
by Zemian Deng
· 209,572 Views · 3 Likes
article thumbnail
Building Microservices: Inter-Process Communication in a Microservices Architecture
In this article, learn how the different services within a system communicate with one another.
August 20, 2015
by Patrick Nommensen
· 27,347 Views · 8 Likes
  • Previous
  • ...
  • 483
  • 484
  • 485
  • 486
  • 487
  • 488
  • 489
  • 490
  • 491
  • 492
  • ...
  • Next
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook
×