Wednesday, 22 March 2023

Good Practice of Creating URI from String

It is generally recommended to use the java.net.URI class to create and manipulate URIs rather than constructing URIs directly from strings. This is because the URI class provides a higher level of abstraction and ensures that the resulting URI is valid and conforms to the URI syntax rules.The URI class provides constructors and methods to create and manipulate URIs, and it automatically handles any encoding and decoding that needs to be done. For example, if you want to create a URI from a string that contains special characters, you can use the URI(String) constructor as follows:

URI uri = new URI("http", "example.com", "/path with spaces", "query=string", "fragment");

This will create a URI with the following components:

http://example.com/path%20with%20spaces?query=string#fragment

Note that the path component, which contains spaces, is automatically encoded as %20.When creating a URI from user input, it is important to validate the input and ensure that it does not contain any invalid characters or sequences. This can be done using the java.net.URI.create(String) method, which will throw an IllegalArgumentException if the input string is not a valid URI.Overall, using the URI class provides a more robust and reliable way to create and manipulate URIs in Java.



Sunday, 12 February 2023

MySql Database

1. Database In General

Relation database, Document database. 

Database Table Relationships

One to one:

mainly used for optimize a big table into two, one table contains often-visited columns, and another one contains rarely-visited columns. By this way, min. IO operations, i.e. reducing the amount data set that need to be loaded from persistences to memory.   

One to many: 

one entry ref. to many entries in another table

Many to many:

mutually ref. to many entries.

Self-reference:

entries ref. to anther entry located at the same table. 


Appendix 1. 

When we use SQL database, and when we select NoSQL database

SQL (Structured Query Language) databases and NoSQL databases are both types of databases that can be used to store and manage data. The choice between the two depends on several factors, including:

SQL databases are best suited for structured data, meaning data that can be organized into tables with defined relationships between the tables. This type of data is well suited for tasks such as financial reporting, where data is typically highly organized and predictable. SQL databases are also well suited for applications that require complex transactions, such as banking or e-commerce, where data consistency and integrity is critical.

NoSQL databases, on the other hand, are best suited for unstructured or semi-structured data, meaning data that doesn't fit neatly into a fixed table structure. NoSQL databases are often used for big data and real-time web applications, where data is generated at high volumes and speeds and needs to be processed and analyzed quickly. They are also well suited for cloud-based applications and distributed systems, where horizontal scalability is important.

In summary, the choice between SQL and NoSQL databases depends on the type of data you need to store and the demands of your application. If you have structured data and need to support complex transactions, an SQL database may be the best choice. If you have large amounts of unstructured data and need to handle real-time data processing, a NoSQL database may be a better fit.

 
 




Wednesday, 4 January 2023

Git commands

git-shell commands:

Git Local Config

git config --global user.email: showing current git user default email. 

git config --global user.name "John Doe": config git user name 

git config --list : check your local git config 


As committing
git init: creating a local git repository, i.e. .git in the current folder.
git add . : adding all files in a current folder for commit
git add filename.* : adding a specific file in the current folder for commit
git commit -m 'another commit' : commit added files to the local repository with a commit message.
git commit -a : commit all changes in the current dir.
git commit -am "message": commit all changes with a message in the current dir.
git remote add origin https://github.com/yichunzhao/Java8.git : link local repository to remote repository.
git push -u  dst  src ; git updating remote with a local source; -u: update

git remote rm origin: disconnect the link with the remote repository.

git pull: it is a shorthand for git fetch + git merge fetch_head

Info. 
git status: current branch status.
git remote -v  v: verbose displaying info. of remote repository

Branch 
git branch -r: remote branches
git branch: local branches

git branch -d|D branch-name: removing a local branch
git branch -d|D combined with -r branch-name: removing a remote branch

Push 
git push --set-upstream origin red: push local feature branch to the remote, when at the first time.

Stash 
git stash
git stash show

git stash show stash@{1}

git stash list : list all stash
git stash apply: applying the most recent stashed changes
Or
git stash pop : applying the most recently changes to your repo. 


Creating a new branch
git branch dev
git checkout master:  switching to another branch.

View history
git log :
git log --oneline
git reflog
git log --all --graph --decorate --online
git diff: working directory, a difference between commits

Switching between different branches
git checkout master: switch to master branch
git checkout dev: switch to the dev branch

by default, a remote repository is named as an origin by Git.
git push origin dev: push dev branch to the remote by the following command:

Removing a file or folder
git rm x.text
git commit -m "removing a file"
git push origin dev: don't forget to update remote

Git Merging
as standing on the master and merging changes from dev branch in
git checkout master
git merge dev
git add .  : add all changes from the dev branch
git commit -m "changes from dev"
git push origin master: commit local master into remote

When conflicts happen
git merge -- abort: get back the state before merge conflicts

editing confliction; OR:  choose

Alternatively, you can tell Git that you'll simply go with one of the edited versions, called "ours" or "theirs".

git checkout -- ours path/to/conflict-file.css

git checkout -- .  : git discard all changes that are not staged for commit

merger from a feature branch into local master

git checkout master
git pull
git checkout feature
git merge master

Git Revert
git revert undoes a specific commit and then creating a new commit.

git revert by default pops up a vi editor to modify the commit message; press ESC to command line, ZZ(Capital) command to save the file.

git revert specific-commit --n
git revert specific-commit -- no-edit

git log --oneline: it shows the commit ref(s)
git reflog

git revert commit-ref: then modifying the commit message; normally using the default text revert xxx

Press ESC, shift zz; then quit from the vi editor.
git log: it shows a revert commit created.

Git Reset

git reset: having three types of invocations. --soft(the commit tree head), --mixed(stagging index), or --hard(working directory).

Git/Linux Command
ps -ef|grep git: checking git process running
rm -f .git/index.lock : remove index locker file located in the ./git folder

Git Remove remote folder
making sure you are at the right branch
git checkout branch-expected
git rm --cached -rf ./.idea; -rf:  recursive and force
git commit -m "rm remote folder"
git push 

Git Remove remote and local folder
#remove a file
git rm password.text

#remove a folder
git rm -rf ./.idea

Config git

It allows to config git user name and email.

git config --global user.name "my-user-name"
git config --global user.email "my-email"

Git ignoring

Git disconnect remote repository

git remote -v: display all remote repositories linking to local repo.
git remote add remote_repo_name another_remote_git_repo_url: pointing to local repo. to another remote repo.
git remote rm remote_repo_name: removing the link to the remote repo, not rm remote repo.


Monday, 19 September 2022

MySQL 5.7 default DateTime

 MySQL 5.7 default dateTime mode, zero dateTime is not allowed.  

Since 0000-00-00 00:00:00 is not a valid DATETIME value, your database is broken. That is why MySQL 5.7 – which comes with NO_ZERO_DATE mode enabled by default – outputs an error when you try to perform a write operation.

So a solution to solve this error by reset the mode, i.e.

SET SQL_MODE='ALLOW_INVALID_DATES';



Can Jackson Deserialize Java Time ZonedDateTime

Yes, but must include JSR310. Thus ZonedDateTime can be deserialized directly from JSON response to POJO field. <dependency> <g...