0%

Steps

Create Repository at Github website.

Img

To avoid errors, do not initialize the new repository with README, license, or gitignore files. You can add these files after your project has been pushed to GitHub.

Initialize local repository

script
1
2
3
git init -b main
# Add .gitignore file.
git add . && git commit -m "First commit"

Bind local and remote repository

Img

script
1
2
3
4
git remote add origin  <REMOTE_URL> 
# Sets the new remote
git remote -v
# Verifies the new remote URL

Authentication

Generate token as following:
Img

Use token:

script
1
git remote set-url origin https://<generated_token>@github.com/<user-name>/<remote_repository_name>.git

Push to remote

script
1
git push -u origin main

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

食材

罗氏虾,蒜末,姜末,葱末, 小米椒

步骤

  1. 罗氏虾去虾线.
  2. 锅内加入宽油,待油温升至冒烟,将虾下去油锅(怕油溅的朋友可以把锅盖上).
  3. 炸至虾变色后捞出,剩下的虾油可以储存好,下次做菜用.
  4. 下一步锅内放油 、 蒜末、姜末 、 小米椒,爆香.
  5. 加入爆好的大虾翻炒均匀,加入半罐啤酒焖一下,锅内要剩余一些汁水.
  6. 加生抽调味出锅.
    一道美味的油爆大虾就做好啦,汤汁拌饭也是一绝哦(๑•̀ㅂ•́)و✧

罗氏虾

食材

辣椒切段, 大蒜切粒, 两到三个皮蛋.

步骤

  1. 锅开火不放油, 下辣椒加少量盐小火烤
  2. 烤至辣椒起虎皮后, 加入油和大蒜翻炒
  3. 加入皮蛋, 用铲子压碎后, 一起翻炒
  4. 加蚝油生抽翻炒出锅

皮蛋

Usage

Adding the @Transactional annotation at the class level or method level.

1
2
3
4
5
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class PayServiceImpl implements IPayService {
// 省略方法...
}

Implementation

Spring will create a Proxy class by AOP when detects the Annotated class/method runs, it will:

  1. start the transaction
  2. run the business logic
  3. commit the transaction or rollback

Exception handling

If RunTimeException thrown, the Proxy will roll back the transaction, otherwise(no exception thrown or no-RunTimeException thrown), the Proxy will commit the transaction.
But you can also rollback the transaction by rollbackFor property, for example:

1
@Transactional(propagation= Propagation.REQUIRED, rollbackFor= PayException.class)

Background

Persistence Context

Persistence Context is the middle layer between Database with Business Code. It’s a staging area for:

  • Convert the Database Row to Entity.
  • Ready for the Client to read Entity.
  • The alerted Entity by business code.

Lifecycle

Managed Entity

A managed entity is a representation of a database table row.

1
2
3
4
5
6
Session session = sessionFactory.openSession();
assertThat(getManagedEntities(session)).isEmpty();

List<FootballPlayer> players = s.createQuery("from FootballPlayer").getResultList();

assertThat(getManagedEntities(session)).size().isEqualTo(3);

Detached Entity

A detached entity is a Entity POJO corresponds to a decision table row, but not tracked by the Persistence Context.
A managed entity can converted into detached entity by below ways:

  1. The Session creates the entity is closed.
  2. Call Session.evict(entity) or Session.clear()
1
2
3
4
5
6
7
8
FootballPlayer cr7 = session.get(FootballPlayer.class, 1L);

assertThat(getManagedEntities(session)).size().isEqualTo(1);
assertThat(getManagedEntities(session).get(0).getId()).isEqualTo(cr7.getId());

session.evict(cr7);

assertThat(getManagedEntities(session)).size().isEqualTo(0);

But when Session.update() or Session.merge() called, the entity will be tracked by Persistence Context again.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
FootballPlayer messi = session.get(FootballPlayer.class, 2L);

session.evict(messi);
messi.setName("Leo Messi");
transaction.commit();

assertThat(getDirtyEntities()).isEmpty();

transaction = startTransaction(session);
session.update(messi);
transaction.commit();

assertThat(getDirtyEntities()).size().isEqualTo(1);
assertThat(getDirtyEntities().get(0).getName()).isEqualTo("Leo Messi");

Transient entity

A entity POJO that not exist in the Persistent Context store and not managed.
A typical example is to create a instance by constructor.
To make a transient entity persistent, we need to call Session.save(entity) or Session.saveOrUpdate(entity):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
FootballPlayer neymar = new FootballPlayer();
neymar.setName("Neymar");
session.save(neymar);

assertThat(getManagedEntities(session)).size().isEqualTo(1);
assertThat(neymar.getId()).isNotNull();

int count = queryCount("select count(*) from Football_Player where name='Neymar'");

assertThat(count).isEqualTo(0);

transaction.commit();
count = queryCount("select count(*) from Football_Player where name='Neymar'");

assertThat(count).isEqualTo(1);

Deleted Entity

Session.delete is called.

1
2
3
session.delete(neymar);

assertThat(getManagedEntities(session).get(0).getStatus()).isEqualTo(Status.DELETED);

Introduce

Hibernate is a ORM framework that implementes the JPA API.

Use Hibernate

Configure Data Source

1
2
3
4
5
6
7
8
9
10
@Configuration
@ComponentScan
@EnableTransactionManagement
@PropertySource("jdbc.properties")
public class AppConfig {
@Bean
DataSource createDataSource() {
...
}
}

Create SessionFactory

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public class AppConfig {
@Bean
LocalSessionFactoryBean createSessionFactory(@Autowired DataSource dataSource) {
var props = new Properties();
props.setProperty("hibernate.hbm2ddl.auto", "update");
props.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
props.setProperty("hibernate.show_sql", "true");
var sessionFactoryBean = new LocalSessionFactoryBean();
sessionFactoryBean.setDataSource(dataSource);
// Scan package to get entity class:
sessionFactoryBean.setPackagesToScan("com.itranswarp.learnjava.entity");
sessionFactoryBean.setHibernateProperties(props);
return sessionFactoryBean;
}

@Bean
HibernateTemplate createHibernateTemplate(@Autowired SessionFactory sessionFactory) {
return new HibernateTemplate(sessionFactory);
}

@Bean
PlatformTransactionManager createTxManager(@Autowired SessionFactory sessionFactory) {
return new HibernateTransactionManager(sessionFactory);
}
}

Create Entity Class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
@Entity
@Table(name = "...")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false, updatable = false)
public Long getId() { ... }

@Column(nullable = false, unique = true, length = 100)
public String getEmail() { ... }

@Column(nullable = false, length = 100)
public String getPassword() { ... }

@Column(nullable = false, length = 100)
public String getName() { ... }

@Column(nullable = false, updatable = false)
public Long getCreatedAt() { ... }
}

Save Entity

1
2
3
4
5
6
7
8
9
10
public User register(String email, String password, String name) {
User user = new User();
user.setEmail(email);
user.setPassword(password);
user.setName(name);
// Don't need to set id.s
hibernateTemplate.save(user);
System.out.println(user.getId());
return user;
}

Stream supplier

Provide a not-closed stream every time.

1
2
Supplier<Stream<String>> streamSupplier = () -> Stream.of("A", "B", "C");
Optional<String> item = streamSupplier.get().findAndy();

醋溜白茶

  1. 调汁: 两勺陈醋, 一勺生抽, 一勺蚝油, 少许盐和鸡精, 半勺淀粉.
  2. 蒜切碎, 小米椒切圈.
  3. 白菜切段, 分开菜梗和菜叶.
  4. 锅中放大蒜和小米椒炒香.
  5. 放入菜梗炒至断生, 然后放入菜叶继续翻炒.
  6. 最后放入调好的汁, 即可出锅.

Goal

Introduce how Email is implemented in current Internet and related tech-skills.

Overview

Strature

Email Client

When a user wants to send/receive the email to/from a Email, he has to use the Email Cleint to interact with Email Server.

SMTP Server

SMTP is a protocol to transfer Email information.
For example, when a Email Client wants to send a Email to the Email Server, or a Email Server(@qq.com, etc.) want to send Email to another Email Server(@163.com, etc.)

IMAP/POP3

SMTP is responsible for sending email while IMAP/POP3 is responsbile for fetching Email.
Email Server builds a IMAP/POP3 Server to store emails, then the user can use the Email Client to access IMAP/POP3 Server to fetch Emails.