mNOte
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
import java.io.Serializable; import java.util.Objects; import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; import javax.persistence.Transient; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import javax.persistence.IdClass; @Entity @IdClass(mpkey3.class) @JsonIgnoreProperties(ignoreUnknown = true) @Table(name = "n")// COMMENT olarakta public class mN implements Serializable { private static final long serialVersionUID = 141161231232L; @JsonIgnore @com.datastax.driver.mapping.annotations.Transient // THIS TRANSIENTS very importnat. > HIBERNATE bunlar olmadan HATA VERIYOR ! public static final String tn = "n"; @com.datastax.driver.mapping.annotations.Transient public String toWhereComp() { return " where " + mpkey3.fsc + "=" + sc + " and " + mpkey3.foi + "=" + oi + " and " + mpkey3.fot + "=" + ot; // // " and " + mpkey5.fri + "=" + ri; } @Transient public String toWhereAll() { return toWhereComp(); } @Id @Basic(optional = false) @Column(name = mpkey3.fsc, nullable = false) private Long sc; public Long getSc() { return sc; } public void setSc(Long sc) { this.sc = sc; } @Id @Basic(optional = false) @Column(name = mpkey3.foi, nullable = true) private Long oi; public Long getOi() { return oi; } public void setOi(Long oi) { this.oi = oi; } @Transient public Long getBayinoteid() { return getOi(); } @Transient public void SetBayinoteid(Long oi) { setOi(oi); } @Id @Basic(optional = false) @Column(name = mpkey3.fot, nullable = true) private Long ot; public Long getOt() { return ot; } public void setOt(Long ot) { this.ot = ot; } @JsonIgnore @Transient public static final String fc = "c"; // @Column(name = fc, nullable = true) private String c; public String getC() { return c; } public void setC(String c) { this.c = c; } public String getCategory() { return getC(); } public void setCategory(String c) { setC(c); } /** * TO t | character varying | * <br> * */ @JsonIgnore @Transient public static final String ft = "t"; // @Column(name = ft, nullable = true) private String t; public String getT() { return t; } public void setT(String t) { this.t = t; } /** * * @return */ @Transient public String getTitle() { return getT(); } /** * * @param t */ @Transient public void setTitle(String t) { setT(t); } /** * TO t | character varying | * <br> * */ @JsonIgnore @Transient public static final String fa = "a"; // @Column(name = fa, nullable = true) private String a; public String getA() { return a; } public void setA(String a) { this.a = a; } @Transient public String getAbout() { return getA(); } @Transient public void setAbout(String a) { setA(a); } /** * TO t | character varying | * <br> * */ @JsonIgnore @Transient public static final String fd = "d"; // @Column(name = fd, nullable = true) private String d; public String getD() { return d; } public void setD(String d) { this.d = d; } @Transient protected int listQueueNo; @Transient public int getListQueueNo() { return listQueueNo; } @Transient public void setListQueueNo(int listQueueNo) { this.listQueueNo = listQueueNo; } @Transient public String getTask() { return getD(); } @Transient public void setTask(String d) { setD(d); } /** * TO n | character varying | * <br> * */ @JsonIgnore @Transient public static final String fn = "n"; // @Column(name = fn, nullable = true) private String n; public String getN() { return n; } public void setN(String n) { this.n = n; } @Transient public String getNote() { return getN(); } @Transient public String getNote(int chars_max) { if (n != null) { if (n.length() >= chars_max) { return n.substring(0, chars_max); } return n; } else { return ""; } } @Transient public void setNote(String n) { setN(n); } @JsonIgnore @Transient public static final String fj = "j"; @Column(name = fj, nullable = true) private String j; public String getJ() { return j; } public void setJ(String j) { this.j = j; } /** * utime | bigint | update time. */ @JsonIgnore @Transient public static final String fut = "ut"; // todo _Replace all @Column(name = fut, nullable = true) private Long ut; public Long getUt() { return ut; } public void setUt(Long ut) { this.ut = ut; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof mpkey3)) { return false; } mpkey3 that = (mpkey3) o; return Objects.equals(getOi(), that.getOi()) && Objects.equals(getOt(), that.getOt()) && Objects.equals(getSc(), that.getSc()) && Objects.equals(getOi(), that.getOi()); } /** * * @return */ @Override public int hashCode() { return Objects.hash(getSc(), getOi(), getOt()); } @com.datastax.driver.mapping.annotations.Transient public mpkey3 gtMKey() { return new mpkey3(sc, oi, oi); } @com.datastax.driver.mapping.annotations.Transient @Override public String toString() { return mpkey3.fsc + ":" + sc + "," + mpkey3.fot + ":" + ot + "," + mpkey3.foi + ":" + oi + ",t:" + t; } /** * */ @JsonIgnore @Transient public static final String fall = mpkey3.fsc + "," + mpkey3.fot + "," + mpkey3.foi + "," + fc + "," + ft + "," + fa + "," + fd + "," + fn + "," + fj + "," + fut; |
adr
1 2 3 4 5 6 7 8 9 10 11 12 |
@Column(name = fglt, nullable = true) private BigDecimal glt; public BigDecimal getGlt() { return glt; } public void setGlt(BigDecimal glt) { this.glt = glt; } |
mOCA
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
package bayimodels; import generic.tools.db.model.acFlyer; import generic.tools.db.mysql.kmysql; import java.io.Serializable; import java.util.Hashtable; import java.util.UUID; import com.datastax.driver.mapping.annotations.PartitionKey; import com.datastax.driver.mapping.annotations.Transient; import generic.tools.convert.cConvert; import java.io.File; import javax.persistence.Column; import com.fasterxml.jackson.annotation.JsonIgnore; @com.datastax.driver.mapping.annotations.Table(keyspace = "o1", name = "c1") public class mCategories implements Serializable { public mCategories() { } public mCategories(Long sc, Long pparent, acFlyer.QUEUE_WAITING_OPERATION peos) { this.bayi_kodu = sc; this.parent = pparent; this.eos = peos; } @Transient @JsonIgnore public mCategories oldBackup; @Transient public Byte recordType; @Transient public Byte ownerType; @JsonIgnore @Transient public Long oi; @Transient public Long oi2; @Transient public Short rt; @Transient @JsonIgnore // AQ: ci : company : Owner TYPE ! onemli! public Byte parentType; @Transient public mCategories copyOf() { return g_etCopy(); } @JsonIgnore @Transient public acFlyer.QUEUE_WAITING_OPERATION eos; @Transient private static final long serialVersionUID = 101417281588L; @Transient public static final String tableName = "c1"; // ok @Transient public static final String fupdateDate = "update_date"; // "update_date" "bigint" "regular" , ok @Transient public static final String fIdKeyTUID = "id"; // "id" "timeuuid" "clustering", ok @Transient public String toJson() { return cConvert.toJson(this); } @Transient public String toWhere_composite_partition_keys() { return toWhere_composite_partition_keys(true); } @Transient public String toInsert() { return " insert into " + db + "." + tn + "(" + fBKodu + "," + flevel + "," + fparent + "," + fcreationDate + "," + fIdKeyTUID + "," + fBCatId + "," + fcorder + "," + fDesc + "," + fName + "," + fupdateDate + " ) values ( " + getBayiKodu() + "," + getClevel() + "," + getParent() + "," + getCreation_date() + "," + getId() + "," + getBayiCategoryId() + "," + getOrder() + ",'" + getDescription() + "'" + ",'" + getName() + "'," + getUpdateDate() + ")"; } @Transient public String toPath() { return File.separator + "p" + File.separator + getParent() + File.separator + getName(); } @Transient public String toWhere() { return toWhere(true); /*return " where " + fIdKeyTUID + "=" + gtIdStr() + " and " + fcreationDate + "=" + getCreation_date() + " and " + fparent + "=" + getParent() + " and " + flevel + "=" + getClevel() + " and " + toWhere_composite_partition_keys(false);*/ } @Transient public String toDelete_SQl() { return " delete from " + db + "." + tn + " " + toWhere(); } @Transient public static final String f_pkey = fcreationDate + "," + fparent + "," + flevel + "," + fIdKeyTUID; @Transient public static final String f_composite = fBKodu; @Transient public static final String f_cluster_fields = f_composite + "," + f_pkey; @Transient public static final String f_all_fields_to_stream = f_cluster_fields + "," + fBCatId + "," + fcorder + "," + fDesc + "," + fName + "," + fupdateDate; public enum sql_Reading_fields { fall((byte) 1), fcomposite_and_primary((byte) 2), fcomposite((byte) 3); public int value; // private sql_Reading_fields(byte value) { this.value = value; } } @Transient public String toWhere_full_update() { return toWhere(); } @Transient public String toFull_Select(boolean withpayload) { if (withpayload) { return "select * from " + db + "." + tn + " " + toWhere(); } else { return "select " + f_cluster_fields + " from " + db + "." + tn + " " + toWhere(); } } @Transient public String toSelect_exists() { return "select " + f_pkey + " from " + db + "." + tn + " " + toWhere_full_update(); } @JsonIgnore @Transient // this is only for cache! --- when product is readed! public Hashtable<UUID, mProductsPart1> productsOfCategory; @Transient @Override public int hashCode() { return toUniqString().hashCode(); } @Transient public String toUniqString() { return (getBayiKodu() + "-" + getParent() + "-" + getClevel() + "-" + getIdStr() + "-" + creation_date); } @Transient @Override public boolean equals(Object object) { if (object == null) { return false; } if (!(object instanceof mCategories)) { return false; } mCategories other = (mCategories) object; if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id)) || // (this.bayi_kodu == null && other.bayi_kodu != null) || (this.bayi_kodu != null && !this.bayi_kodu.equals(other.bayi_kodu)) || // (this.clevel == null && other.clevel != null) || (this.clevel != null && !this.clevel.equals(other.clevel)) || (this.creation_date == null && other.creation_date != null) || (this.creation_date != null && !this.creation_date.equals(other.creation_date)) || // (this.parent == null && other.parent != null) || (this.parent != null && !this.parent.equals(other.parent))) { return false; } return true; } @Transient public boolean equalDir(Object object) { if (object == null) { return false; } if (!(object instanceof mCategories)) { return false; } mCategories other = (mCategories) object; if ((this.name == null && other.name != null) || (this.name != null && !this.name.equals(other.name)) || // (this.bayi_kodu == null && other.bayi_kodu != null) || (this.bayi_kodu != null && !this.bayi_kodu.equals(other.bayi_kodu)) || // (this.description == null && other.description != null) || (this.description != null && !this.description.equals(other.description)) // || (this.creation_date == null && other.creation_date != null) || (this.creation_date != null && !this.creation_date.equals(other.creation_date)) || // (this.parent == null && other.parent != null) || (this.parent != null && !this.parent.equals(other.parent))) { return false; } return true; } @Transient public Hashtable<Long, mCategories> sub_categories; /** * BayiCatID, Category ! * */ @Transient public Hashtable<Long, mCategories> gtSubCategories() { return sub_categories; } @Transient public void stSubCategories(Hashtable<Long, mCategories> subCategories) { this.sub_categories = subCategories; } @JsonIgnore @Transient public boolean isExists; @JsonIgnore @Transient public boolean isError; @JsonIgnore @Transient public String infoMsg; @JsonIgnore @Transient private Integer listQueueNo; @Transient public Integer gtListQueueNo() { return listQueueNo; } @Transient public void stListQueueNo(Integer listQueueNo) { this.listQueueNo = listQueueNo; } @Transient @Override public String toString() { return getName() + "," + getDescription() + ",p" + getParent() + ",cid" + getBayiCategoryId() + ",l" + getClevel() + ",sc" + getBayiKodu(); } @JsonIgnore @Transient public String getIdStr() { if (this.id != null) { return this.id.toString(); } else { return null; } } @Transient public void setIdStr(String ptId) { this.id = kmysql.getUUIDFromStr(ptId); } // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) @PartitionKey(4) @Column(name = fIdKeyTUID, nullable = false) private java.util.UUID id; // TIME UUID "id","timeuuid","partition_key" public java.util.UUID getId() { return id; } public void setId(java.util.UUID id) { this.id = id; } // - - - @PartitionKey(0) @Column(name = fBKodu, nullable = false) private Long bayi_kodu; @Transient public Long getBayiKodu() { return bayi_kodu; } @Transient public void setBayiKodu(Long bayi_kodu) { this.bayi_kodu = bayi_kodu; } @PartitionKey(1) @Column(name = fcreationDate) private Long creation_date; public Long getCreation_date() { return creation_date; } public void setCreation_date(Long creationDate) { this.creation_date = creationDate; } // // @Column(name = fBCatId) private Long bayi_category_id; // // /** * LONG because of , milisecond can be usable in the future. */ @PartitionKey(2) @Column(name = fparent, nullable = false) private Long parent; public Long getParent() { return parent; } public void setParent(Long parent) { this.parent = parent; } @PartitionKey(3) @Column(name = flevel, nullable = false) private Integer clevel; /** * I1 . Generic * * @return */ public Integer getClevel() { return clevel; } /** * I1 . Generic * * @param clevel */ public void setClevel(Integer clevel) { this.clevel = clevel; } @Column(name = fcorder) private Integer corder; @Transient public Integer getOrder() { return corder; } @Transient public void setOrder(Integer order) { this.corder = order; } @Column(name = fDesc) private String description; @Column(name = fName) private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } @Transient public Long getBayiCategoryId() { return bayi_category_id; } @Transient public void setBayiCategoryId(Long bayiCategoryId) { this.bayi_category_id = bayiCategoryId; } @Transient public void setBayiCategoryId(Integer bayiCategoryId) { this.bayi_category_id = bayiCategoryId.longValue(); } public String getDescription() { return description; } /** * Used for parent of the directory. {@link getDescription()} * * @param description */ public void setDescription(String description) { this.description = description; } @Column(name = fupdateDate) private Long update_date; @Transient public Long getUpdateDate() { return update_date; } @Transient public void setUpdateDate(Long updateDate) { this.update_date = updateDate; } } |
Data JPA
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
// https://start.spring.io/ // Spring initializer // POM DATA <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.5.2</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>accessing-data-jpa-complete</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> // -> Customer JAVA package com.example.accessingdatajpa; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @Entity public class Customer { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id; private String firstName; private String lastName; protected Customer() {} public Customer(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; } @Override public String toString() { return String.format( "Customer[id=%d, firstName='%s', lastName='%s']", id, firstName, lastName); } public Long getId() { return id; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } } // Query -> CustomerRepository package com.example.accessingdatajpa; import java.util.List; import org.springframework.data.repository.CrudRepository; public interface CustomerRepository extends CrudRepository<Customer, Long> { List<Customer> findByLastName(String lastName); Customer findById(long id); } // Application Class package com.example.accessingdatajpa; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class AccessingDataJpaApplication { public static void main(String[] args) { SpringApplication.run(AccessingDataJpaApplication.class, args); } } // |
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
package com.example.accessingdatajpa; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; @SpringBootApplication public class AccessingDataJpaApplication { private static final Logger log = LoggerFactory.getLogger(AccessingDataJpaApplication.class); public static void main(String[] args) { SpringApplication.run(AccessingDataJpaApplication.class); } @Bean public CommandLineRunner demo(CustomerRepository repository) { return (args) -> { // save a few customers repository.save(new Customer("Jack", "Bauer")); repository.save(new Customer("Chloe", "O'Brian")); repository.save(new Customer("Kim", "Bauer")); repository.save(new Customer("David", "Palmer")); repository.save(new Customer("Michelle", "Dessler")); // fetch all customers log.info("Customers found with findAll():"); log.info("-------------------------------"); for (Customer customer : repository.findAll()) { log.info(customer.toString()); } log.info(""); // fetch an individual customer by ID Customer customer = repository.findById(1L); log.info("Customer found with findById(1L):"); log.info("--------------------------------"); log.info(customer.toString()); log.info(""); // fetch customers by last name log.info("Customer found with findByLastName('Bauer'):"); log.info("--------------------------------------------"); repository.findByLastName("Bauer").forEach(bauer -> { log.info(bauer.toString()); }); // for (Customer bauer : repository.findByLastName("Bauer")) { // log.info(bauer.toString()); // } log.info(""); }; } } /* The AccessingDataJpaApplication class includes a demo() method that puts the CustomerRepository through a few tests. First, it fetches the CustomerRepository from the Spring application context. Then it saves a handful of Customer objects, demonstrating the save() method and setting up some data to work with. Next, it calls findAll() to fetch all Customer objects from the database. Then it calls findById() to fetch a single Customer by its ID. Finally, it calls findByLastName() to find all customers whose last name is "Bauer". The demo() method returns a CommandLineRunner bean that automatically runs the code when the application launches. */ |
Native Query : Component
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import java.util.List; import java.util.Optional; @Component public class crepocomponentMessage implements irepoMessage{ @Override @Query(value = "select * from msg where msg.sc = ?1", nativeQuery = true) public List<meMessage> findByShopID(Long sc) { List<meMessage> lom = new ArrayList<>(); return null; } |
Ref: https://spring.io/guides/gs/accessing-data-jpa/