우리FISA/강의 🔒

2024.01.11

닉네임생각즁 2024. 1. 11. 17:04

 

코드레벨에서는 동그라미 친 부분만 하면됨

 

실제로 Log4j인지 Logback인지는 내부에서 처리함

 

강사님은 slf4j 2.0.6 / Logback 1.4.5 깔으심

 

로그백 디폴트 로깅 비활성화 방법
https://stackoverflow.com/questions/3257154/how-to-prevent-logback-from-outputting-its-own-status-at-the-start-of-every-log

 

How to prevent logback from outputting its own status at the start of every log when using a layout

This seems like a carelessness error, but I can't seem to find the cause. Logging with logback/slf4j (most recent version slf4j-api-1.6.1, logback core/classic 0.9.24). Simplest log configuration for

stackoverflow.com

 

 

 

---

이 코드 그대로 log4j를 쓰든 logback을 쓰든 하려고하는건데

logback을 없애고 log4j를 쓰려고 하면 이렇게 메세지가 뜬다 세번째줄 링크를 들어가보면 slf4j와 log4j를 바인딩해주는 뭔가 필요하다는 설명이 나옴

 

https://logging.apache.org/log4j/2.x/log4j-slf4j-impl.html

 

Log4j – Log4j 2 SLF4J Binding

<!-- 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 Apa

logging.apache.org

- log4j2랑 slf4j 바인딩하는 역할

log4j-slf4j2-impl 

2.20 버전 다운

설치해준 후 라이브러리 추가해주면 정상적으로 작동함

 

 

--

여기에서 다시 logback 라이브러리를 추가해주고 실행하면

이런 메세지가 뜬다

 

-찾아보니까 중복되는게 있을때 보내는 메세지인듯,, 하나를 제거해주거나 무슨 코드를 넣으면 되는거같,,,,,,,,,,?

 

 

--

 

파사드패턴 적용 전

 

public class CPU {
	public void freeze() {
		System.out.println("CPU 정지");
	}

	public void execute() {
		System.out.println("CPU 동작");
	}
}

 

public class HardDrive {
	public byte[] read(long bootSector, int sectorSize) {
		byte[] result = new byte[sectorSize];
		
		System.out.println(String.format("position: %d, data: %d", bootSector, sectorSize));
		
		return result;
	}

}

 

public class Memory {
	public void load(long position, byte[] data) {
		System.out.println(String.format("position: %d, data: %d", position, data));
	}
}

 

BeforeFacade

public class BeforeFacade {

	public static void main(String[] args) {
		CPU cpu = new CPU();
		HardDrive hdd = new HardDrive();
		Memory memory = new Memory();
		
		cpu.freeze();
		memory.load(100, hdd.read(150, 200));
		cpu.execute();

	}

}

 

 

파사드 패턴 적용 후

public class Computer {
	private CPU cpu;
	private HardDrive hdd;
	private Memory memory;
	
	Computer() {
		cpu = new CPU();
		hdd = new HardDrive();
		memory = new Memory();
	}
	
	public void boot() {
		// TODO Auto-generated method stub
		cpu.freeze();
		memory.load(100, hdd.read(150, 200));
		cpu.execute();

	}

}

 

public class AfterFacade {

	public static void main(String[] args) {
		
		Computer computer = new Computer();
		computer.boot();
	}

}

 

 

------------

 

빌더 패턴(Builder) - 객체의 생성에 대한 패턴

직접 자바 코드로 빌더 패턴을 구현해보기

 

 

객체 생성 방법 

- new 생성자()

public class Person {
	// 점층적 생성자 패턴
	new Person(); // 기본 생성자
	new Person(5, "lim"); // 매개변수가 있는 생성자
	new Person(5, "lim", "상암동");
	new Person(5, "lim", "상암동", "10612");
    new Person(5, "lim", "상암동", "10612", ....);
    new Person(5, "lim", "상암동", "10612", ...., ////);
    
}

 

단점 

- 끊임없이 길어질 수 있음

- 순서가 달라지면 제대로 생성안됨,, 매개변수 넣는 순서를 외워야하는 불편함

 

이런 단점을 보완한 빌더패턴!

 

 

https://refactoring.guru/ko/design-patterns/facade

 

퍼사드 패턴

/ 디자인 패턴들 / 구조 패턴 퍼사드 패턴 다음 이름으로도 불립니다: Facade 의도 퍼사드 패턴은 라이브러리에 대한, 프레임워크에 대한 또는 다른 클래스들의 복잡한 집합에 대한 단순화된 인터

refactoring.guru

 

 

 

(혼자해본거)

https://dreamcoding.tistory.com/56#article-1--1--%EC%83%9D%EC%84%B1%EC%9E%90%EC%97%90-%EC%9D%B8%EC%9E%90%EB%A5%BC-%EB%84%A3%EC%96%B4-%EC%9D%B8%EC%8A%A4%ED%84%B4%EC%8A%A4%EB%A5%BC-%EC%83%9D%EC%84%B1%ED%95%98%EB%8A%94-%EB%B0%A9%EB%B2%95

 

[디자인 패턴] 빌더 패턴(Builder Pattern)

스프링 인 액션 5판 스터디를 진행하던 중에 스프링 시큐리티에서 빌더 패턴이 사용되는 부분을 보고 빌더 패턴에 대한 포스팅을 해보겠습니다. 빌더 패턴은 소프트 웨어 디자인 패턴 중에 하나

dreamcoding.tistory.com

이거 보고 바꿔봄

 

UserBuilder

package dev.syntax.practice;

public class UserBuilder {
	private final String name;
	private final int age;
	private final String address;
	
	
	public UserBuilder(Builder builder) {
		this.name = builder.name;
		this.age = builder.age;
		this.address = builder.address;
	}
	
	public static class Builder {
			
		private String name;
		private int age;
		private String address;
		
		public Builder name(String name) {
			this.name = name;
			return this;
		}
		
		public Builder age(int age) {
			this.age = age;
			return this;
		}

		public Builder address(String address) {
			this.address = address;
			return this;
		}
		
		public UserBuilder build() {
			return new UserBuilder(this);
		}
		
	}

		
		
	@Override
	public String toString() {
		return "name=" + name + ", age=" + age + ", address=" + address;	
	}
}

 

 

Main

public class Main {
	
	public static void main(String[] args) {
		UserBuilder user = new UserBuilder.Builder()
				.name("임성실")
				.age(20)
				.address("상암동")
				.build();
		
		UserBuilder user2 = new UserBuilder.Builder()
				.age(26)
				.build();
		
		System.out.println(user2);
	}
}

 

 

====================================

Database

 

DB와 DBMS 차이를 알아야함

- DBMS : 관리를 도와주는,,

 

ANSI
표준화된 문법(어느 벤더에서나 공통적으로 통용, 적용되는 문법)
즉, 표준화된 문법을 사용하는 것이 좋음, 표준어 사용 권장

---> 쿼리를 ANSI 표준으로 써두면 다른 데이터베이스에 옮길때도 좋다

 

데이터베이스 : 데이터를 관리, 저장, 유지

 

 

8.0.35 설치

 

 

들어가서 로그인없이 다운로드

 

워크벤치(GUI 툴) 이용하려고 Full로!

Execute

 

 

계속 next 하다가

 

비밀번호 그냥 1234하기

 

만약에 실행안될때는 서비스 검색해서 들어가서 저기 이름인 MySQL80 찾아서 켜주면됨

 

뭔가 설치했을때는 cmd 들어가서 버전 확인하기

-> 환경변수 설정해야되니까 아직 안뜸

 

https://bskyvision.com/entry/MySQL-%EC%9C%88%EB%8F%84%EC%9A%B0-PC%EC%97%90%EC%84%9C-MySQL-%ED%99%98%EA%B2%BD-%EB%B3%80%EC%88%98-%EC%84%A4%EC%A0%95%ED%95%98%EB%8A%94-%EB%B0%A9%EB%B2%95

 

[MySQL] 윈도우 PC에서 MySQL 환경 변수 설정하는 방법

MySQL이 PC에 설치되어 있는 상황에서 cmd를 열고 mysql -V을 쳤는데 다음과 같은 내용이 콘솔에 출력되지 않았다면 환경 변수를 설정해줄 필요가 있습니다. path에 mysql.exe가 있는 경로를 추가해줘야

bskyvision.com

 

뜸!!

 

=========

 

DML, DDL 잘 알고있으면됨

DML이 80퍼는 됨

 

cmd

mysql -u root -p

서버 접근

-> 프롬포트가 mysql로 변경됨

 

show databases;

schema = database

현재있는 모든 데이터 조회

 

mysql> use mysql;
Database changed
mysql> show tables;

 

desc user;

desc = describe 

-> 테이블이 어떻게 구성되어있나 볼 수 있음

 

SELECT * from user LIMIT 5;

워크벤치

ctrl+enter -> 쿼리 실행

-- -> 주석

select host, user from user LIMIT 5;

 

 

워크벤치!

show databases; -- 쿼리 실행: Ctrl + Enter

use sakila; -- sakila DB를 사용하겠다고 명시

show tables; -- sakila DB 내 테이블 조회

DESC customer; -- cutomer 테이블 정보 조회

SELECT version(), user(), database();

use mysql;

데이터가 안나온다면 특정 db를 선택한 상태는 아닌지 확인

 

 

 

https://www.wanted.co.kr/events/22_03_s04_b03

 

'내 트리를 꾸며줘!'에 250만 명이 열광한 이유 | 원티드

어느샌가 당연해져버린 비대면 일상 속 온라인 롤링페이퍼로 친구의 트리를 꾸며준다는 기획은 요즘 트렌드를 완벽히 관통하는 트렌디함 그 자체였죠.

www.wanted.co.kr

 

 

----------

select *(select절) from language(from절)

select절

select @ (컬럼 이름 들어감)

 

 

별칭쓸때 중간에 공백이 있으면 " " 이렇게 문자열 형태로 해줘야 인식 다 가능

 

WHERE + 조건식 : 필터링하는것

 

-- MySQL DBMS에게 질의(Query)
-- SQL 쿼리문장은 절(Clause)로 구성됨
SELECT now(); -- 내장함수

-- language 테이블에서 모든 열에 해당하는 전체 데이터를 조회
SELECT * FROM language; -- Error Code: 1146. Table 'mysql.language' doesn't exist
use sakila;
SELECT * FROM language;
SELECT name FROM language;

SELECT language_id, name, last_update FROM language;

-- 다른 필드로 별칭(Alias)을 지정해서 조회
SELECT language_id AS 언어ID, name AS 언어명, last_update AS "마지막 업데이트" FROM language;

-- film_actor 테이블에서 전체 데이터를 (상위)5개 까지만 조회
SELECT * FROM film_actor LIMIT 5;


-- WHERE 절

-- CATEGORY 테이블에서 모든 데이터 조회
SELECT * FROM category;

-- category가 Sci-Fi인 film만 조회 (FROM 절 뒤에 WHERE 절 기술)
SELECT * FROM category WHERE category_id = 14; -- category_id가 14번인 레코드(행)만 조회

 

------------

 

 

 

실행되는 순서가 있어서 제대로 실행안됨

select / from / where

 from : 테이블 먼저 찾아놔야 뭘 할 수 있으니 -> where -> select

-> as는 출력할때 별칭으로,,

 

select first_name AS fn, last_name
From actor
WHERE fn = 'NICK'; -- Error Code: 1054. Unknown column 'fn' in 'where clause'	0.000 sec

 

조건절에서는 fn이 뭐로 별칭됐는지 알 수 없기 때문에 에러가 남(select가 가장 마지막에 수행되니까)

 

 

 

 

 

기본키 primary key

 

합쳐진 테이블에서 뽑아내는,,

이름에 해당하는 id가 뭔지 알아내서 최종적으로 뽑아냄

 

select * from customer 
where first_name="KAREN";

select first_name, last_name from actor where first_name="NICK";

-- WHERE 절에서 병칭으로 지정한 칼럼 참조
select first_name AS fn, last_name
From actor
WHERE fn = 'NICK'; -- Error Code: 1054. Unknown column 'fn' in 'where clause'	0.000 sec

-- 열 값을 연결하여 조회 - 내장함수(concat())
-- film 테이블에서 영화의 title과 description을 연결해서 표시
select concat(title, '의 줄거리', description) AS Summary
from film;

-- AND, OR 연산
select * from customer 
where first_name="VIRGINIA" and last_name="BLUE";

select * from customer 
where first_name="VIRGINIA" and last_name="GREEN";
select * from category;
select * from film_category LIMIT 2;
select * from film_category WHERE category_id = 2 or category_id = 10;

select * from customer 
where (first_name="STEVEN" or last_name="YOUNG") and create_date >= '2006-01-01';

-- 동등 조건(Equality)
-- actor 테이블에서 first_name이 'GRACE'인 배우(Actor)의 데이터 조회
select * from actor where first_name = 'GRACE';

-- 부등 조건
-- category 테이블에서 name이 Family가 아닌 모든 카테고리 조회
select * from category where name <> 'Family';

-- 범위 조건
-- rental 테이블에서 rental_date가 2005-05-25 이전에 빌려간 회원의 id와 대여 날짜를 조회
select customer_id, rental_date from rental where rental_date <= '2005-05-25';

-- (BETWEEN A AND B) 문법 검색 및 활용
-- rental 테이블에서 rental_date가 2005-05-24부터 2005-05-25 사이의 rental_date 열 조회
select * from rental where rental_date between '2005-05-24' and '2005-05-25';

-- 2005-05-24 23시 정각부터 2005-05-24 자정까지 1시간 동안
select * from rental where rental_date between '2005-05-24 23:00:00' and '2005-05-25';





select last_name, first_name from customer where last_name like 'Q%' or last_name like 'Y%';


show databases;
use perfomance_schema;
show tables;
select * from actor_info;
-- (perfomance_schema 데이터베이스에 있는) actor_info 테이블에서 film_info 가 Animation에 속하는 열의 모든 데이터 조회
select * from actor_info where film_info like 'Animation%';

show databases;
use perfomance_schema;
show tables;
select * from film_text;
-- film_text 테이블에서 title이 MA로 시작하는 열의 description 조회
select description from film_text where title like 'MA%';

--

 

-- 2005-05-24 23시 정각부터 2005-05-24 자정까지 1시간 동안
select * from rental where rental_date between '2005-05-24 23:00:00' and '2005-05-25';

-> 날짜 쓰면 기본적으로 자정까지로 하기때문에 뒷부분은 2005-05-25로 해도됨

 

쿼리에 날짜(’2005-05-24’)까지만 명시할 경우, 시간은 기본적으로 자정으로 설정됨.

rental 테이블에서 rental_date가 2005-05-25 자정부터 2005-05-25 오전 1시까지 1시간 동안의 rental_date 열 조회

SELECT rental_date FROM rental WHERE rental_date WHERE rental_date BETWEEN '2005-05-25' AND '2005-05-25 01:00:00';

 

 

 

 

join

 

-- 에전 방식
select c.first_name, c.last_name, a.address 
from customer as c join address as a 
where c.address_id = a.address_id; -- where는 필터링하는건데 여기서는 묶기 위한 용도로 사용
-- ANSI 표준 문법(SQL92)을 활용한 JOIN Query
select c.first_name, c.last_name, a.address , a.postal_code
from customer as c INNER JOIN address as a 
ON c.address_id = a.address_id -- 두 테이블 간의 조인을 수행하기 위한 조건 기술(조인 조건)
where a.postal_code = 52137; -- 필터링 조건

 

==> 필터링 조건과 조인 조건을 구분해주는게 좋음

 

join 많을수록 조회 속도 느려짐 / 적당한 join 필요!!

 

 

 

-- customer 테이블 정보 조회
desc customer;

-- address 테이블 정보 조회
desc address;

select c.first_name, c.last_name, a.address 
from customer as c join address as a limit 100;

-- 에전 방식
select c.first_name, c.last_name, a.address 
from customer as c join address as a 
where c.address_id = a.address_id; -- where는 필터링하는건데 여기서는 묶기 위한 용도로 사용 

-- ANSI 표준 문법(SQL92)을 활용한 JOIN Query
select c.first_name, c.last_name, a.address , a.postal_code
from customer as c INNER JOIN address as a 
ON c.address_id = a.address_id -- 두 테이블 간의 조인을 수행하기 위한 조건 기술(조인 조건)
where a.postal_code = 52137; -- 필터링 조건

 

 

 

--

 

group by

 

-- 대여 횟수가 40번 미만인 데이터는 제외(필터링)하여 조회(잘못된 wWHERE 절 사용 예시)
SELECT customer_id, count(*)
FROM rental
WHERE count(*) < 40
GROUP BY customer_id;
-- Error Code: 1111. Invalid use of group function
-- 쿼리 실행되는 순서(11번 참고)

아직 그룹핑되기전에 조건을 쓰려고하니까!

 

SELECT customer_id, count(*)
FROM rental
GROUP BY customer_id
HAVING count(*) < 40 -- groupby에 대한 조건절
ORDER BY 2 DESC; -- order by는 가장 마지막에 작성

이렇게 수정해줘야함

 

실행순서 참고

 

 

desc rental;

-- rental 테이블을 조회해서 가장 대여를 많이 한 고객에게 사은품을 주어야하는데, 그러한 고객을 찾기 위한 방법
select * from rental limit 20;
select * from rental group by customer_id;

-- rental 테이블에서 customer_id, rental_date열 데이터를 위에서부터 30행 조회
select customer_id, rental_date from rental limit 30;

-- customer_id 를 기준으로 그룹핑하여 조회
select customer_id from rental group by customer_id;

-- rental 테이블의 전체 row 조회
select count(*) from rental;

select customer_id, count(rental_date)
from rental
group by customer_id;

-- rental 테이블에서 customer_id 및 각 customer가 대여(rental)한 횟수를 카운트하여 '대여한 횟수를 기준으로 내림차순'하며 조회
select customer_id, count(*) from rental
group by custommer_id
order by 2 desc; -- DESC(DESENDING) -- 오름차순이 default

-- 대여 횟수가 40번 미만인 데이터는 제외(필터링)하여 조회(잘못된 wWHERE 절 사용 예시)
SELECT customer_id, count(*)
FROM rental
GROUP BY customer_id
HAVING count(*) < 40 -- groupby에 대한 조건절
ORDER BY 2 DESC; -- order by는 가장 마지막에 작성
-- Error Code: 1111. Invalid use of group function
-- 쿼리 실행되는 순서(11번 참고)

'우리FISA > 강의 🔒' 카테고리의 다른 글

2024.02.27  (0) 2024.02.27
2024.02.23  (0) 2024.02.23
2024.02.22  (1) 2024.02.22