| 1 |
/* |
| 2 |
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 3 |
* and the EPL 1.0 (https://h2database.com/html/license.html). |
| 4 |
* Initial Developer: H2 Group |
| 5 |
*/ |
| 6 |
package org.h2.constraint; |
| 7 |
|
| 8 |
import org.h2.table.Column; |
| 9 |
import org.h2.table.ColumnResolver; |
| 10 |
import org.h2.value.TypeInfo; |
| 11 |
import org.h2.value.Value; |
| 12 |
|
| 13 |
/** |
| 14 |
* The single column resolver resolves the VALUE column. |
| 15 |
* It is used to parse a domain constraint. |
| 16 |
*/ |
| 17 |
public class DomainColumnResolver implements ColumnResolver { |
| 18 |
|
| 19 |
private final Column column; |
| 20 |
private Value value; |
| 21 |
private String name; |
| 22 |
|
| 23 |
public DomainColumnResolver(TypeInfo typeInfo) { |
| 24 |
this.column = new Column("VALUE", typeInfo); |
| 25 |
} |
| 26 |
|
| 27 |
public void setValue(Value value) { |
| 28 |
this.value = value; |
| 29 |
} |
| 30 |
|
| 31 |
@Override |
| 32 |
public Value getValue(Column col) { |
| 33 |
return value; |
| 34 |
} |
| 35 |
|
| 36 |
@Override |
| 37 |
public Column[] getColumns() { |
| 38 |
return new Column[] { column }; |
| 39 |
} |
| 40 |
|
| 41 |
@Override |
| 42 |
public Column findColumn(String name) { |
| 43 |
return null; |
| 44 |
} |
| 45 |
|
| 46 |
void setColumnName(String newName) { |
| 47 |
name = newName; |
| 48 |
} |
| 49 |
|
| 50 |
void resetColumnName() { |
| 51 |
name = null; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Return column name to use or null. |
| 56 |
* |
| 57 |
* @return column name to use or null |
| 58 |
*/ |
| 59 |
public String getColumnName() { |
| 60 |
return name; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Return the type of the column. |
| 65 |
* |
| 66 |
* @return the type of the column |
| 67 |
*/ |
| 68 |
public TypeInfo getValueType() { |
| 69 |
return column.getType(); |
| 70 |
} |
| 71 |
|
| 72 |
} |